Skip to content

Commit 9905e60

Browse files
committed
Update WatchtowerPersister to use channel_id
The WatchtowerPersister test utility keys its maps using the channel's funding_outpoint. Since this is being removed from the Persist trait in the next commit, update the maps to be keyed by ChannelId instead. This is fine for testing where there isn't any previously persisted data.
1 parent afed8ad commit 9905e60

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,8 +2773,7 @@ fn do_test_forming_justice_tx_from_monitor_updates(broadcast_initial_commitment:
27732773
let node_cfgs = create_node_cfgs_with_persisters(2, &chanmon_cfgs, persisters.iter().collect());
27742774
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
27752775
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
2776-
let (_, _, channel_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 0, 1);
2777-
let funding_txo = OutPoint { txid: funding_tx.compute_txid(), index: 0 };
2776+
let (_, _, channel_id, _) = create_announced_chan_between_nodes(&nodes, 0, 1);
27782777

27792778
if !broadcast_initial_commitment {
27802779
// Send a payment to move the channel forward
@@ -2790,7 +2789,7 @@ fn do_test_forming_justice_tx_from_monitor_updates(broadcast_initial_commitment:
27902789
// Send another payment, now revoking the previous commitment tx
27912790
send_payment(&nodes[0], &vec!(&nodes[1])[..], 5_000_000);
27922791

2793-
let justice_tx = persisters[1].justice_tx(funding_txo, &revoked_commitment_tx.compute_txid()).unwrap();
2792+
let justice_tx = persisters[1].justice_tx(channel_id, &revoked_commitment_tx.compute_txid()).unwrap();
27942793
check_spends!(justice_tx, revoked_commitment_tx);
27952794

27962795
mine_transactions(&nodes[1], &[revoked_commitment_tx, &justice_tx]);

lightning/src/util/test_utils.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,10 @@ pub(crate) struct WatchtowerPersister {
533533
/// ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTxInfo. We'll store the justice tx
534534
/// amount, and commitment number so we can build the justice tx after our counterparty
535535
/// revokes it.
536-
unsigned_justice_tx_data: Mutex<HashMap<OutPoint, VecDeque<JusticeTxData>>>,
536+
unsigned_justice_tx_data: Mutex<HashMap<ChannelId, VecDeque<JusticeTxData>>>,
537537
/// After receiving a revoke_and_ack for a commitment number, we'll form and store the justice
538538
/// tx which would be used to provide a watchtower with the data it needs.
539-
watchtower_state: Mutex<HashMap<OutPoint, HashMap<Txid, Transaction>>>,
539+
watchtower_state: Mutex<HashMap<ChannelId, HashMap<Txid, Transaction>>>,
540540
destination_script: ScriptBuf,
541541
}
542542

@@ -556,12 +556,12 @@ impl WatchtowerPersister {
556556

557557
#[cfg(test)]
558558
pub(crate) fn justice_tx(
559-
&self, funding_txo: OutPoint, commitment_txid: &Txid,
559+
&self, channel_id: ChannelId, commitment_txid: &Txid,
560560
) -> Option<Transaction> {
561561
self.watchtower_state
562562
.lock()
563563
.unwrap()
564-
.get(&funding_txo)
564+
.get(&channel_id)
565565
.unwrap()
566566
.get(commitment_txid)
567567
.cloned()
@@ -596,13 +596,13 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> Persist<Signer> for WatchtowerPers
596596
.unsigned_justice_tx_data
597597
.lock()
598598
.unwrap()
599-
.insert(funding_txo, VecDeque::new())
599+
.insert(data.channel_id(), VecDeque::new())
600600
.is_none());
601601
assert!(self
602602
.watchtower_state
603603
.lock()
604604
.unwrap()
605-
.insert(funding_txo, new_hash_map())
605+
.insert(data.channel_id(), new_hash_map())
606606
.is_none());
607607

608608
let initial_counterparty_commitment_tx =
@@ -613,7 +613,7 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> Persist<Signer> for WatchtowerPers
613613
self.unsigned_justice_tx_data
614614
.lock()
615615
.unwrap()
616-
.get_mut(&funding_txo)
616+
.get_mut(&data.channel_id())
617617
.unwrap()
618618
.push_back(justice_data);
619619
}
@@ -632,7 +632,7 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> Persist<Signer> for WatchtowerPers
632632
.into_iter()
633633
.filter_map(|commitment_tx| self.form_justice_data_from_commitment(&commitment_tx));
634634
let mut channels_justice_txs = self.unsigned_justice_tx_data.lock().unwrap();
635-
let channel_state = channels_justice_txs.get_mut(&funding_txo).unwrap();
635+
let channel_state = channels_justice_txs.get_mut(&data.channel_id()).unwrap();
636636
channel_state.extend(justice_datas);
637637

638638
while let Some(JusticeTxData { justice_tx, value, commitment_number }) =
@@ -651,7 +651,7 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> Persist<Signer> for WatchtowerPers
651651
.watchtower_state
652652
.lock()
653653
.unwrap()
654-
.get_mut(&funding_txo)
654+
.get_mut(&data.channel_id())
655655
.unwrap()
656656
.insert(commitment_txid, signed_justice_tx);
657657
assert!(dup.is_none());

0 commit comments

Comments
 (0)