Skip to content

Commit

Permalink
Merge remote-tracking branch 'nervosnetwork/main' into refactor-gossi…
Browse files Browse the repository at this point in the history
…p-protocol
  • Loading branch information
contrun committed Dec 10, 2024
2 parents f936f42 + d72a274 commit 1e78fa8
Show file tree
Hide file tree
Showing 96 changed files with 9,699 additions and 2,310 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
with:
tool: nextest
- run: |
RUST_BACKTRACE=full RUST_LOG=trace cargo nextest run
RUST_BACKTRACE=full RUST_LOG=trace cargo nextest run --no-fail-fast
fmt:
name: Rustfmt
Expand Down Expand Up @@ -80,3 +80,22 @@ jobs:
flags: unittests
verbose: false
token: ${{ secrets.CODECOV_TOKEN }}

build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
profile: [dev, release]
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v2
- uses: dsherret/rust-toolchain-file@v1
- name: Install Dependencies (Windows)
if: contains(matrix.os, 'windows')
run: |
vcpkg integrate install
vcpkg install openssl:x64-windows-static-md
- run: cargo build --verbose --profile ${{ matrix.profile }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
tests/nodes/.ports
/coverage-report
/*.info
.vscode
53 changes: 51 additions & 2 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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",
"lz4"
], default-features = false }
serde_with = { version = "3.7.0", features = ["macros", "base64"] }
hex = "0.4.3"
Expand All @@ -48,7 +48,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
socket2 = "0.5.7"
lnd-grpc-tonic-client = "0.3.0"
git-version = "0.3.9"
fiber-sphinx = "1.0.1"
fiber-sphinx = "2.1.0"
strum = { version = "0.26", features = ["derive"] }
tokio = { version = "1", features = [
"io-util",
Expand All @@ -60,6 +60,9 @@ tokio = { version = "1", features = [
"time",
"signal",
] }
indicatif = "0.16"
console = "0.15.8"
bincode = "1.3.3"

[profile.release]
panic = "abort"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GRCOV_EXCL_LINE = ^\s*(\})*(\))*(;)*$$|\s*((log::|tracing::)?(trace|debug|info|w

.PHONY: test
test:
RUST_LOG=off cargo nextest run
RUST_LOG=off cargo nextest run --no-fail-fast

.PHONY: clippy
clippy:
Expand Down
38 changes: 21 additions & 17 deletions src/cch/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::fiber::hash_algorithm::HashAlgorithm;
use crate::fiber::types::{Hash256, RemoveTlcFulfill, RemoveTlcReason};
use crate::fiber::{NetworkActorCommand, NetworkActorMessage};
use crate::invoice::Currency;
use crate::now_timestamp;
use crate::now_timestamp_as_millis_u64;

use super::error::CchDbError;
use super::{CchConfig, CchError, CchOrderStatus, CchOrdersDb, ReceiveBTCOrder, SendBTCOrder};
Expand Down Expand Up @@ -355,7 +355,7 @@ impl CchActor {
}

order.channel_id = Some(tlc_notification.channel_id);
order.tlc_id = Some(tlc_notification.tlc.id.into());
order.tlc_id = Some(tlc_notification.tlc.tlc_id.into());
state.orders_db.update_send_btc_order(order.clone()).await?;

let req = routerrpc::SendPaymentRequest {
Expand Down Expand Up @@ -588,13 +588,12 @@ 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"),
),
expiry: now_timestamp() + self.config.ckb_final_tlc_expiry_delta,
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,
onion_packet: vec![],
onion_packet: None,
previous_tlc: None,
},
rpc_reply,
Expand Down Expand Up @@ -644,6 +643,12 @@ impl LndPaymentsTracker {
}

async fn run(self) {
tracing::debug!(
target: "fnn::cch::actor::tracker::lnd_payments",
"will connect {}",
self.lnd_connection.uri
);

// TODO: clean up expired orders
loop {
select! {
Expand All @@ -654,6 +659,7 @@ impl LndPaymentsTracker {
}
Err(err) => {
tracing::error!(
target: "fnn::cch::actor::tracker::lnd_payments",
"Error tracking LND payments, retry 15 seconds later: {:?}",
err
);
Expand All @@ -678,10 +684,6 @@ impl LndPaymentsTracker {
}

async fn run_inner(&self) -> Result<()> {
tracing::debug!(
"[LndPaymentsTracker] will connect {}",
self.lnd_connection.uri
);
let mut client = self.lnd_connection.create_router_client().await?;
let mut stream = client
.track_payments(routerrpc::TrackPaymentsRequest {
Expand All @@ -708,7 +710,7 @@ impl LndPaymentsTracker {
}

async fn on_payment(&self, payment: lnrpc::Payment) -> Result<()> {
tracing::debug!("[LndPaymentsTracker] payment: {:?}", payment);
tracing::debug!(target: "fnn::cch::actor::tracker::lnd_payments", "payment: {:?}", payment);
let event = CchMessage::SettleSendBTCOrder(SettleSendBTCOrderEvent {
payment_hash: format!("0x{}", payment.payment_hash),
preimage: (!payment.payment_preimage.is_empty())
Expand Down Expand Up @@ -749,6 +751,11 @@ impl LndInvoiceTracker {
}

async fn run(self) {
tracing::debug!(
target: "fnn::cch::actor::tracker::lnd_invoice",
"will connect {}",
self.lnd_connection.uri
);
loop {
select! {
result = self.run_inner() => {
Expand All @@ -758,6 +765,7 @@ impl LndInvoiceTracker {
}
Err(err) => {
tracing::error!(
target: "fnn::cch::actor::tracker::lnd_invoice",
"Error tracking LND invoices, retry 15 seconds later: {:?}",
err
);
Expand All @@ -782,10 +790,6 @@ impl LndInvoiceTracker {
}

async fn run_inner(&self) -> Result<()> {
tracing::debug!(
"[LndInvoiceTracker] will connect {}",
self.lnd_connection.uri
);
let mut client = self.lnd_connection.create_invoices_client().await?;
// TODO: clean up expired orders
let mut stream = client
Expand Down
3 changes: 2 additions & 1 deletion src/cch/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub struct CchConfig {
)]
pub btc_final_tlc_expiry: u64,

/// Tlc expiry time for CKB network in blocks.
/// Tlc expiry time for CKB network in blocks.
#[default(DEFAULT_CKB_FINAL_TLC_EXPIRY_DELTA)]
#[arg(
name = "CCH_CKB_FINAL_TLC_EXPIRY_DELTA",
Expand All @@ -105,6 +105,7 @@ pub struct CchConfig {

/// Ignore the failure when starting the cch service.
#[default(false)]
#[arg(skip)]
pub ignore_startup_failure: bool,
}

Expand Down
Loading

0 comments on commit 1e78fa8

Please sign in to comment.