From 97e89b3afe2f9752538ffc6de29501114f07ec12 Mon Sep 17 00:00:00 2001 From: andri lim Date: Wed, 13 Nov 2019 13:18:01 +0700 Subject: [PATCH] implement 'getCommittedStorage' --- nimbus/db/state_db.nim | 13 +++++++++++-- nimbus/p2p/executor.nim | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/nimbus/db/state_db.nim b/nimbus/db/state_db.nim index c8bd1ca94..3422db2c3 100644 --- a/nimbus/db/state_db.nim +++ b/nimbus/db/state_db.nim @@ -16,6 +16,7 @@ logScope: type AccountStateDB* = ref object trie: SecureHexaryTrie + originalRoot: KeccakHash # will be updated for every transaction ReadOnlyStateDB* = distinct AccountStateDB @@ -29,6 +30,7 @@ proc newAccountStateDB*(backingStore: TrieDatabaseRef, root: KeccakHash, pruneTrie: bool): AccountStateDB = result.new() result.trie = initSecureHexaryTrie(backingStore, root, pruneTrie) + result.originalRoot = root template createRangeFromAddress(address: EthAddress): ByteRange = ## XXX: The name of this proc is intentionally long, because it @@ -208,8 +210,15 @@ proc isDeadAccount*(db: AccountStateDB, address: EthAddress): bool = result = true proc getCommittedStorage*(db: AccountStateDB, address: EthAddress, slot: UInt256): UInt256 = - discard - # TODO: stub + let tmpHash = db.rootHash + 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 getAccount*(db: ReadOnlyStateDB, address: EthAddress): Account {.borrow.} diff --git a/nimbus/p2p/executor.nim b/nimbus/p2p/executor.nim index 2bd729e70..096f82940 100644 --- a/nimbus/p2p/executor.nim +++ b/nimbus/p2p/executor.nim @@ -67,6 +67,7 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta debug "state clearing", account db.deleteAccount(account) + vmState.accountDb.updateOriginalRoot() result = gasUsed type