Skip to content

Commit

Permalink
Merge pull request #453 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
chore: merge develop for 0.2.0 release
  • Loading branch information
quake authored Jan 7, 2025
2 parents c963248 + 81014d3 commit 087b087
Show file tree
Hide file tree
Showing 62 changed files with 8,957 additions and 3,149 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
profile: [dev, release]
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
steps:
- uses: actions/checkout@v2
- uses: dsherret/rust-toolchain-file@v1
Expand Down
20 changes: 15 additions & 5 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
fi
# Prebuild the program so that we can run the following script faster
export FNN="$(cargo build --message-format=json-render-diagnostics | jq -js '[.[] | select(.reason == "compiler-artifact") | select(.executable != null)] | last | .executable')"
cargo build
cd tests/deploy/udt-init && cargo build && cd -
if [ ${{ matrix.workflow }} = "router-pay" ]; then
export START_BOOTNODE=y
Expand All @@ -81,9 +81,9 @@ jobs:
if [ -f $port_file ]; then
break
else
retry_count=$((retry_count + 1))
echo "File $port_file not found. Retrying in 2 seconds..."
sleep 2
retry_count=$((retry_count + 1))
fi
done
Expand All @@ -92,11 +92,15 @@ jobs:
ports+=("$line")
done < ./tests/nodes/.ports
for i in {1..20}; do
echo "Checking if all ports are open ... ${ports[@]}"
try_number=60
count=0
while [ $count -lt $try_number ]; do
all_open=true
for port in $ports; do
echo "Checking port $port"
for port in "${ports[@]}"; do
if ! nc -z 127.0.0.1 $port; then
echo "Port $port is not open yet ..."
all_open=false
break
fi
Expand All @@ -105,11 +109,17 @@ jobs:
echo "All ports are open now ..."
break
else
count=$((count + 1))
if [ $count -eq $try_number ]; then
echo "Reached maximum number of tries ($try_number), exiting with status 1"
exit 1
fi
echo "Not all ports are open, waiting 3 seconds before retrying"
sleep 3
fi
done
(cd ./tests/bruno; npm exec -- @usebruno/[email protected] run e2e/${{ matrix.workflow }} -r --env ${{ matrix.test_env }} ${{ matrix.extra_bru_args }} ) &
# -n means we will exit when any of the background processes exits.
Expand Down
24 changes: 23 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fnn"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down Expand Up @@ -63,6 +63,7 @@ tokio = { version = "1", features = [
indicatif = "0.16"
console = "0.15.8"
bincode = "1.3.3"
num_enum = "0.7.3"

[features]
default = []
Expand Down
4 changes: 2 additions & 2 deletions 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 --no-fail-fast
TEST_TEMP_RETAIN=1 RUST_LOG=off cargo nextest run --no-fail-fast

.PHONY: clippy
clippy:
Expand Down Expand Up @@ -55,7 +55,7 @@ coverage: coverage-run-unittests coverage-collect-data coverage-generate-report

.PHONY: gen-rpc-doc
gen-rpc-doc:
cargo install fiber-rpc-gen
$(if $(shell command -v fiber-rpc-gen),,cargo install fiber-rpc-gen --force)
fiber-rpc-gen ./src/rpc
if grep -q "TODO: add desc" ./src/rpc/README.md; then \
echo "Warning: There are 'TODO: add desc' in src/rpc/README.md, please add documentation comments to resolve them"; \
Expand Down
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ Fiber Network Node (FNN) is a reference implementation of Fiber Network Protocol
* Payments over fiber channel (via [fiber-scripts])
* Cross-chain asset transfer

Please note that the implementation is still under development, there are two major features not implemented yet:

* Watchtower service to monitor and revoke on-chain transactions
* Multihop payments
Please note that the implementation is still under development, there are many limitations and known issues, you may find or report them in the issue tracker.

But as a prototype, it's a good starting point for developers to understand the FNP and try out the integration with their applications.

## Build and run a testnet node

1. Build the project:
1. Build the project, if you are using the released binary, you can skip this step:

```
cargo build --release
Expand All @@ -26,6 +23,7 @@ cargo build --release

```
mkdir /folder-to/my-fnn
// if you are using the released binary, replace target/release/fnn with the path of released binary
cp target/release/fnn /folder-to/my-fnn
cp config/testnet/config.yml /folder-to/my-fnn
cd /folder-to/my-fnn
Expand All @@ -46,6 +44,20 @@ head -n 1 ./ckb/exported-key > ./ckb/key
RUST_LOG=info ./fnn -c config.yml -d .
```

## Testnet compatibility issues

The current state of the FNN is not stable, the protocol and storage format may changed between versions. We strongly recommend you to close the channel before upgrading the node, otherwise, you may lose the channel state:

1. [list all channels](./src/rpc/README.md#channel-list_channels) and [close](./src/rpc/README.md#channel-shutdown_channel) them via RPC.

2. Stop the node and remove the storage of the node:

```
rm -rf /folder-to/my-fnn/fiber/store
```

3. Repalce the binary with the new version and start the node again.

## Documentation

* [Light Paper](./docs/light-paper.md)
Expand Down
14 changes: 11 additions & 3 deletions docs/specs/p2p-message.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,19 @@ After establishing a channel, nodes can perform payment operations by sending Ad
| | | |
| |--(2)---- commitment_signed -->| |
| |<-(3)---- revoke_and_ack -----| |
| | | |
| |<-(4)---- commitment_signed ---| |
| |--(5)---- revoke_and_ack ---->| |
| | | |
| A | | B |
| |<-(4)---- remove_tlc -----| |
| | | |
| |<-(5)---- commitment_signed ---| |
| |--(6)---- revoke_and_ack ---->| |
| |<-(6)---- remove_tlc -----| |
| | | |
| |<-(7)---- commitment_signed ---| |
| |--(8)---- revoke_and_ack ---->| |
| | | |
| |--(9)---- commitment_signed -->| |
| |<-(10)---- revoke_and_ack ----| |
+-------+ +-------+
```

Expand Down
4 changes: 2 additions & 2 deletions src/actors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ractor::{async_trait as rasync_trait, Actor, ActorProcessingErr, ActorRef, SupervisionEvent};
use tokio_util::{sync::CancellationToken, task::TaskTracker};
use tracing::{debug, error};
use tracing::debug;

/// A root actor that listens for cancellation token and stops all sub actors (those who started by spawn_linked).
pub struct RootActor;
Expand Down Expand Up @@ -69,7 +69,7 @@ impl Actor for RootActor {
}
},
SupervisionEvent::ActorPanicked(who, err) => {
error!("Actor unexpectedly panicked (id: {:?}): {:?}", who, err);
panic!("Actor unexpectedly panicked (id: {:?}): {:?}", who, err);
}
_ => {}
}
Expand Down
11 changes: 3 additions & 8 deletions src/ckb/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ractor::{
concurrency::{sleep, Duration},
Actor, ActorProcessingErr, ActorRef, RpcReplyPort,
};
use tracing::debug;

use crate::ckb::contracts::{get_script_by_contract, Contract};

Expand Down Expand Up @@ -81,7 +82,7 @@ impl Actor for CkbChainActor {

async fn pre_start(
&self,
myself: ActorRef<Self::Msg>,
_myself: ActorRef<Self::Msg>,
config: Self::Arguments,
) -> Result<Self::State, ActorProcessingErr> {
let secret_key = config.read_secret_key()?;
Expand All @@ -90,12 +91,6 @@ impl Actor for CkbChainActor {
let pub_key_hash = ckb_hash::blake2b_256(pub_key.serialize());
let funding_source_lock_script =
get_script_by_contract(Contract::Secp256k1Lock, &pub_key_hash[0..20]);
tracing::info!(
"[{}] funding lock args: {}",
myself.get_name().unwrap_or_default(),
funding_source_lock_script.args()
);

Ok(CkbChainState {
config,
secret_key,
Expand Down Expand Up @@ -180,7 +175,7 @@ impl Actor for CkbChainActor {
},
reply_port,
) => {
tracing::info!(
debug!(
"[{}] trace transaction {} with {} confs",
myself.get_name().unwrap_or_default(),
tx_hash,
Expand Down
17 changes: 15 additions & 2 deletions src/ckb/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ckb_hash::blake2b_256;
use clap_serde_derive::ClapSerde;
use secp256k1::SecretKey;
use secp256k1::{Secp256k1, SecretKey};
use serde_with::serde_as;
use std::{
io::{ErrorKind, Read},
Expand All @@ -13,12 +14,14 @@ use ckb_types::prelude::Pack;
use ckb_types::H256;
use ckb_types::{
core::DepType,
packed::{CellDep, OutPoint},
packed::{CellDep, OutPoint, Script},
};
use clap_serde_derive::clap::{self};
use molecule::prelude::Entity;
use serde::{Deserialize, Serialize};

use super::contracts::{get_script_by_contract, Contract};

pub const DEFAULT_CKB_BASE_DIR_NAME: &str = "ckb";
const DEFAULT_CKB_NODE_RPC_URL: &str = "http://127.0.0.1:8114";

Expand Down Expand Up @@ -101,6 +104,16 @@ impl CkbConfig {
std::io::Error::new(ErrorKind::InvalidData, "invalid secret key data").into()
})
}

pub fn get_default_funding_lock_script(&self) -> crate::Result<Script> {
let secret_key = self.read_secret_key()?;
let secp = Secp256k1::new();
let pubkey_hash = blake2b_256(secret_key.public_key(&secp).serialize());
Ok(get_script_by_contract(
Contract::Secp256k1Lock,
&pubkey_hash[0..20],
))
}
}

serde_with::serde_conv!(
Expand Down
1 change: 1 addition & 0 deletions src/ckb/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ impl Actor for MockChainActor {
}
}
TraceTx(tx, reply_port) => {
debug!("Tracing transaction: {:?}", &tx);
match state.tx_status.get(&tx.tx_hash).cloned() {
Some((tx_view, status)) => {
reply_trace_tx(Some(tx_view), status, reply_port);
Expand Down
Loading

0 comments on commit 087b087

Please sign in to comment.