Skip to content

Commit

Permalink
changes bump fee calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Aug 19, 2024
1 parent 30a7716 commit dcd74c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion e2etest/submitter_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestSubmitterSubmissionReplace(t *testing.T) {

tm.Config.Submitter.PollingIntervalSeconds = 2
tm.Config.Submitter.ResendIntervalSeconds = 2
tm.Config.Submitter.ResubmitFeeMultiplier = 2.6
tm.Config.Submitter.ResubmitFeeMultiplier = 2.1
// create submitter
vigilantSubmitter, _ := submitter.New(
&tm.Config.Submitter,
Expand Down
19 changes: 5 additions & 14 deletions submitter/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,15 @@ func (rl *Relayer) shouldResendCheckpoint(ckptInfo *types.CheckpointInfo, bumped
// based on the current BTC load, considering both tx sizes
// the result is multiplied by ResubmitFeeMultiplier set in config
func (rl *Relayer) calculateBumpedFee(ckptInfo *types.CheckpointInfo) btcutil.Amount {
feeRate := rl.getFeeRate()
newTx1Fee := feeRate.FeeForVSize(ckptInfo.Tx1.Size)
newTx2Fee := feeRate.FeeForVSize(ckptInfo.Tx2.Size)
// minus the old fee of the first transaction because we do not want to pay again for the first transaction
bumpedFee := newTx1Fee + newTx2Fee - ckptInfo.Tx1.Fee

return bumpedFee.MulF64(rl.config.ResubmitFeeMultiplier)
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) {
// set output value of the second tx to be the balance minus the bumped fee
// if the bumped fee is higher than the balance, then set the bumped fee to
// be equal to the balance to ensure the output value is not negative
//balance := tx2.Utxo.Amount
balance := btcutil.Amount(tx2.Tx.TxOut[1].Value) // todo Lazar check this as well
balance := btcutil.Amount(tx2.Tx.TxOut[1].Value)

if bumpedFee > balance {
rl.logger.Debugf("the bumped fee %v Satoshis for the second tx is more than UTXO amount %v Satoshis",
Expand Down Expand Up @@ -330,8 +323,7 @@ func (rl *Relayer) buildTxWithData(data []byte, firstTx *wire.MsgTx) (*types.Btc
txID := firstTx.TxHash()
outPoint := wire.NewOutPoint(&txID, 1)
txIn := wire.NewTxIn(outPoint, nil, nil)
// Enable replace-by-fee
// See https://river.com/learn/terms/r/replace-by-fee-rbf
// Enable replace-by-fee, see https://river.com/learn/terms/r/replace-by-fee-rbf
txIn.Sequence = math.MaxUint32 - 2
tx.AddTxIn(txIn)
}
Expand All @@ -354,7 +346,7 @@ func (rl *Relayer) buildTxWithData(data []byte, firstTx *wire.MsgTx) (*types.Btc
return nil, err
}

rl.logger.Debugf("Building a BTC tx using %s with data %x", rawTxResult.Transaction.TxID, data)
rl.logger.Debugf("Building a BTC tx using %s with data %x", rawTxResult.Transaction.TxID(), data)

_, addresses, _, err := txscript.ExtractPkScriptAddrs(
rawTxResult.Transaction.TxOut[1].PkScript,
Expand Down Expand Up @@ -384,8 +376,7 @@ func (rl *Relayer) buildTxWithData(data []byte, firstTx *wire.MsgTx) (*types.Btc
return nil, fmt.Errorf("the value of the utxo is not sufficient for relaying the tx. Require: %v. Have: %v", minRelayFee, changeAmount)
}

//txFee := rl.getFeeRate().FeeForVSize(txSize)
txFee := rawTxResult.Fee // todo Lazar, check with Konrad if we should use the calcd fee from FundRawTransaction or manually calc it
txFee := rawTxResult.Fee
// ensuring the tx fee is not lower than the minimum relay fee
if txFee < minRelayFee {
txFee = minRelayFee
Expand Down

0 comments on commit dcd74c2

Please sign in to comment.