A zero-length upfront_shutdown_script is stored as NULL, not an empty blob. BOLT #2 lets a node which negotiated `option_upfront_shutdown_script` send either a real `shutdown_scriptpubkey` or a zero-length one (ie. `0x0000`) meaning "no upfront script". We send the zero-length form whe
(node_factory, bitcoind)
| 3787 | @unittest.skipIf(TEST_NETWORK != 'regtest', 'address encoding differs on elements') |
| 3788 | @pytest.mark.openchannel('v1') |
| 3789 | def test_zero_length_upfront_shutdown_script(node_factory, bitcoind): |
| 3790 | """A zero-length upfront_shutdown_script is stored as NULL, not an empty blob. |
| 3791 | |
| 3792 | BOLT #2 lets a node which negotiated `option_upfront_shutdown_script` send |
| 3793 | either a real `shutdown_scriptpubkey` or a zero-length one (ie. `0x0000`) |
| 3794 | meaning "no upfront script". We send the zero-length form whenever the |
| 3795 | feature is negotiated and the caller gave no `close_to`, so this is what an |
| 3796 | ordinary open puts on the wire. The receiver collapses that to NULL. |
| 3797 | |
| 3798 | Then keep commitment 0 around and shift 80% of the channel to l2, so the |
| 3799 | kept commitment is badly out of date. |
| 3800 | |
| 3801 | l1 then points its shutdown script at commitment 0's own to_local output |
| 3802 | and publishes that commitment. Every output now matches a shutdown script |
| 3803 | l2 has on record, so classifying a funding spend by its outputs alone calls |
| 3804 | this a mutual close and never penalizes it. Assert l2 recognises it as a |
| 3805 | revoked commitment, sweeps it with OUR_PENALTY_TX, and that l1's to_local |
| 3806 | sweep is dead by the time its CSV matures. |
| 3807 | """ |
| 3808 | OPT_UPFRONT_SHUTDOWN_SCRIPT = 4 |
| 3809 | STATIC_REMOTEKEY = 12 |
| 3810 | ANCHORS_ZERO_FEE_HTLC_TX = 22 |
| 3811 | |
| 3812 | # l1 drops the connection the instant it has sent WIRE_SHUTDOWN, and won't |
| 3813 | # reconnect: that guarantees it never follows up with a closing message. |
| 3814 | # l1 will also broadcast a revoked commitment below, so allow it to fail and |
| 3815 | # to log the "did *we* cheat?" line its onchaind emits for that. |
| 3816 | # Neither side reconnects: l1 drops the connection the instant it has sent |
| 3817 | # WIRE_SHUTDOWN, and with both on dev-no-reconnect the shutdown never turns |
| 3818 | # into a completed mutual close (which would spend the funding before we can |
| 3819 | # broadcast the stale commitment). l1 also broadcasts a revoked commitment |
| 3820 | # below, so allow it to fail and to log the "did *we* cheat?" line. |
| 3821 | l1, l2 = node_factory.get_nodes( |
| 3822 | 2, |
| 3823 | opts=[{'disconnect': ['+WIRE_SHUTDOWN'], |
| 3824 | 'dev-no-reconnect': None, |
| 3825 | 'may_fail': True, |
| 3826 | 'broken_log': r"onchaind-chan#[0-9]*: Could not find resolution" |
| 3827 | r" for output .*: did \*we\* cheat\?"}, |
| 3828 | {'dev-no-reconnect': None}]) |
| 3829 | l1.fundwallet(10**7) |
| 3830 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 3831 | |
| 3832 | # We only send the zero-length script if the feature was negotiated: |
| 3833 | # otherwise openingd omits the TLV altogether and this proves nothing. |
| 3834 | their_features = int(only_one(l1.rpc.listpeers()['peers'])['features'], 16) |
| 3835 | assert their_features & ((1 << OPT_UPFRONT_SHUTDOWN_SCRIPT) |
| 3836 | | (1 << (OPT_UPFRONT_SHUTDOWN_SCRIPT + 1))) |
| 3837 | |
| 3838 | # No close_to, so openingd substitutes the zero-length script. |
| 3839 | ret = l1.rpc.fundchannel(l2.info['id'], FUNDAMOUNT, push_msat=0, |
| 3840 | channel_type=[STATIC_REMOTEKEY]) |
| 3841 | cid = ret['channel_id'] |
| 3842 | assert ret['channel_type']['bits'] == [STATIC_REMOTEKEY] |
| 3843 | assert ANCHORS_ZERO_FEE_HTLC_TX not in ret['channel_type']['bits'] |
| 3844 | |
| 3845 | # Hang on to commitment 0, before anything moves the channel off it. |
| 3846 | commitment_0 = l1.rpc.dev_sign_last_tx(l2.info['id'])['tx'] |
nothing calls this directly
no test coverage detected