diff --git a/Cargo.lock b/Cargo.lock index b9b488db..2d8c3788 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -889,7 +889,8 @@ dependencies = [ [[package]] name = "ckb-sdk" version = "3.1.0" -source = "git+https://github.com/chenyukang/ckb-sdk-rust.git?branch=v3.1.0-with-pcn-udt#4b712fa35652bcd8b1f9e832cf0ad85681d0c6f5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8487deb2c0a77bbc4d33c812aa8f3f93c8786730c37a516eebfc4246602413ca" dependencies = [ "anyhow", "bech32 0.8.1", diff --git a/Cargo.toml b/Cargo.toml index d7ed01f4..beb23123 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,8 +38,7 @@ tokio = { version = "1", features = [ "signal", ] } home = "0.5.9" -#ckb-sdk = "3.1.0" -ckb-sdk = { git = "https://github.com/chenyukang/ckb-sdk-rust.git", branch = "v3.1.0-with-pcn-udt" } +ckb-sdk = "3.1.0" thiserror = "1.0.58" anyhow = "1.0.81" env_logger = "0.11.3" diff --git a/src/ckb/channel.rs b/src/ckb/channel.rs index 977f3d59..f987c674 100644 --- a/src/ckb/channel.rs +++ b/src/ckb/channel.rs @@ -643,10 +643,6 @@ where .get_commitment_point(commitment_number + 1), next_local_nonce: state.get_local_musig2_pubnonce(), }; - warn!( - "anan set accept_channel funding script: {:?}", - funding_type_script - ); let command = PCNMessageWithPeerId { peer_id, @@ -1154,11 +1150,6 @@ impl ChannelActorState { commitment_number, remote_commitment_number ); - warn!( - "anan new_inbound_channel funding_type_script: {:?}", - funding_type_script - ); - Self { state: ChannelState::NegotiatingFunding(NegotiatingFundingFlags::THEIR_INIT_SENT), peer_id, @@ -1377,19 +1368,11 @@ impl ChannelActorState { } pub fn get_funding_request(&self, fee_rate: u64) -> FundingRequest { - let udt_info = if let Some(type_script) = &self.funding_type_script { - Some(FundingUdtInfo { - type_script: type_script.clone(), - // FIXME(yukang): this is hardcoded to 61 * 10^8 * 2 shannons - local_ckb_amount: 122000000000, - remote_ckb_amount: 122000000000, - }) - } else { - None - }; - warn!("anan get_funding_request: {:?}", udt_info); FundingRequest { - udt_info, + udt_info: self + .funding_type_script + .clone() + .map(FundingUdtInfo::new_with_script), script: self.get_funding_lock_script(), local_amount: self.to_local_amount as u64, local_fee_rate: fee_rate, @@ -2001,10 +1984,6 @@ impl ChannelActorState { self.to_remote_amount = accept_channel.funding_amount; self.remote_nonce = Some(accept_channel.next_local_nonce.clone()); self.funding_type_script = accept_channel.funding_type_script.clone(); - warn!( - "anan handle_accept_channel funding type script: {:?}", - &self.funding_type_script - ); let remote_pubkeys = (&accept_channel).into(); self.remote_channel_parameters = Some(ChannelParametersOneParty { @@ -2689,18 +2668,10 @@ impl ChannelActorState { ); if let Some(type_script) = &self.funding_type_script { - warn!( - "anan UDT local_amount: {}, remote_amount: {}", + debug!( + "UDT local_amount: {}, remote_amount: {}", self.to_local_amount, self.to_remote_amount ); - // FIXME(yukang): how to handle the CKB amount here, - // after substracting tx fee, we should return the lefted CKB to the holder - // let minimal_capacity = 61_0000_0000 as u64; - // let holder_output = CellOutput::new_builder() - // .capacity(minimal_capacity.pack()) - // .type_(Some(type_script.clone()).pack()) - // .lock(local_shutdown_script) - // .build(); let holder_output_data = self.to_local_amount.to_le_bytes().pack(); let dummy_output = CellOutput::new_builder() .lock(local_shutdown_script.clone()) diff --git a/src/ckb/network.rs b/src/ckb/network.rs index 8995b9cd..a9d33557 100644 --- a/src/ckb/network.rs +++ b/src/ckb/network.rs @@ -348,7 +348,6 @@ where } } NetworkActorCommand::AcceptChannel(accept_channel, reply) => { - warn!("anan acceptchannel: {:?}", accept_channel); let result = state .create_inbound_channel(accept_channel, self.store.clone()) .await @@ -374,7 +373,6 @@ where "Updating channel funding for channel {:?}, current tx: {:?}", &channel_id, old_tx ); - warn!("anan fundingrequest: {:?}", request); let mut tx = FundingTx::new(); tx.update_for_self(old_tx)?; let tx = match call_t!( @@ -608,11 +606,6 @@ impl NetworkActorState { return Ok((channel.clone(), temp_channel_id, id)); } - warn!( - "anan create_inbound_channel: accept_funding_type_script: {:?}, open_funding_type: {:?}", - funding_type_script, open_channel.funding_type_script - ); - match ( open_channel.funding_type_script.as_ref(), funding_type_script.as_ref(), @@ -1046,23 +1039,14 @@ where // TODO: Here we implies the one who receives AcceptChannel message // will send TxUpdate message first. dbg!(&script); - let udt_info = if let Some(funding_script) = funding_script { - Some(FundingUdtInfo { - type_script: funding_script, - // FIXME(yukang): this is hardcoded to 61 * 10^8 * 2 shannons - local_ckb_amount: 122000000000, - remote_ckb_amount: 122000000000, - }) - } else { - None - }; myself .send_message(NetworkActorMessage::new_command( NetworkActorCommand::UpdateChannelFunding( new, Default::default(), FundingRequest { - udt_info, + udt_info: funding_script + .map(FundingUdtInfo::new_with_script), script, local_amount: local as u64, local_fee_rate: 0, diff --git a/src/ckb_chain/funding/funding_tx.rs b/src/ckb_chain/funding/funding_tx.rs index a4f0320d..911dec97 100644 --- a/src/ckb_chain/funding/funding_tx.rs +++ b/src/ckb_chain/funding/funding_tx.rs @@ -65,6 +65,18 @@ pub struct FundingUdtInfo { pub remote_ckb_amount: u64, } +impl FundingUdtInfo { + pub fn new_with_script(type_script: packed::Script) -> Self { + // FIXME(yukang): make sure the udt_amount is enough for split into at least 2 cells + let two_cells_amount: u64 = (142 + 10) * (10 as u64).pow(8); + Self { + type_script, + local_ckb_amount: two_cells_amount, + remote_ckb_amount: two_cells_amount, + } + } +} + #[serde_as] #[derive(Clone, Debug, Default, Deserialize)] pub struct FundingRequest { @@ -126,9 +138,7 @@ impl TxBuilder for FundingTxBuilder { } } - warn!("anan build_base now : {:?}", self.request.udt_info); if let Some(ref udt_info) = self.request.udt_info { - let local_ckb_amount = udt_info.local_ckb_amount; let udt_amount = self.request.local_amount as u128; if udt_amount > 0 { @@ -146,20 +156,11 @@ impl TxBuilder for FundingTxBuilder { let (owner_cells, _) = cell_collector.collect_live_cells(&owner_query, true)?; let mut found_udt_cell = false; for cell in owner_cells.iter() { - let cell_capacity: u64 = cell.output.capacity().unpack(); let mut amount_bytes = [0u8; 16]; amount_bytes.copy_from_slice(&cell.output_data.as_ref()[0..16]); let cell_udt_amount = u128::from_le_bytes(amount_bytes); //FIXME(yukang): we may need to revise the check here - warn!( - "anan compare : {:?} >= {:?} && {:?} >= {:?} result: {:?}", - cell_capacity, - local_ckb_amount, - cell_udt_amount, - udt_amount, - cell_capacity >= local_ckb_amount && cell_udt_amount >= udt_amount - ); - if cell_capacity >= local_ckb_amount && cell_udt_amount >= udt_amount { + if cell_udt_amount >= udt_amount { inputs.push(CellInput::new(cell.out_point.clone(), 0)); if cell_udt_amount > udt_amount { let change_output_data: Bytes = @@ -183,7 +184,7 @@ impl TxBuilder for FundingTxBuilder { outputs.push(change_output); outputs_data.push(change_output_data); } - warn!("anan find proper UDT owner cell: {:?}", cell); + warn!("find proper UDT owner cell: {:?}", cell); found_udt_cell = true; break; } @@ -222,7 +223,7 @@ impl TxBuilder for FundingTxBuilder { .set_outputs(outputs) .set_outputs_data(outputs_data) .set_cell_deps(cell_deps.into_iter().collect()); - warn!("anan tx_builder: {:?}", tx_builder); + warn!("tx_builder: {:?}", tx_builder); let tx = tx_builder.build(); Ok(tx) } @@ -337,7 +338,7 @@ impl FundingTxBuilder { let mut funding_tx = self.funding_tx; let tx_builder = tx.as_advanced_builder(); - warn!("anan final tx_builder: {:?}", tx_builder); + warn!("final tx_builder: {:?}", tx_builder); funding_tx.update_for_self(tx)?; Ok(funding_tx) }