Commit 40a0a24e authored by Hamdi Allam's avatar Hamdi Allam

rename some files. comments

parent 0b345704
...@@ -161,8 +161,6 @@ func (c *client) TxByHash(hash common.Hash) (*types.Transaction, error) { ...@@ -161,8 +161,6 @@ func (c *client) TxByHash(hash common.Hash) (*types.Transaction, error) {
return nil, ethereum.NotFound return nil, ethereum.NotFound
} }
// NOTE: why does ethclient do something different here
return tx, nil return tx, nil
} }
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
// L1ProcessInitiatedBridgeEvents will query the database for new bridge events that have been initiated between // L1ProcessInitiatedBridgeEvents will query the database for bridge events that have been initiated between
// the specified block range. This covers every part of the multi-layered stack: // the specified block range. This covers every part of the multi-layered stack:
// 1. OptimismPortal // 1. OptimismPortal
// 2. L1CrossDomainMessenger // 2. L1CrossDomainMessenger
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
// L2ProcessInitiatedBridgeEvents will query the database for new bridge events that have been initiated between // L2ProcessInitiatedBridgeEvents will query the database for bridge events that have been initiated between
// the specified block range. This covers every part of the multi-layered stack: // the specified block range. This covers every part of the multi-layered stack:
// 1. OptimismPortal // 1. OptimismPortal
// 2. L2CrossDomainMessenger // 2. L2CrossDomainMessenger
......
...@@ -15,6 +15,11 @@ import ( ...@@ -15,6 +15,11 @@ import (
// Legacy Bridge Initiation // Legacy Bridge Initiation
// LegacyL1ProcessInitiatedEvents will query the data for bridge events within the specified block range
// according the pre-bedrock protocol. This follows:
// 1. CanonicalTransactionChain
// 2. L1CrossDomainMessenger
// 3. L1StandardBridge
func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, chainConfig config.ChainConfig, fromHeight *big.Int, toHeight *big.Int) error { func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, chainConfig config.ChainConfig, fromHeight *big.Int, toHeight *big.Int) error {
// (1) CanonicalTransactionChain // (1) CanonicalTransactionChain
ctcTxDepositEvents, err := contracts.LegacyCTCDepositEvents(chainConfig.L1Contracts.LegacyCanonicalTransactionChain, db, fromHeight, toHeight) ctcTxDepositEvents, err := contracts.LegacyCTCDepositEvents(chainConfig.L1Contracts.LegacyCanonicalTransactionChain, db, fromHeight, toHeight)
...@@ -31,8 +36,11 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, chain ...@@ -31,8 +36,11 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, chain
deposit := ctcTxDepositEvents[i] deposit := ctcTxDepositEvents[i]
ctcTxDeposits[logKey{deposit.Event.BlockHash, deposit.Event.LogIndex}] = &deposit ctcTxDeposits[logKey{deposit.Event.BlockHash, deposit.Event.LogIndex}] = &deposit
transactionDeposits[i] = database.L1TransactionDeposit{ transactionDeposits[i] = database.L1TransactionDeposit{
SourceHash: deposit.TxHash, // We re-use the L2 Transaction hash as the source hash
L2TransactionHash: deposit.TxHash, // TODO: check that this is right // to remain consistent in the schema.
SourceHash: deposit.TxHash,
L2TransactionHash: deposit.TxHash,
InitiatedL1EventGUID: deposit.Event.GUID, InitiatedL1EventGUID: deposit.Event.GUID,
GasLimit: deposit.GasLimit, GasLimit: deposit.GasLimit,
Tx: deposit.Tx, Tx: deposit.Tx,
...@@ -93,12 +101,12 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, chain ...@@ -93,12 +101,12 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, chain
sentMessage, ok := sentMessages[logKey{initiatedBridge.Event.BlockHash, initiatedBridge.Event.LogIndex - 1}] sentMessage, ok := sentMessages[logKey{initiatedBridge.Event.BlockHash, initiatedBridge.Event.LogIndex - 1}]
if !ok { if !ok {
log.Error("missing cross domain message for bridge transfer", "tx_hash", initiatedBridge.Event.TransactionHash.String()) log.Error("missing cross domain message for bridge transfer", "tx_hash", initiatedBridge.Event.TransactionHash.String())
return fmt.Errorf("expected SentMessage preceding TransactionEnqeueud event. tx_hash = %s", initiatedBridge.Event.TransactionHash.String()) return fmt.Errorf("expected SentMessage preceding DepositInitiated event. tx_hash = %s", initiatedBridge.Event.TransactionHash.String())
} }
ctcTxDeposit, ok := ctcTxDeposits[logKey{initiatedBridge.Event.BlockHash, initiatedBridge.Event.LogIndex - 2}] ctcTxDeposit, ok := ctcTxDeposits[logKey{initiatedBridge.Event.BlockHash, initiatedBridge.Event.LogIndex - 2}]
if !ok { if !ok {
log.Error("missing transaction deposit for bridge transfer", "tx_hash", initiatedBridge.Event.TransactionHash.String()) log.Error("missing transaction deposit for bridge transfer", "tx_hash", initiatedBridge.Event.TransactionHash.String())
return fmt.Errorf("expected TransactionEnqueued preceding BridgeInitiated event. tx_hash = %s", initiatedBridge.Event.TransactionHash.String()) return fmt.Errorf("expected TransactionEnqueued preceding DepostInitiated event. tx_hash = %s", initiatedBridge.Event.TransactionHash.String())
} }
initiatedBridge.BridgeTransfer.CrossDomainMessageHash = &sentMessage.BridgeMessage.MessageHash initiatedBridge.BridgeTransfer.CrossDomainMessageHash = &sentMessage.BridgeMessage.MessageHash
...@@ -117,8 +125,14 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, chain ...@@ -117,8 +125,14 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, chain
return nil return nil
} }
// LegacyL2ProcessInitiatedEvents will query the data for bridge events within the specified block range
// according the pre-bedrock protocol. This follows:
// 1. L2CrossDomainMessenger
// - The LegacyMessagePasser contract cannot be used as entrypoint to bridge transactions from L2. The protocol
// only allows the L2CrossDomainMessenger as the sole sender when relaying a bridged message.
// 2. L2StandardBridge
func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, fromHeight *big.Int, toHeight *big.Int) error { func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, fromHeight *big.Int, toHeight *big.Int) error {
// (1) L2CrossDomainMessenger -> This is the root-most contract for which bridge events since withdrawals must be initiated from the L2CrossDomainMessenger // (1) L2CrossDomainMessenger
crossDomainSentMessages, err := contracts.CrossDomainMessengerSentMessageEvents("l2", predeploys.L2CrossDomainMessengerAddr, db, fromHeight, toHeight) crossDomainSentMessages, err := contracts.CrossDomainMessengerSentMessageEvents("l2", predeploys.L2CrossDomainMessengerAddr, db, fromHeight, toHeight)
if err != nil { if err != nil {
return err return err
...@@ -135,9 +149,8 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, fromH ...@@ -135,9 +149,8 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, fromH
sentMessage := crossDomainSentMessages[i] sentMessage := crossDomainSentMessages[i]
sentMessages[logKey{sentMessage.Event.BlockHash, sentMessage.Event.LogIndex}] = &sentMessage sentMessages[logKey{sentMessage.Event.BlockHash, sentMessage.Event.LogIndex}] = &sentMessage
// To ensure consistency in our schema, we duplicate this as the "root" transaction withdrawal. We re-use the same withdrawal hash as the storage // To ensure consistency in the schema, we duplicate this as the "root" transaction withdrawal. We re-use the same withdrawal hash as the storage
// key for the proof sha3(calldata + sender) can be derived from the fields. (NOTE: should we just use the storage key here?) // key for the proof sha3(calldata + sender) can be derived from the fields. (NOTE: should we just use the storage key here?)
l2BridgeMessages[i] = database.L2BridgeMessage{TransactionWithdrawalHash: sentMessage.BridgeMessage.MessageHash, BridgeMessage: sentMessage.BridgeMessage}
l2TransactionWithdrawals[i] = database.L2TransactionWithdrawal{ l2TransactionWithdrawals[i] = database.L2TransactionWithdrawal{
WithdrawalHash: sentMessage.BridgeMessage.MessageHash, WithdrawalHash: sentMessage.BridgeMessage.MessageHash,
InitiatedL2EventGUID: sentMessage.Event.GUID, InitiatedL2EventGUID: sentMessage.Event.GUID,
...@@ -151,6 +164,11 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, fromH ...@@ -151,6 +164,11 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, fromH
Timestamp: sentMessage.Event.Timestamp, Timestamp: sentMessage.Event.Timestamp,
}, },
} }
l2BridgeMessages[i] = database.L2BridgeMessage{
TransactionWithdrawalHash: sentMessage.BridgeMessage.MessageHash,
BridgeMessage: sentMessage.BridgeMessage,
}
} }
if len(l2BridgeMessages) > 0 { if len(l2BridgeMessages) > 0 {
......
...@@ -30,9 +30,8 @@ var ( ...@@ -30,9 +30,8 @@ var (
{Name: "sender", Type: addressType}, {Name: "sender", Type: addressType},
{Name: "data", Type: bytesType}, {Name: "data", Type: bytesType},
{Name: "nonce", Type: uint256Type}, {Name: "nonce", Type: uint256Type},
// The actual transaction on the legacy L1CrossDomainMessenger // The actual transaction on the legacy L1CrossDomainMessenger has a trailing
// actually has a trailing proof argument but is ignored for the // proof argument but is ignored for the `XDomainCallData` encoding
// `XDomainCallData` encoding
}, },
abi.Arguments{}, // outputs abi.Arguments{}, // outputs
) )
...@@ -44,8 +43,9 @@ type CrossDomainMessengerSentMessageEvent struct { ...@@ -44,8 +43,9 @@ type CrossDomainMessengerSentMessageEvent struct {
} }
type CrossDomainMessengerRelayedMessageEvent struct { type CrossDomainMessengerRelayedMessageEvent struct {
Event *database.ContractEvent Event *database.ContractEvent
MessageHash common.Hash MessageHash common.Hash
MessageCallData []byte
} }
func CrossDomainMessengerSentMessageEvents(chainSelector string, contractAddress common.Address, db *database.DB, fromHeight, toHeight *big.Int) ([]CrossDomainMessengerSentMessageEvent, error) { func CrossDomainMessengerSentMessageEvents(chainSelector string, contractAddress common.Address, db *database.DB, fromHeight, toHeight *big.Int) ([]CrossDomainMessengerSentMessageEvent, error) {
......
...@@ -3,6 +3,7 @@ package contracts ...@@ -3,6 +3,7 @@ package contracts
import ( import (
"math/big" "math/big"
"github.com/ethereum-optimism/optimism/indexer/bigint"
"github.com/ethereum-optimism/optimism/indexer/database" "github.com/ethereum-optimism/optimism/indexer/database"
legacy_bindings "github.com/ethereum-optimism/optimism/op-bindings/legacy-bindings" legacy_bindings "github.com/ethereum-optimism/optimism/op-bindings/legacy-bindings"
...@@ -38,15 +39,15 @@ func LegacyCTCDepositEvents(contractAddress common.Address, db *database.DB, fro ...@@ -38,15 +39,15 @@ func LegacyCTCDepositEvents(contractAddress common.Address, db *database.DB, fro
return nil, err return nil, err
} }
zeroAmt := big.NewInt(0) // Enqueued Deposits do not carry a `msg.value` amount. ETH is only minted on L2 via the L1StandardBrige
ctcTxDeposits[i] = LegacyCTCDepositEvent{ ctcTxDeposits[i] = LegacyCTCDepositEvent{
Event: &events[i].ContractEvent, Event: &events[i].ContractEvent,
GasLimit: txEnqueued.GasLimit, GasLimit: txEnqueued.GasLimit,
TxHash: types.NewTransaction(0, txEnqueued.Target, zeroAmt, txEnqueued.GasLimit.Uint64(), nil, txEnqueued.Data).Hash(), TxHash: types.NewTransaction(0, txEnqueued.Target, bigint.Zero, txEnqueued.GasLimit.Uint64(), nil, txEnqueued.Data).Hash(),
Tx: database.Transaction{ Tx: database.Transaction{
FromAddress: txEnqueued.L1TxOrigin, FromAddress: txEnqueued.L1TxOrigin,
ToAddress: txEnqueued.Target, ToAddress: txEnqueued.Target,
Amount: zeroAmt, Amount: bigint.Zero,
Data: txEnqueued.Data, Data: txEnqueued.Data,
Timestamp: events[i].Timestamp, Timestamp: events[i].Timestamp,
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment