From 4f6cdab641600099d4ee499377a7c04565ec6dba Mon Sep 17 00:00:00 2001 From: andri lim Date: Sun, 22 Oct 2023 14:05:20 +0700 Subject: [PATCH] Engine API simulator: pass first Cancun test (#1838) --- .../nodocker/engine/cancun/blobs.nim | 2 +- .../engine/cancun/step_newpayloads.nim | 8 +++---- .../nodocker/engine/cancun_tests.nim | 8 +++---- hive_integration/nodocker/engine/clmock.nim | 21 +++++++------------ .../nodocker/engine/engine_env.nim | 2 +- .../nodocker/engine/tx_sender.nim | 2 +- 6 files changed, 17 insertions(+), 26 deletions(-) diff --git a/hive_integration/nodocker/engine/cancun/blobs.nim b/hive_integration/nodocker/engine/cancun/blobs.nim index 1e59b962c..9052a1b62 100644 --- a/hive_integration/nodocker/engine/cancun/blobs.nim +++ b/hive_integration/nodocker/engine/cancun/blobs.nim @@ -81,7 +81,7 @@ func verifyBlob*(blobId: BlobID, blob: kzg.KzgBlob): bool = return true -proc fillBlob(blobid: BlobID): KzgBlob = +proc fillBlob(blobId: BlobID): KzgBlob = if blobId == 0: # Blob zero is empty blob, so leave as is return diff --git a/hive_integration/nodocker/engine/cancun/step_newpayloads.nim b/hive_integration/nodocker/engine/cancun/step_newpayloads.nim index 012df10d1..fcebff16f 100644 --- a/hive_integration/nodocker/engine/cancun/step_newpayloads.nim +++ b/hive_integration/nodocker/engine/cancun/step_newpayloads.nim @@ -131,9 +131,9 @@ proc verifyBlobBundle(step: NewPayloads, proofs=len(blobBundle.proofs), kzgs=len(blobBundle.commitments) return false - + if len(blobBundle.blobs) != step.expectedIncludedBlobCount: - error "expected", + error "expected blobs", expect=step.expectedIncludedBlobCount, get=len(blobBundle.blobs) return false @@ -168,9 +168,7 @@ proc verifyBlobBundle(step: NewPayloads, for expectedBlob in step.expectedBlobs: var found = false for blobData in blobDataInPayload: - if not expectedBlob.verifyBlob(blobData.blob): - return false - else: + if expectedBlob.verifyBlob(blobData.blob): found = true break diff --git a/hive_integration/nodocker/engine/cancun_tests.nim b/hive_integration/nodocker/engine/cancun_tests.nim index f66a1c7c7..a71f463d4 100644 --- a/hive_integration/nodocker/engine/cancun_tests.nim +++ b/hive_integration/nodocker/engine/cancun_tests.nim @@ -19,7 +19,7 @@ import # Precalculate the first data gas cost increase const - DATA_GAS_COST_INCREMENT_EXCEED_BLOBS = getMinExcessBlobsForBlobGasPrice(2) + DATA_GAS_COST_INCREMENT_EXCEED_BLOBS = getMinExcessBlobsForBlobGasPrice(2).int TARGET_BLOBS_PER_BLOCK = int(TARGET_BLOB_GAS_PER_BLOCK div GAS_PER_BLOB) proc getGenesis(param: NetworkParams) = @@ -56,7 +56,7 @@ proc specExecute(ws: BaseSpec): bool = result = true for stepId, step in cs.testSequence: - echo "INFO: Executing step", stepId+1, ": ", step.description() + echo "INFO: Executing step ", stepId+1, ": ", step.description() if not step.execute(blobTestCtx): fatal "FAIL: Error executing", step=stepId+1 result = false @@ -100,7 +100,7 @@ let cancunTestList* = [ # We create the first payload, and verify that the blob transactions # are included in the payload. # We also verify that the blob transactions are included in the blobs bundle. - #[NewPayloads( + NewPayloads( expectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, expectedBlobs: getBlobList(0, TARGET_BLOBS_PER_BLOCK), ), @@ -128,7 +128,7 @@ let cancunTestList* = [ # But it will be included in the next payload NewPayloads( expectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, - ),]# + ), ] ) ), diff --git a/hive_integration/nodocker/engine/clmock.nim b/hive_integration/nodocker/engine/clmock.nim index 81a845387..d6b88d950 100644 --- a/hive_integration/nodocker/engine/clmock.nim +++ b/hive_integration/nodocker/engine/clmock.nim @@ -332,26 +332,19 @@ proc getNextPayload(cl: CLMocker): bool = return true -func versionedHashes(bb: BlobsBundleV1): seq[Web3Hash] = - #doAssert(bb.commitments.len > 0) - result = newSeqOfCap[BlockHash](bb.commitments.len) - - for com in bb.commitments: - var h = keccakHash(com.bytes) - h.data[0] = VERSIONED_HASH_VERSION_KZG - result.add w3Hash h +func versionedHashes(payload: ExecutionPayload): seq[Web3Hash] = + result = newSeqOfCap[BlockHash](payload.transactions.len) + for x in payload.transactions: + let tx = rlp.decode(distinctBase(x), Transaction) + for vs in tx.versionedHashes: + result.add w3Hash vs proc broadcastNewPayload(cl: CLMocker, payload: ExecutionPayload): Result[PayloadStatusV1, string] = - var versionedHashes: seq[Web3Hash] - if cl.latestBlobsBundle.isSome: - # Broadcast the blob bundle to all clients - versionedHashes = versionedHashes(cl.latestBlobsBundle.get) - case payload.version of Version.V1: return cl.client.newPayloadV1(payload.V1) of Version.V2: return cl.client.newPayloadV2(payload.V2) of Version.V3: return cl.client.newPayloadV3(payload.V3, - versionedHashes, + versionedHashes(payload), cl.latestPayloadAttributes.parentBeaconBlockRoot.get) proc broadcastNextNewPayload(cl: CLMocker): bool = diff --git a/hive_integration/nodocker/engine/engine_env.nim b/hive_integration/nodocker/engine/engine_env.nim index 481139789..80b3156af 100644 --- a/hive_integration/nodocker/engine/engine_env.nim +++ b/hive_integration/nodocker/engine/engine_env.nim @@ -97,7 +97,7 @@ proc newEngineEnv*(conf: var NimbusConf, chainFile: string, enableAuth: bool): E let hooks = if enableAuth: @[httpJwtAuth(key)] else: @[] - server = newRpcHttpServer(["127.0.0.1:" & $conf.rpcPort], hooks) + server = newRpcHttpServerWithParams("127.0.0.1:" & $conf.rpcPort, hooks) sealer = SealingEngineRef.new( chain, ctx, conf.engineSigner, txPool, EngineStopped) diff --git a/hive_integration/nodocker/engine/tx_sender.nim b/hive_integration/nodocker/engine/tx_sender.nim index b29e889d8..eba447346 100644 --- a/hive_integration/nodocker/engine/tx_sender.nim +++ b/hive_integration/nodocker/engine/tx_sender.nim @@ -248,7 +248,7 @@ proc makeTx*(params: MakeTxParams, tc: BlobTx): Transaction = else: gasTipPrice let unsignedTx = Transaction( - txType : TxEIP4844, + txType : TxEip4844, chainId : params.chainId, nonce : params.nonce, maxPriorityFee: gasTipCap,