Skip to content

Commit df55910

Browse files
Remove Channel's ChannelMonitor copy
1 parent f3a8a1c commit df55910

File tree

2 files changed

+1
-57
lines changed

2 files changed

+1
-57
lines changed

lightning/src/ln/channel.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,6 @@ pub(super) struct Channel<ChanSigner: ChannelKeys> {
386386

387387
their_shutdown_scriptpubkey: Option<Script>,
388388

389-
/// Used exclusively to broadcast the latest local state, mostly a historical quirk that this
390-
/// is here:
391-
channel_monitor: Option<ChannelMonitor<ChanSigner>>,
392389
commitment_secrets: CounterpartyCommitmentSecrets,
393390

394391
network_sync: UpdateStatus,
@@ -557,7 +554,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
557554

558555
their_shutdown_scriptpubkey: None,
559556

560-
channel_monitor: None,
561557
commitment_secrets: CounterpartyCommitmentSecrets::new(),
562558

563559
network_sync: UpdateStatus::Fresh,
@@ -786,7 +782,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
786782

787783
their_shutdown_scriptpubkey,
788784

789-
channel_monitor: None,
790785
commitment_secrets: CounterpartyCommitmentSecrets::new(),
791786

792787
network_sync: UpdateStatus::Fresh,
@@ -1222,7 +1217,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
12221217
payment_preimage: payment_preimage_arg.clone(),
12231218
}],
12241219
};
1225-
self.channel_monitor.as_mut().unwrap().update_monitor_ooo(monitor_update.clone(), logger).unwrap();
12261220

12271221
if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32 | ChannelState::PeerDisconnected as u32 | ChannelState::MonitorUpdateFailed as u32)) != 0 {
12281222
for pending_update in self.holding_cell_htlc_updates.iter() {
@@ -1552,7 +1546,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
15521546
} }
15531547
}
15541548

1555-
self.channel_monitor = Some(create_monitor!());
15561549
let channel_monitor = create_monitor!();
15571550

15581551
self.channel_state = ChannelState::FundingSent as u32;
@@ -1618,7 +1611,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
16181611
} }
16191612
}
16201613

1621-
self.channel_monitor = Some(create_monitor!());
16221614
let channel_monitor = create_monitor!();
16231615

16241616
assert_eq!(self.channel_state & (ChannelState::MonitorUpdateFailed as u32), 0); // We have no had any monitor(s) yet to fail update!
@@ -2060,7 +2052,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
20602052
htlc_outputs: htlcs_and_sigs
20612053
}]
20622054
};
2063-
self.channel_monitor.as_mut().unwrap().update_monitor_ooo(monitor_update.clone(), logger).unwrap();
20642055

20652056
for htlc in self.pending_inbound_htlcs.iter_mut() {
20662057
let new_forward = if let &InboundHTLCState::RemoteAnnounced(ref forward_info) = &htlc.state {
@@ -2280,7 +2271,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
22802271
secret: msg.per_commitment_secret,
22812272
}],
22822273
};
2283-
self.channel_monitor.as_mut().unwrap().update_monitor_ooo(monitor_update.clone(), logger).unwrap();
22842274

22852275
// Update state now that we've passed all the can-fail calls...
22862276
// (note that we may still fail to generate the new commitment_signed message, but that's
@@ -3115,14 +3105,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
31153105
self.user_id
31163106
}
31173107

3118-
/// May only be called after funding has been initiated (ie is_funding_initiated() is true)
3119-
pub fn channel_monitor(&mut self) -> &mut ChannelMonitor<ChanSigner> {
3120-
if self.channel_state < ChannelState::FundingSent as u32 {
3121-
panic!("Can't get a channel monitor until funding has been created");
3122-
}
3123-
self.channel_monitor.as_mut().unwrap()
3124-
}
3125-
31263108
/// Guaranteed to be Some after both FundingLocked messages have been exchanged (and, thus,
31273109
/// is_usable() returns true).
31283110
/// Allowed in any state (including after shutdown)
@@ -3397,9 +3379,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
33973379
if header.bitcoin_hash() != self.last_block_connected {
33983380
self.last_block_connected = header.bitcoin_hash();
33993381
self.update_time_counter = cmp::max(self.update_time_counter, header.time);
3400-
if let Some(channel_monitor) = self.channel_monitor.as_mut() {
3401-
channel_monitor.last_block_hash = self.last_block_connected;
3402-
}
34033382
if self.funding_tx_confirmations > 0 {
34043383
if self.funding_tx_confirmations == self.minimum_depth as u64 {
34053384
let need_commitment_update = if non_shutdown_state == ChannelState::FundingSent as u32 {
@@ -3458,9 +3437,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
34583437
self.funding_tx_confirmations = self.minimum_depth as u64 - 1;
34593438
}
34603439
self.last_block_connected = header.bitcoin_hash();
3461-
if let Some(channel_monitor) = self.channel_monitor.as_mut() {
3462-
channel_monitor.last_block_hash = self.last_block_connected;
3463-
}
34643440
false
34653441
}
34663442

@@ -3871,7 +3847,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
38713847
their_revocation_point: self.their_cur_commitment_point.unwrap()
38723848
}]
38733849
};
3874-
self.channel_monitor.as_mut().unwrap().update_monitor_ooo(monitor_update.clone(), logger).unwrap();
38753850
self.channel_state |= ChannelState::AwaitingRemoteRevoke as u32;
38763851
Ok((res, monitor_update))
38773852
}
@@ -4242,8 +4217,6 @@ impl<ChanSigner: ChannelKeys + Writeable> Writeable for Channel<ChanSigner> {
42424217
self.their_shutdown_scriptpubkey.write(writer)?;
42434218

42444219
self.commitment_secrets.write(writer)?;
4245-
4246-
self.channel_monitor.as_ref().unwrap().write_for_disk(writer)?;
42474220
Ok(())
42484221
}
42494222
}
@@ -4398,13 +4371,6 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for Channel<ChanSigner> {
43984371
let their_shutdown_scriptpubkey = Readable::read(reader)?;
43994372
let commitment_secrets = Readable::read(reader)?;
44004373

4401-
let (monitor_last_block, channel_monitor) = Readable::read(reader)?;
4402-
// We drop the ChannelMonitor's last block connected hash cause we don't actually bother
4403-
// doing full block connection operations on the internal ChannelMonitor copies
4404-
if monitor_last_block != last_block_connected {
4405-
return Err(DecodeError::InvalidValue);
4406-
}
4407-
44084374
Ok(Channel {
44094375
user_id,
44104376

@@ -4476,7 +4442,6 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for Channel<ChanSigner> {
44764442

44774443
their_shutdown_scriptpubkey,
44784444

4479-
channel_monitor: Some(channel_monitor),
44804445
commitment_secrets,
44814446

44824447
network_sync: UpdateStatus::Fresh,

lightning/src/ln/channelmonitor.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
828828
// (we do *not*, however, update them in update_monitor to ensure any local user copies keep
829829
// their last_block_hash from its state and not based on updated copies that didn't run through
830830
// the full block_connected).
831-
pub(crate) last_block_hash: BlockHash,
831+
last_block_hash: BlockHash,
832832
secp_ctx: Secp256k1<secp256k1::All>, //TODO: dedup this a bit...
833833
}
834834

@@ -1369,27 +1369,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13691369
}
13701370
}
13711371

1372-
/// Used in Channel to cheat wrt the update_ids since it plays games, will be removed soon!
1373-
pub(super) fn update_monitor_ooo<L: Deref>(&mut self, mut updates: ChannelMonitorUpdate, logger: &L) -> Result<(), MonitorUpdateError> where L::Target: Logger {
1374-
for update in updates.updates.drain(..) {
1375-
match update {
1376-
ChannelMonitorUpdateStep::LatestLocalCommitmentTXInfo { commitment_tx, htlc_outputs } => {
1377-
if self.lockdown_from_offchain { panic!(); }
1378-
self.provide_latest_local_commitment_tx_info(commitment_tx, htlc_outputs)?
1379-
},
1380-
ChannelMonitorUpdateStep::LatestRemoteCommitmentTXInfo { unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point } =>
1381-
self.provide_latest_remote_commitment_tx_info(&unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point, logger),
1382-
ChannelMonitorUpdateStep::PaymentPreimage { payment_preimage } =>
1383-
self.provide_payment_preimage(&PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()), &payment_preimage),
1384-
ChannelMonitorUpdateStep::CommitmentSecret { idx, secret } =>
1385-
self.provide_secret(idx, secret)?,
1386-
ChannelMonitorUpdateStep::ChannelForceClosed { .. } => {},
1387-
}
1388-
}
1389-
self.latest_update_id = updates.update_id;
1390-
Ok(())
1391-
}
1392-
13931372
/// Updates a ChannelMonitor on the basis of some new information provided by the Channel
13941373
/// itself.
13951374
///

0 commit comments

Comments
 (0)