From d975dbd96ba6cf699a2642475c074e9fd4a6b17d Mon Sep 17 00:00:00 2001 From: niftynei Date: Tue, 13 Jul 2021 09:53:33 -0500 Subject: [PATCH] dual-funding: update init_rbf, replacing 'fee_step' with explicit fee You gotta make your feerate at least 65/64ths of the previous though --- lnprototest/clightning/clightning.py | 6 ++- lnprototest/event.py | 8 ++-- lnprototest/proposals.py | 2 +- tests/test_bolt2-20-open_channel_accepter.py | 43 +++++++++++--------- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/lnprototest/clightning/clightning.py b/lnprototest/clightning/clightning.py index 5355755..b73f63b 100644 --- a/lnprototest/clightning/clightning.py +++ b/lnprototest/clightning/clightning.py @@ -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 diff --git a/lnprototest/event.py b/lnprototest/event.py index a7954f5..760f946 100644 --- a/lnprototest/event.py +++ b/lnprototest/event.py @@ -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 diff --git a/lnprototest/proposals.py b/lnprototest/proposals.py index 97c5fb5..92794f5 100644 --- a/lnprototest/proposals.py +++ b/lnprototest/proposals.py @@ -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,", diff --git a/tests/test_bolt2-20-open_channel_accepter.py b/tests/test_bolt2-20-open_channel_accepter.py index a245441..a14ac14 100644 --- a/tests/test_bolt2-20-open_channel_accepter.py +++ b/tests/test_bolt2-20-open_channel_accepter.py @@ -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'))), @@ -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'), @@ -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), @@ -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, @@ -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'))), @@ -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'), @@ -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), @@ -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'))), @@ -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'))), @@ -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(), @@ -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 @@ -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'), @@ -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), @@ -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'))), @@ -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(), @@ -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'))), @@ -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'))),