Skip to content

Commit be44caa

Browse files
committed
fix event watcher
1 parent 4281ecb commit be44caa

File tree

2 files changed

+19
-43
lines changed

2 files changed

+19
-43
lines changed

bridge/abi/bridge_abi.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ const (
2323
// CommitBatchEventSignature = keccak256("CommitBatch(bytes32)")
2424
CommitBatchEventSignature = "2cdc615c74452778c0fb6184735e014c13aad2b62774fe0b09bd1dcc2cc14a62"
2525

26-
// CommitBatchesEventSignature = keccak256("CommitBatches(bytes32)")
27-
CommitBatchesEventSignature = "188adc06d38d0173d973ad47531a02ad89cd941508eab21b3d41f3bb41bf9eb9"
28-
2926
// FinalizedBatchEventSignature = keccak256("FinalizeBatch(bytes32)")
3027
FinalizedBatchEventSignature = "6be443154c959a7a1645b4392b6fa97d8e8ab6e8fd853d7085e8867083737d79"
3128
)

bridge/l1/watcher.go

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ type relayedMessage struct {
3333
}
3434

3535
type rollupEvent struct {
36-
batchID common.Hash
37-
txHash common.Hash
38-
status types.RollupStatus
36+
batchHash common.Hash
37+
txHash common.Hash
38+
status types.RollupStatus
3939
}
4040

4141
// Watcher will listen for smart contract events from Eth L1.
@@ -222,8 +222,7 @@ func (w *Watcher) FetchContractEvent(blockHeight uint64) error {
222222
query.Topics[0][1] = common.HexToHash(bridge_abi.RelayedMessageEventSignature)
223223
query.Topics[0][2] = common.HexToHash(bridge_abi.FailedRelayedMessageEventSignature)
224224
query.Topics[0][3] = common.HexToHash(bridge_abi.CommitBatchEventSignature)
225-
query.Topics[0][4] = common.HexToHash(bridge_abi.CommitBatchesEventSignature)
226-
query.Topics[0][5] = common.HexToHash(bridge_abi.FinalizedBatchEventSignature)
225+
query.Topics[0][4] = common.HexToHash(bridge_abi.FinalizedBatchEventSignature)
227226

228227
logs, err := w.client.FilterLogs(w.ctx, query)
229228
if err != nil {
@@ -245,22 +244,22 @@ func (w *Watcher) FetchContractEvent(blockHeight uint64) error {
245244
log.Info("L1 events types", "SentMessageCount", len(sentMessageEvents), "RelayedMessageCount", len(relayedMessageEvents), "RollupEventCount", len(rollupEvents))
246245

247246
// use rollup event to update rollup results db status
248-
var batchIDs []string
247+
var batchHashes []string
249248
for _, event := range rollupEvents {
250-
batchIDs = append(batchIDs, event.batchID.String())
249+
batchHashes = append(batchHashes, event.batchHash.String())
251250
}
252-
statuses, err := w.db.GetRollupStatusByIDList(batchIDs)
251+
statuses, err := w.db.GetRollupStatusByIDList(batchHashes)
253252
if err != nil {
254253
log.Error("Failed to GetRollupStatusByIDList", "err", err)
255254
return err
256255
}
257-
if len(statuses) != len(batchIDs) {
258-
log.Error("RollupStatus.Length mismatch with BatchIDs.Length", "RollupStatus.Length", len(statuses), "BatchIDs.Length", len(batchIDs))
256+
if len(statuses) != len(batchHashes) {
257+
log.Error("RollupStatus.Length mismatch with batchHashes.Length", "RollupStatus.Length", len(statuses), "batchHashes.Length", len(batchHashes))
259258
return nil
260259
}
261260

262261
for index, event := range rollupEvents {
263-
batchID := event.batchID.String()
262+
batchID := event.batchHash.String()
264263
status := statuses[index]
265264
// only update when db status is before event status
266265
if event.status > status {
@@ -366,57 +365,37 @@ func (w *Watcher) parseBridgeEventLogs(logs []geth_types.Log) ([]*types.L1Messag
366365
})
367366
case common.HexToHash(bridge_abi.CommitBatchEventSignature):
368367
event := struct {
369-
BatchID common.Hash
370368
BatchHash common.Hash
371369
}{}
372370
// BatchID is in topics[1]
373-
event.BatchID = common.HexToHash(vLog.Topics[1].String())
371+
event.BatchHash = common.HexToHash(vLog.Topics[1].String())
374372
err := w.scrollchainABI.UnpackIntoInterface(&event, "CommitBatch", vLog.Data)
375373
if err != nil {
376374
log.Warn("Failed to unpack layer1 CommitBatch event", "err", err)
377375
return l1Messages, relayedMessages, rollupEvents, err
378376
}
379377

380378
rollupEvents = append(rollupEvents, rollupEvent{
381-
batchID: event.BatchID,
382-
txHash: vLog.TxHash,
383-
status: types.RollupCommitted,
384-
})
385-
case common.HexToHash(bridge_abi.CommitBatchesEventSignature):
386-
event := struct {
387-
BatchID common.Hash
388-
BatchHash common.Hash
389-
}{}
390-
// BatchID is in topics[1]
391-
event.BatchID = common.HexToHash(vLog.Topics[1].String())
392-
err := w.scrollchainABI.UnpackIntoInterface(&event, "CommitBatches", vLog.Data)
393-
if err != nil {
394-
log.Warn("Failed to unpack layer1 CommitBatches event", "err", err)
395-
return l1Messages, relayedMessages, rollupEvents, err
396-
}
397-
398-
rollupEvents = append(rollupEvents, rollupEvent{
399-
batchID: event.BatchID,
400-
txHash: vLog.TxHash,
401-
status: types.RollupCommitted,
379+
batchHash: event.BatchHash,
380+
txHash: vLog.TxHash,
381+
status: types.RollupCommitted,
402382
})
403383
case common.HexToHash(bridge_abi.FinalizedBatchEventSignature):
404384
event := struct {
405-
BatchID common.Hash
406385
BatchHash common.Hash
407386
}{}
408-
// BatchID is in topics[1]
409-
event.BatchID = common.HexToHash(vLog.Topics[1].String())
387+
// BatchHash is in topics[1]
388+
event.BatchHash = common.HexToHash(vLog.Topics[1].String())
410389
err := w.scrollchainABI.UnpackIntoInterface(&event, "FinalizeBatch", vLog.Data)
411390
if err != nil {
412391
log.Warn("Failed to unpack layer1 FinalizeBatch event", "err", err)
413392
return l1Messages, relayedMessages, rollupEvents, err
414393
}
415394

416395
rollupEvents = append(rollupEvents, rollupEvent{
417-
batchID: event.BatchID,
418-
txHash: vLog.TxHash,
419-
status: types.RollupFinalized,
396+
batchHash: event.BatchHash,
397+
txHash: vLog.TxHash,
398+
status: types.RollupFinalized,
420399
})
421400
default:
422401
log.Error("Unknown event", "topic", vLog.Topics[0], "txHash", vLog.TxHash)

0 commit comments

Comments
 (0)