Skip to content

Commit d0056d2

Browse files
Remove Channel's ChannelMonitor copy
1 parent f700f9e commit d0056d2

File tree

2 files changed

+0
-48
lines changed

2 files changed

+0
-48
lines changed

lightning/src/ln/channel.rs

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

391391
their_shutdown_scriptpubkey: Option<Script>,
392392

393-
/// Used exclusively to broadcast the latest local state, mostly a historical quirk that this
394-
/// is here:
395-
channel_monitor: Option<ChannelMonitor<ChanSigner>>,
396393
commitment_secrets: CounterpartyCommitmentSecrets,
397394

398395
network_sync: UpdateStatus,
@@ -562,7 +559,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
562559

563560
their_shutdown_scriptpubkey: None,
564561

565-
channel_monitor: None,
566562
commitment_secrets: CounterpartyCommitmentSecrets::new(),
567563

568564
network_sync: UpdateStatus::Fresh,
@@ -792,7 +788,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
792788

793789
their_shutdown_scriptpubkey,
794790

795-
channel_monitor: None,
796791
commitment_secrets: CounterpartyCommitmentSecrets::new(),
797792

798793
network_sync: UpdateStatus::Fresh,
@@ -1281,7 +1276,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
12811276
payment_preimage: payment_preimage_arg.clone(),
12821277
}],
12831278
};
1284-
self.channel_monitor.as_mut().unwrap().update_monitor_ooo(monitor_update.clone(), logger).unwrap();
12851279

12861280
if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32 | ChannelState::PeerDisconnected as u32 | ChannelState::MonitorUpdateFailed as u32)) != 0 {
12871281
for pending_update in self.holding_cell_htlc_updates.iter() {
@@ -1611,7 +1605,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
16111605
} }
16121606
}
16131607

1614-
self.channel_monitor = Some(create_monitor!());
16151608
let channel_monitor = create_monitor!();
16161609

16171610
self.channel_state = ChannelState::FundingSent as u32;
@@ -1677,7 +1670,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
16771670
} }
16781671
}
16791672

1680-
self.channel_monitor = Some(create_monitor!());
16811673
let channel_monitor = create_monitor!();
16821674

16831675
assert_eq!(self.channel_state & (ChannelState::MonitorUpdateFailed as u32), 0); // We have no had any monitor(s) yet to fail update!
@@ -2136,7 +2128,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
21362128
htlc_outputs: htlcs_and_sigs
21372129
}]
21382130
};
2139-
self.channel_monitor.as_mut().unwrap().update_monitor_ooo(monitor_update.clone(), logger).unwrap();
21402131

21412132
for htlc in self.pending_inbound_htlcs.iter_mut() {
21422133
let new_forward = if let &InboundHTLCState::RemoteAnnounced(ref forward_info) = &htlc.state {
@@ -2356,7 +2347,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
23562347
secret: msg.per_commitment_secret,
23572348
}],
23582349
};
2359-
self.channel_monitor.as_mut().unwrap().update_monitor_ooo(monitor_update.clone(), logger).unwrap();
23602350

23612351
// Update state now that we've passed all the can-fail calls...
23622352
// (note that we may still fail to generate the new commitment_signed message, but that's
@@ -3470,9 +3460,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
34703460
if header.bitcoin_hash() != self.last_block_connected {
34713461
self.last_block_connected = header.bitcoin_hash();
34723462
self.update_time_counter = cmp::max(self.update_time_counter, header.time);
3473-
if let Some(channel_monitor) = self.channel_monitor.as_mut() {
3474-
channel_monitor.last_block_hash = self.last_block_connected;
3475-
}
34763463
if self.funding_tx_confirmations > 0 {
34773464
if self.funding_tx_confirmations == self.minimum_depth as u64 {
34783465
let need_commitment_update = if non_shutdown_state == ChannelState::FundingSent as u32 {
@@ -3531,9 +3518,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
35313518
self.funding_tx_confirmations = self.minimum_depth as u64 - 1;
35323519
}
35333520
self.last_block_connected = header.bitcoin_hash();
3534-
if let Some(channel_monitor) = self.channel_monitor.as_mut() {
3535-
channel_monitor.last_block_hash = self.last_block_connected;
3536-
}
35373521
false
35383522
}
35393523

@@ -3944,7 +3928,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
39443928
their_revocation_point: self.their_cur_commitment_point.unwrap()
39453929
}]
39463930
};
3947-
self.channel_monitor.as_mut().unwrap().update_monitor_ooo(monitor_update.clone(), logger).unwrap();
39483931
self.channel_state |= ChannelState::AwaitingRemoteRevoke as u32;
39493932
Ok((res, monitor_update))
39503933
}
@@ -4323,8 +4306,6 @@ impl<ChanSigner: ChannelKeys + Writeable> Writeable for Channel<ChanSigner> {
43234306
self.their_shutdown_scriptpubkey.write(writer)?;
43244307

43254308
self.commitment_secrets.write(writer)?;
4326-
4327-
self.channel_monitor.as_ref().unwrap().write_for_disk(writer)?;
43284309
Ok(())
43294310
}
43304311
}
@@ -4492,13 +4473,6 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for Channel<ChanSigner> {
44924473
let their_shutdown_scriptpubkey = Readable::read(reader)?;
44934474
let commitment_secrets = Readable::read(reader)?;
44944475

4495-
let (monitor_last_block, channel_monitor) = Readable::read(reader)?;
4496-
// We drop the ChannelMonitor's last block connected hash cause we don't actually bother
4497-
// doing full block connection operations on the internal ChannelMonitor copies
4498-
if monitor_last_block != last_block_connected {
4499-
return Err(DecodeError::InvalidValue);
4500-
}
4501-
45024476
Ok(Channel {
45034477
user_id,
45044478

@@ -4571,7 +4545,6 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for Channel<ChanSigner> {
45714545

45724546
their_shutdown_scriptpubkey,
45734547

4574-
channel_monitor: Some(channel_monitor),
45754548
commitment_secrets,
45764549

45774550
network_sync: UpdateStatus::Fresh,

lightning/src/ln/channelmonitor.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,27 +1363,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13631363
}
13641364
}
13651365

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

0 commit comments

Comments
 (0)