From b468eb4206fc7ff71385616ffe91fabc8e46813d Mon Sep 17 00:00:00 2001 From: wjrjerome Date: Thu, 5 Dec 2024 15:07:18 +1100 Subject: [PATCH] fix: staking tx should not be RBFable --- package-lock.json | 4 ++-- package.json | 2 +- src/staking/transactions.ts | 4 ++-- tests/staking/createStakingTx.test.ts | 6 +++--- tests/staking/observable/createStakingTx.test.ts | 4 ++-- tests/staking/psbt/stakingPsbt.test.ts | 4 ++-- tests/staking/transactions/stakingTransaction.test.ts | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 14ac127..c97f59f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@babylonlabs-io/btc-staking-ts", - "version": "0.4.0-canary.3", + "version": "0.4.0-canary.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@babylonlabs-io/btc-staking-ts", - "version": "0.4.0-canary.3", + "version": "0.4.0-canary.4", "license": "SEE LICENSE IN LICENSE", "dependencies": { "@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3", diff --git a/package.json b/package.json index 9387cf2..0f9772c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/staking/transactions.ts b/src/staking/transactions.ts index 3a54bab..23c42e6 100644 --- a/src/staking/transactions.ts +++ b/src/staking/transactions.ts @@ -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"; @@ -92,7 +92,7 @@ export function stakingTransaction( tx.addInput( transactionIdToHash(input.txid), input.vout, - RBF_SEQUENCE, + NON_RBF_SEQUENCE, ); } diff --git a/tests/staking/createStakingTx.test.ts b/tests/staking/createStakingTx.test.ts index ed4a010..80c4044 100644 --- a/tests/staking/createStakingTx.test.ts +++ b/tests/staking/createStakingTx.test.ts @@ -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"; @@ -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) => diff --git a/tests/staking/observable/createStakingTx.test.ts b/tests/staking/observable/createStakingTx.test.ts index a37e76b..a1c93a1 100644 --- a/tests/staking/observable/createStakingTx.test.ts +++ b/tests/staking/observable/createStakingTx.test.ts @@ -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"; @@ -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) diff --git a/tests/staking/psbt/stakingPsbt.test.ts b/tests/staking/psbt/stakingPsbt.test.ts index 34e233b..cf751a0 100644 --- a/tests/staking/psbt/stakingPsbt.test.ts +++ b/tests/staking/psbt/stakingPsbt.test.ts @@ -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"; @@ -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); }; diff --git a/tests/staking/transactions/stakingTransaction.test.ts b/tests/staking/transactions/stakingTransaction.test.ts index a2d5da5..d56f656 100644 --- a/tests/staking/transactions/stakingTransaction.test.ts +++ b/tests/staking/transactions/stakingTransaction.test.ts @@ -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"; @@ -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); };