Skip to content

Commit d898a1f

Browse files
Verify commitment point on ChannelReestablish (no updates case).
Adds a test for PR lightningdevkit#537.
1 parent 33b7c90 commit d898a1f

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4260,17 +4260,20 @@ mod tests {
42604260
use bitcoin::blockdata::script::{Script, Builder};
42614261
use bitcoin::blockdata::transaction::Transaction;
42624262
use bitcoin::blockdata::opcodes;
4263+
use bitcoin::network::constants::Network;
42634264
use bitcoin_hashes::hex::FromHex;
42644265
use hex;
42654266
use ln::channelmanager::{HTLCSource, PaymentPreimage, PaymentHash};
4266-
use ln::channel::{Channel,ChannelKeys,InboundHTLCOutput,OutboundHTLCOutput,InboundHTLCState,OutboundHTLCState,HTLCOutputInCommitment,TxCreationKeys};
4267+
use ln::channel::{Channel,ChannelKeys,InboundHTLCOutput,OutboundHTLCOutput,InboundHTLCState,OutboundHTLCState,HTLCOutputInCommitment,TxCreationKeys,ChannelState};
42674268
use ln::channel::MAX_FUNDING_SATOSHIS;
4269+
use ln::msgs::{DecodeError, OptionalField, DataLossProtect};
42684270
use ln::chan_utils;
42694271
use ln::chan_utils::{LocalCommitmentTransaction, ChannelPublicKeys};
42704272
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
42714273
use chain::keysinterface::{InMemoryChannelKeys, KeysInterface};
42724274
use chain::transaction::OutPoint;
42734275
use util::config::UserConfig;
4276+
use util::enforcing_trait_impls::EnforcingChannelKeys;
42744277
use util::test_utils;
42754278
use util::logger::Logger;
42764279
use secp256k1::{Secp256k1, Message, Signature, All};
@@ -4280,6 +4283,7 @@ mod tests {
42804283
use bitcoin_hashes::hash160::Hash as Hash160;
42814284
use bitcoin_hashes::Hash;
42824285
use std::sync::Arc;
4286+
use rand::{thread_rng,Rng};
42834287

42844288
struct TestFeeEstimator {
42854289
fee_est: u64
@@ -4327,6 +4331,33 @@ mod tests {
43274331
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode(hex).unwrap()[..]).unwrap())
43284332
}
43294333

4334+
#[test]
4335+
fn channel_reestablish_no_updates() {
4336+
let feeest = TestFeeEstimator{fee_est: 15000};
4337+
let logger : Arc<Logger> = Arc::new(test_utils::TestLogger::new());
4338+
let secp_ctx = Secp256k1::new();
4339+
let mut seed = [0; 32];
4340+
let mut rng = thread_rng();
4341+
rng.fill_bytes(&mut seed);
4342+
let keys_provider = test_utils::TestKeysInterface::new(&seed, Network::Testnet, logger.clone() as Arc<Logger>);
4343+
4344+
let their_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
4345+
let mut config = UserConfig::default();
4346+
config.channel_options.announced_channel = false;
4347+
let mut chan = Channel::<EnforcingChannelKeys>::new_outbound(&&feeest, &&keys_provider, their_node_id, 10000000, 100000, 42, Arc::clone(&logger), &config).unwrap();
4348+
chan.channel_state = ChannelState::PeerDisconnected as u32;
4349+
chan.cur_remote_commitment_transaction_number -= 1;
4350+
let expected_commitment_point = PublicKey::from_secret_key(&secp_ctx, &chan.build_local_commitment_secret(chan.cur_local_commitment_transaction_number + 1));
4351+
let msg = chan.get_channel_reestablish();
4352+
match msg.data_loss_protect {
4353+
OptionalField::Present(DataLossProtect { my_current_per_commitment_point, .. }) => {
4354+
assert_eq!(expected_commitment_point, my_current_per_commitment_point);
4355+
},
4356+
_ => panic!()
4357+
}
4358+
}
4359+
4360+
43304361
#[test]
43314362
fn outbound_commitment_test() {
43324363
// Test vectors from BOLT 3 Appendix C:

0 commit comments

Comments
 (0)