allow zero state root

This commit is contained in:
Roy Crihfield 2024-04-16 18:26:54 +08:00
parent 1bc449d036
commit f4fecc2f07
2 changed files with 9 additions and 9 deletions

View File

@ -108,11 +108,11 @@ func validateTrie() {
WithField("storage root", storageRoot).
Debug("Validating storage trie")
if err = v.ValidateStorageTrie(stateRoot, addr, storageRoot); err != nil {
logWithCommand.Fatalf("Validation failed", err)
logWithCommand.Fatal("Validation failed", err)
}
logWithCommand.Infof("Storage trie for contract %s and root %s is complete", addr, storageRoot)
default:
logWithCommand.Fatalf("Invalid traversal level: '%s'", traversal)
logWithCommand.Fatal("Invalid traversal level:", traversal)
}
stats := v.GetCacheStats()

View File

@ -302,22 +302,22 @@ var _ = Describe("PG-IPFS Validator", func() {
err = ResetTestDB(db)
Expect(err).ToNot(HaveOccurred())
})
It("Returns an error the storage root node is missing", func() {
loadTrie(trieStateNodes, missingRootStorageNodes)
err = v.ValidateStorageTrie(stateRoot, contractAddr, storageRoot)
It("Returns an error if the storage root node is missing", func() {
loadTrie(nil, missingRootStorageNodes)
err = v.ValidateStorageTrie(common.Hash{}, contractAddr, storageRoot)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("missing trie node"))
})
It("Returns an error if the entire storage trie cannot be validated", func() {
loadTrie(trieStateNodes, missingNodeStorageNodes)
err = v.ValidateStorageTrie(stateRoot, contractAddr, storageRoot)
loadTrie(nil, missingNodeStorageNodes)
err = v.ValidateStorageTrie(common.Hash{}, contractAddr, storageRoot)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("missing trie node"))
Expect(err.Error()).To(ContainSubstring("path %x", missingStorageNodePath))
})
It("Returns no error if the entire storage trie can be validated", func() {
loadTrie(trieStateNodes, trieStorageNodes)
err = v.ValidateStorageTrie(stateRoot, contractAddr, storageRoot)
loadTrie(nil, trieStorageNodes)
err = v.ValidateStorageTrie(common.Hash{}, contractAddr, storageRoot)
Expect(err).ToNot(HaveOccurred())
})
})