@@ -202,7 +202,7 @@ func (tc InvalidMissingAncestorReOrgSyncTest) GetName() string {
202
202
if tc .EmptyTransactions {
203
203
name += "Empty Txs, "
204
204
}
205
- name += fmt .Sprintf (", Invalid P%d', Reveal using sync" , tc .InvalidIndex )
205
+ name += fmt .Sprintf ("Invalid P%d', Reveal using sync" , tc .InvalidIndex )
206
206
if tc .ReOrgFromCanonical {
207
207
name += " (ReOrg from Canonical)"
208
208
}
@@ -240,30 +240,17 @@ func (tc InvalidMissingAncestorReOrgSyncTest) Execute(t *test.Env) {
240
240
t .CLMock .WaitForTTD ()
241
241
242
242
// Produce blocks before starting the test
243
- var cA * types.Block
244
-
245
- cAHeight := tc .CommonAncestorHeight
246
- if cAHeight == nil {
247
- // Default is to produce 5 PoS blocks before the common ancestor
248
- cAHeight = big .NewInt (5 )
243
+ // Default is to produce 5 PoS blocks before the common ancestor
244
+ cAHeight := 5
245
+ if tc .CommonAncestorHeight != nil {
246
+ cAHeight = int (tc .CommonAncestorHeight .Int64 ())
249
247
}
250
248
251
249
// Save the common ancestor
252
- if cAHeight .Cmp (big0 ) == 0 {
253
- // Common ancestor is the proof-of-work terminal block
254
- ctx , cancel := context .WithTimeout (t .TestContext , globals .RPCTimeout )
255
- defer cancel ()
256
- b , err := secondaryClient .BlockByNumber (ctx , nil )
257
- if err != nil {
258
- t .Fatalf ("FAIL (%s): Error while getting latest block: %v" , t .TestName , err )
259
- }
260
- cA = b
250
+ if cAHeight == 0 {
251
+ t .Fatalf ("FAIL (%s): Invalid common ancestor height: %d" , t .TestName , cAHeight )
261
252
} else {
262
- t .CLMock .ProduceBlocks (int (cAHeight .Int64 ()), clmock.BlockProcessCallbacks {})
263
- cA , err = typ .ExecutableDataToBlock (t .CLMock .LatestPayloadBuilt )
264
- if err != nil {
265
- t .Fatalf ("FAIL (%s): Error converting payload to block: %v" , t .TestName , err )
266
- }
253
+ t .CLMock .ProduceBlocks (cAHeight , clmock.BlockProcessCallbacks {})
267
254
}
268
255
269
256
// Amount of blocks to deviate starting from the common ancestor
@@ -274,15 +261,17 @@ func (tc InvalidMissingAncestorReOrgSyncTest) Execute(t *test.Env) {
274
261
}
275
262
276
263
// Slice to save the side B chain
277
- altChainPayloads := make ([]* types. Block , 0 )
264
+ altChainPayloads := make ([]* typ. ExecutableData , 0 )
278
265
279
266
// Append the common ancestor
280
- altChainPayloads = append (altChainPayloads , cA )
267
+ cA := t .CLMock .LatestPayloadBuilt
268
+ altChainPayloads = append (altChainPayloads , & cA )
281
269
282
270
// Produce blocks but at the same time create an side chain which contains an invalid payload at some point (INV_P)
283
271
// CommonAncestor◄─▲── P1 ◄─ P2 ◄─ P3 ◄─ ... ◄─ Pn
284
272
// │
285
273
// └── P1' ◄─ P2' ◄─ ... ◄─ INV_P ◄─ ... ◄─ Pn'
274
+ t .Log ("INFO: Starting canonical chain production" )
286
275
t .CLMock .ProduceBlocks (n , clmock.BlockProcessCallbacks {
287
276
288
277
OnPayloadProducerSelected : func () {
@@ -312,7 +301,7 @@ func (tc InvalidMissingAncestorReOrgSyncTest) Execute(t *test.Env) {
312
301
err error
313
302
)
314
303
// Insert extraData to ensure we deviate from the main payload, which contains empty extradata
315
- pHash := altChainPayloads [len (altChainPayloads )- 1 ].Hash ()
304
+ pHash := altChainPayloads [len (altChainPayloads )- 1 ].BlockHash
316
305
customizer := & helper.CustomPayloadData {
317
306
ParentHash : & pHash ,
318
307
ExtraData : & ([]byte {0x01 }),
@@ -327,7 +316,9 @@ func (tc InvalidMissingAncestorReOrgSyncTest) Execute(t *test.Env) {
327
316
t .Fatalf ("FAIL (%s): Unable to customize payload: %v" , t .TestName , err )
328
317
}
329
318
}
319
+ altChainPayloads = append (altChainPayloads , sidePayload )
330
320
321
+ // TODO: REMOVE THIS
331
322
sideBlock , err := typ .ExecutableDataToBlock (* sidePayload )
332
323
if err != nil {
333
324
t .Fatalf ("FAIL (%s): Error converting payload to block: %v" , t .TestName , err )
@@ -351,10 +342,9 @@ func (tc InvalidMissingAncestorReOrgSyncTest) Execute(t *test.Env) {
351
342
t .Fatalf ("FAIL (%s): Unable to customize payload block: %v" , t .TestName , err )
352
343
}
353
344
}
354
-
355
- altChainPayloads = append (altChainPayloads , sideBlock )
356
345
},
357
346
})
347
+ t .Log ("INFO: Starting side chain production" )
358
348
t .CLMock .ProduceSingleBlock (clmock.BlockProcessCallbacks {
359
349
// Note: We perform the test in the middle of payload creation by the CL Mock, in order to be able to
360
350
// re-org back into this chain and use the new payload without issues.
@@ -369,30 +359,30 @@ func (tc InvalidMissingAncestorReOrgSyncTest) Execute(t *test.Env) {
369
359
} else if i > tc .InvalidIndex {
370
360
payloadValidStr = "VALID with INVALID ancestor"
371
361
}
372
- payloadJs , _ := json .MarshalIndent (altChainPayloads [i ]. Header () , "" , " " )
362
+ payloadJs , _ := json .MarshalIndent (altChainPayloads [i ], "" , " " )
373
363
t .Logf ("INFO (%s): Invalid chain payload %d (%s):\n %s" , t .TestName , i , payloadValidStr , payloadJs )
374
364
375
365
if i < tc .InvalidIndex {
376
- p := typ . BlockToExecutableData ( altChainPayloads [i ], common . Big0 )
377
- r := secondaryTestClient .TestEngineNewPayload (& p )
366
+ p := altChainPayloads [i ]
367
+ r := secondaryTestClient .TestEngineNewPayload (p )
378
368
r .ExpectationDescription = "Sent modified payload to secondary client, expected to be accepted"
379
369
r .ExpectStatusEither (test .Valid , test .Accepted )
380
370
381
371
s := secondaryTestClient .TestEngineForkchoiceUpdated (& api.ForkchoiceStateV1 {
382
372
HeadBlockHash : p .BlockHash ,
383
- SafeBlockHash : cA .Hash () ,
373
+ SafeBlockHash : cA .BlockHash ,
384
374
FinalizedBlockHash : common.Hash {},
385
375
}, nil , p .Timestamp )
386
376
s .ExpectationDescription = "Sent modified payload forkchoice updated to secondary client, expected to be accepted"
387
377
s .ExpectAnyPayloadStatus (test .Valid , test .Syncing )
388
378
389
379
} else {
390
- invalidBlock := altChainPayloads [i ]
380
+ invalidBlock , err := typ . ExecutableDataToBlock ( * altChainPayloads [i ])
391
381
if err != nil {
392
382
t .Fatalf ("FAIL (%s): TEST ISSUE - Failed to create block from payload: %v" , t .TestName , err )
393
383
}
394
384
395
- if err := secondaryClient .SetBlock (invalidBlock , altChainPayloads [i - 1 ].NumberU64 () , altChainPayloads [i - 1 ].Root () ); err != nil {
385
+ if err := secondaryClient .SetBlock (invalidBlock , altChainPayloads [i - 1 ].Number , altChainPayloads [i - 1 ].StateRoot ); err != nil {
396
386
t .Fatalf ("FAIL (%s): TEST ISSUE - Failed to set invalid block: %v" , t .TestName , err )
397
387
}
398
388
t .Logf ("INFO (%s): Invalid block successfully set %d (%s): %v" , t .TestName , i , payloadValidStr , invalidBlock .Hash ())
@@ -406,8 +396,8 @@ func (tc InvalidMissingAncestorReOrgSyncTest) Execute(t *test.Env) {
406
396
t .Fatalf ("FAIL (%s): TEST ISSUE - Secondary Node unable to reatrieve latest header: %v" , t .TestName , err )
407
397
408
398
}
409
- if head .Hash () != altChainPayloads [n - 1 ].Hash () {
410
- t .Fatalf ("FAIL (%s): TEST ISSUE - Secondary Node has invalid blockhash got %v want %v gotNum %v wantNum %d" , t .TestName , head .Hash (), altChainPayloads [n - 1 ].Hash () , head .Number , altChainPayloads [n ].NumberU64 () )
399
+ if head .Hash () != altChainPayloads [n - 1 ].BlockHash {
400
+ t .Fatalf ("FAIL (%s): TEST ISSUE - Secondary Node has invalid blockhash got %v want %v gotNum %v wantNum %d" , t .TestName , head .Hash (), altChainPayloads [n - 1 ].BlockHash , head .Number , altChainPayloads [n ].Number )
411
401
} else {
412
402
t .Logf ("INFO (%s): Secondary Node has correct block" , t .TestName )
413
403
}
@@ -425,24 +415,23 @@ func (tc InvalidMissingAncestorReOrgSyncTest) Execute(t *test.Env) {
425
415
t .Logf ("INFO (%s): Latest block on main client before sync: hash=%v, number=%d" , t .TestName , l .Hash (), l .Number ())
426
416
}
427
417
// If we are syncing through p2p, we need to keep polling until the client syncs the missing payloads
428
- ed := typ .BlockToExecutableData (altChainPayloads [n ], common .Big0 )
429
418
for {
430
- r := t .TestEngine .TestEngineNewPayload (& ed )
419
+ r := t .TestEngine .TestEngineNewPayload (altChainPayloads [ n ] )
431
420
t .Logf ("INFO (%s): Response from main client: %v" , t .TestName , r .Status )
432
421
s := t .TestEngine .TestEngineForkchoiceUpdated (& api.ForkchoiceStateV1 {
433
- HeadBlockHash : altChainPayloads [n ].Hash () ,
434
- SafeBlockHash : altChainPayloads [n ].Hash () ,
422
+ HeadBlockHash : altChainPayloads [n ].BlockHash ,
423
+ SafeBlockHash : altChainPayloads [n ].BlockHash ,
435
424
FinalizedBlockHash : common.Hash {},
436
- }, nil , ed .Timestamp )
425
+ }, nil , altChainPayloads [ n ] .Timestamp )
437
426
t .Logf ("INFO (%s): Response from main client fcu: %v" , t .TestName , s .Response .PayloadStatus )
438
427
439
428
if r .Status .Status == test .Invalid {
440
429
// We also expect that the client properly returns the LatestValidHash of the block on the
441
430
// side chain that is immediately prior to the invalid payload (or zero if parent is PoW)
442
431
var lvh common.Hash
443
- if cAHeight . Cmp ( big0 ) != 0 || tc .InvalidIndex != 1 {
432
+ if cAHeight != 0 || tc .InvalidIndex != 1 {
444
433
// Parent is NOT Proof of Work
445
- lvh = altChainPayloads [tc .InvalidIndex - 1 ].Hash ()
434
+ lvh = altChainPayloads [tc .InvalidIndex - 1 ].BlockHash
446
435
}
447
436
r .ExpectLatestValidHash (& lvh )
448
437
// Response on ForkchoiceUpdated should be the same
0 commit comments