Skip to content

Commit

Permalink
fix: staking tx should not be RBFable
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab committed Dec 5, 2024
1 parent 965c43b commit b468eb4
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@babylonlabs-io/btc-staking-ts",
"version": "0.4.0-canary.3",
"version": "0.4.0-canary.4",
"description": "Library exposing methods for the creation and consumption of Bitcoin transactions pertaining to Babylon's Bitcoin Staking protocol.",
"module": "dist/index.js",
"main": "dist/index.cjs",
Expand Down
4 changes: 2 additions & 2 deletions src/staking/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { isValidBitcoinAddress, transactionIdToHash } from "../utils/btc";
import { getStakingTxInputUTXOsAndFees, getWithdrawTxFee } from "../utils/fee";
import { inputValueSum } from "../utils/fee/utils";
import { buildStakingTransactionOutputs } from "../utils/staking";
import { NON_RBF_SEQUENCE, TRANSACTION_VERSION, RBF_SEQUENCE } from "../constants/psbt";
import { NON_RBF_SEQUENCE, TRANSACTION_VERSION } from "../constants/psbt";
import { CovenantSignature } from "../types/covenantSignatures";
import { REDEEM_VERSION } from "../constants/transaction";

Expand Down Expand Up @@ -92,7 +92,7 @@ export function stakingTransaction(
tx.addInput(
transactionIdToHash(input.txid),
input.vout,
RBF_SEQUENCE,
NON_RBF_SEQUENCE,
);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/staking/createStakingTx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StakingParams } from "../../src/types/params";
import { UTXO } from "../../src/types/UTXO";
import { StakingError, StakingErrorCode } from "../../src/error";
import { BTC_DUST_SAT } from "../../src/constants/dustSat";
import { RBF_SEQUENCE } from "../../src/constants/psbt";
import { NON_RBF_SEQUENCE } from "../../src/constants/psbt";
import * as stakingUtils from "../../src/utils/staking";
import * as stakingTx from "../../src/staking/transactions";
import { Staking, transactionIdToHash } from "../../src";
Expand Down Expand Up @@ -154,8 +154,8 @@ describe.each(testingNetworks)("Create staking transaction", ({
expect(psbt.data.inputs[0].witnessUtxo?.script.toString("hex")).toEqual(utxos[0].scriptPubKey);

// Validate sequences
transaction.ins.forEach(input => expect(input.sequence).toBe(RBF_SEQUENCE));
psbt.txInputs.forEach(input => expect(input.sequence).toBe(RBF_SEQUENCE));
transaction.ins.forEach(input => expect(input.sequence).toBe(NON_RBF_SEQUENCE));
psbt.txInputs.forEach(input => expect(input.sequence).toBe(NON_RBF_SEQUENCE));

// Calculate and validate amounts
const psbtInputAmount = psbt.data.inputs.reduce((sum, input) =>
Expand Down
4 changes: 2 additions & 2 deletions tests/staking/observable/createStakingTx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ObservableStakingParams } from "../../../src/types/params";
import { UTXO } from "../../../src/types/UTXO";
import { StakingError, StakingErrorCode } from "../../../src/error";
import { BTC_DUST_SAT } from "../../../src/constants/dustSat";
import { RBF_SEQUENCE } from "../../../src/constants/psbt";
import { NON_RBF_SEQUENCE } from "../../../src/constants/psbt";
import * as stakingUtils from "../../../src/utils/staking";
import * as staking from "../../../src/staking/transactions";

Expand Down Expand Up @@ -141,7 +141,7 @@ describe.each(testingNetworks)("Observal - Create staking transaction", ({
expect(transaction.locktime).toBe(params.activationHeight - 1);
expect(transaction.version).toBe(2);
transaction.ins.map((input) => {
expect(input.sequence).toBe(RBF_SEQUENCE);
expect(input.sequence).toBe(NON_RBF_SEQUENCE);
});

// Check the data embed script(OP_RETURN)
Expand Down
4 changes: 2 additions & 2 deletions tests/staking/psbt/stakingPsbt.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { address, Psbt } from "bitcoinjs-lib";
import { BTC_DUST_SAT } from "../../../src/constants/dustSat";
import { RBF_SEQUENCE } from "../../../src/constants/psbt";
import { NON_RBF_SEQUENCE } from "../../../src/constants/psbt";
import { StakingScripts, stakingTransaction } from "../../../src/index";
import { ObservableStakingScripts } from "../../../src/staking/observable";
import { DEFAULT_TEST_FEE_RATE, testingNetworks } from "../../helper";
Expand Down Expand Up @@ -176,7 +176,7 @@ describe.each(testingNetworks)("Transactions - ", (
).toBeDefined();

psbt.txInputs.map((input) => {
expect(input.sequence).toBe(RBF_SEQUENCE);
expect(input.sequence).toBe(NON_RBF_SEQUENCE);
});
expect(psbt.version).toBe(2);
};
Expand Down
4 changes: 2 additions & 2 deletions tests/staking/transactions/stakingTransaction.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { address } from "bitcoinjs-lib";
import { BTC_DUST_SAT } from "../../../src/constants/dustSat";
import { RBF_SEQUENCE } from "../../../src/constants/psbt";
import { NON_RBF_SEQUENCE } from "../../../src/constants/psbt";
import { StakingScripts, stakingTransaction, transactionIdToHash, UTXO } from "../../../src/index";
import { ObservableStakingScripts } from "../../../src/staking/observable";
import { TransactionResult } from "../../../src/types/transaction";
Expand Down Expand Up @@ -378,7 +378,7 @@ describe.each(testingNetworks)("Transactions - ", (
).toBeDefined();

transaction.ins.map((input) => {
expect(input.sequence).toBe(RBF_SEQUENCE);
expect(input.sequence).toBe(NON_RBF_SEQUENCE);
});
expect(transaction.version).toBe(2);
};
Expand Down

0 comments on commit b468eb4

Please sign in to comment.