Commit 1b5d57d2 authored by Hamdi Allam's avatar Hamdi Allam

minted/withdrawn eth metrics

parent b97f2866
......@@ -28,15 +28,13 @@ func L1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
log.Info("detected transaction deposits", "size", len(optimismPortalTxDeposits))
}
portalDepositAmount := 0
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
if len(depositTx.Tx.Data) == 0 {
portalDepositAmount = portalDepositAmount + int(depositTx.Tx.Amount.Uint64())
}
mintedETH = mintedETH + int(depositTx.Tx.Amount.Uint64())
transactionDeposits[i] = database.L1TransactionDeposit{
SourceHash: depositTx.DepositTx.SourceHash,
......@@ -50,8 +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.RecordL1InitiatedBridgeTransfers(database.ETHTokenPair.LocalTokenAddress, portalDepositAmount)
metrics.RecordL1TransactionDeposits(len(transactionDeposits), mintedETH)
}
// (2) L1CrossDomainMessenger
......@@ -183,7 +180,6 @@ func L1ProcessFinalizedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
log.Info("detected finalized withdrawals", "size", len(finalizedWithdrawals))
}
portalWithdrawalAmount := 0
for i := range finalizedWithdrawals {
finalizedWithdrawal := finalizedWithdrawals[i]
withdrawal, err := db.BridgeTransactions.L2TransactionWithdrawal(finalizedWithdrawal.WithdrawalHash)
......@@ -194,10 +190,6 @@ func L1ProcessFinalizedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
return fmt.Errorf("missing indexed withdrawal on finalization! tx_hash: %s", finalizedWithdrawal.Event.TransactionHash.String())
}
if len(withdrawal.Tx.Data) == 0 {
portalWithdrawalAmount = portalWithdrawalAmount + int(withdrawal.Tx.Amount.Int64())
}
if err = db.BridgeTransactions.MarkL2TransactionWithdrawalFinalizedEvent(finalizedWithdrawal.WithdrawalHash, finalizedWithdrawal.Event.GUID, finalizedWithdrawal.Success); err != nil {
log.Error("failed to mark withdrawal as finalized", "err", err, "tx_hash", finalizedWithdrawal.Event.TransactionHash.String())
return err
......@@ -205,7 +197,6 @@ func L1ProcessFinalizedBridgeEvents(log log.Logger, db *database.DB, metrics L1M
}
if len(finalizedWithdrawals) > 0 {
metrics.RecordL1FinalizedWithdrawals(len(finalizedWithdrawals))
metrics.RecordL1FinalizedBridgeTransfers(database.ETHTokenPair.LocalTokenAddress, portalWithdrawalAmount)
}
// (3) L1CrossDomainMessenger
......
......@@ -28,15 +28,13 @@ func L2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L2M
log.Info("detected transaction withdrawals", "size", len(l2ToL1MPMessagesPassed))
}
l2ToL1WithdrawalAmount := 0
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
if len(messagePassed.Tx.Data) == 0 {
l2ToL1WithdrawalAmount = l2ToL1WithdrawalAmount + int(messagePassed.Tx.Amount.Int64())
}
withdrawnETH = withdrawnETH + int(messagePassed.Tx.Amount.Int64())
transactionWithdrawals[i] = database.L2TransactionWithdrawal{
WithdrawalHash: messagePassed.WithdrawalHash,
......@@ -50,8 +48,7 @@ func L2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metrics L2M
if err := db.BridgeTransactions.StoreL2TransactionWithdrawals(transactionWithdrawals); err != nil {
return err
}
metrics.RecordL2InitiatedBridgeTransfers(database.ETHTokenPair.LocalTokenAddress, l2ToL1WithdrawalAmount)
metrics.RecordL2TransactionWithdrawals(len(transactionWithdrawals))
metrics.RecordL2TransactionWithdrawals(len(transactionWithdrawals), withdrawnETH)
}
// (2) L2CrossDomainMessenger
......
......@@ -31,15 +31,14 @@ func LegacyL1ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
log.Info("detected legacy transaction deposits", "size", len(ctcTxDepositEvents))
}
ctcDepositAmount := 0
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
if len(deposit.Tx.Data) == 0 {
ctcDepositAmount = ctcDepositAmount + int(deposit.Tx.Amount.Uint64())
}
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,
......@@ -53,8 +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.RecordL1InitiatedBridgeTransfers(database.ETHTokenPair.LocalTokenAddress, ctcDepositAmount)
metrics.RecordL1TransactionDeposits(len(transactionDeposits), mintedETH)
}
// (2) L1CrossDomainMessenger
......@@ -161,16 +159,14 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, metri
log.Info("detected legacy transaction withdrawals (via L2CrossDomainMessenger)", "size", len(crossDomainSentMessages))
}
messengerWithdrawalAmount := 0
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
if len(sentMessage.BridgeMessage.Tx.Data) == 0 {
messengerWithdrawalAmount = messengerWithdrawalAmount + int(sentMessage.BridgeMessage.Tx.Amount.Int64())
}
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.
......@@ -201,9 +197,8 @@ 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))
metrics.RecordL2InitiatedBridgeTransfers(database.ETHTokenPair.LocalTokenAddress, messengerWithdrawalAmount)
}
// (2) L2StandardBridge
......
......@@ -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 withdrawan 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) {
......
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