Skip to content

Commit 90c760f

Browse files
committed
simulators/ethereum/engine: Transition Payload checks
1 parent f2838a6 commit 90c760f

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed

simulators/ethereum/engine/engineclient.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ type PayloadStatus int
172172
type PayloadStatusSlice []PayloadStatus
173173

174174
const (
175-
Valid PayloadStatus = iota
175+
Unknown PayloadStatus = iota
176+
Valid
176177
Invalid
177178
Accepted
178179
Syncing
179-
InvalidTerminalBlock
180180
InvalidBlockHash
181181
)
182182

simulators/ethereum/engine/mergetests.go

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ type MergeTestSpec struct {
6868
// Whether or not to wait for TTD to be reached by the main client
6969
SkipMainClientTTDWait bool
7070

71+
// If set, the main client will be polled with `newPayload` until status!=`SYNCING` is returned.
72+
// If `VALID`, `latestValidHash` is also checked to be the hash of the transition block.
73+
// If `INVALID`, {status: INVALID, latestValidHash: 0x00..00, payloadId: null} is expected.
74+
TransitionPayloadStatus PayloadStatus
75+
7176
// Number of PoS blocks to build on top of the MainClient.
7277
// Blocks will be built before any of the other clients is started, leading to a potential Post-PoS re-org.
7378
// Requires SkipMainClientFcU==false
@@ -94,6 +99,19 @@ var mergeTestSpecs = []MergeTestSpec{
9499
},
95100
},
96101
},
102+
{
103+
Name: "Single Block PoW Re-org to Higher-Total-Difficulty Chain, Equal Height (Transition Payload)",
104+
TTD: 196608,
105+
MainChainFile: "blocks_1_td_196608.rlp",
106+
TransitionPayloadStatus: Valid,
107+
SecondaryClientSpecs: []SecondaryClientSpec{
108+
{
109+
ChainFile: "blocks_1_td_196704.rlp",
110+
BuildPoSChainOnTop: true,
111+
MainClientShallSync: true,
112+
},
113+
},
114+
},
97115
{
98116
Name: "Single Block PoW Re-org to Lower-Total-Difficulty Chain, Equal Height",
99117
TTD: 196608,
@@ -260,7 +278,6 @@ var mergeTestSpecs = []MergeTestSpec{
260278
TTD: 196608,
261279
MainChainFile: "blocks_1_td_196608.rlp",
262280
MainClientPoSBlocks: 1,
263-
TimeoutSeconds: 180,
264281
KeepCheckingUntilTimeout: true,
265282
SecondaryClientSpecs: []SecondaryClientSpec{
266283
{
@@ -271,12 +288,26 @@ var mergeTestSpecs = []MergeTestSpec{
271288
},
272289
},
273290
},
291+
{
292+
Name: "Transition to a Chain with Invalid Terminal Block, Higher Configured Total Difficulty (Transition Payload)",
293+
TTD: 196608,
294+
MainChainFile: "blocks_1_td_196608.rlp",
295+
MainClientPoSBlocks: 1,
296+
TransitionPayloadStatus: Invalid,
297+
SecondaryClientSpecs: []SecondaryClientSpec{
298+
{
299+
TTD: 393120,
300+
ChainFile: "blocks_2_td_393120.rlp",
301+
BuildPoSChainOnTop: true,
302+
MainClientShallSync: false,
303+
},
304+
},
305+
},
274306
{
275307
Name: "Transition to a Chain with Invalid Terminal Block, Lower Configured Total Difficulty",
276308
TTD: 393120,
277309
MainChainFile: "blocks_2_td_393120.rlp",
278310
MainClientPoSBlocks: 1,
279-
TimeoutSeconds: 180,
280311
KeepCheckingUntilTimeout: true,
281312
SecondaryClientSpecs: []SecondaryClientSpec{
282313
{
@@ -287,6 +318,21 @@ var mergeTestSpecs = []MergeTestSpec{
287318
},
288319
},
289320
},
321+
{
322+
Name: "Transition to a Chain with Invalid Terminal Block, Lower Configured Total Difficulty (Transition Payload)",
323+
TTD: 393120,
324+
MainChainFile: "blocks_2_td_393120.rlp",
325+
MainClientPoSBlocks: 1,
326+
TransitionPayloadStatus: Invalid,
327+
SecondaryClientSpecs: []SecondaryClientSpec{
328+
{
329+
TTD: 196608,
330+
ChainFile: "blocks_1_td_196608.rlp",
331+
BuildPoSChainOnTop: true,
332+
MainClientShallSync: false,
333+
},
334+
},
335+
},
290336

291337
/* TODOs:
292338
- reorg to a block with uncles
@@ -424,7 +470,8 @@ func GenerateMergeTestSpec(mergeTestSpec MergeTestSpec) TestSpec {
424470

425471
// Test end state of the main client
426472
for {
427-
if mergeTestSpec.SecondaryClientSpecs.AnyPoSChainOnTop() {
473+
if mergeTestSpec.SecondaryClientSpecs.AnyPoSChainOnTop() && (mergeTestSpec.TransitionPayloadStatus == Unknown ||
474+
t.CLMock.FirstPoSBlockNumber == nil) {
428475
// Build a block and check whether the main client switches
429476
t.CLMock.produceSingleBlock(BlockProcessCallbacks{
430477
OnPayloadProducerSelected: prevRandaoFunc,
@@ -438,7 +485,22 @@ func GenerateMergeTestSpec(mergeTestSpec MergeTestSpec) TestSpec {
438485
}
439486
}
440487

441-
if header, err := t.Eth.HeaderByNumber(t.Ctx(), nil); err == nil {
488+
if mergeTestSpec.TransitionPayloadStatus != Unknown {
489+
// We are specifically checking the transition payload in this test case
490+
p := t.TestEngine.TestEngineNewPayloadV1(&t.CLMock.LatestExecutedPayload)
491+
p.ExpectNoError()
492+
if p.Status.Status != Syncing {
493+
p.ExpectStatus(mergeTestSpec.TransitionPayloadStatus)
494+
if mergeTestSpec.TransitionPayloadStatus == Valid {
495+
p.ExpectLatestValidHash(&t.CLMock.LatestExecutedPayload.BlockHash)
496+
} else if mergeTestSpec.TransitionPayloadStatus == Invalid {
497+
p.ExpectLatestValidHash(&(common.Hash{}))
498+
}
499+
break
500+
}
501+
502+
} else if header, err := t.Eth.HeaderByNumber(t.Ctx(), nil); err == nil {
503+
// We are not checking the transition block, we are checking that the client sticks to the correct chain.
442504
if header.Hash() == mustHeadHash {
443505
t.Logf("INFO (%s): Main client is now synced to the expected head, %v", t.TestName, header.Hash())
444506
break

0 commit comments

Comments
 (0)