Skip to content

Commit 66cc962

Browse files
committed
Drop test_dup_htlc_onchain_fails_on_reload as it no longer applies
test_dup_htlc_onchain_fails_on_reload tested our outbound payment tracking to ensure we never sent more than one PaymentSent event to users per payment in the case of a manager-monitor storage order inversion which was common. However, now that we require monitors be persisted when a block is connected, that inversion can never occur, and thus the test isn't testing anything.
1 parent 0600342 commit 66cc962

File tree

2 files changed

+2
-111
lines changed

2 files changed

+2
-111
lines changed

lightning/src/chain/channelmonitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,8 @@ pub(crate) struct ChannelMonitorImpl<Signer: Sign> {
659659
// during chain data processing. This prevents a race in ChainMonitor::update_channel (and
660660
// presumably user implementations thereof as well) where we update the in-memory channel
661661
// object, then before the persistence finishes (as its all under a read-lock), we return
662-
// pending events to the user or to the relevant ChannelManager. This could cause duplicate
663-
// events.
662+
// pending events to the user or to the relevant ChannelManager. Then, on reload, we'll have
663+
// the pre-event state here, but have processed the event in the ChannelManager.
664664
// Note that because the `event_lock` in `ChainMonitor` is only taken in
665665
// block/transaction-connected events and *not* during block/transaction-disconnected events,
666666
// we further MUST NOT generate events during block/transaction-disconnection.

lightning/src/ln/functional_tests.rs

-109
Original file line numberDiff line numberDiff line change
@@ -4185,115 +4185,6 @@ fn mpp_failure() {
41854185
fail_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_hash);
41864186
}
41874187

4188-
#[test]
4189-
fn test_dup_htlc_onchain_fails_on_reload() {
4190-
// When a Channel is closed, any outbound HTLCs which were relayed through it are simply
4191-
// dropped when the Channel is. From there, the ChannelManager relies on the ChannelMonitor
4192-
// having a copy of the relevant fail-/claim-back data and processes the HTLC fail/claim when
4193-
// the ChannelMonitor tells it to.
4194-
//
4195-
// If, due to an on-chain event, an HTLC is failed/claimed, and then we serialize the
4196-
// ChannelManager, we generally expect there not to be a duplicate HTLC fail/claim (eg via a
4197-
// PaymentPathFailed event appearing). However, because we may not serialize the relevant
4198-
// ChannelMonitor at the same time, this isn't strictly guaranteed. In order to provide this
4199-
// consistency, the ChannelManager explicitly tracks pending-onchain-resolution outbound HTLCs
4200-
// and de-duplicates ChannelMonitor events.
4201-
//
4202-
// This tests that explicit tracking behavior.
4203-
let chanmon_cfgs = create_chanmon_cfgs(2);
4204-
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
4205-
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
4206-
let persister: test_utils::TestPersister;
4207-
let new_chain_monitor: test_utils::TestChainMonitor;
4208-
let nodes_0_deserialized: ChannelManager<EnforcingSigner, &test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>;
4209-
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
4210-
4211-
let chan_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2;
4212-
4213-
// Route a payment, but force-close the channel before the HTLC fulfill message arrives at
4214-
// nodes[0].
4215-
let (payment_preimage, _, _) = route_payment(&nodes[0], &[&nodes[1]], 10000000);
4216-
nodes[0].node.force_close_channel(&nodes[0].node.list_channels()[0].channel_id).unwrap();
4217-
check_closed_broadcast!(nodes[0], true);
4218-
check_added_monitors!(nodes[0], 1);
4219-
check_closed_event!(nodes[0], 1, ClosureReason::HolderForceClosed);
4220-
4221-
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
4222-
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
4223-
4224-
// Connect blocks until the CLTV timeout is up so that we get an HTLC-Timeout transaction
4225-
connect_blocks(&nodes[0], TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1);
4226-
let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
4227-
assert_eq!(node_txn.len(), 3);
4228-
assert_eq!(node_txn[0], node_txn[1]);
4229-
4230-
assert!(nodes[1].node.claim_funds(payment_preimage));
4231-
check_added_monitors!(nodes[1], 1);
4232-
4233-
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
4234-
connect_block(&nodes[1], &Block { header, txdata: vec![node_txn[1].clone(), node_txn[2].clone()]});
4235-
check_closed_broadcast!(nodes[1], true);
4236-
check_added_monitors!(nodes[1], 1);
4237-
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
4238-
let claim_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
4239-
4240-
header.prev_blockhash = nodes[0].best_block_hash();
4241-
connect_block(&nodes[0], &Block { header, txdata: vec![node_txn[1].clone(), node_txn[2].clone()]});
4242-
4243-
// Serialize out the ChannelMonitor before connecting the on-chain claim transactions. This is
4244-
// fairly normal behavior as ChannelMonitor(s) are often not re-serialized when on-chain events
4245-
// happen, unlike ChannelManager which tends to be re-serialized after any relevant event(s).
4246-
let mut chan_0_monitor_serialized = test_utils::TestVecWriter(Vec::new());
4247-
get_monitor!(nodes[0], chan_id).write(&mut chan_0_monitor_serialized).unwrap();
4248-
4249-
header.prev_blockhash = nodes[0].best_block_hash();
4250-
let claim_block = Block { header, txdata: claim_txn};
4251-
connect_block(&nodes[0], &claim_block);
4252-
expect_payment_sent!(nodes[0], payment_preimage);
4253-
4254-
// ChannelManagers generally get re-serialized after any relevant event(s). Since we just
4255-
// connected a highly-relevant block, it likely gets serialized out now.
4256-
let mut chan_manager_serialized = test_utils::TestVecWriter(Vec::new());
4257-
nodes[0].node.write(&mut chan_manager_serialized).unwrap();
4258-
4259-
// Now reload nodes[0]...
4260-
persister = test_utils::TestPersister::new();
4261-
let keys_manager = &chanmon_cfgs[0].keys_manager;
4262-
new_chain_monitor = test_utils::TestChainMonitor::new(Some(nodes[0].chain_source), nodes[0].tx_broadcaster.clone(), nodes[0].logger, node_cfgs[0].fee_estimator, &persister, keys_manager);
4263-
nodes[0].chain_monitor = &new_chain_monitor;
4264-
let mut chan_0_monitor_read = &chan_0_monitor_serialized.0[..];
4265-
let (_, mut chan_0_monitor) = <(BlockHash, ChannelMonitor<EnforcingSigner>)>::read(
4266-
&mut chan_0_monitor_read, keys_manager).unwrap();
4267-
assert!(chan_0_monitor_read.is_empty());
4268-
4269-
let (_, nodes_0_deserialized_tmp) = {
4270-
let mut channel_monitors = HashMap::new();
4271-
channel_monitors.insert(chan_0_monitor.get_funding_txo().0, &mut chan_0_monitor);
4272-
<(BlockHash, ChannelManager<EnforcingSigner, &test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>)>
4273-
::read(&mut io::Cursor::new(&chan_manager_serialized.0[..]), ChannelManagerReadArgs {
4274-
default_config: Default::default(),
4275-
keys_manager,
4276-
fee_estimator: node_cfgs[0].fee_estimator,
4277-
chain_monitor: nodes[0].chain_monitor,
4278-
tx_broadcaster: nodes[0].tx_broadcaster.clone(),
4279-
logger: nodes[0].logger,
4280-
channel_monitors,
4281-
}).unwrap()
4282-
};
4283-
nodes_0_deserialized = nodes_0_deserialized_tmp;
4284-
4285-
assert!(nodes[0].chain_monitor.watch_channel(chan_0_monitor.get_funding_txo().0, chan_0_monitor).is_ok());
4286-
check_added_monitors!(nodes[0], 1);
4287-
nodes[0].node = &nodes_0_deserialized;
4288-
4289-
// Note that if we re-connect the block which exposed nodes[0] to the payment preimage (but
4290-
// which the current ChannelMonitor has not seen), the ChannelManager's de-duplication of
4291-
// payment events should kick in, leaving us with no pending events here.
4292-
let height = nodes[0].blocks.lock().unwrap().len() as u32 - 1;
4293-
nodes[0].chain_monitor.chain_monitor.block_connected(&claim_block, height);
4294-
assert!(nodes[0].node.get_and_clear_pending_events().is_empty());
4295-
}
4296-
42974188
#[test]
42984189
fn test_manager_serialize_deserialize_events() {
42994190
// This test makes sure the events field in ChannelManager survives de/serialization

0 commit comments

Comments
 (0)