@@ -255,7 +255,6 @@ enum HTLCUpdateAwaitingACK {
255
255
/// Note that `PeerDisconnected` can be set on both `ChannelReady` and `FundingSent`.
256
256
/// `ChannelReady` can then get all remaining flags set on it, until we finish shutdown, then we
257
257
/// move on to `ShutdownComplete`, at which point most calls into this channel are disallowed.
258
- #[derive(Clone, Copy)]
259
258
enum ChannelState {
260
259
/// Implies we have (or are prepared to) send our open_channel/accept_channel message
261
260
OurInitSent = 1 << 0,
@@ -319,54 +318,6 @@ const STATE_FLAGS: u32 =
319
318
ChannelState::OurChannelReady as u32 |
320
319
ChannelState::AwaitingRemoteRevoke as u32 |
321
320
ChannelState::WaitingForBatch as u32;
322
- const CHANNEL_STATE_ENUMS: [ChannelState; 14] = [
323
- ChannelState::OurInitSent,
324
- ChannelState::TheirInitSent,
325
- ChannelState::FundingCreated,
326
- ChannelState::FundingSent,
327
- ChannelState::TheirChannelReady,
328
- ChannelState::OurChannelReady,
329
- ChannelState::ChannelReady,
330
- ChannelState::PeerDisconnected,
331
- ChannelState::MonitorUpdateInProgress,
332
- ChannelState::AwaitingRemoteRevoke,
333
- ChannelState::RemoteShutdownSent,
334
- ChannelState::LocalShutdownSent,
335
- ChannelState::ShutdownComplete,
336
- ChannelState::WaitingForBatch,
337
- ];
338
-
339
- struct ChannelStateInt(u32);
340
-
341
- impl IntoIterator for ChannelStateInt {
342
- type Item = ChannelState;
343
- type IntoIter = Box<dyn Iterator<Item = ChannelState>>;
344
-
345
- fn into_iter(self) -> Self::IntoIter {
346
- Box::new(
347
- CHANNEL_STATE_ENUMS.iter()
348
- .filter(move |&channel_state| self.0 & *channel_state as u32 != 0)
349
- .map(|channel_state| channel_state.clone())
350
- )
351
- }
352
- }
353
-
354
- impl_writeable_tlv_based_enum_upgradable!(ChannelState,
355
- (0, OurInitSent) => {},
356
- (2, TheirInitSent) => {},
357
- (4, FundingCreated) => {},
358
- (6, FundingSent) => {},
359
- (8, TheirChannelReady) => {},
360
- (10, OurChannelReady) => {},
361
- (12, ChannelReady) => {},
362
- (14, PeerDisconnected) => {},
363
- (16, MonitorUpdateInProgress) => {},
364
- (18, AwaitingRemoteRevoke) => {},
365
- (20, RemoteShutdownSent) => {},
366
- (22, LocalShutdownSent) => {},
367
- (24, ShutdownComplete) => {},
368
- (26, WaitingForBatch) => {},
369
- );
370
321
371
322
pub const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1;
372
323
@@ -854,6 +805,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
854
805
pub(crate) channel_transaction_parameters: ChannelTransactionParameters,
855
806
funding_transaction: Option<Transaction>,
856
807
funding_txid: Option<Txid>,
808
+ is_batch_funding: Option<bool>,
857
809
858
810
counterparty_cur_commitment_point: Option<PublicKey>,
859
811
counterparty_prev_commitment_point: Option<PublicKey>,
@@ -1990,7 +1942,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1990
1942
fn if_unbroadcasted_funding<F, O>(&self, f: F) -> Option<O>
1991
1943
where F: Fn() -> Option<O> {
1992
1944
if self.channel_state & ChannelState::FundingCreated as u32 != 0 ||
1993
- self.channel_state & ChannelState::WaitingForBatch as u32 != 0 {
1945
+ self.channel_state & ChannelState::WaitingForBatch as u32 != 0 {
1994
1946
f()
1995
1947
} else {
1996
1948
None
@@ -2009,6 +1961,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2009
1961
self.if_unbroadcasted_funding(|| self.funding_txid.clone())
2010
1962
}
2011
1963
1964
+ /// Returns whether the channel is funded in a batch.
1965
+ pub fn is_batch_funding(&self) -> bool {
1966
+ self.is_batch_funding.unwrap_or(false)
1967
+ }
1968
+
2012
1969
/// Gets the latest commitment transaction and any dependent transactions for relay (forcing
2013
1970
/// shutdown of this channel - no more calls into this Channel may be made afterwards except
2014
1971
/// those explicitly stated to be allowed after shutdown completes, eg some simple getters).
@@ -2552,7 +2509,7 @@ impl<SP: Deref> Channel<SP> where
2552
2509
/// Handles a funding_signed message from the remote end.
2553
2510
/// If this call is successful, broadcast the funding transaction (and not before!)
2554
2511
pub fn funding_signed<L: Deref>(
2555
- &mut self, msg: &msgs::FundingSigned, best_block: BestBlock, signer_provider: &SP, is_batch_funding: bool, logger: &L
2512
+ &mut self, msg: &msgs::FundingSigned, best_block: BestBlock, signer_provider: &SP, logger: &L
2556
2513
) -> Result<ChannelMonitor<<SP::Target as SignerProvider>::Signer>, ChannelError>
2557
2514
where
2558
2515
L::Target: Logger
@@ -2627,7 +2584,7 @@ impl<SP: Deref> Channel<SP> where
2627
2584
counterparty_initial_commitment_tx.to_countersignatory_value_sat(), logger);
2628
2585
2629
2586
assert_eq!(self.context.channel_state & (ChannelState::MonitorUpdateInProgress as u32), 0); // We have no had any monitor(s) yet to fail update!
2630
- if is_batch_funding {
2587
+ if self.context. is_batch_funding() {
2631
2588
self.context.channel_state = ChannelState::FundingSent as u32 | ChannelState::WaitingForBatch as u32;
2632
2589
} else {
2633
2590
self.context.channel_state = ChannelState::FundingSent as u32;
@@ -5830,6 +5787,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5830
5787
},
5831
5788
funding_transaction: None,
5832
5789
funding_txid: None,
5790
+ is_batch_funding: None,
5833
5791
5834
5792
counterparty_cur_commitment_point: None,
5835
5793
counterparty_prev_commitment_point: None,
@@ -5890,7 +5848,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5890
5848
/// Note that channel_id changes during this call!
5891
5849
/// Do NOT broadcast the funding transaction until after a successful funding_signed call!
5892
5850
/// If an Err is returned, it is a ChannelError::Close.
5893
- pub fn get_funding_created<L: Deref>(mut self, funding_transaction: Transaction, funding_txo: OutPoint, logger: &L)
5851
+ pub fn get_funding_created<L: Deref>(mut self, funding_transaction: Transaction, funding_txo: OutPoint, is_batch_funding: bool, logger: &L)
5894
5852
-> Result<(Channel<SP>, msgs::FundingCreated), (Self, ChannelError)> where L::Target: Logger {
5895
5853
if !self.context.is_outbound() {
5896
5854
panic!("Tried to create outbound funding_created message on an inbound channel!");
@@ -5924,6 +5882,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5924
5882
self.context.channel_id = funding_txo.to_channel_id();
5925
5883
self.context.funding_transaction = Some(funding_transaction);
5926
5884
self.context.funding_txid = self.context.funding_transaction.as_ref().map(|tx| tx.txid());
5885
+ self.context.is_batch_funding = Some(is_batch_funding);
5927
5886
5928
5887
let channel = Channel {
5929
5888
context: self.context,
@@ -6474,6 +6433,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
6474
6433
},
6475
6434
funding_transaction: None,
6476
6435
funding_txid: None,
6436
+ is_batch_funding: None,
6477
6437
6478
6438
counterparty_cur_commitment_point: Some(msg.first_per_commitment_point),
6479
6439
counterparty_prev_commitment_point: None,
@@ -7090,9 +7050,9 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
7090
7050
(35, pending_outbound_skimmed_fees, optional_vec),
7091
7051
(37, holding_cell_skimmed_fees, optional_vec),
7092
7052
(
7093
- if self.context.channel_state & ChannelState::WaitingForBatch as u32 != 0 { 38 } else { 39 },
7094
- ChannelStateInt( self.context.channel_state).into_iter().collect::<Vec<ChannelState>>() ,
7095
- optional_vec
7053
+ if self.context.is_batch_funding() { 38 } else { 39 },
7054
+ self.context.is_batch_funding ,
7055
+ option
7096
7056
),
7097
7057
});
7098
7058
@@ -7378,8 +7338,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7378
7338
let mut pending_outbound_skimmed_fees_opt: Option<Vec<Option<u64>>> = None;
7379
7339
let mut holding_cell_skimmed_fees_opt: Option<Vec<Option<u64>>> = None;
7380
7340
7381
- let mut _channel_states_even : Option<Vec<ChannelState>> ;
7382
- let mut _channel_states_uneven : Option<Vec<ChannelState>> ;
7341
+ let mut is_batch_funding_even : Option<bool> = None ;
7342
+ let mut is_batch_funding_uneven : Option<bool> = None ;
7383
7343
7384
7344
read_tlv_fields!(reader, {
7385
7345
(0, announcement_sigs, option),
@@ -7406,8 +7366,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7406
7366
(31, channel_pending_event_emitted, option),
7407
7367
(35, pending_outbound_skimmed_fees_opt, optional_vec),
7408
7368
(37, holding_cell_skimmed_fees_opt, optional_vec),
7409
- (38, _channel_states_even, optional_vec ),
7410
- (39, _channel_states_uneven, optional_vec ),
7369
+ (38, is_batch_funding_even, option ),
7370
+ (39, is_batch_funding_uneven, option ),
7411
7371
});
7412
7372
7413
7373
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -7566,6 +7526,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
7566
7526
channel_transaction_parameters: channel_parameters,
7567
7527
funding_transaction,
7568
7528
funding_txid,
7529
+ is_batch_funding: is_batch_funding_even.or(is_batch_funding_uneven),
7569
7530
7570
7531
counterparty_cur_commitment_point,
7571
7532
counterparty_prev_commitment_point,
@@ -7798,11 +7759,11 @@ mod tests {
7798
7759
value: 10000000, script_pubkey: output_script.clone(),
7799
7760
}]};
7800
7761
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
7801
- let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, &&logger).map_err(|_| ()).unwrap();
7762
+ let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
7802
7763
let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7803
7764
7804
7765
// Node B --> Node A: funding signed
7805
- let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, false, &&logger).unwrap();
7766
+ let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
7806
7767
7807
7768
// Put some inbound and outbound HTLCs in A's channel.
7808
7769
let htlc_amount_msat = 11_092_000; // put an amount below A's effective dust limit but above B's.
@@ -7925,11 +7886,11 @@ mod tests {
7925
7886
value: 10000000, script_pubkey: output_script.clone(),
7926
7887
}]};
7927
7888
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
7928
- let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, &&logger).map_err(|_| ()).unwrap();
7889
+ let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
7929
7890
let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
7930
7891
7931
7892
// Node B --> Node A: funding signed
7932
- let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, false, &&logger).unwrap();
7893
+ let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
7933
7894
7934
7895
// Now disconnect the two nodes and check that the commitment point in
7935
7896
// Node B's channel_reestablish message is sane.
@@ -8113,11 +8074,11 @@ mod tests {
8113
8074
value: 10000000, script_pubkey: output_script.clone(),
8114
8075
}]};
8115
8076
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
8116
- let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, &&logger).map_err(|_| ()).unwrap();
8077
+ let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
8117
8078
let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg, best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
8118
8079
8119
8080
// Node B --> Node A: funding signed
8120
- let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, false, &&logger).unwrap();
8081
+ let _ = node_a_chan.funding_signed(&funding_signed_msg, best_block, &&keys_provider, &&logger).unwrap();
8121
8082
8122
8083
// Make sure that receiving a channel update will update the Channel as expected.
8123
8084
let update = ChannelUpdate {
@@ -9168,6 +9129,7 @@ mod tests {
9168
9129
let (mut node_a_chan, funding_created_msg) = node_a_chan.get_funding_created(
9169
9130
tx.clone(),
9170
9131
funding_outpoint,
9132
+ true,
9171
9133
&&logger,
9172
9134
).map_err(|_| ()).unwrap();
9173
9135
let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(
@@ -9190,7 +9152,6 @@ mod tests {
9190
9152
&funding_signed_msg,
9191
9153
best_block,
9192
9154
&&keys_provider,
9193
- true,
9194
9155
&&logger,
9195
9156
).unwrap();
9196
9157
let node_a_updates = node_a_chan.monitor_updating_restored(
0 commit comments