Skip to content

Commit

Permalink
proto.btc.tx.new: set sequence numbers for all inputs explicitly
Browse files Browse the repository at this point in the history
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’.
  • Loading branch information
mmgen committed Jan 4, 2023
1 parent 458a010 commit 5552898
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions mmgen/proto/btc/tx/new.py
Expand Up @@ -110,18 +110,18 @@ async def create_serialized(self,locktime=None,bump=None):

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}

Expand Down

0 comments on commit 5552898

Please sign in to comment.