Skip to content

Commit

Permalink
check CKB amount range when open channel
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Oct 20, 2024
1 parent 6783283 commit 6922c0f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/fiber/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2647,6 +2647,12 @@ where
reserved_ckb_amount
)));
}
if udt_type_script.is_none() && funding_amount as u64 >= u64::MAX {
return Err(ProcessingChannelError::InvalidParameter(format!(
"The CKB amount of the channel should be less than {:?}",
u64::MAX
)));
}
let funding_amount = if udt_type_script.is_some() {
funding_amount
} else {
Expand Down
32 changes: 32 additions & 0 deletions src/fiber/tests/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,38 @@ async fn do_test_channel_with_simple_update_operation(algorithm: HashAlgorithm)
// TODO: maybe also check shutdown tx outputs and output balances here.
}

#[tokio::test]
async fn test_open_channel_with_invalid_ckb_amount_range() {
init_tracing();

let [node_a, node_b] = NetworkNode::new_n_interconnected_nodes().await;
let message = |rpc_reply| {
NetworkActorMessage::Command(NetworkActorCommand::OpenChannel(
OpenChannelCommand {
peer_id: node_b.peer_id.clone(),
public: true,
shutdown_script: None,
funding_amount: 0xfffffffffffffffffffffffffffffff,
funding_udt_type_script: None,
commitment_fee_rate: None,
funding_fee_rate: None,
tlc_locktime_expiry_delta: None,
tlc_min_value: None,
tlc_max_value: None,
tlc_fee_proportional_millionths: None,
max_tlc_number_in_flight: None,
max_tlc_value_in_flight: None,
},
rpc_reply,
))
};
let open_channel_result = call!(node_a.network_actor, message).expect("node_a alive");
assert!(open_channel_result
.err()
.unwrap()
.contains("The CKB amount of the channel should be less than 18446744073709551615"));
}

#[tokio::test]
async fn test_revoke_old_commitment_transaction() {
init_tracing();
Expand Down

0 comments on commit 6922c0f

Please sign in to comment.