Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Broadcast {channel,node} information for multihop payment #144

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b2bf810
Add message definition for multihop payment
contrun Aug 12, 2024
0cb6fe7
Always use outpoint to refer to channel
contrun Aug 13, 2024
d02d513
Add more hierarchy to fiber message for easier processing
contrun Aug 13, 2024
db4d7f9
Remove short_channel_id
contrun Aug 14, 2024
2edd97f
Add channel public for broadcasting info
contrun Aug 14, 2024
d91c7bc
Broadcast channel announcement
contrun Aug 14, 2024
5636e3e
Fix test cases
contrun Aug 14, 2024
3c6fc75
Test create public channel
contrun Aug 14, 2024
0653a3f
Try to handle announcement signatures
contrun Aug 14, 2024
ed32a49
Send announce channel nonce
contrun Aug 14, 2024
898477c
Correctly create node signatures
contrun Aug 14, 2024
a3e6caf
Try to process AnnouncementSignatures
contrun Aug 14, 2024
009d3cf
Clarify Schnorr vs ecdsa signatures
contrun Aug 14, 2024
8d71afd
Parse announcement signatures properly
contrun Aug 14, 2024
8ed76fc
Add hash function to broadcast messages
contrun Aug 15, 2024
56bf8bf
Add id function to broadcast messages
contrun Aug 15, 2024
c0737b4
Obtain real node addresses
contrun Aug 15, 2024
4cf82db
Add announced node name to test nodes
contrun Aug 15, 2024
7ed57d3
Implement broadcasting
contrun Aug 15, 2024
1c32cdb
Add more information to trace tx output
contrun Aug 15, 2024
94ab3ab
Verify signatures in broadcast messages
contrun Aug 15, 2024
77e6298
Fix a subtle bug because changing state unexpectedly
contrun Aug 15, 2024
deebf4f
Rename FiberChannelNormalOperationMessage to FiberChannelMessage
contrun Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 66 additions & 14 deletions src/ckb/actor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ckb_sdk::{CkbRpcClient, RpcError};
use ckb_sdk::{rpc::ResponseFormatGetter, CkbRpcClient, RpcError};
use ckb_types::{core::TransactionView, packed, prelude::*};
use ractor::{
concurrency::{sleep, Duration},
Expand Down Expand Up @@ -35,7 +35,22 @@ pub enum CkbChainMessage {
),
Sign(FundingTx, RpcReplyPort<Result<FundingTx, FundingError>>),
SendTx(TransactionView, RpcReplyPort<Result<(), RpcError>>),
TraceTx(TraceTxRequest, RpcReplyPort<ckb_jsonrpc_types::Status>),
TraceTx(TraceTxRequest, RpcReplyPort<TraceTxResponse>),
}

#[derive(Debug)]
pub struct TraceTxResponse {
pub tx: Option<ckb_jsonrpc_types::TransactionView>,
pub status: ckb_jsonrpc_types::TxStatus,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to import ckb_jsonrpc_types, since there are multiple references.


impl TraceTxResponse {
pub fn new(
tx: Option<ckb_jsonrpc_types::TransactionView>,
status: ckb_jsonrpc_types::TxStatus,
) -> Self {
Self { tx, status }
}
}

#[ractor::async_trait]
Expand Down Expand Up @@ -169,8 +184,25 @@ impl Actor for CkbChainActor {
.block_number
.unwrap_or_default()
.into();
(tip_number >= commit_number + confirmations)
.then_some(ckb_jsonrpc_types::Status::Committed)
let transaction = match resp
.transaction
.map(|x| x.get_value())
.transpose()
{
Ok(Some(tx)) => Some(tx),
Ok(None) => None,
Err(err) => {
tracing::error!(
"[{}] get transaction failed: {:?}",
actor_name,
err
);
None
}
};
(tip_number >= commit_number + confirmations).then_some(
TraceTxResponse::new(transaction, resp.tx_status),
)
}
Err(err) => {
tracing::error!(
Expand All @@ -183,7 +215,7 @@ impl Actor for CkbChainActor {
}
}
ckb_jsonrpc_types::Status::Rejected => {
Some(ckb_jsonrpc_types::Status::Rejected)
Some(TraceTxResponse::new(None, resp.tx_status))
}
_ => None,
},
Expand Down Expand Up @@ -233,13 +265,14 @@ mod test_utils {
use std::collections::HashMap;

use anyhow::anyhow;
use ckb_jsonrpc_types::TxStatus;
use ckb_types::{
core::TransactionView,
packed::{CellOutput, OutPoint},
prelude::{Builder, Entity, Pack, PackVec, Unpack},
};

use crate::ckb::TraceTxRequest;
use crate::ckb::{TraceTxRequest, TraceTxResponse};

use super::super::contracts::MockContext;
use super::CkbChainMessage;
Expand All @@ -257,7 +290,13 @@ mod test_utils {

pub struct MockChainActorState {
ctx: MockContext,
tx_status: HashMap<Byte32, ckb_jsonrpc_types::Status>,
tx_status: HashMap<
Byte32,
(
ckb_jsonrpc_types::TransactionView,
ckb_jsonrpc_types::Status,
),
>,
cell_status: HashMap<OutPoint, CellStatus>,
}

Expand Down Expand Up @@ -459,7 +498,7 @@ mod test_utils {
}
};
let (status, result) = f();
state.tx_status.insert(tx.hash(), status);
state.tx_status.insert(tx.hash(), (tx.into(), status));
if let Err(e) = reply_port.send(result) {
error!(
"[{}] send reply failed: {:?}",
Expand All @@ -469,16 +508,27 @@ mod test_utils {
}
}
TraceTx(tx, reply_port) => {
let status = state
.tx_status
.get(&tx.tx_hash)
.cloned()
.unwrap_or(ckb_jsonrpc_types::Status::Unknown);
let (tx_view, status) = match state.tx_status.get(&tx.tx_hash).cloned() {
Some((tx_view, status)) => (Some(tx_view), status),
None => (None, ckb_jsonrpc_types::Status::Unknown),
};

debug!(
"Tracing transaction: {:?}, status: {:?}",
&tx.tx_hash, &status
);
if let Err(e) = reply_port.send(status) {
let status = TxStatus {
status,
block_number: None,
block_hash: None,
reason: None,
};
let response = TraceTxResponse {
tx: tx_view,
status,
};

if let Err(e) = reply_port.send(response) {
error!(
"[{}] send reply failed: {:?}",
myself.get_name().unwrap_or_default(),
Expand Down Expand Up @@ -528,6 +578,8 @@ mod test_utils {
request.clone()
)
.expect("chain actor alive")
.status
.status
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/ckb/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use serde_with::serde_as;
use std::{
io::{ErrorKind, Read},
path::PathBuf,
str::FromStr,
};

use std::str::FromStr;

use ckb_types::prelude::Builder;
use ckb_types::prelude::Pack;
use ckb_types::H256;
Expand Down
2 changes: 1 addition & 1 deletion src/ckb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod config;
mod error;
mod funding;

pub use actor::{CkbChainActor, CkbChainMessage, TraceTxRequest};
pub use actor::{CkbChainActor, CkbChainMessage, TraceTxRequest, TraceTxResponse};
pub use config::{CkbConfig, DEFAULT_CKB_BASE_DIR_NAME};
pub use error::{CkbChainError, FundingError};
pub use funding::{FundingRequest, FundingTx};
Expand Down
Loading
Loading