Skip to content

Commit

Permalink
dual-funding: update init_rbf, replacing 'fee_step' with explicit fee
Browse files Browse the repository at this point in the history
You gotta make your feerate at least 65/64ths of the previous though
  • Loading branch information
niftynei authored and rustyrussell committed Jul 13, 2021
1 parent 740f795 commit ff3750b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
6 changes: 4 additions & 2 deletions lnprototest/clightning/clightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,18 @@ def init_rbf(self, event: Event, conn: Conn,

startweight = 42 + 172 # base weight, funding output
# Build a utxo using the given utxo
fmt_feerate = '{}perkw'.format(feerate)
utxos = ['{}:{}'.format(utxo_txid, utxo_outnum)]
initial_psbt = self.rpc.utxopsbt(amount,
'{}perkw'.format(feerate),
fmt_feerate,
startweight, utxos,
reservedok=True,
min_witness_weight=110,
locktime=0, excess_as_change=True)['psbt']

def _run_rbf(runner: Runner, conn: Conn) -> Dict[str, Any]:
bump = runner.rpc.openchannel_bump(channel_id, amount, initial_psbt)
bump = runner.rpc.openchannel_bump(channel_id, amount, initial_psbt,
funding_feerate=fmt_feerate)
update = runner.rpc.openchannel_update(channel_id, bump['psbt'])

# Run until they're done sending us updates
Expand Down
8 changes: 3 additions & 5 deletions lnprototest/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,29 +377,27 @@ def __init__(self,
amount: ResolvableInt,
utxo_tx: ResolvableStr,
utxo_outnum: ResolvableInt,
last_feerate: ResolvableInt,
feerate: int,
connprivkey: Optional[str] = None):
super().__init__(connprivkey)
self.channel_id = channel_id
self.amount = amount
self.last_feerate = last_feerate
self.feerate = feerate
self.utxo_tx = utxo_tx
self.utxo_outnum = utxo_outnum

def action(self, runner: 'Runner') -> bool:
super().action(runner)
last_feerate = self.resolve_arg('last_feerate', runner, self.last_feerate),
utxo_tx = self.resolve_arg('utxo_tx', runner, self.utxo_tx)
txid = CTransaction.deserialize(bytes.fromhex(utxo_tx)).GetTxid()[::-1].hex()

feerate = last_feerate[0] + last_feerate[0] // 4
runner.init_rbf(self,
self.find_conn(runner),
self.resolve_arg('channel_id', runner, self.channel_id),
self.resolve_arg('amount', runner, self.amount),
txid,
self.resolve_arg('utxo_outnum', runner, self.utxo_outnum),
feerate)
self.feerate)

return True

Expand Down
2 changes: 1 addition & 1 deletion lnprototest/proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"msgdata,init_rbf,channel_id,channel_id,",
"msgdata,init_rbf,funding_satoshis,u64,",
"msgdata,init_rbf,locktime,u32,",
"msgdata,init_rbf,fee_step,byte,",
"msgdata,init_rbf,funding_feerate_perkw,u32,",
"msgtype,ack_rbf,73",
"msgdata,ack_rbf,channel_id,channel_id,",
"msgdata,ack_rbf,funding_satoshis,u64,",
Expand Down
43 changes: 24 additions & 19 deletions tests/test_bolt2-20-open_channel_accepter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ def test_rbf_accepter(runner: Runner, with_proposal: Any) -> None:
Msg('init_rbf',
channel_id=channel_id_v2(local_keyset),
funding_satoshis=rbf_funding_amount,
fee_step=1,
funding_feerate_perkw=253 * 65 // 64,
locktime=0),
# Ignore unknown odd messages
TryAll([], RawMsg(bytes.fromhex('270F'))),
Expand Down Expand Up @@ -1658,6 +1658,8 @@ def test_rbf_opener(runner: Runner, with_proposal: Any) -> None:

funding_amount = funding_amount_for_utxo(input_index)
rbf_funding_amount = funding_amount - 1000
init_feerate = 2000
rbf_feerate = init_feerate * 65 // 64

test = [Block(blockheight=102, txs=[tx_spendable]),
Connect(connprivkey='02'),
Expand All @@ -1668,7 +1670,7 @@ def test_rbf_opener(runner: Runner, with_proposal: Any) -> None:

Msg('init', globalfeatures='', features=bitfield(12, 20, 29)),

FundChannel(amount=funding_amount, feerate=2000),
FundChannel(amount=funding_amount, feerate=init_feerate),

ExpectMsg('open_channel2',
channel_id=channel_id_tmp(local_keyset, Side.remote),
Expand Down Expand Up @@ -1716,19 +1718,19 @@ def test_rbf_opener(runner: Runner, with_proposal: Any) -> None:
amount=rbf_funding_amount,
utxo_tx=rcvd('tx_add_input.prevtx'),
utxo_outnum=rcvd('tx_add_input.prevtx_vout', int),
last_feerate=rcvd('open_channel2.funding_feerate_perkw', int)),
feerate=rbf_feerate * 2),

ExpectMsg('init_rbf',
channel_id=channel_id_v2(local_keyset),
funding_satoshis=rbf_funding_amount,
fee_step=1),
funding_feerate_perkw=rbf_feerate * 2),

# Ignore unknown odd messages
TryAll([], RawMsg(bytes.fromhex('270F'))),

Msg('ack_rbf',
channel_id=channel_id_v2(local_keyset),
funding_satoshis=400000),
funding_satoshis=380000),
]

test += opener_tx_creation(input_index, True, rbf_funding_amount,
Expand Down Expand Up @@ -1816,7 +1818,7 @@ def test_rbf_accepter_funding_locked(runner: Runner, with_proposal: Any) -> None
Msg('init_rbf',
channel_id=channel_id_v2(local_keyset),
funding_satoshis=rbf_funding_amount,
fee_step=1,
funding_feerate_perkw=253 * 65 // 64,
locktime=0),
# Ignore unknown odd messages
TryAll([], RawMsg(bytes.fromhex('270F'))),
Expand Down Expand Up @@ -1879,6 +1881,7 @@ def test_rbf_opener_funding_locked(runner: Runner, with_proposal: Any) -> None:

funding_amount = funding_amount_for_utxo(input_index)
rbf_funding_amount = funding_amount - 1000
init_feerate = 2000

test = [Block(blockheight=102, txs=[tx_spendable]),
Connect(connprivkey='02'),
Expand All @@ -1889,7 +1892,7 @@ def test_rbf_opener_funding_locked(runner: Runner, with_proposal: Any) -> None:

Msg('init', globalfeatures='', features=bitfield(12, 20, 29)),

FundChannel(amount=funding_amount, feerate=2000),
FundChannel(amount=funding_amount, feerate=init_feerate),

ExpectMsg('open_channel2',
channel_id=channel_id_tmp(local_keyset, Side.remote),
Expand Down Expand Up @@ -1937,12 +1940,12 @@ def test_rbf_opener_funding_locked(runner: Runner, with_proposal: Any) -> None:
amount=rbf_funding_amount,
utxo_tx=rcvd('tx_add_input.prevtx'),
utxo_outnum=rcvd('tx_add_input.prevtx_vout', int),
last_feerate=rcvd('open_channel2.funding_feerate_perkw', int)),
feerate=init_feerate * 65 // 64),

ExpectMsg('init_rbf',
channel_id=channel_id_v2(local_keyset),
funding_satoshis=rbf_funding_amount,
fee_step=1),
funding_feerate_perkw=init_feerate * 65 // 64),

# Ignore unknown odd messages
TryAll([], RawMsg(bytes.fromhex('270F'))),
Expand Down Expand Up @@ -2069,7 +2072,7 @@ def test_rbf_accepter_forgets(runner: Runner, with_proposal: Any) -> None:
Msg('init_rbf',
channel_id=channel_id_v2(local_keyset),
funding_satoshis=rbf_funding_amount,
fee_step=1,
funding_feerate_perkw=253 * 65 // 64,
locktime=0),
# Ignore unknown odd messages
TryAll([], RawMsg(bytes.fromhex('270F'))),
Expand Down Expand Up @@ -2100,7 +2103,7 @@ def test_rbf_accepter_forgets(runner: Runner, with_proposal: Any) -> None:
Msg('init_rbf',
channel_id=channel_id_v2(local_keyset),
funding_satoshis=rbf_funding_amount,
fee_step=1,
funding_feerate_perkw=253 * 65 // 64,
locktime=0),

ExpectError(),
Expand Down Expand Up @@ -2134,7 +2137,7 @@ def test_rbf_accepter_forgets(runner: Runner, with_proposal: Any) -> None:
Msg('init_rbf',
channel_id=channel_id_v2(local_keyset),
funding_satoshis=rbf_funding_amount,
fee_step=1,
funding_feerate_perkw=253 * 65 // 64,
locktime=0),

# Ignore unknown odd messages
Expand Down Expand Up @@ -2164,6 +2167,8 @@ def test_rbf_opener_forgets(runner: Runner, with_proposal: Any) -> None:

funding_amount = funding_amount_for_utxo(input_index)
rbf_funding_amount = funding_amount - 1000
initial_feerate = 2000
rbf_feerate = initial_feerate * 65 // 64

test = [Block(blockheight=102, txs=[tx_spendable]),
Connect(connprivkey='02'),
Expand All @@ -2174,7 +2179,7 @@ def test_rbf_opener_forgets(runner: Runner, with_proposal: Any) -> None:

Msg('init', globalfeatures='', features=bitfield(12, 20, 29)),

FundChannel(amount=funding_amount, feerate=2000),
FundChannel(amount=funding_amount, feerate=initial_feerate),

ExpectMsg('open_channel2',
channel_id=channel_id_tmp(local_keyset, Side.remote),
Expand Down Expand Up @@ -2222,12 +2227,12 @@ def test_rbf_opener_forgets(runner: Runner, with_proposal: Any) -> None:
amount=rbf_funding_amount,
utxo_tx=rcvd('tx_add_input.prevtx'),
utxo_outnum=rcvd('tx_add_input.prevtx_vout', int),
last_feerate=rcvd('open_channel2.funding_feerate_perkw', int)),
feerate=rbf_feerate),

ExpectMsg('init_rbf',
channel_id=channel_id_v2(local_keyset),
funding_satoshis=rbf_funding_amount,
fee_step=1),
funding_feerate_perkw=rbf_feerate),

# Ignore unknown odd messages
TryAll([], RawMsg(bytes.fromhex('270F'))),
Expand Down Expand Up @@ -2268,7 +2273,7 @@ def test_rbf_opener_forgets(runner: Runner, with_proposal: Any) -> None:
Msg('init_rbf',
channel_id=channel_id_v2(local_keyset),
funding_satoshis=rbf_funding_amount,
fee_step=1,
funding_feerate_perkw=rbf_feerate,
locktime=100),

ExpectError(),
Expand Down Expand Up @@ -2303,12 +2308,12 @@ def test_rbf_opener_forgets(runner: Runner, with_proposal: Any) -> None:
amount=rbf_funding_amount,
utxo_tx=rcvd('tx_add_input.prevtx'),
utxo_outnum=rcvd('tx_add_input.prevtx_vout', int),
last_feerate=rcvd('open_channel2.funding_feerate_perkw', int)),
feerate=rbf_feerate),

ExpectMsg('init_rbf',
channel_id=channel_id_v2(local_keyset),
funding_satoshis=rbf_funding_amount,
fee_step=1),
funding_feerate_perkw=rbf_feerate),

# Ignore unknown odd messages
TryAll([], RawMsg(bytes.fromhex('270F'))),
Expand Down Expand Up @@ -2395,7 +2400,7 @@ def test_rbf_not_valid_rbf(runner: Runner, with_proposal: Any) -> None:
Msg('init_rbf',
channel_id=channel_id_v2(local_keyset),
funding_satoshis=rbf_funding_amount,
fee_step=1,
funding_feerate_perkw=253 * 65 // 64,
locktime=0),
# Ignore unknown odd messages
TryAll([], RawMsg(bytes.fromhex('270F'))),
Expand Down

0 comments on commit ff3750b

Please sign in to comment.