Re-enable eth_getProof implementation (#2599)
* Re-enable eth_getProof implementation. * Update to use latest Aristo proof changes. * Refactor and cleanup.
This commit is contained in:
parent
c6674311eb
commit
e8a9cfe555
|
@ -858,6 +858,38 @@ proc getEthAccount*(ac: AccountsLedgerRef, address: EthAddress): Account =
|
||||||
raiseAssert "getAccount(): cannot convert account: " & $$rc.error
|
raiseAssert "getAccount(): cannot convert account: " & $$rc.error
|
||||||
rc.value
|
rc.value
|
||||||
|
|
||||||
|
proc getAccountProof*(ac: AccountsLedgerRef, address: EthAddress): seq[seq[byte]] =
|
||||||
|
let accProof = ac.ledger.proof(address.toAccountKey).valueOr:
|
||||||
|
raiseAssert "Failed to get account proof: " & $$error
|
||||||
|
|
||||||
|
accProof[0]
|
||||||
|
|
||||||
|
proc getStorageProof*(ac: AccountsLedgerRef, address: EthAddress, slots: openArray[UInt256]): seq[seq[seq[byte]]] =
|
||||||
|
var storageProof = newSeqOfCap[seq[seq[byte]]](slots.len)
|
||||||
|
|
||||||
|
let
|
||||||
|
addressHash = address.toAccountKey
|
||||||
|
accountExists = ac.ledger.hasPath(addressHash).valueOr:
|
||||||
|
raiseAssert "Call to hasPath failed: " & $$error
|
||||||
|
|
||||||
|
for slot in slots:
|
||||||
|
if not accountExists:
|
||||||
|
storageProof.add(@[])
|
||||||
|
continue
|
||||||
|
|
||||||
|
let
|
||||||
|
slotKey = ac.slots.lruFetch(slot).valueOr:
|
||||||
|
slot.toBytesBE.keccakHash
|
||||||
|
slotProof = ac.ledger.slotProof(addressHash, slotKey).valueOr:
|
||||||
|
if error.aErr == FetchPathNotFound:
|
||||||
|
storageProof.add(@[])
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raiseAssert "Failed to get slot proof: " & $$error
|
||||||
|
storageProof.add(slotProof[0])
|
||||||
|
|
||||||
|
storageProof
|
||||||
|
|
||||||
proc state*(db: ReadOnlyStateDB): KeccakHash {.borrow.}
|
proc state*(db: ReadOnlyStateDB): KeccakHash {.borrow.}
|
||||||
proc getCodeHash*(db: ReadOnlyStateDB, address: EthAddress): Hash256 {.borrow.}
|
proc getCodeHash*(db: ReadOnlyStateDB, address: EthAddress): Hash256 {.borrow.}
|
||||||
proc getStorageRoot*(db: ReadOnlyStateDB, address: EthAddress): Hash256 {.borrow.}
|
proc getStorageRoot*(db: ReadOnlyStateDB, address: EthAddress): Hash256 {.borrow.}
|
||||||
|
@ -875,3 +907,5 @@ func inAccessList*(ac: ReadOnlyStateDB, address: EthAddress): bool {.borrow.}
|
||||||
func inAccessList*(ac: ReadOnlyStateDB, address: EthAddress, slot: UInt256): bool {.borrow.}
|
func inAccessList*(ac: ReadOnlyStateDB, address: EthAddress, slot: UInt256): bool {.borrow.}
|
||||||
func getTransientStorage*(ac: ReadOnlyStateDB,
|
func getTransientStorage*(ac: ReadOnlyStateDB,
|
||||||
address: EthAddress, slot: UInt256): UInt256 {.borrow.}
|
address: EthAddress, slot: UInt256): UInt256 {.borrow.}
|
||||||
|
func getAccountProof*(db: ReadOnlyStateDB, eAddr: EthAddress): seq[seq[byte]] {.borrow.}
|
||||||
|
func getStorageProof*(db: ReadOnlyStateDB, eAddr: EthAddress, slots: openArray[UInt256]): seq[seq[seq[byte]]] {.borrow.}
|
||||||
|
|
|
@ -296,6 +296,12 @@ proc getEthAccount*(ldg: LedgerRef, eAddr: EthAddress): Account =
|
||||||
result = ldg.ac.getEthAccount(eAddr)
|
result = ldg.ac.getEthAccount(eAddr)
|
||||||
ldg.ifTrackApi: debug apiTxt, api, elapsed, result
|
ldg.ifTrackApi: debug apiTxt, api, elapsed, result
|
||||||
|
|
||||||
|
proc getAccountProof*(ldg: LedgerRef, eAddr: EthAddress): seq[seq[byte]] =
|
||||||
|
result = ldg.ac.getAccountProof(eAddr)
|
||||||
|
|
||||||
|
proc getStorageProof*(ldg: LedgerRef, eAddr: EthAddress, slots: openArray[UInt256]): seq[seq[seq[byte]]] =
|
||||||
|
result = ldg.ac.getStorageProof(eAddr, slots)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public virtual read-only methods
|
# Public virtual read-only methods
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -316,6 +322,8 @@ proc getCommittedStorage*(db: ReadOnlyStateDB, eAddr: EthAddress, slot: UInt256)
|
||||||
func inAccessList*(db: ReadOnlyStateDB, eAddr: EthAddress): bool {.borrow.}
|
func inAccessList*(db: ReadOnlyStateDB, eAddr: EthAddress): bool {.borrow.}
|
||||||
func inAccessList*(db: ReadOnlyStateDB, eAddr: EthAddress, slot: UInt256): bool {.borrow.}
|
func inAccessList*(db: ReadOnlyStateDB, eAddr: EthAddress, slot: UInt256): bool {.borrow.}
|
||||||
func getTransientStorage*(db: ReadOnlyStateDB, eAddr: EthAddress, slot: UInt256): UInt256 {.borrow.}
|
func getTransientStorage*(db: ReadOnlyStateDB, eAddr: EthAddress, slot: UInt256): UInt256 {.borrow.}
|
||||||
|
func getAccountProof*(db: ReadOnlyStateDB, eAddr: EthAddress): seq[seq[byte]] {.borrow.}
|
||||||
|
func getStorageProof*(db: ReadOnlyStateDB, eAddr: EthAddress, slots: openArray[UInt256]): seq[seq[seq[byte]]] {.borrow.}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
After change to the *Aristo* single state database, the proof logic in
|
|
||||||
*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
|
|
||||||
to the differently organised legacy database.
|
|
|
@ -31,32 +31,10 @@ import
|
||||||
../evm/evm_errors,
|
../evm/evm_errors,
|
||||||
./filters
|
./filters
|
||||||
|
|
||||||
const
|
|
||||||
AccountAndStorageProofAvailableAndWorking = false
|
|
||||||
## Need to include this module despite non-working proof functions. See
|
|
||||||
## `TODO-P2P.md` for some explanation.
|
|
||||||
|
|
||||||
type
|
type
|
||||||
BlockHeader = eth_types.BlockHeader
|
BlockHeader = eth_types.BlockHeader
|
||||||
Hash256 = eth_types.Hash256
|
Hash256 = eth_types.Hash256
|
||||||
|
|
||||||
when not AccountAndStorageProofAvailableAndWorking:
|
|
||||||
type
|
|
||||||
MptNodeRlpBytes = seq[byte]
|
|
||||||
AccountProof = seq[MptNodeRlpBytes]
|
|
||||||
SlotProof = seq[MptNodeRlpBytes]
|
|
||||||
func getAccountProof(
|
|
||||||
db: LedgerRef;
|
|
||||||
eAddr: EthAddress;
|
|
||||||
): AccountProof =
|
|
||||||
discard
|
|
||||||
func getStorageProof(
|
|
||||||
db: LedgerRef;
|
|
||||||
eAddr: EthAddress;
|
|
||||||
slot: seq[UInt256];
|
|
||||||
): seq[SlotProof] =
|
|
||||||
discard
|
|
||||||
|
|
||||||
proc getProof*(
|
proc getProof*(
|
||||||
accDB: LedgerRef,
|
accDB: LedgerRef,
|
||||||
address: EthAddress,
|
address: EthAddress,
|
||||||
|
|
|
@ -39,6 +39,6 @@ cliBuilder:
|
||||||
#./test_merge, -- fails
|
#./test_merge, -- fails
|
||||||
./test_eip4844,
|
./test_eip4844,
|
||||||
./test_beacon/test_skeleton,
|
./test_beacon/test_skeleton,
|
||||||
#./test_getproof_json, -- fails
|
./test_getproof_json,
|
||||||
./test_aristo,
|
./test_aristo,
|
||||||
./test_coredb
|
./test_coredb
|
||||||
|
|
Loading…
Reference in New Issue