Skip to content

Commit 837b9cc

Browse files
committed
Implement Holder HTLC claim chunking for 0FC channels
Otherwise, we could hit the max 10_000vB size limit on V3 transactions (BIP 431 rule 4). Also introduce a `max_tx_weight` parameter to `select_confirmed_utxos`. This constraint makes sure anchor and HTLC transactions in 0FC channels satisfy the `TRUC_MAX_WEIGHT` and the `TRUC_CHILD_MAX_WEIGHT` maximums. Expand the coin-selection algorithm provided for any `T: WalletSource` to satisfy this new constraint.
1 parent 19a9dbd commit 837b9cc

File tree

10 files changed

+460
-159
lines changed

10 files changed

+460
-159
lines changed

lightning/src/chain/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use bitcoin::block::{Block, Header};
1313
use bitcoin::constants::genesis_block;
1414
use bitcoin::hash_types::{BlockHash, Txid};
15+
use bitcoin::hashes::sha256::Hash as Sha256;
16+
use bitcoin::hashes::{Hash, HashEngine};
1517
use bitcoin::network::Network;
1618
use bitcoin::script::{Script, ScriptBuf};
1719
use bitcoin::secp256k1::PublicKey;
@@ -21,6 +23,7 @@ use crate::chain::transaction::{OutPoint, TransactionData};
2123
use crate::impl_writeable_tlv_based;
2224
use crate::ln::types::ChannelId;
2325
use crate::sign::ecdsa::EcdsaChannelSigner;
26+
use crate::sign::HTLCDescriptor;
2427

2528
#[allow(unused_imports)]
2629
use crate::prelude::*;
@@ -442,3 +445,14 @@ where
442445
/// This is not exported to bindings users as we just use [u8; 32] directly.
443446
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
444447
pub struct ClaimId(pub [u8; 32]);
448+
449+
impl ClaimId {
450+
pub(crate) fn from_htlcs(htlcs: &[HTLCDescriptor]) -> ClaimId {
451+
let mut engine = Sha256::engine();
452+
for htlc in htlcs {
453+
engine.input(&htlc.commitment_txid.to_byte_array());
454+
engine.input(&htlc.htlc.transaction_output_index.unwrap().to_be_bytes());
455+
}
456+
ClaimId(Sha256::from_engine(engine).to_byte_array())
457+
}
458+
}

lightning/src/chain/onchaintx.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
1515
use bitcoin::amount::Amount;
1616
use bitcoin::hash_types::{BlockHash, Txid};
17-
use bitcoin::hashes::sha256::Hash as Sha256;
18-
use bitcoin::hashes::{Hash, HashEngine};
17+
use bitcoin::hashes::Hash;
1918
use bitcoin::locktime::absolute::LockTime;
2019
use bitcoin::script::{Script, ScriptBuf};
2120
use bitcoin::secp256k1;
@@ -882,12 +881,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
882881
// claim, which will always be unique per request. Once a claim ID
883882
// is generated, it is assigned and remains unchanged, even if the
884883
// underlying set of HTLCs changes.
885-
let mut engine = Sha256::engine();
886-
for htlc in htlcs {
887-
engine.input(&htlc.commitment_txid.to_byte_array());
888-
engine.input(&htlc.htlc.transaction_output_index.unwrap().to_be_bytes());
889-
}
890-
ClaimId(Sha256::from_engine(engine).to_byte_array())
884+
ClaimId::from_htlcs(htlcs)
891885
},
892886
};
893887
debug_assert!(self.pending_claim_requests.get(&claim_id).is_none());

0 commit comments

Comments
 (0)