Skip to content

Commit

Permalink
merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Nov 12, 2024
2 parents af56da6 + a482523 commit 01fd032
Show file tree
Hide file tree
Showing 75 changed files with 1,481 additions and 1,291 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ jobs:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v2
- uses: dsherret/rust-toolchain-file@v1
- run: cargo test
- uses: taiki-e/install-action@v2
with:
tool: nextest
- run: |
RUST_BACKTRACE=full RUST_LOG=trace cargo nextest run
fmt:
name: Rustfmt
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/tests/nodes/*/fiber/store
/tests/nodes/*/config.yml
/tests/nodes/*/dev.toml
/tests/deploy/udt-init/target
tests/nodes/.ports
/coverage-report
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ molecule = { version = "0.8.0", default-features = false }
ckb-types = "0.118.0"
ckb-gen-types = "0.118.0"
ckb-jsonrpc-types = "0.118.0"
ckb-chain-spec = "0.118.0"
ckb-resource = "0.118.0"
rocksdb = { package = "ckb-rocksdb", version = "=0.21.1", features = [
"snappy",
], default-features = false }
Expand Down
34 changes: 33 additions & 1 deletion config/testnet/config.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
fiber:
listening_addr: "/ip4/127.0.0.1/tcp/8228"
network: "Testnet"
bootnode_addrs:
- "/ip4/54.179.226.154/tcp/8228/p2p/Qmes1EBD4yNo9Ywkfe6eRw9tG1nVNGLDmMud1xJMsoYFKy"
- "/ip4/54.179.226.154/tcp/18228/p2p/QmdyQWjPtbK4NWWsvy8s69NGJaQULwgeQDT5ZpNDrTNaeV"
announce_listening_addr: true
# chain spec, can be mainnet | testnet | "path to chain spec file"
chain: testnet
# lock script configurations related to fiber network
# https://github.com/nervosnetwork/fiber-scripts/blob/main/deployment/testnet/migrations/2024-09-14-084742.json
scripts:
- name: FundingLock
script:
code_hash: 0x6c67887fe201ee0c7853f1682c0b77c0e6214044c156c7558269390a8afa6d7c
hash_type: type
args: 0x
cell_deps:
- out_point:
tx_hash: 0x89af398edc7ed0054506b33349b031097d94378e11e77bf0690ee69d82623a43
index: 0x0
dep_type: code
- out_point:
tx_hash: 0xbfd6d68b328a02606f1f65ee0f79f8ed5f76dfe86998c7aaa9ee4720d53f4c49 # ckb_auth
index: 0x0
dep_type: code
- name: CommitmentLock
script:
code_hash: 0x740dee83f87c6f309824d8fd3fbdd3c8380ee6fc9acc90b1a748438afcdf81d8
hash_type: type
args: 0x
cell_deps:
- out_point:
tx_hash: 0x89af398edc7ed0054506b33349b031097d94378e11e77bf0690ee69d82623a43
index: 0x1
dep_type: code
- out_point:
tx_hash: 0xbfd6d68b328a02606f1f65ee0f79f8ed5f76dfe86998c7aaa9ee4720d53f4c49 #ckb_auth
index: 0x0
dep_type: code

rpc:
listening_addr: "127.0.0.1:8227"
Expand Down
15 changes: 10 additions & 5 deletions src/actors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ impl Actor for RootActor {
_state: &mut Self::State,
) -> Result<(), ActorProcessingErr> {
match message {
SupervisionEvent::ActorTerminated(who, _, _) => {
debug!("Actor {:?} terminated", who);
}
SupervisionEvent::ActorPanicked(who, _) => {
error!("Actor {:?} panicked", who);
SupervisionEvent::ActorTerminated(who, _state, reason) => match reason {
Some(reason) => {
debug!("Actor terminated for {:?} (id: {:?})", reason, who,);
}
None => {
debug!("Actor terminated for unknown reason (id: {:?})", who);
}
},
SupervisionEvent::ActorPanicked(who, err) => {
error!("Actor unexpectedly panicked (id: {:?}): {:?}", who, err);
}
_ => {}
}
Expand Down
9 changes: 5 additions & 4 deletions src/cch/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ use crate::fiber::channel::{
AddTlcCommand, ChannelCommand, ChannelCommandWithId, RemoveTlcCommand, TlcNotification,
};
use crate::fiber::hash_algorithm::HashAlgorithm;
use crate::fiber::types::{Hash256, LockTime, RemoveTlcFulfill, RemoveTlcReason};
use crate::fiber::types::{Hash256, RemoveTlcFulfill, RemoveTlcReason};
use crate::fiber::{NetworkActorCommand, NetworkActorMessage};
use crate::invoice::Currency;
use crate::now_timestamp;

use super::error::CchDbError;
use super::{CchConfig, CchError, CchOrderStatus, CchOrdersDb, ReceiveBTCOrder, SendBTCOrder};
Expand Down Expand Up @@ -311,7 +312,7 @@ impl CchActor {
fee_sats,
currency: send_btc.currency,
created_at: duration_since_epoch.as_secs(),
ckb_final_tlc_expiry: self.config.ckb_final_tlc_expiry_blocks,
ckb_final_tlc_expiry_delta: self.config.ckb_final_tlc_expiry_delta,
btc_pay_req: send_btc.btc_pay_req,
ckb_pay_req: Default::default(),
payment_hash: format!("0x{}", invoice.payment_hash().encode_hex::<String>()),
Expand Down Expand Up @@ -533,7 +534,7 @@ impl CchActor {
let order = ReceiveBTCOrder {
created_at: duration_since_epoch.as_secs(),
expires_after: DEFAULT_ORDER_EXPIRY_SECONDS,
ckb_final_tlc_expiry: receive_btc.final_tlc_expiry,
ckb_final_tlc_expiry_delta: receive_btc.final_tlc_expiry,
btc_pay_req,
payment_hash: receive_btc.payment_hash.clone(),
payment_preimage: None,
Expand Down Expand Up @@ -591,7 +592,7 @@ impl CchActor {
payment_hash: Some(
Hash256::from_str(&order.payment_hash).expect("parse Hash256"),
),
expiry: LockTime::new(self.config.ckb_final_tlc_expiry_blocks),
expiry: now_timestamp() + self.config.ckb_final_tlc_expiry_delta,
hash_algorithm: HashAlgorithm::Sha256,
onion_packet: vec![],
previous_tlc: None,
Expand Down
16 changes: 8 additions & 8 deletions src/cch/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use clap_serde_derive::ClapSerde;
pub const DEFAULT_ORDER_EXPIRY_TIME: u64 = 3600;
/// Default BTC final-hop HTLC expiry time in seconds.
pub const DEFAULT_BTC_FINAL_TLC_EXPIRY_TIME: u64 = 36;
/// Default CKB final-hop HTLC expiry time in blocks.
pub const DEFAULT_CKB_FINAL_TLC_EXPIRY_BLOCKS: u64 = 10;
/// Default CKB final-hop HTLC expiry delta in timestamp (in milliseconds), 24 hours.
pub const DEFAULT_CKB_FINAL_TLC_EXPIRY_DELTA: u64 = 24 * 60 * 60 * 1000;

// Use prefix `cch-`/`CCH_`
#[derive(ClapSerde, Debug, Clone)]
Expand Down Expand Up @@ -93,15 +93,15 @@ pub struct CchConfig {
)]
pub btc_final_tlc_expiry: u64,

/// Final tlc expiry time for CKB network in blocks.
#[default(DEFAULT_CKB_FINAL_TLC_EXPIRY_BLOCKS)]
/// Tlc expiry time for CKB network in blocks.
#[default(DEFAULT_CKB_FINAL_TLC_EXPIRY_DELTA)]
#[arg(
name = "CCH_CKB_FINAL_TLC_EXPIRY_BLOCKS",
long = "cch-ckb-final-tlc-expiry-blocks",
name = "CCH_CKB_FINAL_TLC_EXPIRY_DELTA",
long = "cch-ckb-final-tlc-expiry-delta",
env,
help = format!("final tlc expiry time in blocks for CKB network, default is {}", DEFAULT_CKB_FINAL_TLC_EXPIRY_BLOCKS),
help = format!("final tlc expiry delta in timestamp for CKB network, default is {}", DEFAULT_CKB_FINAL_TLC_EXPIRY_DELTA),
)]
pub ckb_final_tlc_expiry_blocks: u64,
pub ckb_final_tlc_expiry_delta: u64,

/// Ignore the failure when starting the cch service.
#[default(false)]
Expand Down
2 changes: 1 addition & 1 deletion src/cch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use error::{CchError, CchResult};

mod config;
pub use config::{
CchConfig, DEFAULT_BTC_FINAL_TLC_EXPIRY_TIME, DEFAULT_CKB_FINAL_TLC_EXPIRY_BLOCKS,
CchConfig, DEFAULT_BTC_FINAL_TLC_EXPIRY_TIME, DEFAULT_CKB_FINAL_TLC_EXPIRY_DELTA,
DEFAULT_ORDER_EXPIRY_TIME,
};

Expand Down
8 changes: 4 additions & 4 deletions src/cch/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ pub struct SendBTCOrder {
// Seconds after timestamp that the order expires
#[serde_as(as = "U64Hex")]
pub expires_after: u64,
// The minimal expiry in seconds of the final TLC in the CKB network
// The minimal expiry delta in milliseconds of the final TLC hop in the CKB network
#[serde_as(as = "U64Hex")]
pub ckb_final_tlc_expiry: u64,
pub ckb_final_tlc_expiry_delta: u64,

pub currency: Currency,
pub wrapped_btc_type_script: ckb_jsonrpc_types::Script,
Expand Down Expand Up @@ -95,7 +95,7 @@ impl SendBTCOrder {
.map_err(|_| CchError::HexDecodingError(self.payment_hash.clone()))?,
)
.expiry_time(Duration::from_secs(self.expires_after))
.final_cltv(self.ckb_final_tlc_expiry)
.final_expiry_delta(self.ckb_final_tlc_expiry_delta)
.udt_type_script(self.wrapped_btc_type_script.clone().into());

let invoice = invoice_builder.build()?;
Expand All @@ -116,7 +116,7 @@ pub struct ReceiveBTCOrder {
pub expires_after: u64,
// The minimal expiry in seconds of the final TLC in the CKB network
#[serde_as(as = "U64Hex")]
pub ckb_final_tlc_expiry: u64,
pub ckb_final_tlc_expiry_delta: u64,

pub wrapped_btc_type_script: ckb_jsonrpc_types::Script,

Expand Down
Loading

0 comments on commit 01fd032

Please sign in to comment.