From 55528989f19771377b83f3e6b8cf9e1c48b1e9b5 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 4 Jan 2023 13:40:13 +0000 Subject: [PATCH] proto.btc.tx.new: set sequence numbers for all inputs explicitly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bitcoin Core v24.0.1 introduces a welcome but undocumented change in the behavior of the ‘createrawtransaction’ RPC call: when one sequence number is set, then the sequence numbers for the remaining inputs are automatically set to the same value. This occurs even when the ‘replaceable’ and ‘locktime’ arguments are not used. To ensure this behavior across all coins and daemon versions, always set sequence numbers for all inputs explicitly to the same value, ignoring ‘replaceable’ and ‘locktime’. --- mmgen/proto/btc/tx/new.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mmgen/proto/btc/tx/new.py b/mmgen/proto/btc/tx/new.py index faf8761a..a28daa8d 100755 --- a/mmgen/proto/btc/tx/new.py +++ b/mmgen/proto/btc/tx/new.py @@ -110,18 +110,18 @@ class New(Base,TxBase.New): if not bump: self.inputs.sort_bip69() - # do this only after inputs are sorted - if opt.rbf: - self.inputs[0].sequence = self.proto.max_int - 2 # handles the nLockTime case too - elif locktime: - self.inputs[0].sequence = self.proto.max_int - 1 + # Set all sequence numbers to the same value, in conformity with the behavior of most modern wallets: + seqnum_val = self.proto.max_int - (2 if opt.rbf else 1 if locktime else 0) + for i in self.inputs: + i.sequence = seqnum_val self.outputs.sort_bip69() - inputs_list = [ - {'txid':e.txid,'vout':e.vout,'sequence':e.sequence} if n == 0 and e.sequence else - {'txid':e.txid,'vout':e.vout} - for n,e in enumerate(self.inputs) ] + inputs_list = [{ + 'txid': e.txid, + 'vout': e.vout, + 'sequence': e.sequence + } for n,e in enumerate(self.inputs) ] outputs_dict = {e.addr:e.amt for e in self.outputs}