lnsweep: rm one usage of Transaction.get_preimage_script()
get_preimage_script should really have been private API... looks like everywhere it is used outside of transaction.py, it is actually abused :/ Other existing usages in plugin code I don't dare to touch without lots of manual testing...
This commit is contained in:
@@ -458,7 +458,7 @@ def create_htlctx_that_spends_from_our_ctx(
|
|||||||
assert (htlc_direction == RECEIVED) == bool(preimage), 'preimage is required iff htlc is received'
|
assert (htlc_direction == RECEIVED) == bool(preimage), 'preimage is required iff htlc is received'
|
||||||
preimage = preimage or b''
|
preimage = preimage or b''
|
||||||
ctn = extract_ctn_from_tx_and_chan(ctx, chan)
|
ctn = extract_ctn_from_tx_and_chan(ctx, chan)
|
||||||
witness_script, htlc_tx = make_htlc_tx_with_open_channel(
|
witness_script_out, htlc_tx = make_htlc_tx_with_open_channel(
|
||||||
chan=chan,
|
chan=chan,
|
||||||
pcp=our_pcp,
|
pcp=our_pcp,
|
||||||
subject=LOCAL,
|
subject=LOCAL,
|
||||||
@@ -471,9 +471,10 @@ def create_htlctx_that_spends_from_our_ctx(
|
|||||||
remote_htlc_sig = chan.get_remote_htlc_sig_for_htlc(htlc_relative_idx=htlc_relative_idx)
|
remote_htlc_sig = chan.get_remote_htlc_sig_for_htlc(htlc_relative_idx=htlc_relative_idx)
|
||||||
local_htlc_sig = htlc_tx.sign_txin(0, local_htlc_privkey)
|
local_htlc_sig = htlc_tx.sign_txin(0, local_htlc_privkey)
|
||||||
txin = htlc_tx.inputs()[0]
|
txin = htlc_tx.inputs()[0]
|
||||||
witness_program = Transaction.get_preimage_script(txin)
|
witness_script_in = txin.witness_script
|
||||||
txin.witness = make_htlc_tx_witness(remote_htlc_sig, local_htlc_sig, preimage, witness_program)
|
assert witness_script_in
|
||||||
return witness_script, htlc_tx
|
txin.witness = make_htlc_tx_witness(remote_htlc_sig, local_htlc_sig, preimage, witness_script_in)
|
||||||
|
return witness_script_out, htlc_tx
|
||||||
|
|
||||||
|
|
||||||
def create_sweeptx_their_ctx_htlc(
|
def create_sweeptx_their_ctx_htlc(
|
||||||
|
|||||||
@@ -620,14 +620,14 @@ def make_htlc_tx_witness(remotehtlcsig: bytes, localhtlcsig: bytes,
|
|||||||
return construct_witness([0, remotehtlcsig, localhtlcsig, payment_preimage, witness_script])
|
return construct_witness([0, remotehtlcsig, localhtlcsig, payment_preimage, witness_script])
|
||||||
|
|
||||||
def make_htlc_tx_inputs(htlc_output_txid: str, htlc_output_index: int,
|
def make_htlc_tx_inputs(htlc_output_txid: str, htlc_output_index: int,
|
||||||
amount_msat: int, witness_script: str) -> List[PartialTxInput]:
|
amount_msat: int, witness_script: bytes) -> List[PartialTxInput]:
|
||||||
assert type(htlc_output_txid) is str
|
assert type(htlc_output_txid) is str
|
||||||
assert type(htlc_output_index) is int
|
assert type(htlc_output_index) is int
|
||||||
assert type(amount_msat) is int
|
assert type(amount_msat) is int
|
||||||
assert type(witness_script) is str
|
assert type(witness_script) is bytes
|
||||||
txin = PartialTxInput(prevout=TxOutpoint(txid=bfh(htlc_output_txid), out_idx=htlc_output_index),
|
txin = PartialTxInput(prevout=TxOutpoint(txid=bfh(htlc_output_txid), out_idx=htlc_output_index),
|
||||||
nsequence=0)
|
nsequence=0)
|
||||||
txin.witness_script = bfh(witness_script)
|
txin.witness_script = witness_script
|
||||||
txin.script_sig = b''
|
txin.script_sig = b''
|
||||||
txin._trusted_value_sats = amount_msat // 1000
|
txin._trusted_value_sats = amount_msat // 1000
|
||||||
c_inputs = [txin]
|
c_inputs = [txin]
|
||||||
@@ -826,13 +826,15 @@ def possible_output_idxs_of_htlc_in_ctx(*, chan: 'Channel', pcp: bytes, subject:
|
|||||||
other_revocation_pubkey = derive_blinded_pubkey(other_conf.revocation_basepoint.pubkey, pcp)
|
other_revocation_pubkey = derive_blinded_pubkey(other_conf.revocation_basepoint.pubkey, pcp)
|
||||||
other_htlc_pubkey = derive_pubkey(other_conf.htlc_basepoint.pubkey, pcp)
|
other_htlc_pubkey = derive_pubkey(other_conf.htlc_basepoint.pubkey, pcp)
|
||||||
htlc_pubkey = derive_pubkey(conf.htlc_basepoint.pubkey, pcp)
|
htlc_pubkey = derive_pubkey(conf.htlc_basepoint.pubkey, pcp)
|
||||||
preimage_script = make_htlc_output_witness_script(is_received_htlc=htlc_direction == RECEIVED,
|
witness_script = make_htlc_output_witness_script(
|
||||||
remote_revocation_pubkey=other_revocation_pubkey,
|
is_received_htlc=htlc_direction == RECEIVED,
|
||||||
remote_htlc_pubkey=other_htlc_pubkey,
|
remote_revocation_pubkey=other_revocation_pubkey,
|
||||||
local_htlc_pubkey=htlc_pubkey,
|
remote_htlc_pubkey=other_htlc_pubkey,
|
||||||
payment_hash=payment_hash,
|
local_htlc_pubkey=htlc_pubkey,
|
||||||
cltv_abs=cltv_abs)
|
payment_hash=payment_hash,
|
||||||
htlc_address = redeem_script_to_address('p2wsh', preimage_script)
|
cltv_abs=cltv_abs,
|
||||||
|
)
|
||||||
|
htlc_address = redeem_script_to_address('p2wsh', witness_script)
|
||||||
candidates = ctx.get_output_idxs_from_address(htlc_address)
|
candidates = ctx.get_output_idxs_from_address(htlc_address)
|
||||||
return {output_idx for output_idx in candidates
|
return {output_idx for output_idx in candidates
|
||||||
if ctx.outputs()[output_idx].value == htlc.amount_msat // 1000}
|
if ctx.outputs()[output_idx].value == htlc.amount_msat // 1000}
|
||||||
@@ -889,16 +891,18 @@ def make_htlc_tx_with_open_channel(*, chan: 'Channel', pcp: bytes, subject: 'HTL
|
|||||||
local_delayedpubkey=delayedpubkey,
|
local_delayedpubkey=delayedpubkey,
|
||||||
success = is_htlc_success,
|
success = is_htlc_success,
|
||||||
to_self_delay = other_conf.to_self_delay)
|
to_self_delay = other_conf.to_self_delay)
|
||||||
preimage_script = make_htlc_output_witness_script(is_received_htlc=is_htlc_success,
|
witness_script_in = make_htlc_output_witness_script(
|
||||||
remote_revocation_pubkey=other_revocation_pubkey,
|
is_received_htlc=is_htlc_success,
|
||||||
remote_htlc_pubkey=other_htlc_pubkey,
|
remote_revocation_pubkey=other_revocation_pubkey,
|
||||||
local_htlc_pubkey=htlc_pubkey,
|
remote_htlc_pubkey=other_htlc_pubkey,
|
||||||
payment_hash=payment_hash,
|
local_htlc_pubkey=htlc_pubkey,
|
||||||
cltv_abs=cltv_abs)
|
payment_hash=payment_hash,
|
||||||
|
cltv_abs=cltv_abs,
|
||||||
|
)
|
||||||
htlc_tx_inputs = make_htlc_tx_inputs(
|
htlc_tx_inputs = make_htlc_tx_inputs(
|
||||||
commit.txid(), ctx_output_idx,
|
commit.txid(), ctx_output_idx,
|
||||||
amount_msat=amount_msat,
|
amount_msat=amount_msat,
|
||||||
witness_script=preimage_script.hex())
|
witness_script=witness_script_in)
|
||||||
if is_htlc_success:
|
if is_htlc_success:
|
||||||
cltv_abs = 0
|
cltv_abs = 0
|
||||||
htlc_tx = make_htlc_tx(cltv_abs=cltv_abs, inputs=htlc_tx_inputs, output=htlc_tx_output)
|
htlc_tx = make_htlc_tx(cltv_abs=cltv_abs, inputs=htlc_tx_inputs, output=htlc_tx_output)
|
||||||
|
|||||||
@@ -584,7 +584,7 @@ class TestLNUtil(ElectrumTestCase):
|
|||||||
htlc_output_txid=our_commit_tx.txid(),
|
htlc_output_txid=our_commit_tx.txid(),
|
||||||
htlc_output_index=htlc_output_index,
|
htlc_output_index=htlc_output_index,
|
||||||
amount_msat=amount_msat,
|
amount_msat=amount_msat,
|
||||||
witness_script=htlc.hex())
|
witness_script=htlc)
|
||||||
our_htlc_tx = make_htlc_tx(
|
our_htlc_tx = make_htlc_tx(
|
||||||
cltv_abs=cltv_abs,
|
cltv_abs=cltv_abs,
|
||||||
inputs=our_htlc_tx_inputs,
|
inputs=our_htlc_tx_inputs,
|
||||||
|
|||||||
Reference in New Issue
Block a user