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

Function test_commitment_feerate

tests/test_opening.py:3100–3148  ·  view source on GitHub ↗
(bitcoind, node_factory, anchors)

Source from the content-addressed store, hash-verified

3098@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd has different feerates')
3099@pytest.mark.parametrize("anchors", [False, True])
3100def test_commitment_feerate(bitcoind, node_factory, anchors):
3101 opts = {}
3102 if anchors is False:
3103 opts['dev-force-features'] = "-23"
3104
3105 l1, l2 = node_factory.get_nodes(2, opts=opts)
3106
3107 opening_feerate = 2000
3108 if anchors:
3109 # anchors use lowball fees
3110 commitment_feerate = 3750
3111 else:
3112 commitment_feerate = opening_feerate
3113
3114 l1.fundwallet(10**8)
3115 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
3116 l1.rpc.fundchannel(l2.info['id'], 10**6,
3117 feerate=f'{opening_feerate}perkw')
3118
3119 wait_for(lambda: bitcoind.rpc.getrawmempool() != [])
3120 tx = only_one([t for t in bitcoind.rpc.getrawmempool(True).values()])
3121 feerate_perkw = int(tx['fees']['base'] * 100_000_000) / (tx['weight'] / 1000)
3122 assert opening_feerate - 10 < feerate_perkw < opening_feerate + 10
3123
3124 bitcoind.generate_block(1)
3125
3126 l2.stop()
3127 l1.rpc.close(l2.info['id'], unilateraltimeout=1)
3128
3129 # feerate for this will be the same
3130 wait_for(lambda: bitcoind.rpc.getrawmempool() != [])
3131 tx = only_one([t for t in bitcoind.rpc.getrawmempool(True).values()])
3132 fee = int(tx['fees']['base'] * 100_000_000)
3133
3134 # Weight is idealized worst case, and we don't meet it!
3135 if anchors:
3136 # 200 is the approximate cost estimate used for anchor outputs.
3137 assert tx['weight'] < 1124 - 200
3138 else:
3139 assert tx['weight'] < 724
3140
3141 if anchors:
3142 # We pay for two anchors, but only produce one.
3143 fee -= 330
3144 weight = 1124
3145 else:
3146 weight = 724
3147 feerate_perkw = fee / (weight / 1000)
3148 assert commitment_feerate - 10 < feerate_perkw < commitment_feerate + 10
3149
3150
3151@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd has different tx costs')

Callers

nothing calls this directly

Calls 9

wait_forFunction · 0.90
only_oneFunction · 0.90
get_nodesMethod · 0.80
fundwalletMethod · 0.80
generate_blockMethod · 0.80
connectMethod · 0.45
fundchannelMethod · 0.45
stopMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected