Skip to content

Commit

Permalink
fix private channel payment issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jan 27, 2025
1 parent 4c55eac commit 558e2c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 36 deletions.
51 changes: 21 additions & 30 deletions src/fiber/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,6 @@ where
TlcErrorCode::PermanentChannelFailure
}
ChannelState::ChannelReady() => {
eprintln!("debug now InvalidState error: {}", error);
if !state.local_tlc_info.enabled {
// channel is disabled
TlcErrorCode::TemporaryChannelFailure
Expand Down Expand Up @@ -1014,38 +1013,30 @@ where
return Err(ProcessingChannelError::FinalIncorrectPaymentHash);
}
} else {
if state.is_public() {
if add_tlc.expiry
< peeled_onion_packet.current.expiry + state.local_tlc_info.tlc_expiry_delta
{
return Err(ProcessingChannelError::IncorrectTlcExpiry);
}
// here we don't need to check current config is public or enabled, because
// handle_add_tlc_command will check the channel state before forwarding
// and private channel can also forward TLC to public channel
if add_tlc.expiry
< peeled_onion_packet.current.expiry + state.local_tlc_info.tlc_expiry_delta
{
return Err(ProcessingChannelError::IncorrectTlcExpiry);
}

assert!(received_amount >= forward_amount);
assert!(received_amount >= forward_amount);

// Next forwarding channel will get the forward_fee and check if it's enough.
let forward_fee = received_amount.saturating_sub(forward_amount);
// Next forwarding channel will get the forward_fee and check if it's enough.
let forward_fee = received_amount.saturating_sub(forward_amount);

// if this is not the last hop, forward TLC to next hop
self.register_retryable_forward_tlc(
myself,
state,
add_tlc.tlc_id,
add_tlc.payment_hash,
peeled_onion_packet.clone(),
forward_fee,
)
.await;
} else {
// if we don't have public channel info, we can not forward the TLC
// this may happended some malicious sender build a invalid onion router
// here we don't need to check the next channel maybe disabled, because
// handle_add_tlc_command will check the channel state before forwarding
eprintln!("got here .........");
return Err(ProcessingChannelError::InvalidState(
"Received AddTlc message, but the channel is not public".to_string(),
));
}
// if this is not the last hop, forward TLC to next hop
self.register_retryable_forward_tlc(
myself,
state,
add_tlc.tlc_id,
add_tlc.payment_hash,
peeled_onion_packet.clone(),
forward_fee,
)
.await;
}
Ok(())
}
Expand Down
2 changes: 0 additions & 2 deletions src/fiber/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1530,8 +1530,6 @@ where
.write()
.await
.record_payment_fail(&payment_session, error_detail.clone());
eprintln!("yukang payment fail: {:?}", error_detail);
eprintln!("yukang need_to_retry: {:?}", need_to_retry);
if need_to_retry {
// If this is the first hop error, like the WaitingTlcAck error,
// we will just retry later, return Ok here for letting endpoint user
Expand Down
4 changes: 0 additions & 4 deletions src/fiber/tests/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,10 @@ async fn test_send_payment_over_private_channel() {
.await;
} else {
assert!(res.is_err());
source_node
.wait_until_failed(res.unwrap().payment_hash)
.await;
}
}

test(10000000000, true).await;
tokio::time::sleep(tokio::time::Duration::from_millis(2000)).await;
test(30000000000, false).await;
}

Expand Down

0 comments on commit 558e2c0

Please sign in to comment.