diff --git a/nimbus/db/geth_db.nim b/nimbus/db/geth_db.nim deleted file mode 100644 index 49f312c5a..000000000 --- a/nimbus/db/geth_db.nim +++ /dev/null @@ -1,45 +0,0 @@ -# Nimbus -# Copyright (c) 2020-2023 Status Research & Development GmbH -# Licensed under either of -# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or -# http://www.apache.org/licenses/LICENSE-2.0) -# * MIT license ([LICENSE-MIT](LICENSE-MIT) or -# http://opensource.org/licenses/MIT) -# at your option. This file may not be copied, modified, or distributed except -# according to those terms. - -import eth/[rlp, common], core_db - -const - headerPrefix = 'h'.byte # headerPrefix + num (uint64 big endian) + hash -> header - headerHashSuffix = 'n'.byte # headerPrefix + num (uint64 big endian) + headerHashSuffix -> hash - blockBodyPrefix = 'b'.byte # blockBodyPrefix + num (uint64 big endian) + hash -> block body - -proc headerHash*(db: CoreDbRef, number: uint64): Hash256 = - var key: array[10, byte] - key[0] = headerPrefix - key[1..8] = toBytesBE(number)[0..^1] - key[^1] = headerHashSuffix - let res = db.kvt.get(key) - doAssert(res.len == 32) - result.data[0..31] = res[0..31] - -proc blockHeader*(db: CoreDbRef, hash: Hash256, number: uint64): BlockHeader = - var key: array[41, byte] - key[0] = headerPrefix - key[1..8] = toBytesBE(number)[0..^1] - key[9..40] = hash.data[0..^1] - let res = db.kvt.get(key) - result = rlp.decode(res, BlockHeader) - -proc blockHeader*(db: CoreDbRef, number: uint64): BlockHeader = - let hash = db.headerHash(number) - db.blockHeader(hash, number) - -proc blockBody*(db: CoreDbRef, hash: Hash256, number: uint64): BlockBody = - var key: array[41, byte] - key[0] = blockBodyPrefix - key[1..8] = toBytesBE(number)[0..^1] - key[9..40] = hash.data[0..^1] - let res = db.kvt.get(key) - result = rlp.decode(res, BlockBody) diff --git a/nimbus/db/incomplete_db.nim b/nimbus/db/incomplete_db.nim index d92a13e14..252dded83 100644 --- a/nimbus/db/incomplete_db.nim +++ b/nimbus/db/incomplete_db.nim @@ -55,16 +55,10 @@ proc ifNodesExistGetAccount*(trie: AccountsTrie, address: EthAddress): Option[Ac ifNodesExistGetAccountBytes(trie, address).map(accountFromBytes) proc maybeGetCode*(db: CoreDbRef, codeHash: Hash256): Option[seq[byte]] = - when defined(geth): - if db.isLegacy: - db.newKvt.backend.toLegacy.maybeGet(codeHash.data) - else: - db.kvt.get(codeHash.data) + if db.isLegacy: + db.newKvt.backend.toLegacy.maybeGet(contractHashKey(codeHash).toOpenArray) else: - if db.isLegacy: - db.newKvt.backend.toLegacy.maybeGet(contractHashKey(codeHash).toOpenArray) - else: - some(db.kvt.get(contractHashKey(codeHash).toOpenArray)) + some(db.kvt.get(contractHashKey(codeHash).toOpenArray)) proc maybeGetCode*(trie: AccountsTrie, address: EthAddress): Option[seq[byte]] = let maybeAcc = trie.ifNodesExistGetAccount(address) diff --git a/nimbus/db/ledger/accounts_cache.nim b/nimbus/db/ledger/accounts_cache.nim index 8a4efab04..410b86b2f 100644 --- a/nimbus/db/ledger/accounts_cache.nim +++ b/nimbus/db/ledger/accounts_cache.nim @@ -303,10 +303,7 @@ proc persistMode(acc: RefAccount): PersistMode = proc persistCode(acc: RefAccount, db: CoreDbRef) = if acc.code.len != 0: - when defined(geth): - db.kvt.put(acc.account.codeHash.data, acc.code) - else: - db.kvt.put(contractHashKey(acc.account.codeHash).toOpenArray, acc.code) + db.kvt.put(contractHashKey(acc.account.codeHash).toOpenArray, acc.code) proc persistStorage(acc: RefAccount, db: CoreDbRef, clearCache: bool) = if acc.overlayStorage.len == 0: @@ -385,10 +382,7 @@ proc getCode*(ac: AccountsCache, address: EthAddress): seq[byte] = if CodeLoaded in acc.flags or CodeChanged in acc.flags: result = acc.code else: - when defined(geth): - let data = ac.kvt.get(acc.account.codeHash.data) - else: - let data = ac.kvt.get(contractHashKey(acc.account.codeHash).toOpenArray) + let data = ac.kvt.get(contractHashKey(acc.account.codeHash).toOpenArray) acc.code = data acc.flags.incl CodeLoaded diff --git a/nimbus/db/ledger/accounts_ledger.nim b/nimbus/db/ledger/accounts_ledger.nim index 400730bca..9276e5acb 100644 --- a/nimbus/db/ledger/accounts_ledger.nim +++ b/nimbus/db/ledger/accounts_ledger.nim @@ -322,12 +322,8 @@ proc persistMode(acc: AccountRef): PersistMode = proc persistCode(acc: AccountRef, ac: AccountsLedgerRef) = if acc.code.len != 0: - when defined(geth): - let rc = ac.kvt.put( - acc.statement.codeHash.data, acc.code) - else: - let rc = ac.kvt.put( - contractHashKey(acc.statement.codeHash).toOpenArray, acc.code) + let rc = ac.kvt.put( + contractHashKey(acc.statement.codeHash).toOpenArray, acc.code) if rc.isErr: warn logTxt "persistCode()", codeHash=acc.statement.codeHash, error=($$rc.error) @@ -410,11 +406,7 @@ proc getCode*(ac: AccountsLedgerRef, address: EthAddress): seq[byte] = if CodeLoaded in acc.flags or CodeChanged in acc.flags: result = acc.code else: - let rc = block: - when defined(geth): - ac.kvt.get(acc.statement.codeHash.data) - else: - ac.kvt.get(contractHashKey(acc.statement.codeHash).toOpenArray) + let rc = ac.kvt.get(contractHashKey(acc.statement.codeHash).toOpenArray) if rc.isErr: warn logTxt "getCode()", codeHash=acc.statement.codeHash, error=($$rc.error) else: diff --git a/nimbus/evm/state.nim b/nimbus/evm/state.nim index 49f8f33b0..a673c1786 100644 --- a/nimbus/evm/state.nim +++ b/nimbus/evm/state.nim @@ -235,35 +235,29 @@ proc statelessInit*( asyncFactory = asyncFactory) return true -method coinbase*(vmState: BaseVMState): EthAddress {.base, gcsafe.} = +proc coinbase*(vmState: BaseVMState): EthAddress = vmState.blockCtx.coinbase -method blockNumber*(vmState: BaseVMState): BlockNumber {.base, gcsafe.} = +proc blockNumber*(vmState: BaseVMState): BlockNumber = # it should return current block number # and not head.blockNumber vmState.parent.blockNumber + 1 -method difficultyOrPrevRandao*(vmState: BaseVMState): UInt256 {.base, gcsafe.} = +proc difficultyOrPrevRandao*(vmState: BaseVMState): UInt256 = if vmState.com.consensus == ConsensusType.POS: # EIP-4399/EIP-3675 UInt256.fromBytesBE(vmState.blockCtx.prevRandao.data) else: vmState.blockCtx.difficulty -method baseFee*(vmState: BaseVMState): UInt256 {.base, gcsafe.} = +proc baseFee*(vmState: BaseVMState): UInt256 = vmState.blockCtx.fee.get(0.u256) -when defined(geth): - import db/geth_db - method getAncestorHash*( vmState: BaseVMState, blockNumber: BlockNumber): Hash256 {.base, gcsafe, raises: [CatchableError].} = let db = vmState.com.db - when defined(geth): - result = db.headerHash(blockNumber.truncate(uint64)) - else: - result = db.getBlockHash(blockNumber) + db.getBlockHash(blockNumber) proc readOnlyStateDB*(vmState: BaseVMState): ReadOnlyStateDB {.inline.} = ReadOnlyStateDB(vmState.stateDB) diff --git a/nimbus/tracer.nim b/nimbus/tracer.nim index 31b963f4c..b9dd86876 100644 --- a/nimbus/tracer.nim +++ b/nimbus/tracer.nim @@ -20,15 +20,8 @@ import results, ./beacon/web3_eth_conv -when defined(geth): - import db/geth_db - - proc getParentHeader(db: CoreDbRef, header: BlockHeader): BlockHeader = - db.blockHeader(header.blockNumber.truncate(uint64) - 1) - -else: - proc getParentHeader(self: CoreDbRef, header: BlockHeader): BlockHeader = - self.getBlockHeader(header.parentHash) +proc getParentHeader(self: CoreDbRef, header: BlockHeader): BlockHeader = + self.getBlockHeader(header.parentHash) type SaveCtxEnv = object