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

fix: resend tx panic (#154) #157

Merged
merged 1 commit into from
Jan 8, 2025
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Bug Fixes

* [#154](https://github.com/babylonlabs-io/vigilante/pull/154) fix: panic in maybeResendSecondTxOfCheckpointToBTC

## v0.19.0

### Bug Fixes
Expand Down
5 changes: 0 additions & 5 deletions config/grpc.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package config

const (
// DefaultGRPCAddress defines the default address to bind the gRPC server to.
DefaultGRPCAddress = "0.0.0.0:8080"
)

// GRPCConfig defines configuration for the gRPC server.
type GRPCConfig struct {
OneTimeTLSKey bool `mapstructure:"onetime-tls-key"`
Expand Down
5 changes: 0 additions & 5 deletions config/grpcweb.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package config

const (
// DefaultGRPCWebAddress defines the default address to bind the gRPC-web server to.
DefaultGRPCWebAddress = "0.0.0.0:8081"
)

// GRPCWebConfig defines configuration for the gRPC-web server.
type GRPCWebConfig struct {
Placeholder string `mapstructure:"placeholder"`
Expand Down
17 changes: 10 additions & 7 deletions submitter/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,20 @@ func (rl *Relayer) MaybeResubmitSecondCheckpointTx(ckpt *ckpttypes.RawCheckpoint
return nil
}

rl.logger.Debugf("Resending the second tx of the checkpoint %v, old fee of the second tx: %v Satoshis, txid: %s",
rl.logger.Debugf("Maybe resending the second tx of the checkpoint %v, old fee of the second tx: %v Satoshis, txid: %s",
ckptEpoch, rl.lastSubmittedCheckpoint.Tx2.Fee, rl.lastSubmittedCheckpoint.Tx2.TxID.String())

resubmittedTx2, err := rl.resendSecondTxOfCheckpointToBTC(rl.lastSubmittedCheckpoint.Tx2, bumpedFee)
resubmittedTx2, err := rl.maybeResendSecondTxOfCheckpointToBTC(rl.lastSubmittedCheckpoint.Tx2, bumpedFee)
if err != nil {
rl.metrics.FailedResentCheckpointsCounter.Inc()

return fmt.Errorf("failed to re-send the second tx of the checkpoint %v: %w", rl.lastSubmittedCheckpoint.Epoch, err)
}

if resubmittedTx2 == nil {
return nil
}

// record the metrics of the resent tx2
rl.metrics.NewSubmittedCheckpointSegmentGaugeVec.WithLabelValues(
strconv.FormatUint(ckptEpoch, 10),
Expand Down Expand Up @@ -255,17 +259,16 @@ func (rl *Relayer) calculateBumpedFee(ckptInfo *types.CheckpointInfo) btcutil.Am
return ckptInfo.Tx2.Fee.MulF64(rl.config.ResubmitFeeMultiplier)
}

// resendSecondTxOfCheckpointToBTC resends the second tx of the checkpoint with bumpedFee
func (rl *Relayer) resendSecondTxOfCheckpointToBTC(tx2 *types.BtcTxInfo, bumpedFee btcutil.Amount) (*types.BtcTxInfo, error) {
_, status, err := rl.TxDetails(rl.lastSubmittedCheckpoint.Tx2.TxID,
rl.lastSubmittedCheckpoint.Tx2.Tx.TxOut[changePosition].PkScript)
// maybeResendSecondTxOfCheckpointToBTC resends the second tx of the checkpoint with bumpedFee
func (rl *Relayer) maybeResendSecondTxOfCheckpointToBTC(tx2 *types.BtcTxInfo, bumpedFee btcutil.Amount) (*types.BtcTxInfo, error) {
_, status, err := rl.TxDetails(tx2.TxID, tx2.Tx.TxOut[changePosition].PkScript)
if err != nil {
return nil, err
}

// No need to resend, transaction already confirmed
if status == btcclient.TxInChain {
rl.logger.Debugf("Transaction %v is already confirmed", rl.lastSubmittedCheckpoint.Tx2.TxID)
rl.logger.Debugf("Transaction %v is already confirmed", tx2.TxID)

return nil, nil
}
Expand Down
Loading