Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitor AggLayer's SendTx and WaitTxToBeMined Error #231

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions aggregator/aggregator_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import (
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/ethereum/go-ethereum/common"
"github.com/jackc/pgx/v4"
"github.com/0xPolygonHermez/zkevm-node/aggregator/metrics"
)

var (
nowSendTxStartBatchNumber uint64 = 0
nowWaitMinedStartBatchNumber uint64 = 0
initStartBatchNumber bool = false
)

func (a *Aggregator) settleDirect(
Expand Down Expand Up @@ -96,13 +103,26 @@ func (a *Aggregator) settleWithAggLayer(
return false
}

if !initStartBatchNumber {
nowSendTxStartBatchNumber = proof.BatchNumber
nowWaitMinedStartBatchNumber = proof.BatchNumber
initStartBatchNumber = true
}

log.Debug("final proof signedTx: ", signedTx.Tx.ZKP.Proof.Hex())
txHash, err := a.AggLayerClient.SendTx(*signedTx)
if err != nil {
log.Errorf("failed to send tx to the interop: %v", err)
a.handleFailureToSendToAggLayer(ctx, proof)

// Monitor Failure with metrics
if nowSendTxStartBatchNumber == proof.BatchNumber {
metrics.SendTxFailedInc()
}
return false
} else {
// reset counter when success
metrics.SendTxFailedReset()
nowSendTxStartBatchNumber = proof.BatchNumberFinal + 1
}

log.Infof("tx %s sent to agglayer, waiting to be mined", txHash.Hex())
Expand All @@ -112,8 +132,15 @@ func (a *Aggregator) settleWithAggLayer(
if err := a.AggLayerClient.WaitTxToBeMined(txHash, waitCtx); err != nil {
log.Errorf("interop didn't mine the tx: %v", err)
a.handleFailureToSendToAggLayer(ctx, proof)

// Monitor Failure with metrics
if nowWaitMinedStartBatchNumber == proof.BatchNumber {
metrics.WaitMinedFailedInc()
}
return false
}else {
// reset counter when success
metrics.WaitMinedFailedReset()
nowWaitMinedStartBatchNumber = proof.BatchNumberFinal + 1
}

// TODO: wait for synchronizer to catch up
Expand Down
31 changes: 31 additions & 0 deletions aggregator/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const (
prefix = "aggregator_"
currentConnectedProversName = prefix + "current_connected_provers"
currentWorkingProversName = prefix + "current_working_provers"
sendTxFailedCount = prefix + "send_tx_failed_count"
waitTxToBeMinedFailedCount = prefix + "wait_tx_mined_failed_count"
)

// Register the metrics for the sequencer package.
Expand All @@ -22,6 +24,14 @@ func Register() {
Name: currentWorkingProversName,
Help: "[AGGREGATOR] current working provers",
},
{
Name: sendTxFailedCount,
Help: "[AGGREGATOR] agglayerClient.SendTx failed counter",
},
{
Name: waitTxToBeMinedFailedCount,
Help: "[AGGREGATOR] agglayerClient.WaitTxToBeMined failed counter",
},
}

metrics.RegisterGauges(gauges...)
Expand Down Expand Up @@ -49,3 +59,24 @@ func WorkingProver() {
func IdlingProver() {
metrics.GaugeDec(currentWorkingProversName)
}

// SendTxFailedInc increment the gauge for sendTx Failed Counter
func SendTxFailedInc() {
metrics.GaugeInc(sendTxFailedCount)
}

// SendTxFailedReset when a proof is successfully sent to agglayer
func SendTxFailedReset() {
metrics.GaugeSet(sendTxFailedCount, 0)
}

// WaitMinedFailedInc increment the gauge for sendTx Failed Counter
func WaitMinedFailedInc() {
metrics.GaugeInc(waitTxToBeMinedFailedCount)
}

// WaitMinedFailedReset when a proof is successfully sent to agglayer
func WaitMinedFailedReset() {
metrics.GaugeSet(waitTxToBeMinedFailedCount, 0)
}