Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
ccfd332c
Unverified
Commit
ccfd332c
authored
Oct 19, 2023
by
Hamdi Allam
Committed by
GitHub
Oct 19, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7748 from ethereum-optimism/indexer.event.ordering
fix(indexer) bridge event correlation
parents
04f5105c
f6d49f0e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
108 additions
and
41 deletions
+108
-41
cli.go
indexer/cmd/indexer/cli.go
+7
-4
contract_events.go
indexer/database/contract_events.go
+2
-2
bytes.go
indexer/database/serializers/bytes.go
+2
-1
rlp.go
indexer/database/serializers/rlp.go
+2
-1
l1_bridge_processor.go
indexer/processors/bridge/l1_bridge_processor.go
+26
-10
l2_bridge_processor.go
indexer/processors/bridge/l2_bridge_processor.go
+20
-4
legacy_bridge_processor.go
indexer/processors/bridge/legacy_bridge_processor.go
+31
-15
metrics.go
indexer/processors/bridge/metrics.go
+18
-4
No files found.
indexer/cmd/indexer/cli.go
View file @
ccfd332c
...
...
@@ -30,6 +30,8 @@ var (
func
runIndexer
(
ctx
*
cli
.
Context
)
error
{
log
:=
oplog
.
NewLogger
(
oplog
.
AppOut
(
ctx
),
oplog
.
ReadCLIConfig
(
ctx
))
.
New
(
"role"
,
"indexer"
)
oplog
.
SetGlobalLogHandler
(
log
.
GetHandler
())
log
.
Info
(
"running indexer..."
)
cfg
,
err
:=
config
.
LoadConfig
(
log
,
ctx
.
String
(
ConfigFlag
.
Name
))
if
err
!=
nil
{
log
.
Error
(
"failed to load config"
,
"err"
,
err
)
...
...
@@ -49,13 +51,14 @@ func runIndexer(ctx *cli.Context) error {
return
err
}
log
.
Info
(
"running indexer..."
)
return
indexer
.
Run
(
ctx
.
Context
)
}
func
runApi
(
ctx
*
cli
.
Context
)
error
{
log
:=
oplog
.
NewLogger
(
oplog
.
AppOut
(
ctx
),
oplog
.
ReadCLIConfig
(
ctx
))
.
New
(
"role"
,
"api"
)
oplog
.
SetGlobalLogHandler
(
log
.
GetHandler
())
log
.
Info
(
"running api..."
)
cfg
,
err
:=
config
.
LoadConfig
(
log
,
ctx
.
String
(
ConfigFlag
.
Name
))
if
err
!=
nil
{
log
.
Error
(
"failed to load config"
,
"err"
,
err
)
...
...
@@ -69,7 +72,6 @@ func runApi(ctx *cli.Context) error {
}
defer
db
.
Close
()
log
.
Info
(
"running api..."
)
api
:=
api
.
NewApi
(
log
,
db
.
BridgeTransfers
,
cfg
.
HTTPServer
,
cfg
.
MetricsServer
)
return
api
.
Run
(
ctx
.
Context
)
}
...
...
@@ -77,6 +79,8 @@ func runApi(ctx *cli.Context) error {
func
runMigrations
(
ctx
*
cli
.
Context
)
error
{
log
:=
oplog
.
NewLogger
(
oplog
.
AppOut
(
ctx
),
oplog
.
ReadCLIConfig
(
ctx
))
.
New
(
"role"
,
"migrations"
)
oplog
.
SetGlobalLogHandler
(
log
.
GetHandler
())
log
.
Info
(
"running migrations..."
)
cfg
,
err
:=
config
.
LoadConfig
(
log
,
ctx
.
String
(
ConfigFlag
.
Name
))
migrationsDir
:=
ctx
.
String
(
MigrationsFlag
.
Name
)
if
err
!=
nil
{
...
...
@@ -89,9 +93,8 @@ func runMigrations(ctx *cli.Context) error {
log
.
Error
(
"failed to connect to database"
,
"err"
,
err
)
return
err
}
defer
db
.
Close
()
log
.
Info
(
"running migrations..."
)
defer
db
.
Close
(
)
return
db
.
ExecuteSQLMigration
(
migrationsDir
)
}
...
...
indexer/database/contract_events.go
View file @
ccfd332c
...
...
@@ -144,7 +144,7 @@ func (db *contractEventsDB) L1ContractEventsWithFilter(filter ContractEvent, fro
query
:=
db
.
gorm
.
Table
(
"l1_contract_events"
)
.
Where
(
&
filter
)
query
=
query
.
Joins
(
"INNER JOIN l1_block_headers ON l1_contract_events.block_hash = l1_block_headers.hash"
)
query
=
query
.
Where
(
"l1_block_headers.number >= ? AND l1_block_headers.number <= ?"
,
fromHeight
,
toHeight
)
query
=
query
.
Order
(
"l1_block_headers.number ASC"
)
.
Select
(
"l1_contract_events.*"
)
query
=
query
.
Order
(
"l1_block_headers.number ASC
, l1_contract_events.log_index ASC
"
)
.
Select
(
"l1_contract_events.*"
)
// NOTE: We use `Find` here instead of `Scan` since `Scan` doesn't not support
// model hooks like `ContractEvent#AfterFind`. Functionally they are the same
...
...
@@ -211,7 +211,7 @@ func (db *contractEventsDB) L2ContractEventsWithFilter(filter ContractEvent, fro
query
:=
db
.
gorm
.
Table
(
"l2_contract_events"
)
.
Where
(
&
filter
)
query
=
query
.
Joins
(
"INNER JOIN l2_block_headers ON l2_contract_events.block_hash = l2_block_headers.hash"
)
query
=
query
.
Where
(
"l2_block_headers.number >= ? AND l2_block_headers.number <= ?"
,
fromHeight
,
toHeight
)
query
=
query
.
Order
(
"l2_block_headers.number ASC"
)
.
Select
(
"l2_contract_events.*"
)
query
=
query
.
Order
(
"l2_block_headers.number ASC
, l2_contract_events.log_index ASC
"
)
.
Select
(
"l2_contract_events.*"
)
// NOTE: We use `Find` here instead of `Scan` since `Scan` doesn't not support
// model hooks like `ContractEvent#AfterFind`. Functionally they are the same
...
...
indexer/database/serializers/bytes.go
View file @
ccfd332c
...
...
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"reflect"
"strings"
"github.com/ethereum/go-ethereum/common/hexutil"
"gorm.io/gorm/schema"
...
...
@@ -70,5 +71,5 @@ func (BytesSerializer) Value(ctx context.Context, field *schema.Field, dst refle
}
hexStr
:=
hexutil
.
Encode
(
fieldBytes
.
Bytes
())
return
hexStr
,
nil
return
strings
.
ToLower
(
hexStr
)
,
nil
}
indexer/database/serializers/rlp.go
View file @
ccfd332c
...
...
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"reflect"
"strings"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rlp"
...
...
@@ -52,5 +53,5 @@ func (RLPSerializer) Value(ctx context.Context, field *schema.Field, dst reflect
}
hexStr
:=
hexutil
.
Encode
(
rlpBytes
)
return
hexStr
,
nil
return
strings
.
ToLower
(
hexStr
)
,
nil
}
indexer/processors/bridge/l1_bridge_processor.go
View file @
ccfd332c
...
...
@@ -28,11 +28,14 @@ func L1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
log
.
Info
(
"detected transaction deposits"
,
"size"
,
len
(
optimismPortalTxDeposits
))
}
mintedETH
:=
0
portalDeposits
:=
make
(
map
[
logKey
]
*
contracts
.
OptimismPortalTransactionDepositEvent
,
len
(
optimismPortalTxDeposits
))
transactionDeposits
:=
make
([]
database
.
L1TransactionDeposit
,
len
(
optimismPortalTxDeposits
))
for
i
:=
range
optimismPortalTxDeposits
{
depositTx
:=
optimismPortalTxDeposits
[
i
]
portalDeposits
[
logKey
{
depositTx
.
Event
.
BlockHash
,
depositTx
.
Event
.
LogIndex
}]
=
&
depositTx
mintedETH
=
mintedETH
+
int
(
depositTx
.
Tx
.
Amount
.
Uint64
())
transactionDeposits
[
i
]
=
database
.
L1TransactionDeposit
{
SourceHash
:
depositTx
.
DepositTx
.
SourceHash
,
L2TransactionHash
:
types
.
NewTx
(
depositTx
.
DepositTx
)
.
Hash
(),
...
...
@@ -45,7 +48,7 @@ func L1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
if
err
:=
db
.
BridgeTransactions
.
StoreL1TransactionDeposits
(
transactionDeposits
);
err
!=
nil
{
return
err
}
metrics
.
RecordL1TransactionDeposits
(
len
(
transactionDeposits
))
metrics
.
RecordL1TransactionDeposits
(
len
(
transactionDeposits
)
,
mintedETH
)
}
// (2) L1CrossDomainMessenger
...
...
@@ -68,6 +71,9 @@ func L1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
if
!
ok
{
log
.
Error
(
"expected TransactionDeposit preceding SentMessage event"
,
"tx_hash"
,
sentMessage
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected TransactionDeposit preceding SentMessage event. tx_hash = %s"
,
sentMessage
.
Event
.
TransactionHash
.
String
())
}
else
if
portalDeposit
.
Event
.
TransactionHash
!=
sentMessage
.
Event
.
TransactionHash
{
log
.
Error
(
"correlated events tx hash mismatch"
,
"deposit_tx_hash"
,
portalDeposit
.
Event
.
TransactionHash
.
String
(),
"message_tx_hash"
,
sentMessage
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"correlated events tx hash mismatch"
)
}
bridgeMessages
[
i
]
=
database
.
L1BridgeMessage
{
TransactionSourceHash
:
portalDeposit
.
DepositTx
.
SourceHash
,
BridgeMessage
:
sentMessage
.
BridgeMessage
}
...
...
@@ -98,15 +104,22 @@ func L1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
if
!
ok
{
log
.
Error
(
"expected TransactionDeposit following BridgeInitiated event"
,
"tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected TransactionDeposit following BridgeInitiated event. tx_hash = %s"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
}
else
if
portalDeposit
.
Event
.
TransactionHash
!=
initiatedBridge
.
Event
.
TransactionHash
{
log
.
Error
(
"correlated events tx hash mismatch"
,
"deposit_tx_hash"
,
portalDeposit
.
Event
.
TransactionHash
.
String
(),
"bridge_tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"correlated events tx hash mismatch"
)
}
sentMessage
,
ok
:=
sentMessages
[
logKey
{
initiatedBridge
.
Event
.
BlockHash
,
initiatedBridge
.
Event
.
LogIndex
+
2
}]
if
!
ok
{
log
.
Error
(
"expected SentMessage following TransactionDeposit event"
,
"tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected SentMessage following TransactionDeposit event. tx_hash = %s"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
log
.
Error
(
"expected SentMessage following BridgeInitiated event"
,
"tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected SentMessage following BridgeInitiated event. tx_hash = %s"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
}
else
if
sentMessage
.
Event
.
TransactionHash
!=
initiatedBridge
.
Event
.
TransactionHash
{
log
.
Error
(
"correlated events tx hash mismatch"
,
"message_tx_hash"
,
sentMessage
.
Event
.
TransactionHash
.
String
(),
"bridge_tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"correlated events tx hash mismatch"
)
}
initiatedBridge
.
BridgeTransfer
.
CrossDomainMessageHash
=
&
sentMessage
.
BridgeMessage
.
MessageHash
bridgedTokens
[
initiatedBridge
.
BridgeTransfer
.
TokenPair
.
LocalTokenAddress
]
++
initiatedBridge
.
BridgeTransfer
.
CrossDomainMessageHash
=
&
sentMessage
.
BridgeMessage
.
MessageHash
bridgeDeposits
[
i
]
=
database
.
L1BridgeDeposit
{
TransactionSourceHash
:
portalDeposit
.
DepositTx
.
SourceHash
,
BridgeTransfer
:
initiatedBridge
.
BridgeTransfer
,
...
...
@@ -168,17 +181,17 @@ func L1ProcessFinalizedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
}
for
i
:=
range
finalizedWithdrawals
{
finalized
:=
finalizedWithdrawals
[
i
]
withdrawal
,
err
:=
db
.
BridgeTransactions
.
L2TransactionWithdrawal
(
finalized
.
WithdrawalHash
)
finalized
Withdrawal
:=
finalizedWithdrawals
[
i
]
withdrawal
,
err
:=
db
.
BridgeTransactions
.
L2TransactionWithdrawal
(
finalized
Withdrawal
.
WithdrawalHash
)
if
err
!=
nil
{
return
err
}
else
if
withdrawal
==
nil
{
log
.
Error
(
"missing indexed withdrawal on finalization event!"
,
"tx_hash"
,
finalized
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"missing indexed withdrawal on finalization! tx_hash: %s"
,
finalized
.
Event
.
TransactionHash
.
String
())
log
.
Error
(
"missing indexed withdrawal on finalization event!"
,
"tx_hash"
,
finalized
Withdrawal
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"missing indexed withdrawal on finalization! tx_hash: %s"
,
finalized
Withdrawal
.
Event
.
TransactionHash
.
String
())
}
if
err
=
db
.
BridgeTransactions
.
MarkL2TransactionWithdrawalFinalizedEvent
(
finalized
.
WithdrawalHash
,
finalized
.
Event
.
GUID
,
finalized
.
Success
);
err
!=
nil
{
log
.
Error
(
"failed to mark withdrawal as finalized"
,
"err"
,
err
,
"tx_hash"
,
finalized
.
Event
.
TransactionHash
.
String
())
if
err
=
db
.
BridgeTransactions
.
MarkL2TransactionWithdrawalFinalizedEvent
(
finalized
Withdrawal
.
WithdrawalHash
,
finalizedWithdrawal
.
Event
.
GUID
,
finalizedWithdrawal
.
Success
);
err
!=
nil
{
log
.
Error
(
"failed to mark withdrawal as finalized"
,
"err"
,
err
,
"tx_hash"
,
finalized
Withdrawal
.
Event
.
TransactionHash
.
String
())
return
err
}
}
...
...
@@ -234,6 +247,9 @@ func L1ProcessFinalizedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
if
!
ok
{
log
.
Error
(
"expected RelayedMessage following BridgeFinalized event"
,
"tx_hash"
,
finalizedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected RelayedMessage following BridgeFinalized event. tx_hash = %s"
,
finalizedBridge
.
Event
.
TransactionHash
.
String
())
}
else
if
relayedMessage
.
Event
.
TransactionHash
!=
finalizedBridge
.
Event
.
TransactionHash
{
log
.
Error
(
"correlated events tx hash mismatch"
,
"message_tx_hash"
,
relayedMessage
.
Event
.
TransactionHash
.
String
(),
"bridge_tx_hash"
,
finalizedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"correlated events tx hash mismatch"
)
}
// Since the message hash is computed from the relayed message, this ensures the deposit fields must match
...
...
indexer/processors/bridge/l2_bridge_processor.go
View file @
ccfd332c
...
...
@@ -28,11 +28,14 @@ func L2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L2M
log
.
Info
(
"detected transaction withdrawals"
,
"size"
,
len
(
l2ToL1MPMessagesPassed
))
}
withdrawnETH
:=
0
messagesPassed
:=
make
(
map
[
logKey
]
*
contracts
.
L2ToL1MessagePasserMessagePassed
,
len
(
l2ToL1MPMessagesPassed
))
transactionWithdrawals
:=
make
([]
database
.
L2TransactionWithdrawal
,
len
(
l2ToL1MPMessagesPassed
))
for
i
:=
range
l2ToL1MPMessagesPassed
{
messagePassed
:=
l2ToL1MPMessagesPassed
[
i
]
messagesPassed
[
logKey
{
messagePassed
.
Event
.
BlockHash
,
messagePassed
.
Event
.
LogIndex
}]
=
&
messagePassed
withdrawnETH
=
withdrawnETH
+
int
(
messagePassed
.
Tx
.
Amount
.
Int64
())
transactionWithdrawals
[
i
]
=
database
.
L2TransactionWithdrawal
{
WithdrawalHash
:
messagePassed
.
WithdrawalHash
,
InitiatedL2EventGUID
:
messagePassed
.
Event
.
GUID
,
...
...
@@ -45,7 +48,7 @@ func L2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L2M
if
err
:=
db
.
BridgeTransactions
.
StoreL2TransactionWithdrawals
(
transactionWithdrawals
);
err
!=
nil
{
return
err
}
metrics
.
RecordL2TransactionWithdrawals
(
len
(
transactionWithdrawals
))
metrics
.
RecordL2TransactionWithdrawals
(
len
(
transactionWithdrawals
)
,
withdrawnETH
)
}
// (2) L2CrossDomainMessenger
...
...
@@ -68,6 +71,9 @@ func L2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L2M
if
!
ok
{
log
.
Error
(
"expected MessagePassedEvent preceding SentMessage"
,
"tx_hash"
,
sentMessage
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected MessagePassedEvent preceding SentMessage. tx_hash = %s"
,
sentMessage
.
Event
.
TransactionHash
.
String
())
}
else
if
messagePassed
.
Event
.
TransactionHash
!=
sentMessage
.
Event
.
TransactionHash
{
log
.
Error
(
"correlated events tx hash mismatch"
,
"withdraw_tx_hash"
,
messagePassed
.
Event
.
TransactionHash
.
String
(),
"message_tx_hash"
,
sentMessage
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"correlated events tx hash mismatch"
)
}
bridgeMessages
[
i
]
=
database
.
L2BridgeMessage
{
TransactionWithdrawalHash
:
messagePassed
.
WithdrawalHash
,
BridgeMessage
:
sentMessage
.
BridgeMessage
}
...
...
@@ -93,16 +99,23 @@ func L2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L2M
for
i
:=
range
initiatedBridges
{
initiatedBridge
:=
initiatedBridges
[
i
]
// extract the cross domain message hash &
deposit source
hash from the following events
// extract the cross domain message hash &
withdraw
hash from the following events
messagePassed
,
ok
:=
messagesPassed
[
logKey
{
initiatedBridge
.
Event
.
BlockHash
,
initiatedBridge
.
Event
.
LogIndex
+
1
}]
if
!
ok
{
log
.
Error
(
"expected MessagePassed following BridgeInitiated event"
,
"tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected MessagePassed following BridgeInitiated event. tx_hash = %s"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
}
else
if
messagePassed
.
Event
.
TransactionHash
!=
initiatedBridge
.
Event
.
TransactionHash
{
log
.
Error
(
"correlated events tx hash mismatch"
,
"withdraw_tx_hash"
,
messagePassed
.
Event
.
TransactionHash
.
String
(),
"bridge_tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"correlated events tx hash mismatch"
)
}
sentMessage
,
ok
:=
sentMessages
[
logKey
{
initiatedBridge
.
Event
.
BlockHash
,
initiatedBridge
.
Event
.
LogIndex
+
2
}]
if
!
ok
{
log
.
Error
(
"expected SentMessage following MessagePassed event"
,
"tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected SentMessage following MessagePassed event. tx_hash = %s"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
log
.
Error
(
"expected SentMessage following BridgeInitiated event"
,
"tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected SentMessage following BridgeInitiated event. tx_hash = %s"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
}
else
if
sentMessage
.
Event
.
TransactionHash
!=
initiatedBridge
.
Event
.
TransactionHash
{
log
.
Error
(
"correlated events tx hash mismatch"
,
"message_tx_hash"
,
sentMessage
.
Event
.
TransactionHash
.
String
(),
"bridge_tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"correlated events tx hash mismatch"
)
}
initiatedBridge
.
BridgeTransfer
.
CrossDomainMessageHash
=
&
sentMessage
.
BridgeMessage
.
MessageHash
...
...
@@ -180,6 +193,9 @@ func L2ProcessFinalizedBridgeEvents(log log.Logger, db *database.DB, metrics L2M
if
!
ok
{
log
.
Error
(
"expected RelayedMessage following BridgeFinalized event"
,
"tx_hash"
,
finalizedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected RelayedMessage following BridgeFinalized event. tx_hash = %s"
,
finalizedBridge
.
Event
.
TransactionHash
.
String
())
}
else
if
relayedMessage
.
Event
.
TransactionHash
!=
finalizedBridge
.
Event
.
TransactionHash
{
log
.
Error
(
"correlated events tx hash mismatch"
,
"message_tx_hash"
,
relayedMessage
.
Event
.
TransactionHash
.
String
(),
"bridge_tx_hash"
,
finalizedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"correlated events tx hash mismatch"
)
}
// Since the message hash is computed from the relayed message, this ensures the withdrawal fields must match
...
...
indexer/processors/bridge/legacy_bridge_processor.go
View file @
ccfd332c
...
...
@@ -31,17 +31,18 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
log
.
Info
(
"detected legacy transaction deposits"
,
"size"
,
len
(
ctcTxDepositEvents
))
}
mintedETH
:=
0
ctcTxDeposits
:=
make
(
map
[
logKey
]
*
contracts
.
LegacyCTCDepositEvent
,
len
(
ctcTxDepositEvents
))
transactionDeposits
:=
make
([]
database
.
L1TransactionDeposit
,
len
(
ctcTxDepositEvents
))
for
i
:=
range
ctcTxDepositEvents
{
deposit
:=
ctcTxDepositEvents
[
i
]
ctcTxDeposits
[
logKey
{
deposit
.
Event
.
BlockHash
,
deposit
.
Event
.
LogIndex
}]
=
&
deposit
transactionDeposits
[
i
]
=
database
.
L1TransactionDeposit
{
// We re-use the L2 Transaction hash as the source hash
// to remain consistent in the schema.
SourceHash
:
deposit
.
TxHash
,
L2TransactionHash
:
deposit
.
TxHash
,
mintedETH
=
mintedETH
+
int
(
deposit
.
Tx
.
Amount
.
Uint64
())
transactionDeposits
[
i
]
=
database
.
L1TransactionDeposit
{
// We re-use the L2 Transaction hash as the source hash to remain consistent in the schema.
SourceHash
:
deposit
.
TxHash
,
L2TransactionHash
:
deposit
.
TxHash
,
InitiatedL1EventGUID
:
deposit
.
Event
.
GUID
,
GasLimit
:
deposit
.
GasLimit
,
Tx
:
deposit
.
Tx
,
...
...
@@ -51,7 +52,7 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
if
err
:=
db
.
BridgeTransactions
.
StoreL1TransactionDeposits
(
transactionDeposits
);
err
!=
nil
{
return
err
}
metrics
.
RecordL1TransactionDeposits
(
len
(
transactionDeposits
))
metrics
.
RecordL1TransactionDeposits
(
len
(
transactionDeposits
)
,
mintedETH
)
}
// (2) L1CrossDomainMessenger
...
...
@@ -72,8 +73,11 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
// extract the deposit hash from the previous TransactionDepositedEvent
ctcTxDeposit
,
ok
:=
ctcTxDeposits
[
logKey
{
sentMessage
.
Event
.
BlockHash
,
sentMessage
.
Event
.
LogIndex
-
1
}]
if
!
ok
{
log
.
Error
(
"missing transaction deposit for cross domain message"
,
"tx_hash"
,
sentMessage
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"missing preceding TransactionEnqueued for SentMessage event. tx_hash = %s"
,
sentMessage
.
Event
.
TransactionHash
.
String
())
log
.
Error
(
"expected TransactionEnqueued preceding SentMessage event"
,
"tx_hash"
,
sentMessage
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected TransactionEnqueued preceding SentMessage event. tx_hash = %s"
,
sentMessage
.
Event
.
TransactionHash
.
String
())
}
else
if
ctcTxDeposit
.
Event
.
TransactionHash
!=
sentMessage
.
Event
.
TransactionHash
{
log
.
Error
(
"correlated events tx hash mismatch"
,
"deposit_tx_hash"
,
ctcTxDeposit
.
Event
.
TransactionHash
.
String
(),
"message_tx_hash"
,
sentMessage
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"correlated events tx hash mismatch"
)
}
bridgeMessages
[
i
]
=
database
.
L1BridgeMessage
{
TransactionSourceHash
:
ctcTxDeposit
.
TxHash
,
BridgeMessage
:
sentMessage
.
BridgeMessage
}
...
...
@@ -104,13 +108,20 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
// - Event Flow: TransactionEnqueued -> SentMessage -> DepositInitiated
sentMessage
,
ok
:=
sentMessages
[
logKey
{
initiatedBridge
.
Event
.
BlockHash
,
initiatedBridge
.
Event
.
LogIndex
-
1
}]
if
!
ok
{
log
.
Error
(
"
missing cross domain message for bridge transfer"
,
"tx_hash"
,
initiatedBrid
ge
.
Event
.
TransactionHash
.
String
())
log
.
Error
(
"
expected SentMessage preceding BridgeInitiated event"
,
"tx_hash"
,
sentMessa
ge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected SentMessage preceding DepositInitiated event. tx_hash = %s"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
}
else
if
sentMessage
.
Event
.
TransactionHash
!=
initiatedBridge
.
Event
.
TransactionHash
{
log
.
Error
(
"correlated events tx hash mismatch"
,
"message_tx_hash"
,
sentMessage
.
Event
.
TransactionHash
.
String
(),
"bridge_tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"correlated events tx hash mismatch"
)
}
ctcTxDeposit
,
ok
:=
ctcTxDeposits
[
logKey
{
initiatedBridge
.
Event
.
BlockHash
,
initiatedBridge
.
Event
.
LogIndex
-
2
}]
if
!
ok
{
log
.
Error
(
"missing transaction deposit for bridge transfer"
,
"tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected TransactionEnqueued preceding DepostInitiated event. tx_hash = %s"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
log
.
Error
(
"expected TransactionEnqueued preceding BridgeInitiated event"
,
"tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected TransactionEnqueued preceding BridgeInitiated event. tx_hash = %s"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
}
else
if
ctcTxDeposit
.
Event
.
TransactionHash
!=
initiatedBridge
.
Event
.
TransactionHash
{
log
.
Error
(
"correlated events tx hash mismatch"
,
"deposit_tx_hash"
,
ctcTxDeposit
.
Event
.
TransactionHash
.
String
(),
"bridge_tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"correlated events tx hash mismatch"
)
}
initiatedBridge
.
BridgeTransfer
.
CrossDomainMessageHash
=
&
sentMessage
.
BridgeMessage
.
MessageHash
...
...
@@ -148,12 +159,14 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
log
.
Info
(
"detected legacy transaction withdrawals (via L2CrossDomainMessenger)"
,
"size"
,
len
(
crossDomainSentMessages
))
}
withdrawnETH
:=
0
sentMessages
:=
make
(
map
[
logKey
]
*
contracts
.
CrossDomainMessengerSentMessageEvent
,
len
(
crossDomainSentMessages
))
bridgeMessages
:=
make
([]
database
.
L2BridgeMessage
,
len
(
crossDomainSentMessages
))
transactionWithdrawals
:=
make
([]
database
.
L2TransactionWithdrawal
,
len
(
crossDomainSentMessages
))
for
i
:=
range
crossDomainSentMessages
{
sentMessage
:=
crossDomainSentMessages
[
i
]
sentMessages
[
logKey
{
sentMessage
.
Event
.
BlockHash
,
sentMessage
.
Event
.
LogIndex
}]
=
&
sentMessage
withdrawnETH
=
withdrawnETH
+
int
(
sentMessage
.
BridgeMessage
.
Tx
.
Amount
.
Int64
())
// To ensure consistency in the schema, we duplicate this as the "root" transaction withdrawal. The storage key in the message
// passer contract is sha3(calldata + sender). The sender always being the L2CrossDomainMessenger pre-bedrock.
...
...
@@ -184,7 +197,7 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
if
err
:=
db
.
BridgeMessages
.
StoreL2BridgeMessages
(
bridgeMessages
);
err
!=
nil
{
return
err
}
metrics
.
RecordL2TransactionWithdrawals
(
len
(
transactionWithdrawals
))
metrics
.
RecordL2TransactionWithdrawals
(
len
(
transactionWithdrawals
)
,
withdrawnETH
)
metrics
.
RecordL2CrossDomainSentMessages
(
len
(
bridgeMessages
))
}
...
...
@@ -207,12 +220,15 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
// - Event Flow: TransactionEnqueued -> SentMessage -> DepositInitiated
sentMessage
,
ok
:=
sentMessages
[
logKey
{
initiatedBridge
.
Event
.
BlockHash
,
initiatedBridge
.
Event
.
LogIndex
-
1
}]
if
!
ok
{
log
.
Error
(
"expected SentMessage preceding DepositInitiated event"
,
"tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected SentMessage preceding DepositInitiated event. tx_hash = %s"
,
initiatedBridge
.
Event
.
TransactionHash
)
log
.
Error
(
"expected SentMessage preceding BridgeInitiated event"
,
"tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"expected SentMessage preceding BridgeInitiated event. tx_hash = %s"
,
initiatedBridge
.
Event
.
TransactionHash
)
}
else
if
sentMessage
.
Event
.
TransactionHash
!=
initiatedBridge
.
Event
.
TransactionHash
{
log
.
Error
(
"correlated events tx hash mismatch"
,
"message_tx_hash"
,
sentMessage
.
Event
.
TransactionHash
.
String
(),
"bridge_tx_hash"
,
initiatedBridge
.
Event
.
TransactionHash
.
String
())
return
fmt
.
Errorf
(
"correlated events tx hash mismatch"
)
}
initiatedBridge
.
BridgeTransfer
.
CrossDomainMessageHash
=
&
sentMessage
.
BridgeMessage
.
MessageHash
bridgedTokens
[
initiatedBridge
.
BridgeTransfer
.
TokenPair
.
LocalTokenAddress
]
++
initiatedBridge
.
BridgeTransfer
.
CrossDomainMessageHash
=
&
sentMessage
.
BridgeMessage
.
MessageHash
l2BridgeWithdrawals
[
i
]
=
database
.
L2BridgeWithdrawal
{
TransactionWithdrawalHash
:
sentMessage
.
BridgeMessage
.
MessageHash
,
BridgeTransfer
:
initiatedBridge
.
BridgeTransfer
,
...
...
indexer/processors/bridge/metrics.go
View file @
ccfd332c
...
...
@@ -16,7 +16,7 @@ var (
type
L1Metricer
interface
{
RecordLatestIndexedL1Height
(
height
*
big
.
Int
)
RecordL1TransactionDeposits
(
size
int
)
RecordL1TransactionDeposits
(
size
int
,
mintedETH
int
)
RecordL1ProvenWithdrawals
(
size
int
)
RecordL1FinalizedWithdrawals
(
size
int
)
...
...
@@ -30,7 +30,7 @@ type L1Metricer interface {
type
L2Metricer
interface
{
RecordLatestIndexedL2Height
(
height
*
big
.
Int
)
RecordL2TransactionWithdrawals
(
size
int
)
RecordL2TransactionWithdrawals
(
size
int
,
withdrawnETH
int
)
RecordL2CrossDomainSentMessages
(
size
int
)
RecordL2CrossDomainRelayedMessages
(
size
int
)
...
...
@@ -55,7 +55,9 @@ type bridgeMetrics struct {
latestL2Height
prometheus
.
Gauge
txDeposits
prometheus
.
Counter
txMintedETH
prometheus
.
Counter
txWithdrawals
prometheus
.
Counter
txWithdrawnETH
prometheus
.
Counter
provenWithdrawals
prometheus
.
Counter
finalizedWithdrawals
prometheus
.
Counter
...
...
@@ -101,11 +103,21 @@ func NewMetrics(registry *prometheus.Registry) Metricer {
Name
:
"tx_deposits"
,
Help
:
"number of processed transactions deposited from l1"
,
}),
txMintedETH
:
factory
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
MetricsNamespace
,
Name
:
"tx_minted_eth"
,
Help
:
"amount of eth bridged from l1"
,
}),
txWithdrawals
:
factory
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
MetricsNamespace
,
Name
:
"tx_withdrawals"
,
Help
:
"number of processed transactions withdrawn from l2"
,
}),
txWithdrawnETH
:
factory
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
MetricsNamespace
,
Name
:
"tx_withdrawn_eth"
,
Help
:
"amount of eth withdrawn from l2"
,
}),
provenWithdrawals
:
factory
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
MetricsNamespace
,
Name
:
"proven_withdrawals"
,
...
...
@@ -166,8 +178,9 @@ func (m *bridgeMetrics) RecordLatestIndexedL1Height(height *big.Int) {
m
.
latestL1Height
.
Set
(
float64
(
height
.
Uint64
()))
}
func
(
m
*
bridgeMetrics
)
RecordL1TransactionDeposits
(
size
int
)
{
func
(
m
*
bridgeMetrics
)
RecordL1TransactionDeposits
(
size
,
mintedETH
int
)
{
m
.
txDeposits
.
Add
(
float64
(
size
))
m
.
txMintedETH
.
Add
(
float64
(
mintedETH
))
}
func
(
m
*
bridgeMetrics
)
RecordL1ProvenWithdrawals
(
size
int
)
{
...
...
@@ -200,8 +213,9 @@ func (m *bridgeMetrics) RecordLatestIndexedL2Height(height *big.Int) {
m
.
latestL2Height
.
Set
(
float64
(
height
.
Uint64
()))
}
func
(
m
*
bridgeMetrics
)
RecordL2TransactionWithdrawals
(
size
int
)
{
func
(
m
*
bridgeMetrics
)
RecordL2TransactionWithdrawals
(
size
,
withdrawnETH
int
)
{
m
.
txWithdrawals
.
Add
(
float64
(
size
))
m
.
txWithdrawnETH
.
Add
(
float64
(
withdrawnETH
))
}
func
(
m
*
bridgeMetrics
)
RecordL2CrossDomainSentMessages
(
size
int
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment