@@ -17,6 +17,7 @@ import (
17
17
"github.com/0xPolygonHermez/zkevm-node/etherman/ethgasstation"
18
18
"github.com/0xPolygonHermez/zkevm-node/etherman/metrics"
19
19
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/oldpolygonzkevm"
20
+ "github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/oldpolygonzkevmglobalexitroot"
20
21
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/pol"
21
22
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonrollupmanager"
22
23
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevm"
68
69
verifyBatchesSignatureHash = crypto .Keccak256Hash ([]byte ("VerifyBatches(uint64,bytes32,address)" )) // Used in oldZkEvm as well
69
70
sequenceForceBatchesSignatureHash = crypto .Keccak256Hash ([]byte ("SequenceForceBatches(uint64)" )) // Used in oldZkEvm as well
70
71
forceBatchSignatureHash = crypto .Keccak256Hash ([]byte ("ForceBatch(uint64,bytes32,address,bytes)" )) // Used in oldZkEvm as well
71
- sequenceBatchesSignatureHash = crypto .Keccak256Hash ([]byte ("SequenceBatches(uint64)" )) // Used in oldZkEvm as well
72
+ sequenceBatchesSignatureHash = crypto .Keccak256Hash ([]byte ("SequenceBatches(uint64,bytes32 )" )) // Used in oldZkEvm as well
72
73
initialSequenceBatchesSignatureHash = crypto .Keccak256Hash ([]byte ("InitialSequenceBatches(bytes,bytes32,address)" ))
73
74
74
75
// Extra RollupManager
@@ -79,16 +80,17 @@ var (
79
80
emergencyStateActivatedSignatureHash = crypto .Keccak256Hash ([]byte ("EmergencyStateActivated()" )) // EmergencyManager. Used in oldZkEvm as well
80
81
emergencyStateDeactivatedSignatureHash = crypto .Keccak256Hash ([]byte ("EmergencyStateDeactivated()" )) // EmergencyManager. Used in oldZkEvm as well
81
82
82
- // New Ger event
83
+ // New GER event Etrog
83
84
updateL1InfoTreeSignatureHash = crypto .Keccak256Hash ([]byte ("UpdateL1InfoTree(bytes32,bytes32)" ))
84
85
85
- // Old zkevm events
86
+ // PreLxLy events
86
87
updateGlobalExitRootSignatureHash = crypto .Keccak256Hash ([]byte ("UpdateGlobalExitRoot(bytes32,bytes32)" ))
87
88
oldVerifyBatchesTrustedAggregatorSignatureHash = crypto .Keccak256Hash ([]byte ("VerifyBatchesTrustedAggregator(uint64,bytes32,address)" ))
88
89
transferOwnershipSignatureHash = crypto .Keccak256Hash ([]byte ("OwnershipTransferred(address,address)" ))
89
90
updateZkEVMVersionSignatureHash = crypto .Keccak256Hash ([]byte ("UpdateZkEVMVersion(uint64,uint64,string)" ))
90
91
oldConsolidatePendingStateSignatureHash = crypto .Keccak256Hash ([]byte ("ConsolidatePendingState(uint64,bytes32,uint64)" ))
91
92
oldOverridePendingStateSignatureHash = crypto .Keccak256Hash ([]byte ("OverridePendingState(uint64,bytes32,address)" ))
93
+ sequenceBatchesPreEtrogSignatureHash = crypto .Keccak256Hash ([]byte ("SequenceBatches(uint64)" ))
92
94
93
95
// Proxy events
94
96
initializedProxySignatureHash = crypto .Keccak256Hash ([]byte ("Initialized(uint8)" ))
@@ -167,13 +169,14 @@ type externalGasProviders struct {
167
169
168
170
// Client is a simple implementation of EtherMan.
169
171
type Client struct {
170
- EthClient ethereumClient
171
- OldZkEVM * oldpolygonzkevm.Oldpolygonzkevm
172
- ZkEVM * polygonzkevm.Polygonzkevm
173
- RollupManager * polygonrollupmanager.Polygonrollupmanager
174
- GlobalExitRootManager * polygonzkevmglobalexitroot.Polygonzkevmglobalexitroot
175
- Pol * pol.Pol
176
- SCAddresses []common.Address
172
+ EthClient ethereumClient
173
+ OldZkEVM * oldpolygonzkevm.Oldpolygonzkevm
174
+ ZkEVM * polygonzkevm.Polygonzkevm
175
+ RollupManager * polygonrollupmanager.Polygonrollupmanager
176
+ GlobalExitRootManager * polygonzkevmglobalexitroot.Polygonzkevmglobalexitroot
177
+ OldGlobalExitRootManager * oldpolygonzkevmglobalexitroot.Oldpolygonzkevmglobalexitroot
178
+ Pol * pol.Pol
179
+ SCAddresses []common.Address
177
180
178
181
RollupID uint32
179
182
@@ -453,6 +456,8 @@ func (etherMan *Client) processEvent(ctx context.Context, vLog types.Log, blocks
453
456
switch vLog .Topics [0 ] {
454
457
case sequenceBatchesSignatureHash :
455
458
return etherMan .sequencedBatchesEvent (ctx , vLog , blocks , blocksOrder )
459
+ case sequenceBatchesPreEtrogSignatureHash :
460
+ return etherMan .sequencedBatchesPreEtrogEvent (ctx , vLog , blocks , blocksOrder )
456
461
case updateGlobalExitRootSignatureHash :
457
462
return etherMan .updateGlobalExitRootEvent (ctx , vLog , blocks , blocksOrder )
458
463
case updateL1InfoTreeSignatureHash :
@@ -649,17 +654,17 @@ func (etherMan *Client) updateForkId(ctx context.Context, vLog types.Log, blocks
649
654
}
650
655
651
656
func (etherMan * Client ) updateL1InfoTreeEvent (ctx context.Context , vLog types.Log , blocks * []Block , blocksOrder * map [common.Hash ][]Order ) error {
652
- log .Debug ("updateL1InfoTree event detected" )
653
- var err error
654
- //TODO: Check that this way os unpacking parameters are right
655
- MainnetExitRoot := vLog . Topics [ 1 ]
656
- RollupExitRoot := vLog . Topics [ 2 ]
657
-
658
- var gExitRoot L1InfoTree
659
- gExitRoot .MainnetExitRoot = MainnetExitRoot
660
- gExitRoot .RollupExitRoot = RollupExitRoot
657
+ log .Debug ("UpdateL1InfoTree event detected" )
658
+ globalExitRootL1InfoTree , err := etherMan . GlobalExitRootManager . ParseUpdateL1InfoTree ( vLog )
659
+ if err != nil {
660
+ return err
661
+ }
662
+
663
+ var gExitRoot GlobalExitRoot
664
+ gExitRoot .MainnetExitRoot = globalExitRootL1InfoTree . MainnetExitRoot
665
+ gExitRoot .RollupExitRoot = globalExitRootL1InfoTree . RollupExitRoot
661
666
gExitRoot .BlockNumber = vLog .BlockNumber
662
- gExitRoot .GlobalExitRoot . GlobalExitRoot = hash (MainnetExitRoot , RollupExitRoot )
667
+ gExitRoot .GlobalExitRoot = hash (globalExitRootL1InfoTree . MainnetExitRoot , globalExitRootL1InfoTree . RollupExitRoot )
663
668
var block * Block
664
669
if ! isheadBlockInArray (blocks , vLog .BlockHash , vLog .BlockNumber ) {
665
670
// Need to add the block, doesnt mind if inside the blocks because I have to respect the order so insert at end
@@ -672,7 +677,7 @@ func (etherMan *Client) updateL1InfoTreeEvent(ctx context.Context, vLog types.Lo
672
677
// Get the block in the HEAD of the array that contain the current block
673
678
block = & (* blocks )[len (* blocks )- 1 ]
674
679
gExitRoot .PreviousBlockHash = block .ParentHash
675
- gExitRoot .MinTimestamp = block .ReceivedAt
680
+ gExitRoot .Timestamp = block .ReceivedAt
676
681
// Add the event to the block
677
682
block .L1InfoTree = append (block .L1InfoTree , gExitRoot )
678
683
order := Order {
@@ -702,11 +707,11 @@ func isheadBlockInArray(blocks *[]Block, blockHash common.Hash, blockNumber uint
702
707
703
708
func (etherMan * Client ) updateGlobalExitRootEvent (ctx context.Context , vLog types.Log , blocks * []Block , blocksOrder * map [common.Hash ][]Order ) error {
704
709
log .Debug ("UpdateGlobalExitRoot event detected" )
705
- globalExitRoot , err := etherMan .GlobalExitRootManager .ParseUpdateGlobalExitRoot (vLog )
710
+ oldglobalExitRoot , err := etherMan .OldGlobalExitRootManager .ParseUpdateGlobalExitRoot (vLog )
706
711
if err != nil {
707
712
return err
708
713
}
709
- return etherMan .processUpdateGlobalExitRootEvent (ctx , globalExitRoot .MainnetExitRoot , globalExitRoot .RollupExitRoot , vLog , blocks , blocksOrder )
714
+ return etherMan .processUpdateGlobalExitRootEvent (ctx , oldglobalExitRoot .MainnetExitRoot , oldglobalExitRoot .RollupExitRoot , vLog , blocks , blocksOrder )
710
715
}
711
716
712
717
func (etherMan * Client ) processUpdateGlobalExitRootEvent (ctx context.Context , mainnetExitRoot , rollupExitRoot common.Hash , vLog types.Log , blocks * []Block , blocksOrder * map [common.Hash ][]Order ) error {
@@ -790,13 +795,13 @@ func (etherMan *Client) BuildSequenceBatchesTxData(sender common.Address, sequen
790
795
}
791
796
792
797
func (etherMan * Client ) sequenceBatches (opts bind.TransactOpts , sequences []ethmanTypes.Sequence , l2Coinbase common.Address ) (* types.Transaction , error ) {
793
- var batches []polygonzkevm.PolygonRollupBaseBatchData
798
+ var batches []polygonzkevm.PolygonRollupBaseEtrogBatchData
794
799
for _ , seq := range sequences {
795
- batch := polygonzkevm.PolygonRollupBaseBatchData {
796
- Transactions : seq .BatchL2Data ,
797
- GlobalExitRoot : seq .GlobalExitRoot ,
798
- Timestamp : uint64 (seq .Timestamp ),
799
- MinForcedTimestamp : uint64 ( seq .ForcedBatchTimestamp ) ,
800
+ batch := polygonzkevm.PolygonRollupBaseEtrogBatchData {
801
+ Transactions : seq .BatchL2Data ,
802
+ ForcedGlobalExitRoot : seq .GlobalExitRoot ,
803
+ ForcedTimestamp : uint64 (seq .ForcedBatchTimestamp ),
804
+ ForcedBlockHashL1 : seq .PrevBlockHash ,
800
805
}
801
806
802
807
batches = append (batches , batch )
@@ -1054,6 +1059,53 @@ func (etherMan *Client) sequencedBatchesEvent(ctx context.Context, vLog types.Lo
1054
1059
return nil
1055
1060
}
1056
1061
1062
+ func (etherMan * Client ) sequencedBatchesPreEtrogEvent (ctx context.Context , vLog types.Log , blocks * []Block , blocksOrder * map [common.Hash ][]Order ) error {
1063
+ log .Debug ("Pre etrog SequenceBatches event detected" )
1064
+ sb , err := etherMan .OldZkEVM .ParseSequenceBatches (vLog )
1065
+ if err != nil {
1066
+ return err
1067
+ }
1068
+
1069
+ // Read the tx for this event.
1070
+ tx , err := etherMan .EthClient .TransactionInBlock (ctx , vLog .BlockHash , vLog .TxIndex )
1071
+ if err != nil {
1072
+ return err
1073
+ }
1074
+ if tx .Hash () != vLog .TxHash {
1075
+ return fmt .Errorf ("error: tx hash mismatch. want: %s have: %s" , vLog .TxHash , tx .Hash ().String ())
1076
+ }
1077
+ msg , err := core .TransactionToMessage (tx , types .NewLondonSigner (tx .ChainId ()), big .NewInt (0 ))
1078
+ if err != nil {
1079
+ return err
1080
+ }
1081
+
1082
+ sequences , err := decodeSequencesPreEtrog (tx .Data (), sb .NumBatch , msg .From , vLog .TxHash , msg .Nonce )
1083
+ if err != nil {
1084
+ return fmt .Errorf ("error decoding the sequences: %v" , err )
1085
+ }
1086
+
1087
+ if len (* blocks ) == 0 || ((* blocks )[len (* blocks )- 1 ].BlockHash != vLog .BlockHash || (* blocks )[len (* blocks )- 1 ].BlockNumber != vLog .BlockNumber ) {
1088
+ fullBlock , err := etherMan .EthClient .BlockByHash (ctx , vLog .BlockHash )
1089
+ if err != nil {
1090
+ return fmt .Errorf ("error getting hashParent. BlockNumber: %d. Error: %w" , vLog .BlockNumber , err )
1091
+ }
1092
+ block := prepareBlock (vLog , time .Unix (int64 (fullBlock .Time ()), 0 ), fullBlock )
1093
+ block .SequencedBatches = append (block .SequencedBatches , sequences )
1094
+ * blocks = append (* blocks , block )
1095
+ } else if (* blocks )[len (* blocks )- 1 ].BlockHash == vLog .BlockHash && (* blocks )[len (* blocks )- 1 ].BlockNumber == vLog .BlockNumber {
1096
+ (* blocks )[len (* blocks )- 1 ].SequencedBatches = append ((* blocks )[len (* blocks )- 1 ].SequencedBatches , sequences )
1097
+ } else {
1098
+ log .Error ("Error processing SequencedBatches event. BlockHash:" , vLog .BlockHash , ". BlockNumber: " , vLog .BlockNumber )
1099
+ return fmt .Errorf ("error processing SequencedBatches event" )
1100
+ }
1101
+ or := Order {
1102
+ Name : SequenceBatchesOrder ,
1103
+ Pos : len ((* blocks )[len (* blocks )- 1 ].SequencedBatches ) - 1 ,
1104
+ }
1105
+ (* blocksOrder )[(* blocks )[len (* blocks )- 1 ].BlockHash ] = append ((* blocksOrder )[(* blocks )[len (* blocks )- 1 ].BlockHash ], or )
1106
+ return nil
1107
+ }
1108
+
1057
1109
func decodeSequences (txData []byte , lastBatchNumber uint64 , sequencer common.Address , txHash common.Hash , nonce uint64 ) ([]SequencedBatch , error ) {
1058
1110
// Extract coded txs.
1059
1111
// Load contract ABI
@@ -1073,7 +1125,52 @@ func decodeSequences(txData []byte, lastBatchNumber uint64, sequencer common.Add
1073
1125
if err != nil {
1074
1126
return nil , err
1075
1127
}
1076
- var sequences []polygonzkevm.PolygonRollupBaseBatchData
1128
+ var sequences []polygonzkevm.PolygonRollupBaseEtrogBatchData
1129
+ bytedata , err := json .Marshal (data [0 ])
1130
+ if err != nil {
1131
+ return nil , err
1132
+ }
1133
+ err = json .Unmarshal (bytedata , & sequences )
1134
+ if err != nil {
1135
+ return nil , err
1136
+ }
1137
+ coinbase := (data [1 ]).(common.Address )
1138
+ sequencedBatches := make ([]SequencedBatch , len (sequences ))
1139
+ for i , seq := range sequences {
1140
+ bn := lastBatchNumber - uint64 (len (sequences )- (i + 1 ))
1141
+ sequencedBatches [i ] = SequencedBatch {
1142
+ BatchNumber : bn ,
1143
+ SequencerAddr : sequencer ,
1144
+ TxHash : txHash ,
1145
+ Nonce : nonce ,
1146
+ Coinbase : coinbase ,
1147
+ PolygonRollupBaseEtrogBatchData : seq ,
1148
+ }
1149
+ }
1150
+
1151
+ return sequencedBatches , nil
1152
+ }
1153
+
1154
+ func decodeSequencesPreEtrog (txData []byte , lastBatchNumber uint64 , sequencer common.Address , txHash common.Hash , nonce uint64 ) ([]SequencedBatch , error ) {
1155
+ // Extract coded txs.
1156
+ // Load contract ABI
1157
+ smcAbi , err := abi .JSON (strings .NewReader (oldpolygonzkevm .OldpolygonzkevmABI ))
1158
+ if err != nil {
1159
+ return nil , err
1160
+ }
1161
+
1162
+ // Recover Method from signature and ABI
1163
+ method , err := smcAbi .MethodById (txData [:4 ])
1164
+ if err != nil {
1165
+ return nil , err
1166
+ }
1167
+
1168
+ // Unpack method inputs
1169
+ data , err := method .Inputs .Unpack (txData [4 :])
1170
+ if err != nil {
1171
+ return nil , err
1172
+ }
1173
+ var sequences []oldpolygonzkevm.PolygonZkEVMBatchData
1077
1174
bytedata , err := json .Marshal (data [0 ])
1078
1175
if err != nil {
1079
1176
return nil , err
@@ -1087,12 +1184,12 @@ func decodeSequences(txData []byte, lastBatchNumber uint64, sequencer common.Add
1087
1184
for i , seq := range sequences {
1088
1185
bn := lastBatchNumber - uint64 (len (sequences )- (i + 1 ))
1089
1186
sequencedBatches [i ] = SequencedBatch {
1090
- BatchNumber : bn ,
1091
- SequencerAddr : sequencer ,
1092
- TxHash : txHash ,
1093
- Nonce : nonce ,
1094
- Coinbase : coinbase ,
1095
- PolygonRollupBaseBatchData : seq ,
1187
+ BatchNumber : bn ,
1188
+ SequencerAddr : sequencer ,
1189
+ TxHash : txHash ,
1190
+ Nonce : nonce ,
1191
+ Coinbase : coinbase ,
1192
+ PolygonZkEVMBatchData : seq ,
1096
1193
}
1097
1194
}
1098
1195
@@ -1163,6 +1260,7 @@ func (etherMan *Client) forceSequencedBatchesEvent(ctx context.Context, vLog typ
1163
1260
if err != nil {
1164
1261
return err
1165
1262
}
1263
+ // TODO completar los datos de forcedBlockHas, forcedGer y forcedTimestamp
1166
1264
1167
1265
// Read the tx for this batch.
1168
1266
tx , err := etherMan .EthClient .TransactionInBlock (ctx , vLog .BlockHash , vLog .TxIndex )
@@ -1224,7 +1322,7 @@ func decodeSequencedForceBatches(txData []byte, lastBatchNumber uint64, sequence
1224
1322
return nil , err
1225
1323
}
1226
1324
1227
- var forceBatches []polygonzkevm.PolygonRollupBaseForcedBatchData
1325
+ var forceBatches []polygonzkevm.PolygonRollupBaseEtrogBatchData
1228
1326
bytedata , err := json .Marshal (data [0 ])
1229
1327
if err != nil {
1230
1328
return nil , err
@@ -1238,12 +1336,12 @@ func decodeSequencedForceBatches(txData []byte, lastBatchNumber uint64, sequence
1238
1336
for i , force := range forceBatches {
1239
1337
bn := lastBatchNumber - uint64 (len (forceBatches )- (i + 1 ))
1240
1338
sequencedForcedBatches [i ] = SequencedForceBatch {
1241
- BatchNumber : bn ,
1242
- Coinbase : sequencer ,
1243
- TxHash : txHash ,
1244
- Timestamp : time .Unix (int64 (block .Time ()), 0 ),
1245
- Nonce : nonce ,
1246
- PolygonRollupBaseForcedBatchData : force ,
1339
+ BatchNumber : bn ,
1340
+ Coinbase : sequencer ,
1341
+ TxHash : txHash ,
1342
+ Timestamp : time .Unix (int64 (block .Time ()), 0 ),
1343
+ Nonce : nonce ,
1344
+ PolygonRollupBaseEtrogBatchData : force ,
1247
1345
}
1248
1346
}
1249
1347
return sequencedForcedBatches , nil
@@ -1286,9 +1384,10 @@ func (etherMan *Client) EthBlockByNumber(ctx context.Context, blockNumber uint64
1286
1384
return block , nil
1287
1385
}
1288
1386
1289
- // GetLastBatchTimestamp function allows to retrieve the lastTimestamp value in the smc
1290
- func (etherMan * Client ) GetLastBatchTimestamp () (uint64 , error ) {
1291
- return etherMan .ZkEVM .LastTimestamp (& bind.CallOpts {Pending : false })
1387
+ // GetGapLastBatchTimestamp function allows to retrieve the gaplastTimestamp value in the smc
1388
+ // TODO: If nobody uses this function delete
1389
+ func (etherMan * Client ) GetGapLastBatchTimestamp () (uint64 , error ) {
1390
+ return etherMan .ZkEVM .GapLastTimestamp (& bind.CallOpts {Pending : false })
1292
1391
}
1293
1392
1294
1393
// GetLatestBatchNumber function allows to retrieve the latest proposed batch in the smc
0 commit comments