Engine API simulator: pass first Cancun test (#1838)

This commit is contained in:
andri lim 2023-10-22 14:05:20 +07:00 committed by GitHub
parent f32419c81f
commit 4f6cdab641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 26 deletions

View File

@ -81,7 +81,7 @@ func verifyBlob*(blobId: BlobID, blob: kzg.KzgBlob): bool =
return true return true
proc fillBlob(blobid: BlobID): KzgBlob = proc fillBlob(blobId: BlobID): KzgBlob =
if blobId == 0: if blobId == 0:
# Blob zero is empty blob, so leave as is # Blob zero is empty blob, so leave as is
return return

View File

@ -131,9 +131,9 @@ proc verifyBlobBundle(step: NewPayloads,
proofs=len(blobBundle.proofs), proofs=len(blobBundle.proofs),
kzgs=len(blobBundle.commitments) kzgs=len(blobBundle.commitments)
return false return false
if len(blobBundle.blobs) != step.expectedIncludedBlobCount: if len(blobBundle.blobs) != step.expectedIncludedBlobCount:
error "expected", error "expected blobs",
expect=step.expectedIncludedBlobCount, expect=step.expectedIncludedBlobCount,
get=len(blobBundle.blobs) get=len(blobBundle.blobs)
return false return false
@ -168,9 +168,7 @@ proc verifyBlobBundle(step: NewPayloads,
for expectedBlob in step.expectedBlobs: for expectedBlob in step.expectedBlobs:
var found = false var found = false
for blobData in blobDataInPayload: for blobData in blobDataInPayload:
if not expectedBlob.verifyBlob(blobData.blob): if expectedBlob.verifyBlob(blobData.blob):
return false
else:
found = true found = true
break break

View File

@ -19,7 +19,7 @@ import
# Precalculate the first data gas cost increase # Precalculate the first data gas cost increase
const 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) TARGET_BLOBS_PER_BLOCK = int(TARGET_BLOB_GAS_PER_BLOCK div GAS_PER_BLOB)
proc getGenesis(param: NetworkParams) = proc getGenesis(param: NetworkParams) =
@ -56,7 +56,7 @@ proc specExecute(ws: BaseSpec): bool =
result = true result = true
for stepId, step in cs.testSequence: 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): if not step.execute(blobTestCtx):
fatal "FAIL: Error executing", step=stepId+1 fatal "FAIL: Error executing", step=stepId+1
result = false result = false
@ -100,7 +100,7 @@ let cancunTestList* = [
# We create the first payload, and verify that the blob transactions # We create the first payload, and verify that the blob transactions
# are included in the payload. # are included in the payload.
# We also verify that the blob transactions are included in the blobs bundle. # We also verify that the blob transactions are included in the blobs bundle.
#[NewPayloads( NewPayloads(
expectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, expectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK,
expectedBlobs: getBlobList(0, 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 # But it will be included in the next payload
NewPayloads( NewPayloads(
expectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, expectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK,
),]# ),
] ]
) )
), ),

View File

@ -332,26 +332,19 @@ proc getNextPayload(cl: CLMocker): bool =
return true return true
func versionedHashes(bb: BlobsBundleV1): seq[Web3Hash] = func versionedHashes(payload: ExecutionPayload): seq[Web3Hash] =
#doAssert(bb.commitments.len > 0) result = newSeqOfCap[BlockHash](payload.transactions.len)
result = newSeqOfCap[BlockHash](bb.commitments.len) for x in payload.transactions:
let tx = rlp.decode(distinctBase(x), Transaction)
for com in bb.commitments: for vs in tx.versionedHashes:
var h = keccakHash(com.bytes) result.add w3Hash vs
h.data[0] = VERSIONED_HASH_VERSION_KZG
result.add w3Hash h
proc broadcastNewPayload(cl: CLMocker, payload: ExecutionPayload): Result[PayloadStatusV1, string] = 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 case payload.version
of Version.V1: return cl.client.newPayloadV1(payload.V1) of Version.V1: return cl.client.newPayloadV1(payload.V1)
of Version.V2: return cl.client.newPayloadV2(payload.V2) of Version.V2: return cl.client.newPayloadV2(payload.V2)
of Version.V3: return cl.client.newPayloadV3(payload.V3, of Version.V3: return cl.client.newPayloadV3(payload.V3,
versionedHashes, versionedHashes(payload),
cl.latestPayloadAttributes.parentBeaconBlockRoot.get) cl.latestPayloadAttributes.parentBeaconBlockRoot.get)
proc broadcastNextNewPayload(cl: CLMocker): bool = proc broadcastNextNewPayload(cl: CLMocker): bool =

View File

@ -97,7 +97,7 @@ proc newEngineEnv*(conf: var NimbusConf, chainFile: string, enableAuth: bool): E
let let
hooks = if enableAuth: @[httpJwtAuth(key)] hooks = if enableAuth: @[httpJwtAuth(key)]
else: @[] else: @[]
server = newRpcHttpServer(["127.0.0.1:" & $conf.rpcPort], hooks) server = newRpcHttpServerWithParams("127.0.0.1:" & $conf.rpcPort, hooks)
sealer = SealingEngineRef.new( sealer = SealingEngineRef.new(
chain, ctx, conf.engineSigner, chain, ctx, conf.engineSigner,
txPool, EngineStopped) txPool, EngineStopped)

View File

@ -248,7 +248,7 @@ proc makeTx*(params: MakeTxParams, tc: BlobTx): Transaction =
else: gasTipPrice else: gasTipPrice
let unsignedTx = Transaction( let unsignedTx = Transaction(
txType : TxEIP4844, txType : TxEip4844,
chainId : params.chainId, chainId : params.chainId,
nonce : params.nonce, nonce : params.nonce,
maxPriorityFee: gasTipCap, maxPriorityFee: gasTipCap,