Skip to content

Commit e7b77e2

Browse files
committed
Assert we never write channels in pre-funded/shutdown state
1 parent 6ab8d23 commit e7b77e2

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7387,6 +7387,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
73877387
let mut channel_state = self.context.channel_state;
73887388
if matches!(channel_state, ChannelState::AwaitingChannelReady(_)|ChannelState::ChannelReady(_)) {
73897389
channel_state.set_peer_disconnected();
7390+
} else {
7391+
debug_assert!(false, "Pre-funded/shutdown channels should not be written");
73907392
}
73917393
channel_state.to_u32().write(writer)?;
73927394
}
@@ -8756,17 +8758,34 @@ mod tests {
87568758
#[test]
87578759
fn blinding_point_skimmed_fee_ser() {
87588760
// Ensure that channel blinding points and skimmed fees are (de)serialized properly.
8761+
let logger = test_utils::TestLogger::new();
87598762
let feeest = LowerBoundedFeeEstimator::new(&TestFeeEstimator{fee_est: 15000});
87608763
let secp_ctx = Secp256k1::new();
87618764
let seed = [42; 32];
87628765
let network = Network::Testnet;
8766+
let best_block = BestBlock::from_network(network);
87638767
let keys_provider = test_utils::TestKeysInterface::new(&seed, network);
87648768

87658769
let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
87668770
let config = UserConfig::default();
87678771
let features = channelmanager::provided_init_features(&config);
8768-
let outbound_chan = OutboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &features, 10000000, 100000, 42, &config, 0, 42, None).unwrap();
8769-
let mut chan = Channel { context: outbound_chan.context };
8772+
let mut outbound_chan = OutboundV1Channel::<&TestKeysInterface>::new(
8773+
&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &features, 10000000, 100000, 42, &config, 0, 42, None
8774+
).unwrap();
8775+
let inbound_chan = InboundV1Channel::<&TestKeysInterface>::new(
8776+
&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config),
8777+
&features, &outbound_chan.get_open_channel(ChainHash::using_genesis_block(network)), 7, &config, 0, &&logger, false
8778+
).unwrap();
8779+
outbound_chan.accept_channel(&inbound_chan.get_accept_channel_message(), &config.channel_handshake_limits, &features).unwrap();
8780+
let tx = Transaction { version: 1, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
8781+
value: 10000000, script_pubkey: outbound_chan.context.get_funding_redeemscript(),
8782+
}]};
8783+
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
8784+
let (_, funding_created) = outbound_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
8785+
let mut chan = match inbound_chan.funding_created(&funding_created.unwrap(), best_block, &&keys_provider, &&logger) {
8786+
Ok((chan, _, _)) => chan,
8787+
Err((_, e)) => panic!("{}", e),
8788+
};
87708789

87718790
let dummy_htlc_source = HTLCSource::OutboundRoute {
87728791
path: Path {

0 commit comments

Comments
 (0)