Skip to content

Commit db3c067

Browse files
committed
chore: resolve rebase conflicts and fix reconnect tests
1 parent 85b7060 commit db3c067

3 files changed

Lines changed: 74 additions & 83 deletions

File tree

crates/fiber-lib/src/fiber/network.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,10 @@ where
11501150
}
11511151
NetworkActorCommand::DisconnectPeer(pubkey, reason) => {
11521152
let peer_id = PeerId::from_public_key(&tentacle::secio::PublicKey::from(pubkey));
1153-
let session = state.peer_session_map.get(&pubkey).map(|peer| peer.session_id);
1153+
let session = state
1154+
.peer_session_map
1155+
.get(&pubkey)
1156+
.map(|peer| peer.session_id);
11541157
if matches!(reason, PeerDisconnectReason::Requested) {
11551158
state.peer_reconnect_backoff_attempts.remove(&peer_id);
11561159
if session.is_some() {
@@ -3767,7 +3770,12 @@ where
37673770

37683771
fn has_direct_active_channel(&self, peer_id: &PeerId) -> bool {
37693772
self.resolve_peer_pubkey(peer_id)
3770-
.map(|pubkey| !self.store.get_active_channel_ids_by_pubkey(&pubkey).is_empty())
3773+
.map(|pubkey| {
3774+
!self
3775+
.store
3776+
.get_active_channel_ids_by_pubkey(&pubkey)
3777+
.is_empty()
3778+
})
37713779
.unwrap_or(false)
37723780
}
37733781

@@ -3807,7 +3815,8 @@ where
38073815
return;
38083816
}
38093817

3810-
self.peer_reconnect_backoff_attempts.insert(peer_id.clone(), 0);
3818+
self.peer_reconnect_backoff_attempts
3819+
.insert(peer_id.clone(), 0);
38113820
match trigger {
38123821
PeerReconnectTrigger::Disconnected => {
38133822
debug_event!(self.network, "PeerReconnectBackoffSeededByDisconnect");
@@ -5140,10 +5149,12 @@ impl ServiceHandle for NetworkServiceHandle {
51405149
);
51415150
try_send_actor_message(
51425151
&self.actor,
5143-
NetworkActorMessage::new_command(NetworkActorCommand::SeedPeerReconnectBackoff(
5144-
peer_id,
5145-
PeerReconnectTrigger::DialError,
5146-
)),
5152+
NetworkActorMessage::new_command(
5153+
NetworkActorCommand::SeedPeerReconnectBackoff(
5154+
peer_id,
5155+
PeerReconnectTrigger::DialError,
5156+
),
5157+
),
51475158
);
51485159
} else {
51495160
debug!(

crates/fiber-lib/src/fiber/tests/channel.rs

Lines changed: 55 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::ckb::tests::test_utils::complete_commitment_tx;
22
use crate::fiber::channel::{
3-
AddTlcResponse, ChannelState, CloseFlags, MAX_COMMITMENT_DELAY_EPOCHS,
4-
MIN_COMMITMENT_DELAY_EPOCHS, NegotiatingFundingFlags, OutboundTlcStatus, ReplayOrderHint,
5-
TLCId, TlcStatus, UpdateCommand, XUDT_COMPATIBLE_WITNESS,
3+
AddTlcResponse, ChannelState, CloseFlags, NegotiatingFundingFlags, OutboundTlcStatus,
4+
ReplayOrderHint, TLCId, TlcStatus, UpdateCommand, MAX_COMMITMENT_DELAY_EPOCHS,
5+
MIN_COMMITMENT_DELAY_EPOCHS, XUDT_COMPATIBLE_WITNESS,
66
};
77
use crate::fiber::config::{
88
DEFAULT_COMMITMENT_DELAY_EPOCHS, DEFAULT_FINAL_TLC_EXPIRY_DELTA, DEFAULT_TLC_EXPIRY_DELTA,
@@ -13,38 +13,37 @@ use crate::fiber::graph::ChannelInfo;
1313
use crate::fiber::network::{DebugEvent, FiberMessageWithTarget, PeerDisconnectReason};
1414
use crate::fiber::payment::{AttemptStatus, PaymentStatus, SendPaymentCommand};
1515
use crate::fiber::types::{
16-
AddTlc, FiberMessage, Hash256, Init, NO_SHARED_SECRET, PaymentHopData,
17-
PeeledPaymentOnionPacket, Pubkey, TlcErr, TlcErrorCode,
16+
AddTlc, FiberMessage, Hash256, Init, PaymentHopData, PeeledPaymentOnionPacket, Pubkey, TlcErr,
17+
TlcErrorCode, NO_SHARED_SECRET,
1818
};
1919
use crate::invoice::{CkbInvoiceStatus, Currency, InvoiceBuilder};
20-
use crate::test_utils::{NetworkNode, init_tracing};
20+
use crate::test_utils::{init_tracing, NetworkNode};
2121
use crate::tests::test_utils::*;
2222
use crate::{
23-
NetworkServiceEvent,
24-
ckb::contracts::{Contract, get_cell_deps},
23+
ckb::contracts::{get_cell_deps, Contract},
2524
fiber::{
26-
NetworkActorCommand, NetworkActorMessage,
2725
channel::{
28-
AddTlcCommand, ChannelActorStateStore, ChannelCommand, ChannelCommandWithId,
29-
DEFAULT_COMMITMENT_FEE_RATE, InMemorySigner, RemoveTlcCommand, ShutdownCommand,
30-
derive_private_key, derive_tlc_pubkey,
26+
derive_private_key, derive_tlc_pubkey, AddTlcCommand, ChannelActorStateStore,
27+
ChannelCommand, ChannelCommandWithId, InMemorySigner, RemoveTlcCommand,
28+
ShutdownCommand, DEFAULT_COMMITMENT_FEE_RATE,
3129
},
3230
config::DEFAULT_AUTO_ACCEPT_CHANNEL_CKB_FUNDING_AMOUNT,
3331
hash_algorithm::HashAlgorithm,
3432
network::{AcceptChannelCommand, OpenChannelCommand},
3533
types::{Privkey, RemoveTlcFulfill, RemoveTlcReason},
34+
NetworkActorCommand, NetworkActorMessage,
3635
},
3736
gen_rand_fiber_private_key, gen_rand_fiber_public_key, gen_rand_sha256_hash,
38-
now_timestamp_as_millis_u64,
37+
now_timestamp_as_millis_u64, NetworkServiceEvent,
3938
};
4039
use ckb_types::core::EpochNumberWithFraction;
4140
use ckb_types::{
42-
core::{FeeRate, tx_pool::TxStatus},
41+
core::{tx_pool::TxStatus, FeeRate},
4342
packed::{CellInput, Script, Transaction},
4443
prelude::{AsTransactionBuilder, Builder, Entity, Pack, Unpack},
4544
};
46-
use musig2::KeyAggContext;
4745
use musig2::secp::Point;
46+
use musig2::KeyAggContext;
4847
use ractor::call;
4948
use secp256k1::SECP256K1;
5049
use std::collections::{HashMap, HashSet};
@@ -369,11 +368,10 @@ async fn test_create_channel_with_too_large_amounts() {
369368
};
370369
let res = create_channel_with_nodes(&mut node_a, &mut node_b, params).await;
371370
assert!(res.is_err(), "Create channel failed: {:?}", res);
372-
assert!(
373-
res.unwrap_err()
374-
.to_string()
375-
.contains("The total UDT funding amount should be less")
376-
);
371+
assert!(res
372+
.unwrap_err()
373+
.to_string()
374+
.contains("The total UDT funding amount should be less"));
377375
}
378376

379377
#[tokio::test]
@@ -1159,11 +1157,10 @@ async fn test_network_send_payment_keysend_with_payment_hash() {
11591157
..Default::default()
11601158
})
11611159
.await;
1162-
assert!(
1163-
res.err()
1164-
.unwrap()
1165-
.contains("keysend payment should not have payment_hash")
1166-
);
1160+
assert!(res
1161+
.err()
1162+
.unwrap()
1163+
.contains("keysend payment should not have payment_hash"));
11671164
}
11681165

11691166
#[tokio::test]
@@ -1672,11 +1669,10 @@ async fn test_network_send_payment_dry_run_can_still_query() {
16721669
..Default::default()
16731670
})
16741671
.await;
1675-
assert!(
1676-
res.unwrap_err()
1677-
.to_string()
1678-
.contains("Payment session already exists")
1679-
);
1672+
assert!(res
1673+
.unwrap_err()
1674+
.to_string()
1675+
.contains("Payment session already exists"));
16801676

16811677
// now use a different payment hash
16821678
let payment_hash = gen_rand_sha256_hash();
@@ -3211,12 +3207,10 @@ async fn test_channel_update_tlc_expiry() {
32113207
})
32123208
.unwrap();
32133209
assert!(update_result.is_err());
3214-
assert!(
3215-
update_result
3216-
.unwrap_err()
3217-
.to_string()
3218-
.contains("TLC expiry delta is too small")
3219-
);
3210+
assert!(update_result
3211+
.unwrap_err()
3212+
.to_string()
3213+
.contains("TLC expiry delta is too small"));
32203214

32213215
// update channel with new tlc_expiry_delta which is too large
32223216
let update_result = call!(node_b.network_actor, |rpc_reply| {
@@ -3237,12 +3231,10 @@ async fn test_channel_update_tlc_expiry() {
32373231
})
32383232
.unwrap();
32393233
assert!(update_result.is_err());
3240-
assert!(
3241-
update_result
3242-
.unwrap_err()
3243-
.to_string()
3244-
.contains("TLC expiry delta is too large")
3245-
);
3234+
assert!(update_result
3235+
.unwrap_err()
3236+
.to_string()
3237+
.contains("TLC expiry delta is too large"));
32463238

32473239
let epoch_delay_milliseconds =
32483240
(DEFAULT_COMMITMENT_DELAY_EPOCHS as f64 * MILLI_SECONDS_PER_EPOCH as f64 * 2.0 / 3.0)
@@ -3512,11 +3504,10 @@ async fn test_forward_payment_tlc_minimum_value() {
35123504
.send_payment_keysend(&node_c, tlc_amount - 1, false)
35133505
.await;
35143506
assert!(res.is_err());
3515-
assert!(
3516-
res.unwrap_err()
3517-
.to_string()
3518-
.contains("Failed to build route, PathFind error: no path found")
3519-
);
3507+
assert!(res
3508+
.unwrap_err()
3509+
.to_string()
3510+
.contains("Failed to build route, PathFind error: no path found"));
35203511
}
35213512

35223513
#[tokio::test]
@@ -4452,7 +4443,7 @@ async fn test_peer_disconnect_with_active_channel_enters_backoff_reconnect() {
44524443
.await;
44534444
node_a
44544445
.expect_event(|event| {
4455-
matches!(event, NetworkServiceEvent::PeerDisConnected(id, _) if id == &node_b.peer_id)
4446+
matches!(event, NetworkServiceEvent::PeerDisConnected(id, _) if id == &node_b.pubkey)
44564447
})
44574448
.await;
44584449
}
@@ -4758,12 +4749,10 @@ async fn test_shutdown_channel_with_large_size_shutdown_script_should_fail() {
47584749
};
47594750

47604751
let shutdown_channel_result = call!(node_b.network_actor, message).expect("node_b alive");
4761-
assert!(
4762-
shutdown_channel_result
4763-
.err()
4764-
.unwrap()
4765-
.contains("Local balance is not enough to pay the fee")
4766-
);
4752+
assert!(shutdown_channel_result
4753+
.err()
4754+
.unwrap()
4755+
.contains("Local balance is not enough to pay the fee"));
47674756

47684757
let message = |rpc_reply| {
47694758
NetworkActorMessage::Command(NetworkActorCommand::ControlFiberChannel(
@@ -4782,12 +4771,10 @@ async fn test_shutdown_channel_with_large_size_shutdown_script_should_fail() {
47824771
};
47834772

47844773
let shutdown_channel_result = call!(node_a.network_actor, message).expect("node_b alive");
4785-
assert!(
4786-
shutdown_channel_result
4787-
.err()
4788-
.unwrap()
4789-
.contains("Local balance is not enough to pay the fee")
4790-
);
4774+
assert!(shutdown_channel_result
4775+
.err()
4776+
.unwrap()
4777+
.contains("Local balance is not enough to pay the fee"));
47914778
}
47924779

47934780
#[tokio::test]
@@ -5633,11 +5620,9 @@ async fn test_send_payment_will_succeed_with_valid_invoice() {
56335620
node_3.get_invoice_status(ckb_invoice.payment_hash()),
56345621
Some(CkbInvoiceStatus::Paid)
56355622
);
5636-
assert!(
5637-
node_3
5638-
.get_payment_preimage(ckb_invoice.payment_hash())
5639-
.is_none()
5640-
);
5623+
assert!(node_3
5624+
.get_payment_preimage(ckb_invoice.payment_hash())
5625+
.is_none());
56415626
}
56425627

56435628
#[tokio::test]
@@ -5768,11 +5753,9 @@ async fn test_send_payment_will_fail_with_cancelled_invoice() {
57685753
node_3.get_invoice_status(ckb_invoice.payment_hash()),
57695754
Some(CkbInvoiceStatus::Cancelled)
57705755
);
5771-
assert!(
5772-
node_3
5773-
.get_payment_preimage(ckb_invoice.payment_hash())
5774-
.is_some()
5775-
);
5756+
assert!(node_3
5757+
.get_payment_preimage(ckb_invoice.payment_hash())
5758+
.is_some());
57765759
}
57775760

57785761
#[tokio::test]
@@ -5960,11 +5943,8 @@ async fn test_open_channel_tlc_expiry_is_smaller_than_commitment_delay() {
59605943

59615944
eprintln!("open_channel_result: {:?}", open_channel_result);
59625945
let error = open_channel_result.unwrap_err().to_string();
5963-
assert!(
5964-
error.contains(
5965-
"TLC expiry delta 13332 is smaller than 2/3 commitment_delay_epoch delay 13333"
5966-
)
5967-
);
5946+
assert!(error
5947+
.contains("TLC expiry delta 13332 is smaller than 2/3 commitment_delay_epoch delay 13333"));
59685948

59695949
let message = |rpc_reply| {
59705950
NetworkActorMessage::Command(NetworkActorCommand::OpenChannel(

crates/fiber-lib/src/fiber/tests/network.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ async fn test_peer_disconnect_without_active_channel_skips_backoff_reconnect() {
754754
.await;
755755
node1
756756
.expect_event(|event| {
757-
matches!(event, NetworkServiceEvent::PeerDisConnected(id, _) if id == &node2.peer_id)
757+
matches!(event, NetworkServiceEvent::PeerDisConnected(id, _) if id == &node2.pubkey)
758758
})
759759
.await;
760760
}

0 commit comments

Comments
 (0)