2023-03-10 22:16:42 +00:00
|
|
|
import
|
2023-08-04 11:10:09 +00:00
|
|
|
std/options,
|
2023-03-10 22:16:42 +00:00
|
|
|
chronos,
|
|
|
|
stint,
|
|
|
|
eth/common,
|
2023-08-04 11:10:09 +00:00
|
|
|
../../db/core_db
|
2023-03-10 22:16:42 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
AsyncDataSource* = ref object of RootObj
|
2023-08-04 11:10:09 +00:00
|
|
|
ifNecessaryGetSlots*: proc(db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, slots: seq[UInt256], newStateRootForSanityChecking: Hash256): Future[void] {.gcsafe.}
|
|
|
|
ifNecessaryGetCode*: proc(db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, newStateRootForSanityChecking: Hash256): Future[void] {.gcsafe.}
|
|
|
|
ifNecessaryGetAccount*: proc(db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, newStateRootForSanityChecking: Hash256): Future[void] {.gcsafe.}
|
|
|
|
ifNecessaryGetBlockHeaderByNumber*: proc(coreDb: CoreDbRef, blockNumber: BlockNumber): Future[void] {.gcsafe.}
|
2023-04-24 20:59:38 +00:00
|
|
|
# FIXME-Adam: Later.
|
|
|
|
#fetchNodes*: proc(stateRoot: Hash256, paths: seq[seq[seq[byte]]], nodeHashes: seq[Hash256]): Future[seq[seq[byte]]] {.gcsafe.}
|
2023-03-10 22:16:42 +00:00
|
|
|
fetchBlockHeaderWithHash*: proc(h: Hash256): Future[BlockHeader] {.gcsafe.}
|
|
|
|
fetchBlockHeaderWithNumber*: proc(n: BlockNumber): Future[BlockHeader] {.gcsafe.}
|
|
|
|
fetchBlockHeaderAndBodyWithHash*: proc(h: Hash256): Future[(BlockHeader, BlockBody)] {.gcsafe.}
|
|
|
|
fetchBlockHeaderAndBodyWithNumber*: proc(n: BlockNumber): Future[(BlockHeader, BlockBody)] {.gcsafe.}
|
|
|
|
|
|
|
|
# FIXME-Adam: maybe rename this?
|
|
|
|
AsyncOperationFactory* = ref object of RootObj
|
|
|
|
maybeDataSource*: Option[AsyncDataSource]
|
|
|
|
|
|
|
|
|
|
|
|
# FIXME-Adam: Can I make a singleton?
|
|
|
|
proc asyncFactoryWithNoDataSource*(): AsyncOperationFactory =
|
|
|
|
AsyncOperationFactory(maybeDataSource: none[AsyncDataSource]())
|
|
|
|
|
|
|
|
|
|
|
|
# FIXME-Adam: Ugly but straightforward; can this be cleaned up using some combination of:
|
|
|
|
# - an ifSome/map operation on Options
|
|
|
|
# - some kind of "what are we fetching" tuple, so that this is just one thing
|
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
proc ifNecessaryGetSlots*(asyncFactory: AsyncOperationFactory, db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, slots: seq[UInt256], newStateRootForSanityChecking: Hash256): Future[void] {.async.} =
|
2023-03-10 22:16:42 +00:00
|
|
|
if asyncFactory.maybeDataSource.isSome:
|
|
|
|
await asyncFactory.maybeDataSource.get.ifNecessaryGetSlots(db, blockNumber, stateRoot, address, slots, newStateRootForSanityChecking)
|
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
proc ifNecessaryGetCode*(asyncFactory: AsyncOperationFactory, db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, newStateRootForSanityChecking: Hash256): Future[void] {.async.} =
|
2023-03-10 22:16:42 +00:00
|
|
|
if asyncFactory.maybeDataSource.isSome:
|
|
|
|
await asyncFactory.maybeDataSource.get.ifNecessaryGetCode(db, blockNumber, stateRoot, address, newStateRootForSanityChecking)
|
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
proc ifNecessaryGetAccount*(asyncFactory: AsyncOperationFactory, db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, newStateRootForSanityChecking: Hash256): Future[void] {.async.} =
|
2023-03-10 22:16:42 +00:00
|
|
|
if asyncFactory.maybeDataSource.isSome:
|
|
|
|
await asyncFactory.maybeDataSource.get.ifNecessaryGetAccount(db, blockNumber, stateRoot, address, newStateRootForSanityChecking)
|
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
proc ifNecessaryGetBlockHeaderByNumber*(asyncFactory: AsyncOperationFactory, coreDb: CoreDbRef, blockNumber: BlockNumber): Future[void] {.async.} =
|
2023-03-10 22:16:42 +00:00
|
|
|
if asyncFactory.maybeDataSource.isSome:
|
2023-08-04 11:10:09 +00:00
|
|
|
await asyncFactory.maybeDataSource.get.ifNecessaryGetBlockHeaderByNumber(coreDb, blockNumber)
|