@@ -54,15 +54,19 @@ func init() {
54
54
os .Exit (0 )
55
55
}
56
56
57
+ // canonical block at LondonBlock height
57
58
mockBlock = mocks .MockBlock
58
59
txs , rcts := mocks .MockBlock .Transactions (), mocks .MockReceipts
59
60
61
+ // non-canonical block at LondonBlock height
60
62
mockNonCanonicalBlock = mocks .MockNonCanonicalBlock
61
63
nonCanonicalBlockRcts := mocks .MockNonCanonicalBlockReceipts
62
64
65
+ // non-canonical block at LondonBlock height + 1
63
66
mockNonCanonicalBlock2 = mocks .MockNonCanonicalBlock2
64
67
nonCanonicalBlock2Rcts := mocks .MockNonCanonicalBlock2Receipts
65
68
69
+ // encode mock receipts
66
70
buf := new (bytes.Buffer )
67
71
txs .EncodeIndex (0 , buf )
68
72
tx1 = make ([]byte , buf .Len ())
@@ -114,6 +118,7 @@ func init() {
114
118
copy (rct5 , buf .Bytes ())
115
119
buf .Reset ()
116
120
121
+ // encode mock receipts for non-canonical blocks
117
122
nonCanonicalBlockRcts .EncodeIndex (0 , buf )
118
123
nonCanonicalBlockRct1 = make ([]byte , buf .Len ())
119
124
copy (nonCanonicalBlockRct1 , buf .Bytes ())
@@ -146,6 +151,7 @@ func init() {
146
151
state2CID , _ = ipld .RawdataToCid (ipld .MEthStateTrie , mocks .AccountLeafNode , multihash .KECCAK_256 )
147
152
storageCID , _ = ipld .RawdataToCid (ipld .MEthStorageTrie , mocks .StorageLeafNode , multihash .KECCAK_256 )
148
153
154
+ // create raw receipts
149
155
rawRctLeafNodes , rctleafNodeCids := createRctTrie ([][]byte {rct1 , rct2 , rct3 , rct4 , rct5 })
150
156
151
157
rct1CID = rctleafNodeCids [0 ]
@@ -160,6 +166,7 @@ func init() {
160
166
rctLeaf4 = rawRctLeafNodes [3 ]
161
167
rctLeaf5 = rawRctLeafNodes [4 ]
162
168
169
+ // create raw receipts for non-canonical blocks
163
170
nonCanonicalBlockRawRctLeafNodes , nonCanonicalBlockRctLeafNodeCids := createRctTrie ([][]byte {nonCanonicalBlockRct1 , nonCanonicalBlockRct2 })
164
171
165
172
nonCanonicalBlockRct1CID = nonCanonicalBlockRctLeafNodeCids [0 ]
@@ -191,6 +198,8 @@ func init() {
191
198
watchedAt3 = uint64 (20 )
192
199
}
193
200
201
+ // createRctTrie creates a receipt trie from the given raw receipts
202
+ // returns receipt leaf nodes and their CIDs
194
203
func createRctTrie (rcts [][]byte ) ([][]byte , []cid.Cid ) {
195
204
receiptTrie := ipld .NewRctTrie ()
196
205
@@ -213,6 +222,7 @@ func createRctTrie(rcts [][]byte) ([][]byte, []cid.Cid) {
213
222
return orderedRctLeafNodes , rctleafNodeCids
214
223
}
215
224
225
+ // createRctModel creates a models.ReceiptModel object from a given ethereum receipt
216
226
func createRctModel (rct * types.Receipt , cid cid.Cid , blockNumber string ) models.ReceiptModel {
217
227
rctModel := models.ReceiptModel {
218
228
BlockNumber : blockNumber ,
@@ -256,6 +266,7 @@ func tearDown(t *testing.T) {
256
266
require .NoError (t , err )
257
267
}
258
268
269
+ // setupTestData indexes a single mock block along with it's state nodes
259
270
func setupTestData (t * testing.T ) {
260
271
var tx interfaces.Batch
261
272
tx , err = ind .PushBlock (
@@ -278,9 +289,12 @@ func setupTestData(t *testing.T) {
278
289
require .Equal (t , mocks .BlockNumber .String (), tx .(* sql.BatchTx ).BlockNumber )
279
290
}
280
291
292
+ // setupTestData indexes a mock block and a non-canonical mock block at London height
293
+ // and a non-canonical block at London height + 1
294
+ // along with their state nodes
281
295
func setupTestDataNonCanonical (t * testing.T ) {
296
+ // index a canonical block at London height
282
297
var tx1 interfaces.Batch
283
-
284
298
tx1 , err = ind .PushBlock (
285
299
mockBlock ,
286
300
mocks .MockReceipts ,
@@ -298,6 +312,8 @@ func setupTestDataNonCanonical(t *testing.T) {
298
312
t .Fatal (err )
299
313
}
300
314
315
+ // index a non-canonical block at London height
316
+ // has transactions overlapping with that of the canonical block
301
317
var tx2 interfaces.Batch
302
318
tx2 , err = ind .PushBlock (
303
319
mockNonCanonicalBlock ,
@@ -316,6 +332,8 @@ func setupTestDataNonCanonical(t *testing.T) {
316
332
t .Fatal (err )
317
333
}
318
334
335
+ // index a non-canonical block at London height + 1
336
+ // has transactions overlapping with that of the canonical block
319
337
var tx3 interfaces.Batch
320
338
tx3 , err = ind .PushBlock (
321
339
mockNonCanonicalBlock2 ,
@@ -347,6 +365,9 @@ func testPublishAndIndexHeaderNonCanonical(t *testing.T) {
347
365
t .Fatal (err )
348
366
}
349
367
368
+ // expect three blocks to be indexed
369
+ // a canonical and a non-canonical block at London height,
370
+ // non-canonical block at London height + 1
350
371
expectedRes := []models.HeaderModel {
351
372
{
352
373
BlockNumber : mockBlock .Number ().String (),
@@ -426,6 +447,7 @@ func testPublishAndIndexTransactionsNonCanonical(t *testing.T) {
426
447
t .Fatal (err )
427
448
}
428
449
450
+ // expected transactions in the canonical block
429
451
mockBlockTxs := mocks .MockBlock .Transactions ()
430
452
expectedBlockTxs := []models.TxModel {
431
453
{
@@ -490,6 +512,7 @@ func testPublishAndIndexTransactionsNonCanonical(t *testing.T) {
490
512
},
491
513
}
492
514
515
+ // expected transactions in the canonical block at London height
493
516
mockNonCanonicalBlockTxs := mockNonCanonicalBlock .Transactions ()
494
517
expectedNonCanonicalBlockTxs := []models.TxModel {
495
518
{
@@ -518,6 +541,7 @@ func testPublishAndIndexTransactionsNonCanonical(t *testing.T) {
518
541
},
519
542
}
520
543
544
+ // expected transactions in the canonical block at London height + 1
521
545
mockNonCanonicalBlock2Txs := mockNonCanonicalBlock2 .Transactions ()
522
546
expectedNonCanonicalBlock2Txs := []models.TxModel {
523
547
{
@@ -598,20 +622,23 @@ func testPublishAndIndexReceiptsNonCanonical(t *testing.T) {
598
622
t .Fatal (err )
599
623
}
600
624
625
+ // expected receipts in the canonical block
601
626
rctCids := []cid.Cid {rct1CID , rct2CID , rct3CID , rct4CID , rct5CID }
602
627
expectedBlockRctsMap := make (map [string ]models.ReceiptModel , len (mocks .MockReceipts ))
603
628
for i , mockBlockRct := range mocks .MockReceipts {
604
629
rctModel := createRctModel (mockBlockRct , rctCids [i ], mockBlock .Number ().String ())
605
630
expectedBlockRctsMap [rctCids [i ].String ()] = rctModel
606
631
}
607
632
633
+ // expected receipts in the canonical block at London height + 1
608
634
nonCanonicalBlockRctCids := []cid.Cid {nonCanonicalBlockRct1CID , nonCanonicalBlockRct2CID }
609
635
expectedNonCanonicalBlockRctsMap := make (map [string ]models.ReceiptModel , len (mocks .MockNonCanonicalBlockReceipts ))
610
636
for i , mockNonCanonicalBlockRct := range mocks .MockNonCanonicalBlockReceipts {
611
637
rctModel := createRctModel (mockNonCanonicalBlockRct , nonCanonicalBlockRctCids [i ], mockNonCanonicalBlock .Number ().String ())
612
638
expectedNonCanonicalBlockRctsMap [nonCanonicalBlockRctCids [i ].String ()] = rctModel
613
639
}
614
640
641
+ // expected receipts in the canonical block at London height + 1
615
642
nonCanonicalBlock2RctCids := []cid.Cid {nonCanonicalBlock2Rct1CID , nonCanonicalBlock2Rct2CID }
616
643
expectedNonCanonicalBlock2RctsMap := make (map [string ]models.ReceiptModel , len (mocks .MockNonCanonicalBlock2Receipts ))
617
644
for i , mockNonCanonicalBlock2Rct := range mocks .MockNonCanonicalBlock2Receipts {
@@ -695,6 +722,7 @@ func testPublishAndIndexLogsNonCanonical(t *testing.T) {
695
722
}
696
723
mockRcts := make ([]rctWithBlockHash , 0 )
697
724
725
+ // logs in the canonical block
698
726
for _ , mockBlockRct := range mocks .MockReceipts {
699
727
mockRcts = append (mockRcts , rctWithBlockHash {
700
728
mockBlockRct ,
@@ -703,6 +731,7 @@ func testPublishAndIndexLogsNonCanonical(t *testing.T) {
703
731
})
704
732
}
705
733
734
+ // logs in the canonical block at London height + 1
706
735
for _ , mockBlockRct := range mocks .MockNonCanonicalBlockReceipts {
707
736
mockRcts = append (mockRcts , rctWithBlockHash {
708
737
mockBlockRct ,
@@ -711,6 +740,7 @@ func testPublishAndIndexLogsNonCanonical(t *testing.T) {
711
740
})
712
741
}
713
742
743
+ // logs in the canonical block at London height + 1
714
744
for _ , mockBlockRct := range mocks .MockNonCanonicalBlock2Receipts {
715
745
mockRcts = append (mockRcts , rctWithBlockHash {
716
746
mockBlockRct ,
@@ -776,6 +806,7 @@ func testPublishAndIndexStateNonCanonical(t *testing.T) {
776
806
removedNodeCID , _ := cid .Decode (shared .RemovedNodeStateCID )
777
807
stateNodeCIDs := []cid.Cid {state1CID , state2CID , removedNodeCID , removedNodeCID }
778
808
809
+ // expected state nodes in the canonical and the non-canonical block at London height
779
810
expectedStateNodes := make ([]models.StateNodeModel , 0 )
780
811
for i , stateDiff := range mocks .StateDiffs {
781
812
expectedStateNodes = append (expectedStateNodes , models.StateNodeModel {
@@ -795,6 +826,7 @@ func testPublishAndIndexStateNonCanonical(t *testing.T) {
795
826
}
796
827
})
797
828
829
+ // expected state nodes in the non-canonical block at London height + 1
798
830
expectedNonCanonicalBlock2StateNodes := make ([]models.StateNodeModel , 0 )
799
831
for i , stateDiff := range mocks .StateDiffs [:2 ] {
800
832
expectedNonCanonicalBlock2StateNodes = append (expectedNonCanonicalBlock2StateNodes , models.StateNodeModel {
@@ -819,7 +851,7 @@ func testPublishAndIndexStateNonCanonical(t *testing.T) {
819
851
require .Equal (t , expectedStateNode , stateNodes [i ])
820
852
}
821
853
822
- // check state nodes for non-canonical block
854
+ // check state nodes for non-canonical block at London height
823
855
stateNodes = make ([]models.StateNodeModel , 0 )
824
856
err = db .Select (context .Background (), & stateNodes , pgStr , mocks .BlockNumber .Uint64 (), mockNonCanonicalBlock .Hash ().String ())
825
857
if err != nil {
@@ -831,7 +863,7 @@ func testPublishAndIndexStateNonCanonical(t *testing.T) {
831
863
require .Equal (t , expectedStateNode , stateNodes [i ])
832
864
}
833
865
834
- // check state nodes for non-canonical block at another height
866
+ // check state nodes for non-canonical block at London height + 1
835
867
stateNodes = make ([]models.StateNodeModel , 0 )
836
868
err = db .Select (context .Background (), & stateNodes , pgStr , mocks .Block2Number .Uint64 (), mockNonCanonicalBlock2 .Hash ().String ())
837
869
if err != nil {
@@ -855,6 +887,7 @@ func testPublishAndIndexStorageNonCanonical(t *testing.T) {
855
887
removedNodeCID , _ := cid .Decode (shared .RemovedNodeStorageCID )
856
888
storageNodeCIDs := []cid.Cid {storageCID , removedNodeCID , removedNodeCID , removedNodeCID }
857
889
890
+ // expected state nodes in the canonical and the non-canonical block at London height
858
891
expectedStorageNodes := make ([]models.StorageNodeModel , 0 )
859
892
storageNodeIndex := 0
860
893
for _ , stateDiff := range mocks .StateDiffs {
@@ -879,6 +912,7 @@ func testPublishAndIndexStorageNonCanonical(t *testing.T) {
879
912
}
880
913
})
881
914
915
+ // expected state nodes in the non-canonical block at London height + 1
882
916
expectedNonCanonicalBlock2StorageNodes := make ([]models.StorageNodeModel , 0 )
883
917
storageNodeIndex = 0
884
918
for _ , stateDiff := range mocks .StateDiffs [:2 ] {
@@ -908,7 +942,7 @@ func testPublishAndIndexStorageNonCanonical(t *testing.T) {
908
942
require .Equal (t , expectedStorageNode , storageNodes [i ])
909
943
}
910
944
911
- // check storage nodes for non-canonical block
945
+ // check storage nodes for non-canonical block at London height
912
946
storageNodes = make ([]models.StorageNodeModel , 0 )
913
947
err = db .Select (context .Background (), & storageNodes , pgStr , mocks .BlockNumber .Uint64 (), mockNonCanonicalBlock .Hash ().String ())
914
948
if err != nil {
@@ -920,7 +954,7 @@ func testPublishAndIndexStorageNonCanonical(t *testing.T) {
920
954
require .Equal (t , expectedStorageNode , storageNodes [i ])
921
955
}
922
956
923
- // check storage nodes for non-canonical block at another height
957
+ // check storage nodes for non-canonical block at London height + 1
924
958
storageNodes = make ([]models.StorageNodeModel , 0 )
925
959
err = db .Select (context .Background (), & storageNodes , pgStr , mockNonCanonicalBlock2 .NumberU64 (), mockNonCanonicalBlock2 .Hash ().String ())
926
960
if err != nil {
0 commit comments