Skip to content

Commit dc76446

Browse files
authored
simulators/ethereum/engine: test using getPayloadBodiesByRange/Hash after client sync (#709)
Adds a test that verifies engine_getPayloadBodiesByRangeV1 and engine_getPayloadBodiesByHashV1 behavior after client syncs to a given canonical chain.
1 parent 07bb8ff commit dc76446

File tree

2 files changed

+99
-2
lines changed

2 files changed

+99
-2
lines changed

simulators/ethereum/engine/suites/withdrawals/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ All test cases contain the following verifications:
183183
- Requested payload bodies past the highest known block are ignored and absent from the returned list
184184
- Payloads `32'` and `33'` are ignored by all requests since they are not part of the canonical chain.
185185

186+
- Payload Bodies By Hash/Range After Sync - Shanghai Fork on Block 16 - 16 Withdrawal Blocks
187+
- Launch client `A` and create a canonical chain consisting of 32 blocks, where the first shanghai block is number 17
188+
- Payloads produced have: 16 Transactions, 16 Withdrawals
189+
- Launch client `B` and send `NewPayload(P32)` + `FcU(P32)` to it.
190+
- Wait until client `B` syncs the canonical chain, or timeout.
191+
- Make multiple requests to obtain the payload bodies from the canonical chain (see `./tests.go` for full list) to client `B`.
192+
- Verify that:
193+
- Payload bodies of blocks before the Shanghai fork contain `withdrawals==null`
194+
- All transactions and withdrawals are in the correct format and order.
195+
- Requested payload bodies past the highest known block are ignored and absent from the returned list
196+
186197
- Payload Bodies By Hash - Shanghai Fork on Block 16 - 16 Withdrawal Blocks
187198
- Launch client `A` and create a canonical chain consisting of 32 blocks, where the first shanghai block is number 17
188199
- Payloads produced of the following characteristics

simulators/ethereum/engine/suites/withdrawals/tests.go

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,56 @@ var Tests = []test.SpecInterface{
580580
},
581581
},
582582

583+
&GetPayloadBodiesSpec{
584+
WithdrawalsBaseSpec: &WithdrawalsBaseSpec{
585+
Spec: test.Spec{
586+
Name: "GetPayloadBodies After Sync",
587+
About: `
588+
Make multiple withdrawals to 16 accounts each payload.
589+
Spawn a secondary client which must sync the canonical chain
590+
from the first client.
591+
Retrieve many of the payloads' bodies by number range from
592+
this secondary client.
593+
`,
594+
TimeoutSeconds: 240,
595+
SlotsToSafe: big.NewInt(32),
596+
SlotsToFinalized: big.NewInt(64),
597+
},
598+
WithdrawalsForkHeight: 17,
599+
WithdrawalsBlockCount: 16,
600+
WithdrawalsPerBlock: 16,
601+
WithdrawableAccountCount: 1024,
602+
},
603+
GetPayloadBodiesRequests: []GetPayloadBodyRequest{
604+
GetPayloadBodyRequestByRange{
605+
Start: 16,
606+
Count: 2,
607+
},
608+
GetPayloadBodyRequestByRange{
609+
Start: 31,
610+
Count: 3,
611+
},
612+
GetPayloadBodyRequestByHashIndex{
613+
BlockNumbers: []uint64{
614+
1,
615+
16,
616+
2,
617+
17,
618+
},
619+
},
620+
GetPayloadBodyRequestByHashIndex{ // Existing+Random hashes
621+
BlockNumbers: []uint64{
622+
32,
623+
1000,
624+
31,
625+
1000,
626+
30,
627+
1000,
628+
},
629+
},
630+
},
631+
},
632+
583633
&GetPayloadBodiesSpec{
584634
WithdrawalsBaseSpec: &WithdrawalsBaseSpec{
585635
Spec: test.Spec{
@@ -1842,6 +1892,7 @@ type GetPayloadBodiesSpec struct {
18421892
*WithdrawalsBaseSpec
18431893
GetPayloadBodiesRequests []GetPayloadBodyRequest
18441894
GenerateSidechain bool
1895+
AfterSync bool
18451896
}
18461897

18471898
type GetPayloadBodyRequest interface {
@@ -1950,6 +2001,8 @@ func (ws *GetPayloadBodiesSpec) Execute(t *test.Env) {
19502001

19512002
payloadHistory := t.CLMock.ExecutedPayloadHistory
19522003

2004+
testEngine := t.TestEngine
2005+
19532006
if ws.GenerateSidechain {
19542007

19552008
// First generate an extra payload on top of the canonical chain
@@ -1997,11 +2050,44 @@ func (ws *GetPayloadBodiesSpec) Execute(t *test.Env) {
19972050
n1.ExpectStatus(test.Valid)
19982051
n2 := t.TestEngine.TestEngineNewPayloadV2(sidechainHead)
19992052
n2.ExpectStatus(test.Valid)
2053+
} else if ws.AfterSync {
2054+
// Spawn a secondary client which will need to sync to the primary client
2055+
secondaryEngine, err := hive_rpc.HiveRPCEngineStarter{}.StartClient(t.T, t.TestContext, t.Genesis, t.ClientParams, t.ClientFiles, t.Engine)
2056+
if err != nil {
2057+
t.Fatalf("FAIL (%s): Unable to spawn a secondary client: %v", t.TestName, err)
2058+
}
2059+
secondaryEngineTest := test.NewTestEngineClient(t, secondaryEngine)
2060+
t.CLMock.AddEngineClient(secondaryEngine)
2061+
2062+
loop:
2063+
for {
2064+
select {
2065+
case <-t.TimeoutContext.Done():
2066+
t.Fatalf("FAIL (%s): Timeout while waiting for secondary client to sync", t.TestName)
2067+
case <-time.After(time.Second):
2068+
secondaryEngineTest.TestEngineNewPayloadV2(
2069+
&t.CLMock.LatestExecutedPayload,
2070+
)
2071+
r := secondaryEngineTest.TestEngineForkchoiceUpdatedV2(
2072+
&t.CLMock.LatestForkchoice,
2073+
nil,
2074+
)
2075+
if r.Response.PayloadStatus.Status == test.Valid {
2076+
break loop
2077+
}
2078+
if r.Response.PayloadStatus.Status == test.Invalid {
2079+
t.Fatalf("FAIL (%s): Syncing client rejected valid chain: %s", t.TestName, r.Response)
2080+
}
2081+
}
2082+
}
2083+
2084+
// GetPayloadBodies will be sent to the secondary client
2085+
testEngine = secondaryEngineTest
20002086
}
20012087

2002-
// Now send the range request, which should ignore the sidechain
2088+
// Now send the range request, which should ignore any sidechain
20032089
for _, req := range ws.GetPayloadBodiesRequests {
2004-
req.Verify(t.TestEngine, payloadHistory)
2090+
req.Verify(testEngine, payloadHistory)
20052091
}
20062092
}
20072093

0 commit comments

Comments
 (0)