Skip to content

Commit 528cea5

Browse files
Remove Channel's ChannelMonitor copy
1 parent 8aeb375 commit 528cea5

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,
@@ -1284,7 +1279,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
12841279
payment_preimage: payment_preimage_arg.clone(),
12851280
}],
12861281
};
1287-
self.channel_monitor.as_mut().unwrap().update_monitor_ooo(monitor_update.clone(), logger).unwrap();
12881282

12891283
if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32 | ChannelState::PeerDisconnected as u32 | ChannelState::MonitorUpdateFailed as u32)) != 0 {
12901284
for pending_update in self.holding_cell_htlc_updates.iter() {
@@ -1614,7 +1608,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
16141608
} }
16151609
}
16161610

1617-
self.channel_monitor = Some(create_monitor!());
16181611
let channel_monitor = create_monitor!();
16191612

16201613
self.channel_state = ChannelState::FundingSent as u32;
@@ -1680,7 +1673,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
16801673
} }
16811674
}
16821675

1683-
self.channel_monitor = Some(create_monitor!());
16841676
let channel_monitor = create_monitor!();
16851677

16861678
assert_eq!(self.channel_state & (ChannelState::MonitorUpdateFailed as u32), 0); // We have no had any monitor(s) yet to fail update!
@@ -2139,7 +2131,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
21392131
htlc_outputs: htlcs_and_sigs
21402132
}]
21412133
};
2142-
self.channel_monitor.as_mut().unwrap().update_monitor_ooo(monitor_update.clone(), logger).unwrap();
21432134

21442135
for htlc in self.pending_inbound_htlcs.iter_mut() {
21452136
let new_forward = if let &InboundHTLCState::RemoteAnnounced(ref forward_info) = &htlc.state {
@@ -2359,7 +2350,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
23592350
secret: msg.per_commitment_secret,
23602351
}],
23612352
};
2362-
self.channel_monitor.as_mut().unwrap().update_monitor_ooo(monitor_update.clone(), logger).unwrap();
23632353

23642354
// Update state now that we've passed all the can-fail calls...
23652355
// (note that we may still fail to generate the new commitment_signed message, but that's
@@ -3473,9 +3463,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
34733463
if header.bitcoin_hash() != self.last_block_connected {
34743464
self.last_block_connected = header.bitcoin_hash();
34753465
self.update_time_counter = cmp::max(self.update_time_counter, header.time);
3476-
if let Some(channel_monitor) = self.channel_monitor.as_mut() {
3477-
channel_monitor.last_block_hash = self.last_block_connected;
3478-
}
34793466
if self.funding_tx_confirmations > 0 {
34803467
if self.funding_tx_confirmations == self.minimum_depth as u64 {
34813468
let need_commitment_update = if non_shutdown_state == ChannelState::FundingSent as u32 {
@@ -3534,9 +3521,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
35343521
self.funding_tx_confirmations = self.minimum_depth as u64 - 1;
35353522
}
35363523
self.last_block_connected = header.bitcoin_hash();
3537-
if let Some(channel_monitor) = self.channel_monitor.as_mut() {
3538-
channel_monitor.last_block_hash = self.last_block_connected;
3539-
}
35403524
false
35413525
}
35423526

@@ -3947,7 +3931,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
39473931
their_revocation_point: self.their_cur_commitment_point.unwrap()
39483932
}]
39493933
};
3950-
self.channel_monitor.as_mut().unwrap().update_monitor_ooo(monitor_update.clone(), logger).unwrap();
39513934
self.channel_state |= ChannelState::AwaitingRemoteRevoke as u32;
39523935
Ok((res, monitor_update))
39533936
}
@@ -4326,8 +4309,6 @@ impl<ChanSigner: ChannelKeys + Writeable> Writeable for Channel<ChanSigner> {
43264309
self.their_shutdown_scriptpubkey.write(writer)?;
43274310

43284311
self.commitment_secrets.write(writer)?;
4329-
4330-
self.channel_monitor.as_ref().unwrap().write_for_disk(writer)?;
43314312
Ok(())
43324313
}
43334314
}
@@ -4495,13 +4476,6 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for Channel<ChanSigner> {
44954476
let their_shutdown_scriptpubkey = Readable::read(reader)?;
44964477
let commitment_secrets = Readable::read(reader)?;
44974478

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

@@ -4574,7 +4548,6 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for Channel<ChanSigner> {
45744548

45754549
their_shutdown_scriptpubkey,
45764550

4577-
channel_monitor: Some(channel_monitor),
45784551
commitment_secrets,
45794552

45804553
network_sync: UpdateStatus::Fresh,

lightning/src/ln/channelmonitor.rs

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

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

0 commit comments

Comments
 (0)