Skip to content

Commit f6f6512

Browse files
committed
Test that EnforcingChannelKeys doesn't panic on duplicate RAAs
1 parent 7c11768 commit f6f6512

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lightning/src/ln/channel.rs

+3
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ pub(super) struct Channel<ChanSigner: ChannelKeys> {
240240
secp_ctx: Secp256k1<secp256k1::All>,
241241
channel_value_satoshis: u64,
242242

243+
#[cfg(not(test))]
243244
local_keys: ChanSigner,
245+
#[cfg(test)]
246+
pub(super) local_keys: ChanSigner,
244247
shutdown_pubkey: PublicKey,
245248

246249
// Our commitment numbers start at 2^48-1 and count down, whereas the ones used in transaction

lightning/src/ln/functional_tests.rs

+25-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
55
use chain::transaction::OutPoint;
66
use chain::chaininterface::{ChainListener, ChainWatchInterfaceUtil};
7-
use chain::keysinterface::{KeysInterface, SpendableOutputDescriptor};
7+
use chain::keysinterface::{ChannelKeys, KeysInterface, SpendableOutputDescriptor};
88
use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC};
99
use ln::channelmanager::{ChannelManager,ChannelManagerReadArgs,HTLCForwardInfo,RAACommitmentOrder, PaymentPreimage, PaymentHash, BREAKDOWN_TIMEOUT};
1010
use ln::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ManyChannelMonitor, ANTI_REORG_DELAY};
1111
use ln::channel::{ACCEPTED_HTLC_SCRIPT_WEIGHT, OFFERED_HTLC_SCRIPT_WEIGHT, Channel, ChannelError};
12-
use ln::onion_utils;
12+
use ln::{chan_utils, onion_utils};
1313
use ln::router::{Route, RouteHop};
1414
use ln::features::{ChannelFeatures, InitFeatures};
1515
use ln::msgs;
@@ -6767,6 +6767,29 @@ fn test_set_outpoints_partial_claiming() {
67676767
}
67686768
}
67696769

6770+
#[test]
6771+
fn test_counterparty_raa_skip_no_crash() {
6772+
// Previously, if our counterparty sent two RAAs in a row without us having provided a
6773+
// commitment transaction, we would have happily carried on and provided them the next
6774+
// commitment transaction based on one RAA forward. This would probably eventually have led to
6775+
// channel closure, but it would not have resulted in funds loss. Still, our
6776+
// EnforcingChannelKeys would have paniced as it doesn't like jumps into the future. Here, we
6777+
// check simply that the channel is closed in response to such an RAA, but don't check whether
6778+
// we decide to punish our counterparty for revoking their funds (as we don't currently
6779+
// implement that).
6780+
let nodes = create_network(2, &[None, None]);
6781+
let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
6782+
6783+
let commitment_seed = nodes[0].node.channel_state.lock().unwrap().by_id.get_mut(&chan.2).unwrap().local_keys.commitment_seed().clone();
6784+
let next_per_commitment_point = PublicKey::from_secret_key(&Secp256k1::new(),
6785+
&SecretKey::from_slice(&chan_utils::build_commitment_secret(&commitment_seed, (1 << 48) - 3)).unwrap());
6786+
let per_commitment_secret = chan_utils::build_commitment_secret(&commitment_seed, (1 << 48) - 1);
6787+
6788+
nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(),
6789+
&msgs::RevokeAndACK { channel_id: chan.2, per_commitment_secret, next_per_commitment_point });
6790+
assert_eq!(check_closed_broadcast!(nodes[1], true).unwrap().data, "Got a revoke when we weren't expecting one");
6791+
}
6792+
67706793
#[test]
67716794
fn test_bump_txn_sanitize_tracking_maps() {
67726795
// Sanitizing pendning_claim_request and claimable_outpoints used to be buggy,

0 commit comments

Comments
 (0)