From f365e0d472408b3eff1d96bf98b0ea861bf8d218 Mon Sep 17 00:00:00 2001 From: andri lim Date: Fri, 20 Oct 2023 21:02:22 +0700 Subject: [PATCH] Engine API: remove EIP-4844 blobs before insert header to chain (#1834) --- nimbus/beacon/api_handler.nim | 4 ++++ nimbus/beacon/api_handler/api_newpayload.nim | 2 +- nimbus/beacon/payload_conv.nim | 7 ++++--- nimbus/constants.nim | 4 ++-- nimbus/core/validate.nim | 4 ++-- nimbus/transaction.nim | 2 +- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/nimbus/beacon/api_handler.nim b/nimbus/beacon/api_handler.nim index 355ed5c0b..28f318503 100644 --- a/nimbus/beacon/api_handler.nim +++ b/nimbus/beacon/api_handler.nim @@ -32,6 +32,10 @@ func validateVersionedHashed*(payload: ExecutionPayload, for x in payload.transactions: let tx = rlp.decode(distinctBase(x), Transaction) versionedHashes.add tx.versionedHashes + + if versionedHashes.len != expected.len: + return false + for i, x in expected: if distinctBase(x) != versionedHashes[i].data: return false diff --git a/nimbus/beacon/api_handler/api_newpayload.nim b/nimbus/beacon/api_handler/api_newpayload.nim index 5f0351ab5..153aec86a 100644 --- a/nimbus/beacon/api_handler/api_newpayload.nim +++ b/nimbus/beacon/api_handler/api_newpayload.nim @@ -123,7 +123,7 @@ proc newPayload*(ben: BeaconEngineRef, trace "Inserting block without sethead", hash = blockHash, number = header.blockNumber - let body = blockBody(payload) + let body = blockBody(payload, removeBlobs = true) let vres = ben.chain.insertBlockWithoutSetHead(header, body) if vres != ValidationResult.OK: let blockHash = latestValidHash(db, parent, ttd) diff --git a/nimbus/beacon/payload_conv.nim b/nimbus/beacon/payload_conv.nim index e1a6c3803..8561a6e7e 100644 --- a/nimbus/beacon/payload_conv.nim +++ b/nimbus/beacon/payload_conv.nim @@ -105,20 +105,21 @@ func blockHeader*(p: ExecutionPayload, parentBeaconBlockRoot: beaconRoot ) -func blockBody*(p: ExecutionPayload): +func blockBody*(p: ExecutionPayload, removeBlobs: bool): common.BlockBody {.gcsafe, raises:[RlpError].} = common.BlockBody( uncles : @[], - transactions: ethTxs p.transactions, + transactions: ethTxs(p.transactions, removeBlobs), withdrawals : ethWithdrawals p.withdrawals, ) func ethBlock*(p: ExecutionPayload, + removeBlobs: bool, beaconRoot: Option[common.Hash256]): common.EthBlock {.gcsafe, raises:[CatchableError].} = common.Ethblock( header : blockHeader(p, beaconRoot), uncles : @[], - txs : ethTxs p.transactions, + txs : ethTxs(p.transactions, removeBlobs), withdrawals: ethWithdrawals p.withdrawals, ) diff --git a/nimbus/constants.nim b/nimbus/constants.nim index 491e4df92..9da071cc6 100644 --- a/nimbus/constants.nim +++ b/nimbus/constants.nim @@ -84,8 +84,8 @@ const MIN_BLOB_GASPRICE* = 1'u64 BLOB_GASPRICE_UPDATE_FRACTION* = 3338477'u64 MAX_BLOB_GAS_PER_BLOCK* = 786432 - MAX_ALLOWED_BLOB* = MAX_BLOB_GAS_PER_BLOCK div GAS_PER_BLOB - + MAX_BLOBS_PER_BLOCK* = int(MAX_BLOB_GAS_PER_BLOCK div GAS_PER_BLOB) + # EIP-4788 addresses # BEACON_ROOTS_ADDRESS is the address where historical beacon roots are stored as per EIP-4788 BEACON_ROOTS_ADDRESS* = hexToByteArray[20]("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02") diff --git a/nimbus/core/validate.nim b/nimbus/core/validate.nim index 741343300..bd4257566 100644 --- a/nimbus/core/validate.nim +++ b/nimbus/core/validate.nim @@ -274,8 +274,8 @@ proc validateTxBasic*( if tx.versionedHashes.len == 0: return err("invalid tx: there must be at least one blob") - if tx.versionedHashes.len > MAX_ALLOWED_BLOB.int: - return err("invalid tx: versioned hashes len exceeds MAX_ALLOWED_BLOB=" & $MAX_ALLOWED_BLOB & + if tx.versionedHashes.len > MAX_BLOBS_PER_BLOCK: + return err("invalid tx: versioned hashes len exceeds MAX_BLOBS_PER_BLOCK=" & $MAX_BLOBS_PER_BLOCK & ". get=" & $tx.versionedHashes.len) for i, bv in tx.versionedHashes: diff --git a/nimbus/transaction.nim b/nimbus/transaction.nim index 81b2b46d1..a7dbe3a9b 100644 --- a/nimbus/transaction.nim +++ b/nimbus/transaction.nim @@ -139,7 +139,7 @@ proc validateTxEip4844(tx: Transaction) = (acl.storageKeys.len <= MAX_ACCESS_LIST_STORAGE_KEYS) isValid = isValid and - tx.versionedHashes.len <= MAX_ALLOWED_BLOB.int + tx.versionedHashes.len <= MAX_BLOBS_PER_BLOCK for bv in tx.versionedHashes: isValid = isValid and