Skip to content

Commit

Permalink
code cleanup and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Oct 15, 2024
1 parent 57ddc72 commit e372112
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
28 changes: 13 additions & 15 deletions src/fiber/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,6 @@ where
// try to fulfill the payment, find the corresponding payment preimage from payment hash.
let mut preimage = None;
let mut peeled_packet_bytes: Option<Vec<u8>> = None;
let mut forward_to_next_hop = false;

if !add_tlc.onion_packet.is_empty() {
// TODO: Here we call network actor to peel the onion packet. Indeed, this message is forwarded from
Expand All @@ -779,7 +778,7 @@ where
tx
)
))
.expect("call network")
.expect(ASSUME_NETWORK_ACTOR_ALIVE)
.map_err(|err| ProcessingChannelError::PeelingOnionPacketError(err))?;

// check the payment hash and amount
Expand All @@ -788,8 +787,20 @@ where
"Payment hash mismatch".to_string(),
));
}

let received_amount = add_tlc.amount;
let forward_amount = peeled_packet.current.amount;
debug!(
"received_amount: {} forward_amount: {}",
add_tlc.amount, forward_amount
);

// TODO: check the expiry time, if it's expired, we should return an error.
if peeled_packet.is_last() {
if forward_amount != add_tlc.amount {
return Err(ProcessingChannelError::FinalIncorrectHTLCAmount);
}

// if this is the last hop, store the preimage.
// though we will RemoveTlcFulfill the TLC in try_to_settle_down_tlc function,
// here we can do error check early here for better error handling.
Expand All @@ -807,16 +818,6 @@ where
}
} else {
peeled_packet_bytes = Some(peeled_packet.serialize());
forward_to_next_hop = true;
}

let received_amount = add_tlc.amount;
let forward_amount = peeled_packet.current.amount;
debug!(
"received_amount: {} forward_amount: {}",
add_tlc.amount, forward_amount
);
if forward_to_next_hop {
assert!(received_amount >= forward_amount);
let forward_fee = received_amount.saturating_sub(forward_amount);
let fee_rate: u128 = state
Expand All @@ -833,9 +834,6 @@ where
return Err(ProcessingChannelError::TlcForwardFeeIsTooLow);
}
}
if !forward_to_next_hop && received_amount != add_tlc.amount {
return Err(ProcessingChannelError::FinalIncorrectHTLCAmount);
}
}

let tlc = state.create_inbounding_tlc(add_tlc.clone(), preimage)?;
Expand Down
2 changes: 0 additions & 2 deletions src/fiber/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,6 @@ where
continue;
}
}
// info!("weight: {:?} dist: {:?} fee: {:?}", weight, distance, fee);
// TODO: update weight and distance here
let node: NodeHeapElement = NodeHeapElement {
node_id: from,
weight,
Expand Down

0 comments on commit e372112

Please sign in to comment.