Skip to content

Commit 93a910b

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

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

lightning/src/ln/channel.rs

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

0 commit comments

Comments
 (0)