Skip to content
14 changes: 14 additions & 0 deletions lightning/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use bitcoin::block::{Block, Header};
use bitcoin::constants::genesis_block;
use bitcoin::hash_types::{BlockHash, Txid};
use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::{Hash, HashEngine};
use bitcoin::network::Network;
use bitcoin::script::{Script, ScriptBuf};
use bitcoin::secp256k1::PublicKey;
Expand All @@ -21,6 +23,7 @@ use crate::chain::transaction::{OutPoint, TransactionData};
use crate::impl_writeable_tlv_based;
use crate::ln::types::ChannelId;
use crate::sign::ecdsa::EcdsaChannelSigner;
use crate::sign::HTLCDescriptor;

#[allow(unused_imports)]
use crate::prelude::*;
Expand Down Expand Up @@ -442,3 +445,14 @@ where
/// This is not exported to bindings users as we just use [u8; 32] directly.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct ClaimId(pub [u8; 32]);

impl ClaimId {
pub(crate) fn from_htlcs(htlcs: &[HTLCDescriptor]) -> ClaimId {
let mut engine = Sha256::engine();
for htlc in htlcs {
engine.input(&htlc.commitment_txid.to_byte_array());
engine.input(&htlc.htlc.transaction_output_index.unwrap().to_be_bytes());
}
ClaimId(Sha256::from_engine(engine).to_byte_array())
}
}
10 changes: 2 additions & 8 deletions lightning/src/chain/onchaintx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

use bitcoin::amount::Amount;
use bitcoin::hash_types::{BlockHash, Txid};
use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::{Hash, HashEngine};
use bitcoin::hashes::Hash;
use bitcoin::locktime::absolute::LockTime;
use bitcoin::script::{Script, ScriptBuf};
use bitcoin::secp256k1;
Expand Down Expand Up @@ -882,12 +881,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
// claim, which will always be unique per request. Once a claim ID
// is generated, it is assigned and remains unchanged, even if the
// underlying set of HTLCs changes.
let mut engine = Sha256::engine();
for htlc in htlcs {
engine.input(&htlc.commitment_txid.to_byte_array());
engine.input(&htlc.htlc.transaction_output_index.unwrap().to_be_bytes());
}
ClaimId(Sha256::from_engine(engine).to_byte_array())
ClaimId::from_htlcs(htlcs)
},
};
debug_assert!(self.pending_claim_requests.get(&claim_id).is_none());
Expand Down
Loading