implement 'getCommittedStorage'

This commit is contained in:
andri lim 2019-11-13 13:18:01 +07:00 committed by zah
parent a3efd54d90
commit 97e89b3afe
2 changed files with 12 additions and 2 deletions

View File

@ -16,6 +16,7 @@ logScope:
type type
AccountStateDB* = ref object AccountStateDB* = ref object
trie: SecureHexaryTrie trie: SecureHexaryTrie
originalRoot: KeccakHash # will be updated for every transaction
ReadOnlyStateDB* = distinct AccountStateDB ReadOnlyStateDB* = distinct AccountStateDB
@ -29,6 +30,7 @@ proc newAccountStateDB*(backingStore: TrieDatabaseRef,
root: KeccakHash, pruneTrie: bool): AccountStateDB = root: KeccakHash, pruneTrie: bool): AccountStateDB =
result.new() result.new()
result.trie = initSecureHexaryTrie(backingStore, root, pruneTrie) result.trie = initSecureHexaryTrie(backingStore, root, pruneTrie)
result.originalRoot = root
template createRangeFromAddress(address: EthAddress): ByteRange = template createRangeFromAddress(address: EthAddress): ByteRange =
## XXX: The name of this proc is intentionally long, because it ## XXX: The name of this proc is intentionally long, because it
@ -208,8 +210,15 @@ proc isDeadAccount*(db: AccountStateDB, address: EthAddress): bool =
result = true result = true
proc getCommittedStorage*(db: AccountStateDB, address: EthAddress, slot: UInt256): UInt256 = proc getCommittedStorage*(db: AccountStateDB, address: EthAddress, slot: UInt256): UInt256 =
discard let tmpHash = db.rootHash
# TODO: stub db.rootHash = db.originalRoot
var exists: bool
(result, exists) = db.getStorage(address, slot)
db.rootHash = tmpHash
proc updateOriginalRoot*(db: AccountStateDB) =
## this proc will be called for every transaction
db.originalRoot = db.rootHash
proc rootHash*(db: ReadOnlyStateDB): KeccakHash {.borrow.} proc rootHash*(db: ReadOnlyStateDB): KeccakHash {.borrow.}
proc getAccount*(db: ReadOnlyStateDB, address: EthAddress): Account {.borrow.} proc getAccount*(db: ReadOnlyStateDB, address: EthAddress): Account {.borrow.}

View File

@ -67,6 +67,7 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta
debug "state clearing", account debug "state clearing", account
db.deleteAccount(account) db.deleteAccount(account)
vmState.accountDb.updateOriginalRoot()
result = gasUsed result = gasUsed
type type