2023-03-10 22:16:42 +00:00
import
chronos ,
stint ,
eth / common / eth_types ,
.. / .. / common ,
.. / .. / db / distinct_tries ,
.. / .. / db / accounts_cache ,
2023-04-24 20:59:38 +00:00
#../../db/incomplete_db,
2023-03-10 22:16:42 +00:00
.. / types ,
. / data_sources
proc ifNecessaryGetAccount * ( vmState : BaseVMState , address : EthAddress ) : Future [ void ] {. async . } =
await vmState . asyncFactory . ifNecessaryGetAccount ( vmState . com . db . db , vmState . parent . blockNumber , vmState . parent . stateRoot , address , vmState . stateDB . rawTrie . rootHash )
proc ifNecessaryGetCode * ( vmState : BaseVMState , address : EthAddress ) : Future [ void ] {. async . } =
await vmState . asyncFactory . ifNecessaryGetCode ( vmState . com . db . db , vmState . parent . blockNumber , vmState . parent . stateRoot , address , vmState . stateDB . rawTrie . rootHash )
proc ifNecessaryGetSlots * ( vmState : BaseVMState , address : EthAddress , slots : seq [ UInt256 ] ) : Future [ void ] {. async . } =
await vmState . asyncFactory . ifNecessaryGetSlots ( vmState . com . db . db , vmState . parent . blockNumber , vmState . parent . stateRoot , address , slots , vmState . stateDB . rawTrie . rootHash )
proc ifNecessaryGetSlot * ( vmState : BaseVMState , address : EthAddress , slot : UInt256 ) : Future [ void ] {. async . } =
await ifNecessaryGetSlots ( vmState , address , @ [ slot ] )
proc ifNecessaryGetBlockHeaderByNumber * ( vmState : BaseVMState , blockNumber : BlockNumber ) : Future [ void ] {. async . } =
await vmState . asyncFactory . ifNecessaryGetBlockHeaderByNumber ( vmState . com . db , blockNumber )
2023-04-24 20:59:38 +00:00
#[
FIXME - Adam : This is for later .
proc fetchAndPopulateNodes * ( vmState : BaseVMState , paths : seq [ seq [ seq [ byte ] ] ] , nodeHashes : seq [ Hash256 ] ) : Future [ void ] {. async . } =
2023-03-10 22:16:42 +00:00
if vmState . asyncFactory . maybeDataSource . isSome :
# let stateRoot = vmState.stateDB.rawTrie.rootHash # FIXME-Adam: this might not be right, huh? the peer might expect the parent block's final stateRoot, not this weirdo intermediate one
let stateRoot = vmState . parent . stateRoot
let nodes = await vmState . asyncFactory . maybeDataSource . get . fetchNodes ( stateRoot , paths , nodeHashes )
populateDbWithNodes ( vmState . stateDB . rawDb , nodes )
2023-04-24 20:59:38 +00:00
] #
2023-03-10 22:16:42 +00:00
# Sometimes it's convenient to be able to do multiple at once.
proc ifNecessaryGetAccounts * ( vmState : BaseVMState , addresses : seq [ EthAddress ] ) : Future [ void ] {. async . } =
for address in addresses :
await ifNecessaryGetAccount ( vmState , address )
proc ifNecessaryGetCodeForAccounts * ( vmState : BaseVMState , addresses : seq [ EthAddress ] ) : Future [ void ] {. async . } =
for address in addresses :
await ifNecessaryGetCode ( vmState , address )