@@ -165,6 +165,7 @@ struct InboundHTLCOutput {
165
165
state: InboundHTLCState,
166
166
}
167
167
168
+ #[cfg_attr(test, derive(Clone, Debug, PartialEq))]
168
169
enum OutboundHTLCState {
169
170
/// Added by us and included in a commitment_signed (if we were AwaitingRemoteRevoke when we
170
171
/// created it we would have put it in the holding cell instead). When they next revoke_and_ack
@@ -198,6 +199,7 @@ enum OutboundHTLCState {
198
199
}
199
200
200
201
#[derive(Clone)]
202
+ #[cfg_attr(test, derive(Debug, PartialEq))]
201
203
enum OutboundHTLCOutcome {
202
204
/// LDK version 0.0.105+ will always fill in the preimage here.
203
205
Success(Option<PaymentPreimage>),
@@ -222,6 +224,7 @@ impl<'a> Into<Option<&'a HTLCFailReason>> for &'a OutboundHTLCOutcome {
222
224
}
223
225
}
224
226
227
+ #[cfg_attr(test, derive(Clone, Debug, PartialEq))]
225
228
struct OutboundHTLCOutput {
226
229
htlc_id: u64,
227
230
amount_msat: u64,
@@ -234,6 +237,7 @@ struct OutboundHTLCOutput {
234
237
}
235
238
236
239
/// See AwaitingRemoteRevoke ChannelState for more info
240
+ #[cfg_attr(test, derive(Clone, Debug, PartialEq))]
237
241
enum HTLCUpdateAwaitingACK {
238
242
AddHTLC { // TODO: Time out if we're getting close to cltv_expiry
239
243
// always outbound
@@ -7847,23 +7851,25 @@ mod tests {
7847
7851
use bitcoin::blockdata::transaction::{Transaction, TxOut};
7848
7852
use bitcoin::blockdata::opcodes;
7849
7853
use bitcoin::network::constants::Network;
7850
- use crate::ln::PaymentHash;
7854
+ use crate::ln::{ PaymentHash, PaymentPreimage} ;
7851
7855
use crate::ln::channel_keys::{RevocationKey, RevocationBasepoint};
7852
- use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
7856
+ use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
7853
7857
use crate::ln::channel::InitFeatures;
7854
- use crate::ln::channel::{ChannelState, InboundHTLCOutput, OutboundV1Channel, InboundV1Channel, OutboundHTLCOutput, InboundHTLCState, OutboundHTLCState, HTLCCandidate, HTLCInitiator, commit_tx_fee_msat};
7858
+ use crate::ln::channel::{Channel, ChannelState, InboundHTLCOutput, OutboundV1Channel, InboundV1Channel, OutboundHTLCOutput, InboundHTLCState, OutboundHTLCState, HTLCCandidate, HTLCInitiator, HTLCUpdateAwaitingACK , commit_tx_fee_msat};
7855
7859
use crate::ln::channel::{MAX_FUNDING_SATOSHIS_NO_WUMBO, TOTAL_BITCOIN_SUPPLY_SATOSHIS, MIN_THEIR_CHAN_RESERVE_SATOSHIS};
7856
- use crate::ln::features::ChannelTypeFeatures;
7860
+ use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, NodeFeatures};
7861
+ use crate::ln::msgs;
7857
7862
use crate::ln::msgs::{ChannelUpdate, DecodeError, UnsignedChannelUpdate, MAX_VALUE_MSAT};
7858
7863
use crate::ln::script::ShutdownScript;
7859
7864
use crate::ln::chan_utils::{self, htlc_success_tx_weight, htlc_timeout_tx_weight};
7860
7865
use crate::chain::BestBlock;
7861
7866
use crate::chain::chaininterface::{FeeEstimator, LowerBoundedFeeEstimator, ConfirmationTarget};
7862
7867
use crate::sign::{ChannelSigner, InMemorySigner, EntropySource, SignerProvider};
7863
7868
use crate::chain::transaction::OutPoint;
7864
- use crate::routing::router::Path;
7869
+ use crate::routing::router::{ Path, RouteHop} ;
7865
7870
use crate::util::config::UserConfig;
7866
7871
use crate::util::errors::APIError;
7872
+ use crate::util::ser::{ReadableArgs, Writeable};
7867
7873
use crate::util::test_utils;
7868
7874
use crate::util::test_utils::{OnGetShutdownScriptpubkey, TestKeysInterface};
7869
7875
use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature};
@@ -8375,6 +8381,96 @@ use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
8375
8381
assert!(!node_a_chan.channel_update(&update).unwrap());
8376
8382
}
8377
8383
8384
+ #[test]
8385
+ fn blinding_point_ser() {
8386
+ // Ensure that channel blinding points are (de)serialized properly.
8387
+ let feeest = LowerBoundedFeeEstimator::new(&TestFeeEstimator{fee_est: 15000});
8388
+ let secp_ctx = Secp256k1::new();
8389
+ let seed = [42; 32];
8390
+ let network = Network::Testnet;
8391
+ let keys_provider = test_utils::TestKeysInterface::new(&seed, network);
8392
+
8393
+ let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
8394
+ let config = UserConfig::default();
8395
+ let features = channelmanager::provided_init_features(&config);
8396
+ let outbound_chan = OutboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &features, 10000000, 100000, 42, &config, 0, 42, None).unwrap();
8397
+ let mut chan = Channel { context: outbound_chan.context };
8398
+
8399
+ let dummy_htlc_source = HTLCSource::OutboundRoute {
8400
+ path: Path {
8401
+ hops: vec![RouteHop {
8402
+ pubkey: test_utils::pubkey(2), channel_features: ChannelFeatures::empty(),
8403
+ node_features: NodeFeatures::empty(), short_channel_id: 0, fee_msat: 0,
8404
+ cltv_expiry_delta: 0, maybe_announced_channel: false,
8405
+ }],
8406
+ blinded_tail: None
8407
+ },
8408
+ session_priv: test_utils::privkey(42),
8409
+ first_hop_htlc_msat: 0,
8410
+ payment_id: PaymentId([42; 32]),
8411
+ };
8412
+ let dummy_outbound_output = OutboundHTLCOutput {
8413
+ htlc_id: 0,
8414
+ amount_msat: 0,
8415
+ payment_hash: PaymentHash([43; 32]),
8416
+ cltv_expiry: 0,
8417
+ state: OutboundHTLCState::Committed,
8418
+ source: dummy_htlc_source.clone(),
8419
+ skimmed_fee_msat: None,
8420
+ blinding_point: None,
8421
+ };
8422
+ let mut pending_outbound_htlcs = vec![dummy_outbound_output.clone(); 10];
8423
+ for (idx, htlc) in pending_outbound_htlcs.iter_mut().enumerate() {
8424
+ if idx % 2 == 0 {
8425
+ htlc.blinding_point = Some(test_utils::pubkey(42 + idx as u8));
8426
+ }
8427
+ }
8428
+ chan.context.pending_outbound_htlcs = pending_outbound_htlcs.clone();
8429
+
8430
+ let dummy_holding_cell_add_htlc = HTLCUpdateAwaitingACK::AddHTLC {
8431
+ amount_msat: 0,
8432
+ cltv_expiry: 0,
8433
+ payment_hash: PaymentHash([43; 32]),
8434
+ source: dummy_htlc_source.clone(),
8435
+ onion_routing_packet: msgs::OnionPacket {
8436
+ version: 0,
8437
+ public_key: Ok(test_utils::pubkey(1)),
8438
+ hop_data: [0; 20*65],
8439
+ hmac: [0; 32]
8440
+ },
8441
+ skimmed_fee_msat: None,
8442
+ blinding_point: None,
8443
+ };
8444
+ let dummy_holding_cell_claim_htlc = HTLCUpdateAwaitingACK::ClaimHTLC {
8445
+ payment_preimage: PaymentPreimage([42; 32]),
8446
+ htlc_id: 0,
8447
+ };
8448
+ let mut holding_cell_htlc_updates = Vec::with_capacity(10);
8449
+ for i in 0..10 {
8450
+ if i % 3 == 0 {
8451
+ holding_cell_htlc_updates.push(dummy_holding_cell_add_htlc.clone());
8452
+ } else if i % 3 == 1 {
8453
+ holding_cell_htlc_updates.push(dummy_holding_cell_claim_htlc.clone());
8454
+ } else {
8455
+ let mut dummy_add = dummy_holding_cell_add_htlc.clone();
8456
+ if let HTLCUpdateAwaitingACK::AddHTLC { ref mut blinding_point, .. } = &mut dummy_add {
8457
+ *blinding_point = Some(test_utils::pubkey(42 + i));
8458
+ } else { panic!() }
8459
+ holding_cell_htlc_updates.push(dummy_add);
8460
+ }
8461
+ }
8462
+ chan.context.holding_cell_htlc_updates = holding_cell_htlc_updates.clone();
8463
+
8464
+ // Encode and decode the channel and ensure that the HTLCs within are the same.
8465
+ let encoded_chan = chan.encode();
8466
+ let mut s = crate::io::Cursor::new(&encoded_chan);
8467
+ let mut reader = crate::util::ser::FixedLengthReader::new(&mut s, encoded_chan.len() as u64);
8468
+ let features = channelmanager::provided_channel_type_features(&config);
8469
+ let decoded_chan = Channel::read(&mut reader, (&&keys_provider, &&keys_provider, 0, &features)).unwrap();
8470
+ assert_eq!(decoded_chan.context.pending_outbound_htlcs, pending_outbound_htlcs);
8471
+ assert_eq!(decoded_chan.context.holding_cell_htlc_updates, holding_cell_htlc_updates);
8472
+ }
8473
+
8378
8474
#[cfg(feature = "_test_vectors")]
8379
8475
#[test]
8380
8476
fn outbound_commitment_test() {
@@ -9131,7 +9227,7 @@ use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
9131
9227
assert_eq!(chan_utils::build_commitment_secret(&seed, 1),
9132
9228
<Vec<u8>>::from_hex("915c75942a26bb3a433a8ce2cb0427c29ec6c1775cfc78328b57f6ba7bfeaa9c").unwrap()[..]);
9133
9229
}
9134
-
9230
+
9135
9231
#[test]
9136
9232
fn test_key_derivation() {
9137
9233
// Test vectors from BOLT 3 Appendix E:
0 commit comments