-
Notifications
You must be signed in to change notification settings - Fork 974
Add a 'reservation expiration' mechanism #3789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
85ab7a5
9cb5583
01e2a86
fe62472
9a85567
e375d03
90f3e1e
c53daed
ccf85a0
7eaf29c
b6e759c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -557,9 +557,86 @@ def test_reserveinputs(node_factory, bitcoind, chainparams): | |
| assert len([x for x in outputs if not x['reserved']]) == 0 | ||
| assert len([x for x in outputs if x['reserved']]) == 12 | ||
|
|
||
| # FIXME: restart the node, nothing will remain reserved | ||
| # restart the node, things remain reserved | ||
| l1.restart() | ||
| assert len(l1.rpc.listfunds()['outputs']) == 12 | ||
| outputs = l1.rpc.listfunds()['outputs'] | ||
| assert len([x for x in outputs if x['reserved']]) == 12 | ||
|
|
||
| # move the blockchain forward 144 blocks (default reserved value) | ||
| l1.stop() | ||
| bitcoind.generate_block(144) | ||
| l1.start() | ||
| sync_blockheight(bitcoind, [l1]) | ||
| # everything should be back to unreserved now | ||
| outputs = l1.rpc.listfunds()['outputs'] | ||
| assert len([x for x in outputs if not x['reserved']]) == 12 | ||
|
|
||
| # try setting the default reserved to 5 blocks | ||
| reserved = l1.rpc.reserveinputs([{addr: 'all'}], expire_after=5) | ||
| bitcoind.generate_block(5) | ||
| sync_blockheight(bitcoind, [l1]) | ||
| outputs = l1.rpc.listfunds()['outputs'] | ||
| assert len([x for x in outputs if not x['reserved']]) == 12 | ||
|
|
||
| # try turning off the default reservation | ||
| reserved = l1.rpc.reserveinputs([{addr: 'all'}], expire_after=0) | ||
| bitcoind.generate_block(144) | ||
| sync_blockheight(bitcoind, [l1]) | ||
| outputs = l1.rpc.listfunds()['outputs'] | ||
| assert len([x for x in outputs if x['reserved']]) == 12 | ||
|
|
||
|
|
||
| def test_reserve_rbf(node_factory, bitcoind, chainparams): | ||
| """ | ||
| We now default everything to RBF. I'm not really sure how to test this | ||
| """ | ||
| amount = 1000000 | ||
| total_outs = 12 | ||
| coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py') | ||
| l1 = node_factory.get_node(options={'plugin': coin_mvt_plugin}, | ||
| feerates=(7500, 7500, 7500, 7500)) | ||
| l2 = node_factory.get_node() | ||
| addr = chainparams['example_addr'] | ||
|
|
||
| # Add a medley of funds to withdraw later, bech32 + p2sh-p2wpkh | ||
| for i in range(total_outs // 2): | ||
| bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], | ||
| amount / 10**8) | ||
| bitcoind.rpc.sendtoaddress(l1.rpc.newaddr('p2sh-segwit')['p2sh-segwit'], | ||
| amount / 10**8) | ||
| bitcoind.generate_block(1) | ||
| wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == total_outs) | ||
|
|
||
| # Make a PSBT out of our inputs | ||
| reserved = l1.rpc.reserveinputs(outputs=[{addr: Millisatoshi(3 * amount * 1000)}]) | ||
| assert len([x for x in l1.rpc.listfunds()['outputs'] if x['reserved']]) == 4 | ||
|
|
||
| signed_psbt = l1.rpc.signpsbt(reserved['psbt'])['signed_psbt'] | ||
| broadcast_tx = l1.rpc.sendpsbt(signed_psbt) | ||
| assert bitcoind.rpc.getmempoolinfo()['size'] == 1 | ||
|
|
||
| # Try to do it again? | ||
| psbt = bitcoind.rpc.decodepsbt(reserved['psbt']) | ||
| utxos = [] | ||
| unreserve_utxos = [] | ||
| for vin in psbt['tx']['vin']: | ||
| utxos.append(vin['txid'] + ":" + str(vin['vout'])) | ||
| unreserve_utxos.append({'txid': vin['txid'], 'vout': vin['vout'], 'sequence': vin['sequence']}) | ||
| unreserve_psbt = bitcoind.rpc.createpsbt(unreserve_utxos, []) | ||
| unres = l1.rpc.unreserveinputs(unreserve_psbt) | ||
|
|
||
| # let's not set the fee high enough, should explode | ||
| reserved = l1.rpc.reserveinputs([{addr: Millisatoshi(amount * 0.5 * 1000)}], feerate='7000perkw', utxos=utxos) | ||
| signed_psbt = l1.rpc.signpsbt(reserved['psbt'])['signed_psbt'] | ||
| with pytest.raises(RpcError, match=r'insufficient fee, rejecting replacement'): | ||
| l1.rpc.sendpsbt(signed_psbt) | ||
|
|
||
| # now let's do it for reals | ||
| unres = l1.rpc.unreserveinputs(unreserve_psbt) | ||
| reserved = l1.rpc.reserveinputs([{addr: Millisatoshi(amount * 0.5 * 1000)}], feerate='10000perkw', utxos=utxos) | ||
| signed_psbt = l1.rpc.signpsbt(reserved['psbt'])['signed_psbt'] | ||
| l1.rpc.sendpsbt(signed_psbt) | ||
| assert bitcoind.rpc.getmempoolinfo()['size'] == 1 | ||
|
Comment on lines
+638
to
+639
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check that the new tx is in the mempool? Just checking for the size of the mempool might pass despite the old tx still being in there. |
||
|
|
||
|
|
||
| def test_sign_and_send_psbt(node_factory, bitcoind, chainparams): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like an unrelated change.