Simplify pyspec simulator

This commit is contained in:
jangko 2023-09-30 21:31:57 +07:00
parent 369a54d62a
commit 5754a9079b
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
5 changed files with 31 additions and 45 deletions

View File

@ -7,7 +7,8 @@ import
../../../tests/rpcclient/eth_api,
../../../premix/parser,
../../../nimbus/rpc/hexstrings,
../../../nimbus/beacon/execution_types
../../../nimbus/beacon/execution_types,
../../../nimbus/beacon/web3_eth_conv
import web3/engine_api as web3_engine_api
@ -142,14 +143,32 @@ proc newPayloadV3*(client: RpcClient,
wrapTrySimpleRes:
client.engine_newPayloadV3(payload, versionedHashes, parentBeaconBlockRoot)
#proc newPayload*(client: RpcClient,
# payload: ExecutionPayload,
# version: Version):
# Result[PayloadStatusV1, string] =
# if version == Version.V1:
# client.newPayloadV1(payload.V1)
# else:
# client.newPayloadV2(payload.V2)
proc collectBlobHashes(list: openArray[Web3Tx]): seq[Web3Hash] =
for w3tx in list:
let tx = ethTx(w3Tx)
for h in tx.versionedHashes:
result.add w3Hash(h)
proc newPayload*(client: RpcClient,
payload: ExecutionPayload,
version: Version):
Result[PayloadStatusV1, string] =
if version == Version.V1:
client.newPayloadV1(payload.V1)
else:
client.newPayloadV2(payload.V2)
beaconRoot = none(common.Hash256)): Result[PayloadStatusV1, string] =
case payload.version
of Version.V1: return client.newPayloadV1(payload.V1)
of Version.V2: return client.newPayloadV2(payload.V2)
of Version.V3:
let versionedHashes = collectBlobHashes(payload.transactions)
return client.newPayloadV3(payload.V3,
versionedHashes,
w3Hash beaconRoot.get)
proc exchangeCapabilities*(client: RpcClient,
methods: seq[string]):

View File

@ -193,7 +193,7 @@ proc execute*(ws: ReorgSpec, env: TestEnv): bool =
# This block is part of both chains, simply forward it to the secondary client
payload = env.clMock.latestPayloadBuilt
let r = sec.client.newPayload(payload, payload.version)
let r = sec.client.newPayload(payload)
r.expectStatus(valid)
let fcState = ForkchoiceStateV1(
@ -304,7 +304,7 @@ proc execute*(ws: ReorgSpec, env: TestEnv): bool =
hash=payload.blockHash.short,
parentHash=payload.parentHash.short
let r = env.client.newPayload(payload, version)
let r = env.client.newPayload(payload)
r.expectStatusEither(valid, accepted)
let fcState = ForkchoiceStateV1(headBlockHash: payload.blockHash)

View File

@ -109,32 +109,6 @@ proc validatePostState(node: JsonNode, t: TestEnv): bool =
return true
proc collectBlobHashes(list: openArray[Web3Tx]): seq[Web3Hash] =
for w3tx in list:
let tx = ethTx(w3Tx)
for h in tx.versionedHashes:
result.add w3Hash(h)
proc newPayload(client: RpcClient,
payload: ExecutionPayload,
beaconRoot: Option[common.Hash256]): Result[PayloadStatusV1, string] =
case payload.version
of Version.V1: return client.newPayloadV1(payload.V1)
of Version.V2: return client.newPayloadV2(payload.V2)
of Version.V3:
let versionedHashes = collectBlobHashes(payload.transactions)
return client.newPayloadV3(payload.V3,
versionedHashes,
w3Hash beaconRoot.get)
proc forkchoiceUpdated(client: RpcClient, version: Version,
update: ForkchoiceStateV1):
Result[ForkchoiceUpdatedResponse, string] =
case version
of Version.V1: client.forkchoiceUpdatedV1(update)
of Version.V2: client.forkchoiceUpdatedV2(update)
of Version.V3: client.forkchoiceUpdatedV3(update)
proc runTest(node: JsonNode, network: string): TestStatus =
let conf = getChainConfig(network)
var t = TestEnv(conf: makeTestConfig())

View File

@ -9,7 +9,6 @@ import
constants,
transaction,
db/accounts_cache,
core/sealer,
core/chain,
core/tx_pool,
rpc,
@ -28,7 +27,6 @@ type
com: CommonRef
chainRef: ChainRef
rpcServer: RpcHttpServer
sealingEngine: SealingEngineRef
rpcClient*: RpcHttpClient
const
@ -63,10 +61,6 @@ proc setupELClient*(t: TestEnv, conf: ChainConfig, node: JsonNode) =
let txPool = TxPoolRef.new(t.com, engineSigner)
t.rpcServer = newRpcHttpServer(["127.0.0.1:8545"])
t.sealingEngine = SealingEngineRef.new(
t.chainRef, t.ctx, engineSigner,
txPool, EngineStopped
)
let beaconEngine = BeaconEngineRef.new(txPool, t.chainRef)
setupEthRpc(t.ethNode, t.ctx, t.com, txPool, t.rpcServer)
@ -79,5 +73,4 @@ proc setupELClient*(t: TestEnv, conf: ChainConfig, node: JsonNode) =
proc stopELClient*(t: TestEnv) =
waitFor t.rpcClient.close()
waitFor t.sealingEngine.stop()
waitFor t.rpcServer.closeWait()

View File

@ -38,14 +38,14 @@ proc `$`*(stat: SimStat): string =
for c in stat.failingCases:
result.add " - $1 \n" % [c]
result.add "ok: $1, skipped: $2, failed: $3" % [$stat.ok, $stat.skipped, $stat.failed]
result.add " - ok: $1, skipped: $2, failed: $3" % [$stat.ok, $stat.skipped, $stat.failed]
proc print*(stat: SimStat, dur: Duration, name: string) =
var f = open(name & ".md", fmWrite)
f.write("* " & name)
f.write("\n")
f.write(" - " & $stat)
f.write($stat)
f.write("\n")
f.write(" - " & dur.short)
f.write(" - Elapsed: " & dur.short)
f.write("\n")
f.close()