Commit e87edd22 authored by Ethen Pociask's avatar Ethen Pociask

[indexer.bridge_accounting_fix] Added conversions across legacy/bedrock processors

parent d8744f91
......@@ -25,3 +25,9 @@ func Clamp(start, end *big.Int, size uint64) *big.Int {
func Matcher(num int64) func(*big.Int) bool {
return func(bi *big.Int) bool { return bi.Int64() == num }
}
func WeiToETH(wei *big.Int) *big.Float {
f := new(big.Float)
f.SetString(wei.String())
return f.Quo(f, big.NewFloat(1e18))
}
......@@ -53,8 +53,8 @@ func L1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
}
// Convert to from wei to eth
mintedETH := new(big.Int).Div(mintedGWEI, big.NewInt(1e18)).Uint64()
metrics.RecordL1TransactionDeposits(len(transactionDeposits), int(mintedETH))
mintedETH, _ := bigint.WeiToETH(mintedGWEI).Float64()
metrics.RecordL1TransactionDeposits(len(transactionDeposits), mintedETH)
}
// (2) L1CrossDomainMessenger
......
......@@ -29,13 +29,13 @@ func L2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L2M
log.Info("detected transaction withdrawals", "size", len(l2ToL1MPMessagesPassed))
}
var withdrawnGWEI = bigint.Zero
var withdrawnWEI = bigint.Zero
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
withdrawnGWEI = new(big.Int).Add(withdrawnGWEI, messagePassed.Tx.Amount)
withdrawnWEI = new(big.Int).Add(withdrawnWEI, messagePassed.Tx.Amount)
transactionWithdrawals[i] = database.L2TransactionWithdrawal{
WithdrawalHash: messagePassed.WithdrawalHash,
......@@ -50,9 +50,9 @@ func L2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L2M
return err
}
// Convert the withdrawn GWEI to ETH
withdrawnETH := new(big.Int).Div(withdrawnGWEI, big.NewInt(1e9)).Uint64()
metrics.RecordL2TransactionWithdrawals(len(transactionWithdrawals), int(withdrawnETH))
// Convert the withdrawn WEI to ETH
withdrawnETH, _ := bigint.WeiToETH(withdrawnWEI).Float64()
metrics.RecordL2TransactionWithdrawals(len(transactionWithdrawals), withdrawnETH)
}
// (2) L2CrossDomainMessenger
......
......@@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/indexer/bigint"
"github.com/ethereum-optimism/optimism/indexer/config"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum-optimism/optimism/indexer/node"
......@@ -31,13 +32,13 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
log.Info("detected legacy transaction deposits", "size", len(ctcTxDepositEvents))
}
mintedETH := 0
mintedWEI := bigint.Zero
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
mintedETH = mintedETH + int(deposit.Tx.Amount.Uint64())
mintedWEI = new(big.Int).Add(mintedWEI, deposit.Tx.Amount)
transactionDeposits[i] = database.L1TransactionDeposit{
// We re-use the L2 Transaction hash as the source hash to remain consistent in the schema.
......@@ -52,6 +53,8 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
if err := db.BridgeTransactions.StoreL1TransactionDeposits(transactionDeposits); err != nil {
return err
}
mintedETH, _ := bigint.WeiToETH(mintedWEI).Float64()
metrics.RecordL1TransactionDeposits(len(transactionDeposits), mintedETH)
}
......@@ -159,14 +162,14 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
log.Info("detected legacy transaction withdrawals (via L2CrossDomainMessenger)", "size", len(crossDomainSentMessages))
}
withdrawnETH := 0
withdrawnWEI := bigint.Zero
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())
withdrawnWEI = new(big.Int).Add(withdrawnWEI, sentMessage.BridgeMessage.Tx.Amount)
// 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.
......@@ -197,6 +200,8 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
if err := db.BridgeMessages.StoreL2BridgeMessages(bridgeMessages); err != nil {
return err
}
withdrawnETH, _ := bigint.WeiToETH(withdrawnWEI).Float64()
metrics.RecordL2TransactionWithdrawals(len(transactionWithdrawals), withdrawnETH)
metrics.RecordL2CrossDomainSentMessages(len(bridgeMessages))
}
......
......@@ -16,7 +16,7 @@ var (
type L1Metricer interface {
RecordLatestIndexedL1Height(height *big.Int)
RecordL1TransactionDeposits(size int, mintedETH int)
RecordL1TransactionDeposits(size int, mintedETH float64)
RecordL1ProvenWithdrawals(size int)
RecordL1FinalizedWithdrawals(size int)
......@@ -30,7 +30,7 @@ type L1Metricer interface {
type L2Metricer interface {
RecordLatestIndexedL2Height(height *big.Int)
RecordL2TransactionWithdrawals(size int, withdrawnETH int)
RecordL2TransactionWithdrawals(size int, withdrawnETH float64)
RecordL2CrossDomainSentMessages(size int)
RecordL2CrossDomainRelayedMessages(size int)
......@@ -178,9 +178,9 @@ func (m *bridgeMetrics) RecordLatestIndexedL1Height(height *big.Int) {
m.latestL1Height.Set(float64(height.Uint64()))
}
func (m *bridgeMetrics) RecordL1TransactionDeposits(size, mintedETH int) {
func (m *bridgeMetrics) RecordL1TransactionDeposits(size int, mintedETH float64) {
m.txDeposits.Add(float64(size))
m.txMintedETH.Add(float64(mintedETH))
m.txMintedETH.Add(mintedETH)
}
func (m *bridgeMetrics) RecordL1ProvenWithdrawals(size int) {
......@@ -213,9 +213,9 @@ func (m *bridgeMetrics) RecordLatestIndexedL2Height(height *big.Int) {
m.latestL2Height.Set(float64(height.Uint64()))
}
func (m *bridgeMetrics) RecordL2TransactionWithdrawals(size, withdrawnETH int) {
func (m *bridgeMetrics) RecordL2TransactionWithdrawals(size int, withdrawnETH float64) {
m.txWithdrawals.Add(float64(size))
m.txWithdrawnETH.Add(float64(withdrawnETH))
m.txWithdrawnETH.Add(withdrawnETH)
}
func (m *bridgeMetrics) RecordL2CrossDomainSentMessages(size int) {
......
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