MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_rbf_to_chain_before_commit

Function test_rbf_to_chain_before_commit

tests/test_opening.py:1245–1301  ·  view source on GitHub ↗
(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

1243@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
1244@pytest.mark.openchannel('v2')
1245def test_rbf_to_chain_before_commit(node_factory, bitcoind, chainparams):
1246 disconnects = ['=WIRE_COMMITMENT_SIGNED',
1247 '-WIRE_COMMITMENT_SIGNED']
1248 l1, l2 = node_factory.get_nodes(2,
1249 opts=[{'may_reconnect': True,
1250 'dev-no-reconnect': None},
1251 {'disconnect': disconnects,
1252 'may_reconnect': True,
1253 'dev-no-reconnect': None}])
1254
1255 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1256 amount = 2**24
1257 chan_amount = 100000
1258 bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['p2tr'], amount / 10**8 + 0.01)
1259 bitcoind.generate_block(1)
1260 # Wait for it to arrive.
1261 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
1262
1263 res = l1.rpc.fundchannel(l2.info['id'], chan_amount)
1264 chan_id = res['channel_id']
1265 vins = bitcoind.rpc.decoderawtransaction(res['tx'])['vin']
1266 assert(only_one(vins))
1267 prev_utxos = ["{}:{}".format(vins[0]['txid'], vins[0]['vout'])]
1268
1269 # Check that we're waiting for lockin
1270 l1.daemon.wait_for_log(' to DUALOPEND_AWAITING_LOCKIN')
1271
1272 # rbf the lease with a higher amount
1273 rate = int(find_next_feerate(l1, l2)[:-5])
1274 # We 4x the feerate to beat the min-relay fee
1275 next_feerate = '{}perkw'.format(rate * 4)
1276
1277 # Initiate an RBF
1278 startweight = 42 + 172 # base weight, funding output
1279 initpsbt = l1.rpc.utxopsbt(chan_amount, next_feerate, startweight,
1280 prev_utxos, reservedok=True,
1281 excess_as_change=True)
1282
1283 # Peers try RBF, break on initial COMMITMENT_SIGNED
1284 bump = l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
1285 with pytest.raises(RpcError):
1286 l1.rpc.openchannel_update(chan_id, bump['psbt'])
1287 wait_for(lambda: l1.rpc.getpeer(l2.info['id'])['connected'] is False)
1288
1289 # We don't have the commtiments yet, there's no scratch_txid
1290 inflights = only_one(l1.rpc.listpeerchannels()['channels'])['inflight']
1291 assert len(inflights) == 2
1292 assert 'scratch_txid' not in inflights[1]
1293
1294 # Close the channel!
1295 l1.rpc.close(chan_id, 1)
1296 l1.daemon.wait_for_logs(['Broadcasting txid {}'.format(inflights[0]['scratch_txid']),
1297 'sendrawtx exit 0'])
1298
1299 wait_for(lambda: inflights[0]['scratch_txid'] in bitcoind.rpc.getrawmempool())
1300 assert inflights[0]['funding_txid'] in bitcoind.rpc.getrawmempool()
1301 assert inflights[1]['funding_txid'] not in bitcoind.rpc.getrawmempool()
1302

Callers

nothing calls this directly

Calls 15

wait_forFunction · 0.90
only_oneFunction · 0.90
find_next_feerateFunction · 0.85
get_nodesMethod · 0.80
generate_blockMethod · 0.80
wait_for_logMethod · 0.80
utxopsbtMethod · 0.80
openchannel_bumpMethod · 0.80
openchannel_updateMethod · 0.80
listpeerchannelsMethod · 0.80
wait_for_logsMethod · 0.80
connectMethod · 0.45

Tested by

no test coverage detected