Skip to content

Commit

Permalink
fix: resend tx panic (#154)
Browse files Browse the repository at this point in the history
Closes #151
  • Loading branch information
Lazar955 authored Jan 7, 2025
1 parent 3423d05 commit e541143
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
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

0 comments on commit e541143

Please sign in to comment.