@@ -816,6 +816,151 @@ func TestValidateBatchCodecV7(t *testing.T) {
816
816
}, finalizedBatchMeta4 )
817
817
}
818
818
819
+ func TestValidateBatchCodecV8 (t * testing.T ) {
820
+ codecV8 := encoding .NewDACodecV8 ()
821
+
822
+ var finalizedBatchMeta1 * rawdb.FinalizedBatchMeta
823
+ var committedBatchMeta1 * rawdb.CommittedBatchMeta
824
+ {
825
+ block1 := replaceBlockNumber (readBlockFromJSON (t , "./testdata/blockTrace_02.json" ), 1 )
826
+ batch1 := & encoding.Batch {
827
+ Index : 1 ,
828
+ PrevL1MessageQueueHash : common.Hash {},
829
+ PostL1MessageQueueHash : common.Hash {},
830
+ Blocks : []* encoding.Block {block1 },
831
+ }
832
+ batch1LastBlock := batch1 .Blocks [len (batch1 .Blocks )- 1 ]
833
+
834
+ daBatch1 , err := codecV8 .NewDABatch (batch1 )
835
+ require .NoError (t , err )
836
+
837
+ event1 := l1 .NewFinalizeBatchEvent (
838
+ new (big.Int ).SetUint64 (batch1 .Index ),
839
+ daBatch1 .Hash (),
840
+ batch1LastBlock .Header .Root ,
841
+ batch1LastBlock .WithdrawRoot ,
842
+ common .HexToHash ("0x1" ),
843
+ common .HexToHash ("0x1" ),
844
+ 1 ,
845
+ )
846
+
847
+ committedBatchMeta1 = & rawdb.CommittedBatchMeta {
848
+ Version : uint8 (encoding .CodecV8 ),
849
+ PostL1MessageQueueHash : common.Hash {},
850
+ }
851
+
852
+ var endBlock1 uint64
853
+ endBlock1 , finalizedBatchMeta1 , err = validateBatch (event1 .BatchIndex ().Uint64 (), event1 , & rawdb.FinalizedBatchMeta {}, & rawdb.CommittedBatchMeta {}, committedBatchMeta1 , []* encoding.Chunk {{Blocks : batch1 .Blocks }}, nil )
854
+ require .NoError (t , err )
855
+ require .EqualValues (t , 1 , endBlock1 )
856
+ require .Equal (t , & rawdb.FinalizedBatchMeta {
857
+ BatchHash : daBatch1 .Hash (),
858
+ TotalL1MessagePopped : 0 ,
859
+ StateRoot : batch1LastBlock .Header .Root ,
860
+ WithdrawRoot : batch1LastBlock .WithdrawRoot ,
861
+ }, finalizedBatchMeta1 )
862
+ }
863
+
864
+ // finalize 3 batches with CodecV8 at once
865
+ block2 := replaceBlockNumber (readBlockFromJSON (t , "./testdata/blockTrace_03.json" ), 2 )
866
+ batch2 := & encoding.Batch {
867
+ Index : 2 ,
868
+ ParentBatchHash : finalizedBatchMeta1 .BatchHash ,
869
+ PrevL1MessageQueueHash : common.Hash {},
870
+ PostL1MessageQueueHash : common.Hash {},
871
+ Blocks : []* encoding.Block {block2 },
872
+ }
873
+ batch2LastBlock := batch2 .Blocks [len (batch2 .Blocks )- 1 ]
874
+
875
+ daBatch2 , err := codecV8 .NewDABatch (batch2 )
876
+ require .NoError (t , err )
877
+
878
+ block3 := replaceBlockNumber (readBlockFromJSON (t , "./testdata/blockTrace_06.json" ), 3 )
879
+ LastL1MessageQueueHashBatch3 , err := encoding .MessageQueueV2ApplyL1MessagesFromBlocks (common.Hash {}, []* encoding.Block {block3 })
880
+ require .NoError (t , err )
881
+ batch3 := & encoding.Batch {
882
+ Index : 3 ,
883
+ ParentBatchHash : daBatch2 .Hash (),
884
+ PrevL1MessageQueueHash : common.Hash {},
885
+ PostL1MessageQueueHash : LastL1MessageQueueHashBatch3 ,
886
+ Blocks : []* encoding.Block {block3 },
887
+ }
888
+ batch3LastBlock := batch3 .Blocks [len (batch3 .Blocks )- 1 ]
889
+
890
+ daBatch3 , err := codecV8 .NewDABatch (batch3 )
891
+ require .NoError (t , err )
892
+
893
+ block4 := replaceBlockNumber (readBlockFromJSON (t , "./testdata/blockTrace_07.json" ), 4 )
894
+ LastL1MessageQueueHashBatch4 , err := encoding .MessageQueueV2ApplyL1MessagesFromBlocks (LastL1MessageQueueHashBatch3 , []* encoding.Block {block4 })
895
+ require .NoError (t , err )
896
+ batch4 := & encoding.Batch {
897
+ Index : 4 ,
898
+ ParentBatchHash : daBatch3 .Hash (),
899
+ PrevL1MessageQueueHash : LastL1MessageQueueHashBatch3 ,
900
+ PostL1MessageQueueHash : LastL1MessageQueueHashBatch4 ,
901
+ Blocks : []* encoding.Block {block4 },
902
+ }
903
+ batch4LastBlock := batch4 .Blocks [len (batch4 .Blocks )- 1 ]
904
+
905
+ daBatch4 , err := codecV8 .NewDABatch (batch4 )
906
+ require .NoError (t , err )
907
+
908
+ event2 := l1 .NewFinalizeBatchEvent (
909
+ new (big.Int ).SetUint64 (batch4 .Index ),
910
+ daBatch4 .Hash (),
911
+ batch4LastBlock .Header .Root ,
912
+ batch4LastBlock .WithdrawRoot ,
913
+ common .HexToHash ("0x1" ),
914
+ common .HexToHash ("0x1" ),
915
+ 1 ,
916
+ )
917
+
918
+ committedBatchMeta2 := & rawdb.CommittedBatchMeta {
919
+ Version : uint8 (encoding .CodecV8 ),
920
+ PostL1MessageQueueHash : common.Hash {},
921
+ }
922
+
923
+ committedBatchMeta3 := & rawdb.CommittedBatchMeta {
924
+ Version : uint8 (encoding .CodecV8 ),
925
+ PostL1MessageQueueHash : LastL1MessageQueueHashBatch3 ,
926
+ }
927
+
928
+ committedBatchMeta4 := & rawdb.CommittedBatchMeta {
929
+ Version : uint8 (encoding .CodecV8 ),
930
+ PostL1MessageQueueHash : LastL1MessageQueueHashBatch4 ,
931
+ }
932
+
933
+ endBlock2 , finalizedBatchMeta2 , err := validateBatch (2 , event2 , finalizedBatchMeta1 , committedBatchMeta1 , committedBatchMeta2 , []* encoding.Chunk {{Blocks : batch2 .Blocks }}, nil )
934
+ require .NoError (t , err )
935
+ require .EqualValues (t , 2 , endBlock2 )
936
+ require .Equal (t , & rawdb.FinalizedBatchMeta {
937
+ BatchHash : daBatch2 .Hash (),
938
+ TotalL1MessagePopped : 0 ,
939
+ StateRoot : batch2LastBlock .Header .Root ,
940
+ WithdrawRoot : batch2LastBlock .WithdrawRoot ,
941
+ }, finalizedBatchMeta2 )
942
+
943
+ endBlock3 , finalizedBatchMeta3 , err := validateBatch (3 , event2 , finalizedBatchMeta2 , committedBatchMeta2 , committedBatchMeta3 , []* encoding.Chunk {{Blocks : batch3 .Blocks }}, nil )
944
+ require .NoError (t , err )
945
+ require .EqualValues (t , 3 , endBlock3 )
946
+ require .Equal (t , & rawdb.FinalizedBatchMeta {
947
+ BatchHash : daBatch3 .Hash (),
948
+ TotalL1MessagePopped : 1 ,
949
+ StateRoot : batch3LastBlock .Header .Root ,
950
+ WithdrawRoot : batch3LastBlock .WithdrawRoot ,
951
+ }, finalizedBatchMeta3 )
952
+
953
+ endBlock4 , finalizedBatchMeta4 , err := validateBatch (4 , event2 , finalizedBatchMeta3 , committedBatchMeta3 , committedBatchMeta4 , []* encoding.Chunk {{Blocks : batch4 .Blocks }}, nil )
954
+ require .NoError (t , err )
955
+ require .EqualValues (t , 4 , endBlock4 )
956
+ require .Equal (t , & rawdb.FinalizedBatchMeta {
957
+ BatchHash : daBatch4 .Hash (),
958
+ TotalL1MessagePopped : 6 ,
959
+ StateRoot : batch4LastBlock .Header .Root ,
960
+ WithdrawRoot : batch4LastBlock .WithdrawRoot ,
961
+ }, finalizedBatchMeta4 )
962
+ }
963
+
819
964
func readBlockFromJSON (t * testing.T , filename string ) * encoding.Block {
820
965
data , err := os .ReadFile (filename )
821
966
assert .NoError (t , err )
0 commit comments