2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
2024-06-14 07:31:08 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-11-01 03:32:09 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
2023-08-21 02:08:54 +00:00
|
|
|
import
|
|
|
|
chronicles,
|
2023-09-06 09:18:26 +00:00
|
|
|
json_rpc/rpcclient,
|
2023-08-21 02:08:54 +00:00
|
|
|
./wd_base_spec,
|
2023-09-06 09:18:26 +00:00
|
|
|
./wd_history,
|
2023-08-21 02:08:54 +00:00
|
|
|
../test_env,
|
|
|
|
../engine_client,
|
|
|
|
../types
|
|
|
|
|
|
|
|
# Withdrawals sync spec:
|
|
|
|
# Specifies a withdrawals test where the withdrawals happen and then a
|
|
|
|
# client needs to sync and apply the withdrawals.
|
|
|
|
type
|
|
|
|
SyncSpec* = ref object of WDBaseSpec
|
|
|
|
syncSteps*: int # Sync block chunks that will be passed as head through FCUs to the syncing client
|
|
|
|
syncShouldFail*: bool
|
2023-09-28 06:20:12 +00:00
|
|
|
sleep*: int
|
2023-08-21 02:08:54 +00:00
|
|
|
|
2023-09-06 09:18:26 +00:00
|
|
|
proc doSync(ws: SyncSpec, client: RpcClient, clMock: CLMocker): Future[bool] {.async.} =
|
2023-09-28 06:20:12 +00:00
|
|
|
if ws.sleep == 0:
|
|
|
|
ws.sleep = DefaultSleep
|
|
|
|
let period = chronos.seconds(ws.sleep)
|
2023-09-06 09:18:26 +00:00
|
|
|
var loop = 0
|
2023-09-28 06:20:12 +00:00
|
|
|
if ws.timeoutSeconds == 0:
|
|
|
|
ws.timeoutSeconds = DefaultTimeout
|
|
|
|
|
2023-09-06 09:18:26 +00:00
|
|
|
while loop < ws.timeoutSeconds:
|
|
|
|
let res = client.newPayloadV2(clMock.latestExecutedPayload.V1V2)
|
|
|
|
discard res
|
|
|
|
|
|
|
|
let r = client.forkchoiceUpdatedV2(clMock.latestForkchoice)
|
|
|
|
if r.isErr:
|
|
|
|
error "fcu error", msg=r.error
|
|
|
|
return false
|
|
|
|
|
|
|
|
let s = r.get
|
|
|
|
if s.payloadStatus.status == PayloadExecutionStatus.valid:
|
|
|
|
return true
|
|
|
|
|
|
|
|
if s.payloadStatus.status == PayloadExecutionStatus.invalid:
|
|
|
|
error "Syncing client rejected valid chain"
|
|
|
|
|
|
|
|
await sleepAsync(period)
|
2023-09-28 06:20:12 +00:00
|
|
|
loop += ws.sleep
|
2023-09-06 09:18:26 +00:00
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
proc execute*(ws: SyncSpec, env: TestEnv): bool =
|
2023-08-21 02:08:54 +00:00
|
|
|
# Do the base withdrawal test first, skipping base verifications
|
|
|
|
WDBaseSpec(ws).skipBaseVerifications = true
|
2023-09-06 09:18:26 +00:00
|
|
|
testCond WDBaseSpec(ws).execute(env)
|
2023-08-21 02:08:54 +00:00
|
|
|
|
|
|
|
# Spawn a secondary client which will need to sync to the primary client
|
2023-09-06 09:18:26 +00:00
|
|
|
let sec = env.addEngine()
|
2023-08-21 02:08:54 +00:00
|
|
|
|
2023-09-06 09:18:26 +00:00
|
|
|
if ws.syncSteps > 1:
|
2023-08-21 02:08:54 +00:00
|
|
|
# TODO
|
2023-09-06 09:18:26 +00:00
|
|
|
discard
|
2023-08-21 02:08:54 +00:00
|
|
|
else:
|
|
|
|
# Send the FCU to trigger sync on the secondary client
|
2023-09-06 09:18:26 +00:00
|
|
|
let ok = waitFor doSync(ws, sec.client, env.clMock)
|
|
|
|
if not ok:
|
|
|
|
return false
|
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
let bn = env.clMock.latestHeader.number
|
|
|
|
let res = ws.wdHistory.verifyWithdrawals(bn, Opt.none(uint64), sec.client)
|
2023-09-06 09:18:26 +00:00
|
|
|
if res.isErr:
|
|
|
|
error "wd history error", msg=res.error
|
|
|
|
return false
|
|
|
|
|
2023-08-21 02:08:54 +00:00
|
|
|
return true
|