From e6c39664c66c36a913d21950dec6302e6df6b566 Mon Sep 17 00:00:00 2001 From: Hamdi Allam Date: Mon, 27 Nov 2023 16:40:04 -0500 Subject: [PATCH 1/3] fix --- indexer/database/bridge_messages.go | 12 ++++-------- .../bridge/legacy_bridge_processor.go | 17 +++++++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/indexer/database/bridge_messages.go b/indexer/database/bridge_messages.go index 91c0bf41b509..60a7ab86c644 100644 --- a/indexer/database/bridge_messages.go +++ b/indexer/database/bridge_messages.go @@ -61,7 +61,7 @@ type BridgeMessagesDB interface { StoreL2BridgeMessages([]L2BridgeMessage) error MarkRelayedL2BridgeMessage(common.Hash, uuid.UUID) error - StoreL2BridgeMessageV1MessageHash(common.Hash, common.Hash) error + StoreL2BridgeMessageV1MessageHashes([]L2BridgeMessageVersionedMessageHash) error } /** @@ -141,14 +141,10 @@ func (db bridgeMessagesDB) StoreL2BridgeMessages(messages []L2BridgeMessage) err return result.Error } -func (db bridgeMessagesDB) StoreL2BridgeMessageV1MessageHash(msgHash, v1MsgHash common.Hash) error { - if msgHash == v1MsgHash { - return fmt.Errorf("message hash is equal to the v1 message: %s", msgHash) - } - +func (db bridgeMessagesDB) StoreL2BridgeMessageV1MessageHashes(versionedHashes []L2BridgeMessageVersionedMessageHash) error { deduped := db.gorm.Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "message_hash"}}, DoNothing: true}) - result := deduped.Create(&L2BridgeMessageVersionedMessageHash{MessageHash: msgHash, V1MessageHash: v1MsgHash}) - if result.Error == nil && int(result.RowsAffected) < 1 { + result := deduped.Create(&versionedHashes) + if result.Error == nil && int(result.RowsAffected) < len(versionedHashes) { db.log.Warn("ignored L2 bridge v1 message hash duplicates") } diff --git a/indexer/processors/bridge/legacy_bridge_processor.go b/indexer/processors/bridge/legacy_bridge_processor.go index 14e10ed093e9..c409ce23bb5b 100644 --- a/indexer/processors/bridge/legacy_bridge_processor.go +++ b/indexer/processors/bridge/legacy_bridge_processor.go @@ -166,6 +166,7 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri withdrawnWEI := bigint.Zero sentMessages := make(map[logKey]sentMessageEvent, len(crossDomainSentMessages)) bridgeMessages := make([]database.L2BridgeMessage, len(crossDomainSentMessages)) + versionedMessageHashes := make([]database.L2BridgeMessageVersionedMessageHash, len(sentMessages)) transactionWithdrawals := make([]database.L2TransactionWithdrawal, len(crossDomainSentMessages)) for i := range crossDomainSentMessages { sentMessage := crossDomainSentMessages[i] @@ -173,15 +174,14 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri // Since these message can be relayed in bedrock, we utilize the migrated withdrawal hash // and also store the v1 version of the message hash such that the bedrock l1 finalization - // processor works as expected + // processor works as expected. There will be some entries relayed pre-bedrock that will not + // require the entry but we'll store it anyways as a large % of these withdrawals are not relayed + // pre-bedrock. v1MessageHash, err := legacyBridgeMessageV1MessageHash(&sentMessage.BridgeMessage) if err != nil { return fmt.Errorf("failed to compute versioned message hash: %w", err) } - if err := db.BridgeMessages.StoreL2BridgeMessageV1MessageHash(sentMessage.BridgeMessage.MessageHash, v1MessageHash); err != nil { - return err - } withdrawalHash, err := legacyBridgeMessageWithdrawalHash(preset, &sentMessage.BridgeMessage) if err != nil { @@ -203,10 +203,8 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri } sentMessages[logKey{sentMessage.Event.BlockHash, sentMessage.Event.LogIndex}] = sentMessageEvent{&sentMessage, withdrawalHash} - bridgeMessages[i] = database.L2BridgeMessage{ - TransactionWithdrawalHash: sentMessage.BridgeMessage.MessageHash, - BridgeMessage: sentMessage.BridgeMessage, - } + bridgeMessages[i] = database.L2BridgeMessage{TransactionWithdrawalHash: sentMessage.BridgeMessage.MessageHash, BridgeMessage: sentMessage.BridgeMessage} + versionedMessageHashes[i] = database.L2BridgeMessageVersionedMessageHash{MessageHash: sentMessage.BridgeMessage.MessageHash, V1MessageHash: v1MessageHash} } if len(bridgeMessages) > 0 { if err := db.BridgeTransactions.StoreL2TransactionWithdrawals(transactionWithdrawals); err != nil { @@ -215,6 +213,9 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri if err := db.BridgeMessages.StoreL2BridgeMessages(bridgeMessages); err != nil { return err } + if err := db.BridgeMessages.StoreL2BridgeMessageV1MessageHashes(versionedMessageHashes); err != nil { + return err + } withdrawnETH, _ := bigint.WeiToETH(withdrawnWEI).Float64() metrics.RecordL2TransactionWithdrawals(len(transactionWithdrawals), withdrawnETH) From ddace70908634425ef344aa5be804d7c22067455 Mon Sep 17 00:00:00 2001 From: Hamdi Allam Date: Mon, 27 Nov 2023 16:44:55 -0500 Subject: [PATCH 2/3] nit --- indexer/database/bridge_messages.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indexer/database/bridge_messages.go b/indexer/database/bridge_messages.go index 60a7ab86c644..7a126635d84d 100644 --- a/indexer/database/bridge_messages.go +++ b/indexer/database/bridge_messages.go @@ -145,7 +145,7 @@ func (db bridgeMessagesDB) StoreL2BridgeMessageV1MessageHashes(versionedHashes [ deduped := db.gorm.Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "message_hash"}}, DoNothing: true}) result := deduped.Create(&versionedHashes) if result.Error == nil && int(result.RowsAffected) < len(versionedHashes) { - db.log.Warn("ignored L2 bridge v1 message hash duplicates") + db.log.Warn("ignored L2 bridge v1 message hash duplicates", "duplicates", len(versionedHashes)-int(result.RowsAffected)) } return result.Error From 17ba90a24ec0491ff0b0889903a2f11afc34d3ce Mon Sep 17 00:00:00 2001 From: Hamdi Allam Date: Mon, 27 Nov 2023 16:48:11 -0500 Subject: [PATCH 3/3] nit --- indexer/processors/bridge/legacy_bridge_processor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indexer/processors/bridge/legacy_bridge_processor.go b/indexer/processors/bridge/legacy_bridge_processor.go index c409ce23bb5b..ec3084e3b733 100644 --- a/indexer/processors/bridge/legacy_bridge_processor.go +++ b/indexer/processors/bridge/legacy_bridge_processor.go @@ -203,7 +203,7 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri } sentMessages[logKey{sentMessage.Event.BlockHash, sentMessage.Event.LogIndex}] = sentMessageEvent{&sentMessage, withdrawalHash} - bridgeMessages[i] = database.L2BridgeMessage{TransactionWithdrawalHash: sentMessage.BridgeMessage.MessageHash, BridgeMessage: sentMessage.BridgeMessage} + bridgeMessages[i] = database.L2BridgeMessage{TransactionWithdrawalHash: withdrawalHash, BridgeMessage: sentMessage.BridgeMessage} versionedMessageHashes[i] = database.L2BridgeMessageVersionedMessageHash{MessageHash: sentMessage.BridgeMessage.MessageHash, V1MessageHash: v1MessageHash} } if len(bridgeMessages) > 0 {