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
e3d1af10
Commit
e3d1af10
authored
Aug 15, 2023
by
Hamdi Allam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decouple finalization events from needing an rpc
parent
a0acfebf
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
143 deletions
+113
-143
bridge_transfers.go
indexer/database/bridge_transfers.go
+6
-1
bridge_transfers_e2e_test.go
indexer/e2e_tests/bridge_transfers_e2e_test.go
+14
-10
20230523_create_schema.sql
indexer/migrations/20230523_create_schema.sql
+6
-6
l1_processor.go
indexer/processor/l1_processor.go
+21
-24
l2_processor.go
indexer/processor/l2_processor.go
+19
-21
standard_bridge.go
indexer/processor/standard_bridge.go
+47
-81
No files found.
indexer/database/bridge_transfers.go
View file @
e3d1af10
...
@@ -5,9 +5,14 @@ import (
...
@@ -5,9 +5,14 @@ import (
"gorm.io/gorm"
"gorm.io/gorm"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
)
)
var
(
ETHTokenPair
=
TokenPair
{
L1TokenAddress
:
predeploys
.
LegacyERC20ETHAddr
,
L2TokenAddress
:
predeploys
.
LegacyERC20ETHAddr
}
)
/**
/**
* Types
* Types
*/
*/
...
@@ -18,7 +23,7 @@ type TokenPair struct {
...
@@ -18,7 +23,7 @@ type TokenPair struct {
}
}
type
BridgeTransfer
struct
{
type
BridgeTransfer
struct
{
CrossDomainMessageHash
*
common
.
Hash
CrossDomainMessageHash
*
common
.
Hash
`gorm:"serializer:json"`
Tx
Transaction
`gorm:"embedded"`
Tx
Transaction
`gorm:"embedded"`
TokenPair
TokenPair
`gorm:"embedded"`
TokenPair
TokenPair
`gorm:"embedded"`
...
...
indexer/e2e_tests/bridge_transfers_e2e_test.go
View file @
e3d1af10
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"time"
"time"
e2etest_utils
"github.com/ethereum-optimism/optimism/indexer/e2e_tests/utils"
e2etest_utils
"github.com/ethereum-optimism/optimism/indexer/e2e_tests/utils"
"github.com/ethereum-optimism/optimism/indexer/processor"
op_e2e
"github.com/ethereum-optimism/optimism/op-e2e"
op_e2e
"github.com/ethereum-optimism/optimism/op-e2e"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-node/withdrawals"
"github.com/ethereum-optimism/optimism/op-node/withdrawals"
...
@@ -65,9 +64,7 @@ func TestE2EBridgeTransfersStandardBridgeETHDeposit(t *testing.T) {
...
@@ -65,9 +64,7 @@ func TestE2EBridgeTransfersStandardBridgeETHDeposit(t *testing.T) {
// StandardBridge flows through the messenger. We remove the first two significant
// StandardBridge flows through the messenger. We remove the first two significant
// bytes of the nonce dedicated to the version. nonce == 0 (first message)
// bytes of the nonce dedicated to the version. nonce == 0 (first message)
require
.
NotNil
(
t
,
deposit
.
CrossDomainMessengerNonce
)
require
.
NotNil
(
t
,
deposit
.
CrossDomainMessageHash
)
_
,
nonce
:=
processor
.
DecodeVersionedNonce
(
deposit
.
CrossDomainMessengerNonce
.
Int
)
require
.
Zero
(
t
,
nonce
.
Uint64
())
// (2) Test Deposit Finalization via CrossDomainMessenger relayed message
// (2) Test Deposit Finalization via CrossDomainMessenger relayed message
depositReceipt
,
err
=
wait
.
ForReceiptOK
(
context
.
Background
(),
testSuite
.
L2Client
,
types
.
NewTx
(
depositInfo
.
DepositTx
)
.
Hash
())
depositReceipt
,
err
=
wait
.
ForReceiptOK
(
context
.
Background
(),
testSuite
.
L2Client
,
types
.
NewTx
(
depositInfo
.
DepositTx
)
.
Hash
())
...
@@ -77,7 +74,7 @@ func TestE2EBridgeTransfersStandardBridgeETHDeposit(t *testing.T) {
...
@@ -77,7 +74,7 @@ func TestE2EBridgeTransfersStandardBridgeETHDeposit(t *testing.T) {
return
l2Header
!=
nil
&&
l2Header
.
Number
.
Uint64
()
>=
depositReceipt
.
BlockNumber
.
Uint64
(),
nil
return
l2Header
!=
nil
&&
l2Header
.
Number
.
Uint64
()
>=
depositReceipt
.
BlockNumber
.
Uint64
(),
nil
}))
}))
crossDomainBridgeMessage
,
err
:=
testSuite
.
DB
.
BridgeMessages
.
L1BridgeMessage
(
deposit
.
CrossDomainMessengerNonce
.
Int
)
crossDomainBridgeMessage
,
err
:=
testSuite
.
DB
.
BridgeMessages
.
L1BridgeMessage
ByHash
(
*
deposit
.
CrossDomainMessageHash
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
crossDomainBridgeMessage
)
require
.
NotNil
(
t
,
crossDomainBridgeMessage
)
require
.
NotNil
(
t
,
crossDomainBridgeMessage
.
RelayedMessageEventGUID
)
require
.
NotNil
(
t
,
crossDomainBridgeMessage
.
RelayedMessageEventGUID
)
...
@@ -125,7 +122,7 @@ func TestE2EBridgeTransfersOptimismPortalETHReceive(t *testing.T) {
...
@@ -125,7 +122,7 @@ func TestE2EBridgeTransfersOptimismPortalETHReceive(t *testing.T) {
require
.
Len
(
t
,
deposit
.
Tx
.
Data
,
0
)
require
.
Len
(
t
,
deposit
.
Tx
.
Data
,
0
)
// deposit was not sent through the cross domain messenger
// deposit was not sent through the cross domain messenger
require
.
Nil
(
t
,
deposit
.
CrossDomainMess
engerNonce
)
require
.
Nil
(
t
,
deposit
.
CrossDomainMess
ageHash
)
// (2) Test Deposit Finalization
// (2) Test Deposit Finalization
// Nothing to do as we rely on the derivation process to include the deposit
// Nothing to do as we rely on the derivation process to include the deposit
...
@@ -187,9 +184,11 @@ func TestE2EBridgeTransfersStandardBridgeETHWithdrawal(t *testing.T) {
...
@@ -187,9 +184,11 @@ func TestE2EBridgeTransfersStandardBridgeETHWithdrawal(t *testing.T) {
// StandardBridge flows through the messenger. We remove the first two
// StandardBridge flows through the messenger. We remove the first two
// bytes of the nonce dedicated to the version. nonce == 0 (first message)
// bytes of the nonce dedicated to the version. nonce == 0 (first message)
require
.
NotNil
(
t
,
withdrawal
.
CrossDomainMessengerNonce
)
require
.
NotNil
(
t
,
withdrawal
.
CrossDomainMessageHash
)
_
,
nonce
:=
processor
.
DecodeVersionedNonce
(
withdrawal
.
CrossDomainMessengerNonce
.
Int
)
require
.
Zero
(
t
,
nonce
.
Uint64
())
crossDomainBridgeMessage
,
err
:=
testSuite
.
DB
.
BridgeMessages
.
L2BridgeMessageByHash
(
*
withdrawal
.
CrossDomainMessageHash
)
require
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
crossDomainBridgeMessage
.
RelayedMessageEventGUID
)
// (2) Test Withdrawal Proven/Finalized. Test the sql join queries to populate the right transaction
// (2) Test Withdrawal Proven/Finalized. Test the sql join queries to populate the right transaction
require
.
Empty
(
t
,
aliceWithdrawals
[
0
]
.
ProvenL1TransactionHash
)
require
.
Empty
(
t
,
aliceWithdrawals
[
0
]
.
ProvenL1TransactionHash
)
...
@@ -206,6 +205,11 @@ func TestE2EBridgeTransfersStandardBridgeETHWithdrawal(t *testing.T) {
...
@@ -206,6 +205,11 @@ func TestE2EBridgeTransfersStandardBridgeETHWithdrawal(t *testing.T) {
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
proveReceipt
.
TxHash
,
aliceWithdrawals
[
0
]
.
ProvenL1TransactionHash
)
require
.
Equal
(
t
,
proveReceipt
.
TxHash
,
aliceWithdrawals
[
0
]
.
ProvenL1TransactionHash
)
require
.
Equal
(
t
,
finalizeReceipt
.
TxHash
,
aliceWithdrawals
[
0
]
.
FinalizedL1TransactionHash
)
require
.
Equal
(
t
,
finalizeReceipt
.
TxHash
,
aliceWithdrawals
[
0
]
.
FinalizedL1TransactionHash
)
crossDomainBridgeMessage
,
err
=
testSuite
.
DB
.
BridgeMessages
.
L2BridgeMessageByHash
(
*
withdrawal
.
CrossDomainMessageHash
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
crossDomainBridgeMessage
)
require
.
NotNil
(
t
,
crossDomainBridgeMessage
.
RelayedMessageEventGUID
)
}
}
func
TestE2EBridgeTransfersL2ToL1MessagePasserReceive
(
t
*
testing
.
T
)
{
func
TestE2EBridgeTransfersL2ToL1MessagePasserReceive
(
t
*
testing
.
T
)
{
...
@@ -262,7 +266,7 @@ func TestE2EBridgeTransfersL2ToL1MessagePasserReceive(t *testing.T) {
...
@@ -262,7 +266,7 @@ func TestE2EBridgeTransfersL2ToL1MessagePasserReceive(t *testing.T) {
require
.
Len
(
t
,
withdrawal
.
Tx
.
Data
,
0
)
require
.
Len
(
t
,
withdrawal
.
Tx
.
Data
,
0
)
// withdrawal was not sent through the cross domain messenger
// withdrawal was not sent through the cross domain messenger
require
.
Nil
(
t
,
withdrawal
.
CrossDomainMess
engerNonce
)
require
.
Nil
(
t
,
withdrawal
.
CrossDomainMess
ageHash
)
// (2) Test Withdrawal Proven/Finalized. Test the sql join queries to populate the right transaction
// (2) Test Withdrawal Proven/Finalized. Test the sql join queries to populate the right transaction
require
.
Empty
(
t
,
aliceWithdrawals
[
0
]
.
ProvenL1TransactionHash
)
require
.
Empty
(
t
,
aliceWithdrawals
[
0
]
.
ProvenL1TransactionHash
)
...
...
indexer/migrations/20230523_create_schema.sql
View file @
e3d1af10
...
@@ -153,8 +153,8 @@ CREATE TABLE IF NOT EXISTS l2_transaction_withdrawals (
...
@@ -153,8 +153,8 @@ CREATE TABLE IF NOT EXISTS l2_transaction_withdrawals (
-- CrossDomainMessenger
-- CrossDomainMessenger
CREATE
TABLE
IF
NOT
EXISTS
l1_bridge_messages
(
CREATE
TABLE
IF
NOT
EXISTS
l1_bridge_messages
(
nonce
UINT256
NOT
NULL
PRIMARY
KEY
,
nonce
UINT256
NOT
NULL
PRIMARY
KEY
,
message_hash
VARCHAR
NOT
NULL
,
message_hash
VARCHAR
UNIQUE
NOT
NULL
,
transaction_source_hash
VARCHAR
NOT
NULL
REFERENCES
l1_transaction_deposits
(
source_hash
),
transaction_source_hash
VARCHAR
UNIQUE
NOT
NULL
REFERENCES
l1_transaction_deposits
(
source_hash
),
sent_message_event_guid
VARCHAR
NOT
NULL
UNIQUE
REFERENCES
l1_contract_events
(
guid
),
sent_message_event_guid
VARCHAR
NOT
NULL
UNIQUE
REFERENCES
l1_contract_events
(
guid
),
relayed_message_event_guid
VARCHAR
UNIQUE
REFERENCES
l2_contract_events
(
guid
),
relayed_message_event_guid
VARCHAR
UNIQUE
REFERENCES
l2_contract_events
(
guid
),
...
@@ -169,8 +169,8 @@ CREATE TABLE IF NOT EXISTS l1_bridge_messages(
...
@@ -169,8 +169,8 @@ CREATE TABLE IF NOT EXISTS l1_bridge_messages(
);
);
CREATE
TABLE
IF
NOT
EXISTS
l2_bridge_messages
(
CREATE
TABLE
IF
NOT
EXISTS
l2_bridge_messages
(
nonce
UINT256
NOT
NULL
PRIMARY
KEY
,
nonce
UINT256
NOT
NULL
PRIMARY
KEY
,
message_hash
VARCHAR
NOT
NULL
,
message_hash
VARCHAR
UNIQUE
NOT
NULL
,
transaction_withdrawal_hash
VARCHAR
NOT
NULL
REFERENCES
l2_transaction_withdrawals
(
withdrawal_hash
),
transaction_withdrawal_hash
VARCHAR
UNIQUE
NOT
NULL
REFERENCES
l2_transaction_withdrawals
(
withdrawal_hash
),
sent_message_event_guid
VARCHAR
NOT
NULL
UNIQUE
REFERENCES
l2_contract_events
(
guid
),
sent_message_event_guid
VARCHAR
NOT
NULL
UNIQUE
REFERENCES
l2_contract_events
(
guid
),
relayed_message_event_guid
VARCHAR
UNIQUE
REFERENCES
l1_contract_events
(
guid
),
relayed_message_event_guid
VARCHAR
UNIQUE
REFERENCES
l1_contract_events
(
guid
),
...
@@ -190,7 +190,7 @@ CREATE TABLE IF NOT EXISTS l1_bridge_deposits (
...
@@ -190,7 +190,7 @@ CREATE TABLE IF NOT EXISTS l1_bridge_deposits (
-- We allow the cross_domain_message_hash to be NULL-able to account
-- We allow the cross_domain_message_hash to be NULL-able to account
-- for scenarios where ETH is simply sent to the OptimismPortal contract
-- for scenarios where ETH is simply sent to the OptimismPortal contract
cross_domain_message_hash
VARCHAR
UNIQUE
REFERENCES
l1_bridge_messages
(
nonce
),
cross_domain_message_hash
VARCHAR
UNIQUE
REFERENCES
l1_bridge_messages
(
message_hash
),
-- Deposit information
-- Deposit information
from_address
VARCHAR
NOT
NULL
,
from_address
VARCHAR
NOT
NULL
,
...
@@ -206,7 +206,7 @@ CREATE TABLE IF NOT EXISTS l2_bridge_withdrawals (
...
@@ -206,7 +206,7 @@ CREATE TABLE IF NOT EXISTS l2_bridge_withdrawals (
-- We allow the cross_domain_message_hash to be NULL-able to account for
-- We allow the cross_domain_message_hash to be NULL-able to account for
-- scenarios where ETH is simply sent to the L2ToL1MessagePasser contract
-- scenarios where ETH is simply sent to the L2ToL1MessagePasser contract
cross_domain_message_hash
VARCHAR
UNIQUE
REFERENCES
l2_bridge_messages
(
nonce
),
cross_domain_message_hash
VARCHAR
UNIQUE
REFERENCES
l2_bridge_messages
(
message_hash
),
-- Withdrawal information
-- Withdrawal information
from_address
VARCHAR
NOT
NULL
,
from_address
VARCHAR
NOT
NULL
,
...
...
indexer/processor/l1_processor.go
View file @
e3d1af10
...
@@ -12,7 +12,6 @@ import (
...
@@ -12,7 +12,6 @@ import (
"github.com/ethereum-optimism/optimism/indexer/node"
"github.com/ethereum-optimism/optimism/indexer/node"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
legacy_bindings
"github.com/ethereum-optimism/optimism/op-bindings/legacy-bindings"
legacy_bindings
"github.com/ethereum-optimism/optimism/op-bindings/legacy-bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum"
...
@@ -222,7 +221,7 @@ func l1ProcessFn(processLog log.Logger, ethClient node.EthClient, l1Contracts co
...
@@ -222,7 +221,7 @@ func l1ProcessFn(processLog log.Logger, ethClient node.EthClient, l1Contracts co
}
}
// forward along contract events to standard bridge processor
// forward along contract events to standard bridge processor
err
=
l1ProcessContractEventsStandardBridge
(
processLog
,
db
,
ethClient
,
processedContractEvents
)
err
=
l1ProcessContractEventsStandardBridge
(
processLog
,
db
,
processedContractEvents
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -266,11 +265,10 @@ func l1ProcessContractEventsBridgeTransactions(processLog log.Logger, db *databa
...
@@ -266,11 +265,10 @@ func l1ProcessContractEventsBridgeTransactions(processLog log.Logger, db *databa
if
len
(
depositTx
.
Data
)
==
0
&&
depositTx
.
Value
.
BitLen
()
>
0
{
if
len
(
depositTx
.
Data
)
==
0
&&
depositTx
.
Value
.
BitLen
()
>
0
{
ethDeposits
=
append
(
ethDeposits
,
&
database
.
L1BridgeDeposit
{
ethDeposits
=
append
(
ethDeposits
,
&
database
.
L1BridgeDeposit
{
TransactionSourceHash
:
depositTx
.
SourceHash
,
TransactionSourceHash
:
depositTx
.
SourceHash
,
Tx
:
transactionDeposits
[
i
]
.
Tx
,
BridgeTransfer
:
database
.
BridgeTransfer
{
TokenPair
:
database
.
TokenPair
{
Tx
:
transactionDeposits
[
i
]
.
Tx
,
// TODO index eth token if it doesn't exist
// TODO index eth token if it doesn't exist
L1TokenAddress
:
predeploys
.
LegacyERC20ETHAddr
,
TokenPair
:
database
.
ETHTokenPair
,
L2TokenAddress
:
predeploys
.
LegacyERC20ETHAddr
,
},
},
})
})
}
}
...
@@ -443,9 +441,7 @@ func l1ProcessContractEventsBridgeCrossDomainMessages(processLog log.Logger, db
...
@@ -443,9 +441,7 @@ func l1ProcessContractEventsBridgeCrossDomainMessages(processLog log.Logger, db
return
nil
return
nil
}
}
func
l1ProcessContractEventsStandardBridge
(
processLog
log
.
Logger
,
db
*
database
.
DB
,
ethClient
node
.
EthClient
,
events
*
ProcessedContractEvents
)
error
{
func
l1ProcessContractEventsStandardBridge
(
processLog
log
.
Logger
,
db
*
database
.
DB
,
events
*
ProcessedContractEvents
)
error
{
rawEthClient
:=
ethclient
.
NewClient
(
ethClient
.
RawRpcClient
())
// (1) Process New Deposits
// (1) Process New Deposits
initiatedDepositEvents
,
err
:=
StandardBridgeInitiatedEvents
(
events
)
initiatedDepositEvents
,
err
:=
StandardBridgeInitiatedEvents
(
events
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -465,16 +461,18 @@ func l1ProcessContractEventsStandardBridge(processLog log.Logger, db *database.D
...
@@ -465,16 +461,18 @@ func l1ProcessContractEventsStandardBridge(processLog log.Logger, db *database.D
}
}
deposits
[
i
]
=
&
database
.
L1BridgeDeposit
{
deposits
[
i
]
=
&
database
.
L1BridgeDeposit
{
TransactionSourceHash
:
depositTx
.
SourceHash
,
TransactionSourceHash
:
depositTx
.
SourceHash
,
CrossDomainMessengerNonce
:
&
database
.
U256
{
Int
:
initiatedBridgeEvent
.
CrossDomainMessengerNonce
},
BridgeTransfer
:
database
.
BridgeTransfer
{
// TODO index the tokens pairs if they don't exist
CrossDomainMessageHash
:
&
initiatedBridgeEvent
.
CrossDomainMessageHash
,
TokenPair
:
database
.
TokenPair
{
L1TokenAddress
:
initiatedBridgeEvent
.
LocalToken
,
L2TokenAddress
:
initiatedBridgeEvent
.
RemoteToken
},
// TODO index the tokens pairs if they don't exist
Tx
:
database
.
Transaction
{
TokenPair
:
database
.
TokenPair
{
L1TokenAddress
:
initiatedBridgeEvent
.
LocalToken
,
L2TokenAddress
:
initiatedBridgeEvent
.
RemoteToken
},
FromAddress
:
initiatedBridgeEvent
.
From
,
Tx
:
database
.
Transaction
{
ToAddress
:
initiatedBridgeEvent
.
To
,
FromAddress
:
initiatedBridgeEvent
.
From
,
Amount
:
database
.
U256
{
Int
:
initiatedBridgeEvent
.
Amount
},
ToAddress
:
initiatedBridgeEvent
.
To
,
Data
:
initiatedBridgeEvent
.
ExtraData
,
Amount
:
database
.
U256
{
Int
:
initiatedBridgeEvent
.
Amount
},
Timestamp
:
initiatedBridgeEvent
.
Event
.
Timestamp
,
Data
:
initiatedBridgeEvent
.
ExtraData
,
Timestamp
:
initiatedBridgeEvent
.
Event
.
Timestamp
,
},
},
},
}
}
}
}
...
@@ -491,17 +489,17 @@ func l1ProcessContractEventsStandardBridge(processLog log.Logger, db *database.D
...
@@ -491,17 +489,17 @@ func l1ProcessContractEventsStandardBridge(processLog log.Logger, db *database.D
// - We dont need do anything actionable on the database here as this is layered on top of the
// - We dont need do anything actionable on the database here as this is layered on top of the
// bridge transaction & messages that have a tracked lifecyle. We simply walk through and ensure
// bridge transaction & messages that have a tracked lifecyle. We simply walk through and ensure
// that the corresponding initiated withdrawals exist and match as an integrity check
// that the corresponding initiated withdrawals exist and match as an integrity check
finalizedWithdrawalEvents
,
err
:=
StandardBridgeFinalizedEvents
(
rawEthClient
,
events
)
finalizedWithdrawalEvents
,
err
:=
StandardBridgeFinalizedEvents
(
events
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
for
_
,
finalizedWithdrawalEvent
:=
range
finalizedWithdrawalEvents
{
for
_
,
finalizedWithdrawalEvent
:=
range
finalizedWithdrawalEvents
{
withdrawal
,
err
:=
db
.
BridgeTransfers
.
L2BridgeWithdrawal
ByCrossDomainMessengerNonce
(
finalizedWithdrawalEvent
.
CrossDomainMessengerNonce
)
withdrawal
,
err
:=
db
.
BridgeTransfers
.
L2BridgeWithdrawal
WithFilter
(
database
.
BridgeTransfer
{
CrossDomainMessageHash
:
&
finalizedWithdrawalEvent
.
CrossDomainMessageHash
}
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
else
if
withdrawal
==
nil
{
}
else
if
withdrawal
==
nil
{
processLog
.
Error
(
"missing indexed L2StandardBridge withdrawal for finalization"
,
"cross_domain_mess
enger_nonce"
,
finalizedWithdrawalEvent
.
CrossDomainMessengerNonce
)
processLog
.
Error
(
"missing indexed L2StandardBridge withdrawal for finalization"
,
"cross_domain_mess
age_hash"
,
finalizedWithdrawalEvent
.
CrossDomainMessageHash
)
return
errors
.
New
(
"missing indexed L2StandardBridge withdrawal for finalization event"
)
return
errors
.
New
(
"missing indexed L2StandardBridge withdrawal for finalization event"
)
}
}
...
@@ -509,8 +507,7 @@ func l1ProcessContractEventsStandardBridge(processLog log.Logger, db *database.D
...
@@ -509,8 +507,7 @@ func l1ProcessContractEventsStandardBridge(processLog log.Logger, db *database.D
if
finalizedWithdrawalEvent
.
From
!=
withdrawal
.
Tx
.
FromAddress
||
finalizedWithdrawalEvent
.
To
!=
withdrawal
.
Tx
.
ToAddress
||
if
finalizedWithdrawalEvent
.
From
!=
withdrawal
.
Tx
.
FromAddress
||
finalizedWithdrawalEvent
.
To
!=
withdrawal
.
Tx
.
ToAddress
||
finalizedWithdrawalEvent
.
Amount
.
Cmp
(
withdrawal
.
Tx
.
Amount
.
Int
)
!=
0
||
!
bytes
.
Equal
(
finalizedWithdrawalEvent
.
ExtraData
,
withdrawal
.
Tx
.
Data
)
||
finalizedWithdrawalEvent
.
Amount
.
Cmp
(
withdrawal
.
Tx
.
Amount
.
Int
)
!=
0
||
!
bytes
.
Equal
(
finalizedWithdrawalEvent
.
ExtraData
,
withdrawal
.
Tx
.
Data
)
||
finalizedWithdrawalEvent
.
LocalToken
!=
withdrawal
.
TokenPair
.
L1TokenAddress
||
finalizedWithdrawalEvent
.
RemoteToken
!=
withdrawal
.
TokenPair
.
L2TokenAddress
{
finalizedWithdrawalEvent
.
LocalToken
!=
withdrawal
.
TokenPair
.
L1TokenAddress
||
finalizedWithdrawalEvent
.
RemoteToken
!=
withdrawal
.
TokenPair
.
L2TokenAddress
{
processLog
.
Crit
(
"bridge finalization fields mismatch with initiated fields!"
,
"tx_withdrawal_hash"
,
withdrawal
.
TransactionWithdrawalHash
,
"cross_domain_messenger_nonce"
,
withdrawal
.
CrossDomainMessengerNonce
.
Int
)
processLog
.
Crit
(
"bridge finalization fields mismatch with initiated fields!"
,
"tx_withdrawal_hash"
,
withdrawal
.
TransactionWithdrawalHash
,
"cross_domain_message_hash"
,
withdrawal
.
CrossDomainMessageHash
)
return
errors
.
New
(
"bridge tx mismatch!"
)
}
}
}
}
...
...
indexer/processor/l2_processor.go
View file @
e3d1af10
...
@@ -10,7 +10,6 @@ import (
...
@@ -10,7 +10,6 @@ import (
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum-optimism/optimism/indexer/node"
"github.com/ethereum-optimism/optimism/indexer/node"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
...
@@ -160,7 +159,7 @@ func l2ProcessFn(processLog log.Logger, ethClient node.EthClient, l2Contracts L2
...
@@ -160,7 +159,7 @@ func l2ProcessFn(processLog log.Logger, ethClient node.EthClient, l2Contracts L2
}
}
// forward along contract events to standard bridge processor
// forward along contract events to standard bridge processor
err
=
l2ProcessContractEventsStandardBridge
(
processLog
,
db
,
ethClient
,
processedContractEvents
)
err
=
l2ProcessContractEventsStandardBridge
(
processLog
,
db
,
processedContractEvents
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -198,10 +197,9 @@ func l2ProcessContractEventsBridgeTransactions(processLog log.Logger, db *databa
...
@@ -198,10 +197,9 @@ func l2ProcessContractEventsBridgeTransactions(processLog log.Logger, db *databa
if
len
(
withdrawalEvent
.
Data
)
==
0
&&
withdrawalEvent
.
Value
.
BitLen
()
>
0
{
if
len
(
withdrawalEvent
.
Data
)
==
0
&&
withdrawalEvent
.
Value
.
BitLen
()
>
0
{
ethWithdrawals
=
append
(
ethWithdrawals
,
&
database
.
L2BridgeWithdrawal
{
ethWithdrawals
=
append
(
ethWithdrawals
,
&
database
.
L2BridgeWithdrawal
{
TransactionWithdrawalHash
:
withdrawalEvent
.
WithdrawalHash
,
TransactionWithdrawalHash
:
withdrawalEvent
.
WithdrawalHash
,
Tx
:
transactionWithdrawals
[
i
]
.
Tx
,
BridgeTransfer
:
database
.
BridgeTransfer
{
TokenPair
:
database
.
TokenPair
{
Tx
:
transactionWithdrawals
[
i
]
.
Tx
,
L1TokenAddress
:
predeploys
.
LegacyERC20ETHAddr
,
TokenPair
:
database
.
ETHTokenPair
,
L2TokenAddress
:
predeploys
.
LegacyERC20ETHAddr
,
},
},
})
})
}
}
...
@@ -330,9 +328,7 @@ func l2ProcessContractEventsBridgeCrossDomainMessages(processLog log.Logger, db
...
@@ -330,9 +328,7 @@ func l2ProcessContractEventsBridgeCrossDomainMessages(processLog log.Logger, db
return
nil
return
nil
}
}
func
l2ProcessContractEventsStandardBridge
(
processLog
log
.
Logger
,
db
*
database
.
DB
,
ethClient
node
.
EthClient
,
events
*
ProcessedContractEvents
)
error
{
func
l2ProcessContractEventsStandardBridge
(
processLog
log
.
Logger
,
db
*
database
.
DB
,
events
*
ProcessedContractEvents
)
error
{
rawEthClient
:=
ethclient
.
NewClient
(
ethClient
.
RawRpcClient
())
l2ToL1MessagePasserABI
,
err
:=
bindings
.
NewL2ToL1MessagePasser
(
common
.
Address
{},
nil
)
l2ToL1MessagePasserABI
,
err
:=
bindings
.
NewL2ToL1MessagePasser
(
common
.
Address
{},
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -357,14 +353,16 @@ func l2ProcessContractEventsStandardBridge(processLog log.Logger, db *database.D
...
@@ -357,14 +353,16 @@ func l2ProcessContractEventsStandardBridge(processLog log.Logger, db *database.D
withdrawals
[
i
]
=
&
database
.
L2BridgeWithdrawal
{
withdrawals
[
i
]
=
&
database
.
L2BridgeWithdrawal
{
TransactionWithdrawalHash
:
msgPassedEvent
.
WithdrawalHash
,
TransactionWithdrawalHash
:
msgPassedEvent
.
WithdrawalHash
,
CrossDomainMessengerNonce
:
&
database
.
U256
{
Int
:
initiatedBridgeEvent
.
CrossDomainMessengerNonce
},
BridgeTransfer
:
database
.
BridgeTransfer
{
TokenPair
:
database
.
TokenPair
{
L1TokenAddress
:
initiatedBridgeEvent
.
LocalToken
,
L2TokenAddress
:
initiatedBridgeEvent
.
RemoteToken
},
CrossDomainMessageHash
:
&
initiatedBridgeEvent
.
CrossDomainMessageHash
,
Tx
:
database
.
Transaction
{
TokenPair
:
database
.
TokenPair
{
L1TokenAddress
:
initiatedBridgeEvent
.
LocalToken
,
L2TokenAddress
:
initiatedBridgeEvent
.
RemoteToken
},
FromAddress
:
initiatedBridgeEvent
.
From
,
Tx
:
database
.
Transaction
{
ToAddress
:
initiatedBridgeEvent
.
To
,
FromAddress
:
initiatedBridgeEvent
.
From
,
Amount
:
database
.
U256
{
Int
:
initiatedBridgeEvent
.
Amount
},
ToAddress
:
initiatedBridgeEvent
.
To
,
Data
:
initiatedBridgeEvent
.
ExtraData
,
Amount
:
database
.
U256
{
Int
:
initiatedBridgeEvent
.
Amount
},
Timestamp
:
initiatedBridgeEvent
.
Event
.
Timestamp
,
Data
:
initiatedBridgeEvent
.
ExtraData
,
Timestamp
:
initiatedBridgeEvent
.
Event
.
Timestamp
,
},
},
},
}
}
}
}
...
@@ -382,18 +380,18 @@ func l2ProcessContractEventsStandardBridge(processLog log.Logger, db *database.D
...
@@ -382,18 +380,18 @@ func l2ProcessContractEventsStandardBridge(processLog log.Logger, db *database.D
// bridge transaction & messages that have a tracked lifecyle. We simply walk through and ensure
// bridge transaction & messages that have a tracked lifecyle. We simply walk through and ensure
// that the corresponding initiated deposits exist as an integrity check
// that the corresponding initiated deposits exist as an integrity check
finalizedDepositEvents
,
err
:=
StandardBridgeFinalizedEvents
(
rawEthClient
,
events
)
finalizedDepositEvents
,
err
:=
StandardBridgeFinalizedEvents
(
events
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
for
_
,
finalizedDepositEvent
:=
range
finalizedDepositEvents
{
for
_
,
finalizedDepositEvent
:=
range
finalizedDepositEvents
{
deposit
,
err
:=
db
.
BridgeTransfers
.
L1BridgeDeposit
ByCrossDomainMessengerNonce
(
finalizedDepositEvent
.
CrossDomainMessengerNonce
)
deposit
,
err
:=
db
.
BridgeTransfers
.
L1BridgeDeposit
WithFilter
(
database
.
BridgeTransfer
{
CrossDomainMessageHash
:
&
finalizedDepositEvent
.
CrossDomainMessageHash
}
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
else
if
deposit
==
nil
{
}
else
if
deposit
==
nil
{
// Indexed CrossDomainMessenger messages ensure we're in a caught up state here
// Indexed CrossDomainMessenger messages ensure we're in a caught up state here
processLog
.
Error
(
"missing indexed L1StandardBridge deposit on finalization"
,
"cross_domain_m
essenger_nonce"
,
finalizedDepositEvent
.
CrossDomainMessengerNonce
)
processLog
.
Error
(
"missing indexed L1StandardBridge deposit on finalization"
,
"cross_domain_m
assage_hash"
,
finalizedDepositEvent
.
CrossDomainMessageHash
)
return
errors
.
New
(
"missing indexed L1StandardBridge deposit on finalization"
)
return
errors
.
New
(
"missing indexed L1StandardBridge deposit on finalization"
)
}
}
...
@@ -401,7 +399,7 @@ func l2ProcessContractEventsStandardBridge(processLog log.Logger, db *database.D
...
@@ -401,7 +399,7 @@ func l2ProcessContractEventsStandardBridge(processLog log.Logger, db *database.D
if
finalizedDepositEvent
.
From
!=
deposit
.
Tx
.
FromAddress
||
finalizedDepositEvent
.
To
!=
deposit
.
Tx
.
ToAddress
||
if
finalizedDepositEvent
.
From
!=
deposit
.
Tx
.
FromAddress
||
finalizedDepositEvent
.
To
!=
deposit
.
Tx
.
ToAddress
||
finalizedDepositEvent
.
Amount
.
Cmp
(
deposit
.
Tx
.
Amount
.
Int
)
!=
0
||
!
bytes
.
Equal
(
finalizedDepositEvent
.
ExtraData
,
deposit
.
Tx
.
Data
)
||
finalizedDepositEvent
.
Amount
.
Cmp
(
deposit
.
Tx
.
Amount
.
Int
)
!=
0
||
!
bytes
.
Equal
(
finalizedDepositEvent
.
ExtraData
,
deposit
.
Tx
.
Data
)
||
finalizedDepositEvent
.
LocalToken
!=
deposit
.
TokenPair
.
L1TokenAddress
||
finalizedDepositEvent
.
RemoteToken
!=
deposit
.
TokenPair
.
L2TokenAddress
{
finalizedDepositEvent
.
LocalToken
!=
deposit
.
TokenPair
.
L1TokenAddress
||
finalizedDepositEvent
.
RemoteToken
!=
deposit
.
TokenPair
.
L2TokenAddress
{
processLog
.
Error
(
"bridge finalization fields mismatch with initiated fields!"
,
"tx_source_hash"
,
deposit
.
TransactionSourceHash
,
"cross_domain_mess
enger_nonce"
,
deposit
.
CrossDomainMessengerNonce
.
Int
)
processLog
.
Error
(
"bridge finalization fields mismatch with initiated fields!"
,
"tx_source_hash"
,
deposit
.
TransactionSourceHash
,
"cross_domain_mess
age_hash"
,
deposit
.
CrossDomainMessageHash
)
return
errors
.
New
(
"bridge tx mismatch"
)
return
errors
.
New
(
"bridge tx mismatch"
)
}
}
}
}
...
...
indexer/processor/standard_bridge.go
View file @
e3d1af10
This diff is collapsed.
Click to expand it.
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