Skip to content

Commit

Permalink
Merge branch 'master' into proxy-types
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck authored Oct 20, 2024
2 parents 4bef830 + 503dcd4 commit 0fec94d
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 214 deletions.
24 changes: 12 additions & 12 deletions nimbus/beacon/beacon_engine.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ template wrapException(body: untyped): auto =

# setInvalidAncestor is a callback for the downloader to notify us if a bad block
# is encountered during the async sync.
proc setInvalidAncestor(ben: BeaconEngineRef,
func setInvalidAncestor(ben: BeaconEngineRef,
invalid, origin: Header) =
ben.invalidTipsets[origin.blockHash] = invalid
inc ben.invalidBlocksHits.mgetOrPut(invalid.blockHash, 0)
Expand Down Expand Up @@ -112,23 +112,23 @@ func new*(_: type BeaconEngineRef,
# Public functions, setters
# ------------------------------------------------------------------------------

proc put*(ben: BeaconEngineRef,
func put*(ben: BeaconEngineRef,
hash: Hash32, header: Header) =
ben.queue.put(hash, header)

proc put*(ben: BeaconEngineRef, id: Bytes8,
func put*(ben: BeaconEngineRef, id: Bytes8,
blockValue: UInt256, payload: ExecutionPayload,
blobsBundle: Opt[BlobsBundleV1]) =
ben.queue.put(id, blockValue, payload, blobsBundle)

proc put*(ben: BeaconEngineRef, id: Bytes8,
func put*(ben: BeaconEngineRef, id: Bytes8,
blockValue: UInt256, payload: SomeExecutionPayload,
blobsBundle: Opt[BlobsBundleV1]) =
doAssert blobsBundle.isNone == (payload is
ExecutionPayloadV1 | ExecutionPayloadV2)
ben.queue.put(id, blockValue, payload, blobsBundle)

proc put*(ben: BeaconEngineRef, id: Bytes8,
func put*(ben: BeaconEngineRef, id: Bytes8,
blockValue: UInt256,
payload: ExecutionPayloadV1 | ExecutionPayloadV2) =
ben.queue.put(
Expand All @@ -143,17 +143,17 @@ func com*(ben: BeaconEngineRef): CommonRef =
func chain*(ben: BeaconEngineRef): ForkedChainRef =
ben.chain

proc get*(ben: BeaconEngineRef, hash: Hash32,
func get*(ben: BeaconEngineRef, hash: Hash32,
header: var Header): bool =
ben.queue.get(hash, header)

proc get*(ben: BeaconEngineRef, id: Bytes8,
func get*(ben: BeaconEngineRef, id: Bytes8,
blockValue: var UInt256,
payload: var ExecutionPayload,
blobsBundle: var Opt[BlobsBundleV1]): bool =
ben.queue.get(id, blockValue, payload, blobsBundle)

proc get*(ben: BeaconEngineRef, id: Bytes8,
func get*(ben: BeaconEngineRef, id: Bytes8,
blockValue: var UInt256,
payload: var ExecutionPayload,
blobsBundle: var Opt[BlobsBundleV1],
Expand All @@ -165,18 +165,18 @@ func get*(ben: BeaconEngineRef, id: PayloadID,
payload: var ExecutionPayloadV1): bool =
ben.queue.get(id, blockValue, payload)

proc get*(ben: BeaconEngineRef, id: Bytes8,
func get*(ben: BeaconEngineRef, id: Bytes8,
blockValue: var UInt256,
payload: var ExecutionPayloadV2): bool =
ben.queue.get(id, blockValue, payload)

proc get*(ben: BeaconEngineRef, id: Bytes8,
func get*(ben: BeaconEngineRef, id: Bytes8,
blockValue: var UInt256,
payload: var ExecutionPayloadV3,
blobsBundle: var BlobsBundleV1): bool =
ben.queue.get(id, blockValue, payload, blobsBundle)

proc get*(ben: BeaconEngineRef, id: Bytes8,
func get*(ben: BeaconEngineRef, id: Bytes8,
blockValue: var UInt256,
payload: var ExecutionPayloadV1OrV2): bool =
ben.queue.get(id, blockValue, payload)
Expand Down Expand Up @@ -236,7 +236,7 @@ proc generatePayload*(ben: BeaconEngineRef,
blobsBundle: blobsBundle,
blockValue: bundle.blockValue)

proc setInvalidAncestor*(ben: BeaconEngineRef, header: Header, blockHash: Hash32) =
func setInvalidAncestor*(ben: BeaconEngineRef, header: Header, blockHash: Hash32) =
ben.invalidBlocksHits[blockHash] = 1
ben.invalidTipsets[blockHash] = header

Expand Down
8 changes: 7 additions & 1 deletion nimbus/core/chain/forked_chain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,13 @@ proc blockByHash*(c: ForkedChainRef, blockHash: Hash32): Opt[Block] =
c.blocks.withValue(blockHash, val) do:
return Opt.some(val.blk)
do:
return Opt.none(Block)
var
header: Header
body: BlockBody
if c.db.getBlockHeader(blockHash, header) and c.db.getBlockBody(blockHash, body):
return ok(Block.init(move(header), move(body)))
else:
return Opt.none(Block)

proc blockByNumber*(c: ForkedChainRef, number: BlockNumber): Result[Block, string] =
if number > c.cursorHeader.number:
Expand Down
1 change: 1 addition & 0 deletions nimbus/core/tx_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ proc assembleBlock*(
blobsBundle.proofs.add p
for blob in tx.networkPayload.blobs:
blobsBundle.blobs.add blob
blk.header.transactionsRoot = calcTxRoot(blk.txs)

let com = xp.vmState.com
if com.isShanghaiOrLater(blk.header.timestamp):
Expand Down
13 changes: 1 addition & 12 deletions nimbus/core/tx_pool/tx_packer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import
stew/sorted_set,
../../db/[ledger, core_db],
../../db/ledger,
../../common/common,
../../utils/utils,
../../constants,
Expand All @@ -34,14 +34,12 @@ type
# Packer state
vmState: BaseVMState
txDB: TxTabsRef
tr: CoreDbMptRef
cleanState: bool
numBlobPerBlock: int

# Packer results
blockValue: UInt256
stateRoot: Hash32
txRoot: Hash32
receiptsRoot: Hash32
logsBloom: Bloom

Expand Down Expand Up @@ -161,10 +159,6 @@ proc runTxCommit(pst: var TxPacker; item: TxItemRef; gasBurned: GasInt)
vmState.cumulativeGasUsed += gasBurned
vmState.receipts[inx] = vmState.makeReceipt(item.tx.txType)

# Update txRoot
pst.tr.merge(rlp.encode(inx.uint64), rlp.encode(item.tx)).isOkOr:
raiseAssert "runTxCommit(): merge failed, " & $$error

# Add the item to the `packed` bucket. This implicitely increases the
# receipts index `inx` at the next visit of this function.
discard pst.txDB.reassign(item,txItemPacked)
Expand All @@ -182,10 +176,8 @@ proc vmExecInit(xp: TxPoolRef): Result[TxPacker, string]
let packer = TxPacker(
vmState: xp.vmState,
txDB: xp.txDB,
tr: AristoDbMemory.newCoreDbRef().ctx.getGeneric(clearData=true),
numBlobPerBlock: 0,
blockValue: 0.u256,
txRoot: EMPTY_ROOT_HASH,
stateRoot: xp.vmState.parent.stateRoot,
)

Expand Down Expand Up @@ -267,8 +259,6 @@ proc vmExecCommit(pst: var TxPacker) =

pst.receiptsRoot = vmState.receipts.calcReceiptsRoot
pst.logsBloom = vmState.receipts.createBloom
pst.txRoot = pst.tr.state(updateOk=true).valueOr:
raiseAssert "vmExecCommit(): state() failed " & $$error
pst.stateRoot = vmState.stateDB.rootHash


Expand Down Expand Up @@ -314,7 +304,6 @@ proc assembleHeader*(pst: TxPacker): Header =
ommersHash: EMPTY_UNCLE_HASH,
coinbase: pos.feeRecipient,
stateRoot: pst.stateRoot,
transactionsRoot: pst.txRoot,
receiptsRoot: pst.receiptsRoot,
logsBloom: pst.logsBloom,
difficulty: UInt256.zero(),
Expand Down
8 changes: 0 additions & 8 deletions nimbus/db/aristo/aristo_walk/memory_only.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ iterator walkPairs*[T: MemBackendRef|VoidBackendRef](
for (rvid,vtx) in walkPairsImpl[T](db):
yield (rvid,vtx)

iterator replicate*[T: MemBackendRef|VoidBackendRef](
_: type T;
db: AristoDbRef;
): tuple[rvid: RootedVertexID, key: HashKey, vtx: VertexRef, node: NodeRef] =
## Variant of `walkPairsImpl()` for legacy applications.
for (rvid,key,vtx,node) in replicateImpl[T](db):
yield (rvid,key,vtx,node)

# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------
8 changes: 0 additions & 8 deletions nimbus/db/aristo/aristo_walk/persistent.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ iterator walkPairs*[T: RdbBackendRef](
for (rvid,vtx) in walkPairsImpl[T](db):
yield (rvid,vtx)

iterator replicate*[T: RdbBackendRef](
_: type T;
db: AristoDbRef;
): tuple[rvid: RootedVertexID, key: HashKey, vtx: VertexRef, node: NodeRef] =
## Variant of `walkPairsImpl()` for legacy applications.
for (rvid,key,vtx,node) in replicateImpl[T](db):
yield (rvid,key,vtx,node)

# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------
13 changes: 0 additions & 13 deletions nimbus/db/aristo/aristo_walk/walk_private.nim
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,6 @@ iterator walkPairsImpl*[T](
if rvid.vid notin seen:
yield (rvid,vtx)

iterator replicateImpl*[T](
db: AristoDbRef; # Database with top layer & backend filter
): tuple[rvid: RootedVertexID, key: HashKey, vtx: VertexRef, node: NodeRef] =
## Variant of `walkPairsImpl()` for legacy applications.
for (rvid,vtx) in walkPairsImpl[T](db):
let node = block:
let rc = vtx.toNode(rvid.root, db)
if rc.isOk:
rc.value
else:
NodeRef(nil)
yield (rvid, db.getKey rvid, vtx, node)

# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------
74 changes: 0 additions & 74 deletions nimbus/db/core_db/backend/aristo_replicate.nim

This file was deleted.

1 change: 0 additions & 1 deletion nimbus/db/core_db/base/api_tracking.nim
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ type
MptMergeFn = "mpt/merge"
MptProofFn = "mpt/proof"
MptPairsIt = "mpt/pairs"
MptReplicateIt = "mpt/replicate"
MptStateFn = "mpt/state"

TxCommitFn = "commit"
Expand Down
59 changes: 39 additions & 20 deletions nimbus/db/core_db/base_iterators.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import
eth/common,
../../errors,
../aristo as use_ari,
../aristo/[aristo_walk, aristo_serialise],
../kvt as use_kvt,
../kvt/[kvt_init/memory_only, kvt_walk],
./base/[api_tracking, base_config, base_desc]
Expand All @@ -24,12 +23,9 @@ when CoreDbEnableApiJumpTable:
discard
else:
import
../aristo/[aristo_desc, aristo_path, aristo_tx],
../aristo/[aristo_desc, aristo_path],
../kvt/[kvt_desc, kvt_tx]

include
./backend/aristo_replicate

when CoreDbEnableApiTracking:
import
chronicles
Expand All @@ -41,6 +37,44 @@ when CoreDbEnableApiTracking:
# Annotation helper(s)
{.pragma: apiRaise, gcsafe, raises: [CoreDbApiError].}

template valueOrApiError[U,V](rc: Result[U,V]; info: static[string]): U =
rc.valueOr: raise (ref CoreDbApiError)(msg: info)

template dbType(dsc: CoreDbKvtRef | CoreDbMptRef | CoreDbAccRef): CoreDbType =
dsc.distinctBase.parent.dbType

# ---------------

template kvt(dsc: CoreDbKvtRef): KvtDbRef =
dsc.distinctBase.kvt

template call(api: KvtApiRef; fn: untyped; args: varArgs[untyped]): untyped =
when CoreDbEnableApiJumpTable:
api.fn(args)
else:
fn(args)

template call(kvt: CoreDbKvtRef; fn: untyped; args: varArgs[untyped]): untyped =
kvt.distinctBase.parent.kvtApi.call(fn, args)

# ---------------

template mpt(dsc: CoreDbAccRef | CoreDbMptRef): AristoDbRef =
dsc.distinctBase.mpt

template call(api: AristoApiRef; fn: untyped; args: varArgs[untyped]): untyped =
when CoreDbEnableApiJumpTable:
api.fn(args)
else:
fn(args)

template call(
acc: CoreDbAccRef | CoreDbMptRef;
fn: untyped;
args: varArgs[untyped];
): untyped =
acc.distinctBase.parent.ariApi.call(fn, args)

# ------------------------------------------------------------------------------
# Public iterators
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -89,21 +123,6 @@ iterator slotPairs*(acc: CoreDbAccRef; accPath: Hash32): (seq[byte], UInt256) =
acc.ifTrackNewApi:
debug logTxt, api, elapsed

iterator replicate*(mpt: CoreDbMptRef): (seq[byte], seq[byte]) {.apiRaise.} =
## Low level trie dump, only supported for non persistent `CoreDbMptRef`
##
mpt.setTrackNewApi MptReplicateIt
case mpt.dbType:
of AristoDbMemory:
for k,v in aristoReplicate[use_ari.MemBackendRef](mpt):
yield (k,v)
of AristoDbVoid:
for k,v in aristoReplicate[use_ari.VoidBackendRef](mpt):
yield (k,v)
of Ooops, AristoDbRocks:
raiseAssert: "Unsupported database type: " & $mpt.dbType
mpt.ifTrackNewApi: debug logTxt, api, elapsed

# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------
Loading

0 comments on commit 0fec94d

Please sign in to comment.