Skip to content

Commit

Permalink
merge main and resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Dec 5, 2024
2 parents e8c13b5 + a5cde07 commit 5c9888b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 41 deletions.
6 changes: 2 additions & 4 deletions src/cch/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,8 @@ impl CchActor {
command: ChannelCommand::AddTlc(
AddTlcCommand {
amount: order.amount_sats - order.fee_sats,
preimage: None,
payment_hash: Some(
Hash256::from_str(&order.payment_hash).expect("parse Hash256"),
),
payment_hash: Hash256::from_str(&order.payment_hash)
.expect("parse Hash256"),
expiry: now_timestamp_as_millis_u64()
+ self.config.ckb_final_tlc_expiry_delta,
hash_algorithm: HashAlgorithm::Sha256,
Expand Down
16 changes: 2 additions & 14 deletions src/fiber/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ pub enum TxCollaborationCommand {
#[derive(Debug, Clone)]
pub struct AddTlcCommand {
pub amount: u128,
pub preimage: Option<Hash256>,
pub payment_hash: Option<Hash256>,
pub payment_hash: Hash256,
pub expiry: u64,
pub hash_algorithm: HashAlgorithm,
/// Onion packet for the next node
Expand Down Expand Up @@ -173,12 +172,6 @@ pub struct UpdateCommand {
pub tlc_fee_proportional_millionths: Option<u128>,
}

fn get_random_preimage() -> Hash256 {
let mut preimage = [0u8; 32];
preimage.copy_from_slice(&rand::random::<[u8; 32]>());
preimage.into()
}

#[derive(Debug)]
pub struct ChannelCommandWithId {
pub channel_id: Hash256,
Expand Down Expand Up @@ -4583,16 +4576,11 @@ impl ChannelActorState {
"Must not have the same id in pending offered tlcs"
);

let preimage = command.preimage.unwrap_or(get_random_preimage());
let payment_hash = command
.payment_hash
.unwrap_or_else(|| command.hash_algorithm.hash(preimage).into());

TlcKind::AddTlc(AddTlcInfo {
channel_id: self.get_id(),
tlc_id: TLCId::Offered(id),
amount: command.amount,
payment_hash: payment_hash,
payment_hash: command.payment_hash,
expiry: command.expiry,
hash_algorithm: command.hash_algorithm,
created_at: self.get_current_commitment_numbers(),
Expand Down
3 changes: 1 addition & 2 deletions src/fiber/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2184,8 +2184,7 @@ where
let command = ChannelCommand::AddTlc(
AddTlcCommand {
amount: info.amount,
preimage: None,
payment_hash: Some(info.payment_hash),
payment_hash: info.payment_hash,
expiry: info.expiry,
hash_algorithm: info.hash_algorithm,
onion_packet: peeled_onion_packet.next.clone(),
Expand Down
27 changes: 8 additions & 19 deletions src/fiber/tests/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,7 @@ async fn test_network_send_previous_tlc_error() {
command: ChannelCommand::AddTlc(
AddTlcCommand {
amount: 10000,
preimage: None,
payment_hash: Some(generated_payment_hash),
payment_hash: generated_payment_hash,
expiry: DEFAULT_EXPIRY_DELTA + now_timestamp_as_millis_u64(),
hash_algorithm: HashAlgorithm::Sha256,
// invalid onion packet
Expand Down Expand Up @@ -1532,9 +1531,8 @@ async fn do_test_channel_commitment_tx_after_add_tlc(algorithm: HashAlgorithm) {
AddTlcCommand {
amount: tlc_amount,
hash_algorithm: algorithm,
payment_hash: Some(digest.into()),
payment_hash: digest.into(),
expiry: now_timestamp_as_millis_u64() + DEFAULT_EXPIRY_DELTA,
preimage: None,
onion_packet: None,
previous_tlc: None,
},
Expand Down Expand Up @@ -1802,9 +1800,8 @@ async fn do_test_remove_tlc_with_wrong_hash_algorithm(
AddTlcCommand {
amount: tlc_amount,
hash_algorithm: correct_algorithm,
payment_hash: Some(digest.into()),
payment_hash: digest.into(),
expiry: now_timestamp_as_millis_u64() + DEFAULT_EXPIRY_DELTA,
preimage: None,
onion_packet: None,
previous_tlc: None,
},
Expand Down Expand Up @@ -1854,9 +1851,8 @@ async fn do_test_remove_tlc_with_wrong_hash_algorithm(
AddTlcCommand {
amount: tlc_amount,
hash_algorithm: wrong_algorithm,
payment_hash: Some(digest.into()),
payment_hash: digest.into(),
expiry: now_timestamp_as_millis_u64() + DEFAULT_EXPIRY_DELTA,
preimage: None,
onion_packet: None,
previous_tlc: None,
},
Expand Down Expand Up @@ -1912,9 +1908,8 @@ async fn do_test_remove_tlc_with_expiry_error() {
let add_tlc_command = AddTlcCommand {
amount: tlc_amount,
hash_algorithm: HashAlgorithm::CkbHash,
payment_hash: Some(digest.into()),
payment_hash: digest.into(),
expiry: now_timestamp_as_millis_u64() + 10,
preimage: None,
onion_packet: None,
previous_tlc: None,
};
Expand All @@ -1935,9 +1930,8 @@ async fn do_test_remove_tlc_with_expiry_error() {
let add_tlc_command = AddTlcCommand {
amount: tlc_amount,
hash_algorithm: HashAlgorithm::CkbHash,
payment_hash: Some(digest.into()),
payment_hash: digest.into(),
expiry: now_timestamp_as_millis_u64() + MAX_PAYMENT_TLC_EXPIRY_LIMIT + 10,
preimage: None,
onion_packet: None,
previous_tlc: None,
};
Expand Down Expand Up @@ -1974,9 +1968,8 @@ async fn do_test_add_tlc_duplicated() {
let add_tlc_command = AddTlcCommand {
amount: tlc_amount,
hash_algorithm: HashAlgorithm::CkbHash,
payment_hash: Some(digest.into()),
payment_hash: digest.into(),
expiry: now_timestamp_as_millis_u64() + 10,
preimage: None,
onion_packet: None,
previous_tlc: None,
};
Expand Down Expand Up @@ -2016,7 +2009,6 @@ async fn do_test_add_tlc_waiting_ack() {
hash_algorithm: HashAlgorithm::CkbHash,
payment_hash: gen_sha256_hash().into(),
expiry: now_timestamp_as_millis_u64() + 100000000,
preimage: None,
onion_packet: None,
previous_tlc: None,
};
Expand Down Expand Up @@ -2068,7 +2060,6 @@ async fn do_test_add_tlc_number_limit() {
hash_algorithm: HashAlgorithm::CkbHash,
payment_hash: gen_sha256_hash().into(),
expiry: now_timestamp_as_millis_u64() + 100000000,
preimage: None,
onion_packet: None,
previous_tlc: None,
};
Expand Down Expand Up @@ -2121,7 +2112,6 @@ async fn do_test_add_tlc_value_limit() {
hash_algorithm: HashAlgorithm::CkbHash,
payment_hash: gen_sha256_hash().into(),
expiry: now_timestamp_as_millis_u64() + 100000000,
preimage: None,
onion_packet: None,
previous_tlc: None,
};
Expand Down Expand Up @@ -2179,9 +2169,8 @@ async fn do_test_channel_with_simple_update_operation(algorithm: HashAlgorithm)
AddTlcCommand {
amount: tlc_amount,
hash_algorithm: algorithm,
payment_hash: Some(digest.into()),
payment_hash: digest.into(),
expiry: now_timestamp_as_millis_u64() + DEFAULT_EXPIRY_DELTA,
preimage: None,
onion_packet: None,
previous_tlc: None,
},
Expand Down
3 changes: 1 addition & 2 deletions src/rpc/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,7 @@ where
command: ChannelCommand::AddTlc(
AddTlcCommand {
amount: params.amount,
preimage: None,
payment_hash: Some(params.payment_hash),
payment_hash: params.payment_hash,
expiry: params.expiry,
hash_algorithm: params.hash_algorithm.unwrap_or_default(),
onion_packet: None,
Expand Down

0 comments on commit 5c9888b

Please sign in to comment.