Commit d8744f91 authored by Ethen Pociask's avatar Ethen Pociask

[indexer.bridge_accounting_fix] fix(indexer) Changed Withdrawal/Deposit Counters to Use big.Int

parent 0600fe87
......@@ -4,6 +4,7 @@ import (
"fmt"
"math/big"
"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/processors/contracts"
......@@ -28,13 +29,13 @@ func L1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
log.Info("detected transaction deposits", "size", len(optimismPortalTxDeposits))
}
mintedETH := 0
var mintedGWEI = bigint.Zero
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())
mintedGWEI = new(big.Int).Add(mintedGWEI, depositTx.Tx.Amount)
transactionDeposits[i] = database.L1TransactionDeposit{
SourceHash: depositTx.DepositTx.SourceHash,
......@@ -43,12 +44,17 @@ func L1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
GasLimit: depositTx.GasLimit,
Tx: depositTx.Tx,
}
}
if len(transactionDeposits) > 0 {
if err := db.BridgeTransactions.StoreL1TransactionDeposits(transactionDeposits); err != nil {
return err
}
metrics.RecordL1TransactionDeposits(len(transactionDeposits), mintedETH)
// Convert to from wei to eth
mintedETH := new(big.Int).Div(mintedGWEI, big.NewInt(1e18)).Uint64()
metrics.RecordL1TransactionDeposits(len(transactionDeposits), int(mintedETH))
}
// (2) L1CrossDomainMessenger
......
......@@ -5,6 +5,7 @@ import (
"fmt"
"math/big"
"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/processors/contracts"
......@@ -28,13 +29,13 @@ func L2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L2M
log.Info("detected transaction withdrawals", "size", len(l2ToL1MPMessagesPassed))
}
withdrawnETH := 0
var withdrawnGWEI = 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
withdrawnETH = withdrawnETH + int(messagePassed.Tx.Amount.Int64())
withdrawnGWEI = new(big.Int).Add(withdrawnGWEI, messagePassed.Tx.Amount)
transactionWithdrawals[i] = database.L2TransactionWithdrawal{
WithdrawalHash: messagePassed.WithdrawalHash,
......@@ -48,7 +49,10 @@ func L2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L2M
if err := db.BridgeTransactions.StoreL2TransactionWithdrawals(transactionWithdrawals); err != nil {
return err
}
metrics.RecordL2TransactionWithdrawals(len(transactionWithdrawals), withdrawnETH)
// Convert the withdrawn GWEI to ETH
withdrawnETH := new(big.Int).Div(withdrawnGWEI, big.NewInt(1e9)).Uint64()
metrics.RecordL2TransactionWithdrawals(len(transactionWithdrawals), int(withdrawnETH))
}
// (2) L2CrossDomainMessenger
......
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