Skip to content

Commit

Permalink
Cleanup unused exp_getProofsByBlockNumber endpoint (#2577)
Browse files Browse the repository at this point in the history
* Cleanup unused exp_getProofsByBlockNumber endpoint.
  • Loading branch information
bhartnett authored Aug 23, 2024
1 parent 507a9e7 commit 8bf581e
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 509 deletions.
2 changes: 1 addition & 1 deletion nimbus/rpc/TODO-P2P.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
After change to the *Aristo* single state database, the proof logic in
*p2p.nim* and *experimental.nim* is not supported anymore.
*p2p.nim* is not supported anymore.

The proof logic in question refers to functions *state_db.getAccountProof()*
and *state_db.getStorageProof()* which used now unsupported internal access
Expand Down
96 changes: 3 additions & 93 deletions nimbus/rpc/experimental.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,99 +9,9 @@

{.push raises: [].}

import
std/[typetraits],
json_rpc/rpcserver,
web3/conversions,
eth/p2p,
stint,
../core/executor/process_block,
../[transaction, constants],
../beacon/web3_eth_conv,
../stateless/multi_keys,
../evm/[state, types],
../common/common,
../utils/utils,
../db/ledger,
./rpc_types,
./rpc_utils,
./filters,
./p2p

type
BlockHeader = eth_types.BlockHeader

proc getMultiKeys*(
com: CommonRef,
blockHeader: BlockHeader,
statePostExecution: bool): MultiKeysRef
{.raises: [BlockNotFound, ValueError].} =

let
chainDB = com.db
blk = chainDB.getEthBlock(blockHeader.number)
# Initializing the VM will throw a Defect if the state doesn't exist.
# Once we enable pruning we will need to check if the block state has been pruned
# before trying to initialize the VM as we do here.
vmState = BaseVMState.new(blk.header, com).valueOr:
raise newException(ValueError, "Cannot create vm state")

vmState.collectWitnessData = true # Enable saving witness data
vmState.com.hardForkTransition(blockHeader)

let dbTx = vmState.com.db.ctx.newTransaction()
defer: dbTx.dispose()

# Execute the block of transactions and collect the keys of the touched account state
processBlock(vmState, blk).expect("success")

let mkeys = vmState.stateDB.makeMultiKeys()

dbTx.rollback()

mkeys

proc getBlockProofs*(
accDB: LedgerRef,
mkeys: MultiKeysRef): seq[ProofResponse] =

var blockProofs = newSeq[ProofResponse]()

for keyData in mkeys.keys:
let address = keyData.address
var slots = newSeq[UInt256]()

if not keyData.storageKeys.isNil and accDB.accountExists(address):
for slotData in keyData.storageKeys.keys:
slots.add(fromBytesBE(UInt256, slotData.storageSlot))

blockProofs.add(getProof(accDB, address, slots))

return blockProofs
import json_rpc/rpcserver, ../constants, ../common/common

proc setupExpRpc*(com: CommonRef, server: RpcServer) =
# Currently no experimental endpoints

let chainDB = com.db

proc getStateDB(header: BlockHeader): LedgerRef =
## Retrieves the account db from canonical head
# we don't use accounst_cache here because it's only read operations
LedgerRef.init(chainDB, header.stateRoot)

server.rpc("exp_getProofsByBlockNumber") do(quantityTag: BlockTag, statePostExecution: bool) -> seq[ProofResponse]:
## Returns the block proofs for a block by block number or tag.
##
## quantityTag: integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.
## statePostExecution: bool which indicates whether to return the proofs based on the state before or after executing the block.
## Returns seq[ProofResponse]

let
blockHeader = chainDB.headerFromTag(quantityTag)
mkeys = getMultiKeys(com, blockHeader, statePostExecution)

let accDB = if statePostExecution:
getStateDB(blockHeader)
else:
getStateDB(chainDB.getBlockHeader(blockHeader.parentHash))

return getBlockProofs(accDB, mkeys)
discard
1 change: 0 additions & 1 deletion tests/all_tests.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ cliBuilder:
./test_eip4844,
./test_beacon/test_skeleton,
#./test_getproof_json, -- fails
#./test_rpc_experimental_json, -- fails
./test_aristo,
./test_coredb
20 changes: 0 additions & 20 deletions tests/rpc/experimental_rpc_client.nim

This file was deleted.

244 changes: 0 additions & 244 deletions tests/test_rpc_experimental_json.nim

This file was deleted.

Loading

0 comments on commit 8bf581e

Please sign in to comment.