Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
162 changes: 66 additions & 96 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ lru = "0.7.1"
memchr = "2.7"
merkle-cbt = "0.3"
minstant = "0.1.4"
molecule = { version = "0.8.0", default-features = false }
molecule = { version = "0.9.0", default-features = false }
multi_index_map = "0.6.0"
multiaddr = { version = "0.3.6", package = "tentacle-multiaddr" }
num-bigint = "0.4"
Expand Down
49 changes: 39 additions & 10 deletions ckb-bin/src/tests/bats_tests/cli_test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
#!/usr/bin/env bash
set -euxo pipefail

TEST_EXIT_CODE=0
CURRENT_BATS_CASE=bootstrap

function on_error {
local line_no=$1
local command=$2
local exit_code=$3
TEST_EXIT_CODE=$exit_code
echo "cli_test.sh failed at line ${line_no}, exit code ${exit_code}, case ${CURRENT_BATS_CASE}: ${command}"
}
trap 'on_error $LINENO "$BASH_COMMAND" $?' ERR

CKB_BATS_TESTBED=/tmp/ckb_bats_testbed
mkdir -p ${CKB_BATS_TESTBED}

function cleanup {
if [ "${TEST_EXIT_CODE:-0}" -ne 0 ]; then
echo "cli-test failed while running bats file: ${CURRENT_BATS_CASE}"
if [ -n "${TMP_DIR:-}" ] && [ -d "${TMP_DIR}" ]; then
echo "Dumping *.log from ${TMP_DIR}"
find "${TMP_DIR}" -maxdepth 1 -type f -name "*.log" -print -exec tail -n 200 {} \;
fi
fi
echo "Removing ${CKB_BATS_TESTBED}"
rm -rf ${CKB_BATS_TESTBED}
}
Expand All @@ -15,14 +34,19 @@ git_clone_repo_with_retry() {
local dir_name=$3
local retry_count=5
local retry_delay=5
local cloned=0

for i in $(seq 1 $retry_count); do
git clone --depth 1 --branch "$branch" "$repo_address" "$dir_name" && break
rm -rf "$dir_name"
if git clone --depth 1 --branch "$branch" "$repo_address" "$dir_name"; then
cloned=1
break
fi
echo "Attempt $i failed. Retrying in $retry_delay seconds..."
sleep $retry_delay
done

if [ $i -eq $retry_count ]; then
if [ "$cloned" -ne 1 ]; then
echo "Failed to clone repository after $retry_count attempts."
exit 1
fi
Expand All @@ -34,6 +58,7 @@ cp target/prod/ckb ${CKB_BATS_TESTBED}
cp ckb-bin/src/tests/bats_tests/*.bats ${CKB_BATS_TESTBED}
cp -r ckb-bin/src/tests/bats_tests/later_bats_job ${CKB_BATS_TESTBED}
cp ckb-bin/src/tests/bats_tests/*.sh ${CKB_BATS_TESTBED}
cp resource/specs/mainnet.toml ${CKB_BATS_TESTBED}

if [ ! -d "/tmp/ckb_bats_assets/" ]; then
git_clone_repo_with_retry "main" "https://github.com/nervosnetwork/ckb-assets" "/tmp/ckb_bats_assets"
Expand Down Expand Up @@ -68,15 +93,19 @@ export TMP_DIR=${CKB_BATS_TESTBED}/tmp_dir
mkdir ${TMP_DIR}

for bats_cases in *.bats; do
bats --verbose-run --print-output-on-failure --show-output-of-passing-tests "$bats_cases"
ret=$?
if [ "$ret" -ne "0" ]; then
exit "$ret"
CURRENT_BATS_CASE="${bats_cases}"
echo "Running bats file: ${bats_cases}"
if ! bats --verbose-run --print-output-on-failure --show-output-of-passing-tests "$bats_cases"; then
echo "Bats file failed (first attempt): ${bats_cases}"
echo "Retrying once: ${bats_cases}"
bats --verbose-run --print-output-on-failure --show-output-of-passing-tests "$bats_cases"
fi
done

bats --verbose-run --print-output-on-failure --show-output-of-passing-tests ./later_bats_job/change_epoch.bats
ret=$?
if [ "$ret" -ne "0" ]; then
exit "$ret"
CURRENT_BATS_CASE="./later_bats_job/change_epoch.bats"
echo "Running bats file: ${CURRENT_BATS_CASE}"
if ! bats --verbose-run --print-output-on-failure --show-output-of-passing-tests "${CURRENT_BATS_CASE}"; then
echo "Bats file failed (first attempt): ./later_bats_job/change_epoch.bats"
echo "Retrying once: ./later_bats_job/change_epoch.bats"
bats --verbose-run --print-output-on-failure --show-output-of-passing-tests "${CURRENT_BATS_CASE}"
fi
16 changes: 1 addition & 15 deletions ckb-bin/src/tests/bats_tests/graceful_shutdown.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,8 @@ function ckb_graceful_shutdown { #@test

[ "$status" -eq 0 ]

# Keep only the core shutdown invariants to avoid flaky timing-dependent logs.
assert_output --regexp "INFO ckb_bin::subcommand::run Trapped exit signal, exiting..."
assert_output --regexp "INFO ckb_chain::chain_service ChainService received exit signal, exit now"
assert_output --regexp "INFO ckb_sync::synchronizer BlockDownload received exit signal, exit now"
assert_output --regexp "INFO ckb_tx_pool::verify_mgr TxPool chunk_command service received exit signal, exit now"
assert_output --regexp "INFO ckb_tx_pool::service TxPool is saving, please wait..."
assert_output --regexp "INFO ckb_tx_pool::service TxPool reorg process service received exit signal, exit now"
assert_output --regexp "INFO ckb_indexer_sync Indexer received exit signal.*exit now"
assert_output --regexp "INFO ckb_notify NotifyService received exit signal, exit now"
assert_output --regexp "INFO ckb_block_filter::filter BlockFilter received exit signal, exit now"
assert_output --regexp "INFO ckb_shared::types::header_map HeaderMap limit_memory received exit signal, exit now"
assert_output --regexp "INFO ckb_network::network NetworkService receive exit signal, start shutdown..."
assert_output --regexp "INFO ckb_network::network NetworkService shutdown now"
assert_output --regexp "INFO ckb_tx_pool::process TxPool saved successfully"
assert_output --regexp "INFO ckb_tx_pool::service TxPool process_service exit now"
assert_output --regexp "INFO ckb_stop_handler::stop_register Waiting thread ChainService done"
assert_output --regexp "INFO ckb_stop_handler::stop_register Waiting thread BlockDownload done"
assert_output --regexp "INFO ckb_bin Waiting for all tokio tasks to exit..."
assert_output --regexp "INFO ckb_bin All tokio tasks and threads have exited. CKB shutdown"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ function ckb_change_epoch_length_for_dumm_mode { #@test

block_kill ${CKB_NODE_PID}

wget https://raw.githubusercontent.com/nervosnetwork/ckb/develop/resource/specs/mainnet.toml
if [ ! -f mainnet.toml ]; then
echo "mainnet.toml is missing in testbed"
return 1
fi

ckb init -c dev --import-spec mainnet.toml --force

Expand Down
3 changes: 2 additions & 1 deletion network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,8 @@ impl NetworkService {
.set_send_buffer_size(config.max_send_buffer())
.set_channel_size(config.channel_size())
.timeout(Duration::from_secs(5))
.onion_timeout(Duration::from_secs(120));
.onion_timeout(Duration::from_secs(120))
.trusted_proxies(config.trusted_proxies.clone());

#[cfg(not(target_family = "wasm"))]
{
Expand Down
5 changes: 5 additions & 0 deletions resource/ckb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ bootnode_mode = false
# Supported protocols list, only "Sync" and "Identify" are mandatory, others are optional
support_protocols = ["Ping", "Discovery", "Identify", "Feeler", "DisconnectMessage", "Sync", "Relay", "Time", "Alert", "LightClient", "Filter", "HolePunching"]

### A list of trusted proxies' IP addresses.
### When a peer connects through a trusted proxy, the proxy's IP address will be parsed by haproxy protocol and used
### default use with [IpAddr::V4(Ipv4Addr::LOCALHOST), IpAddr::V6(Ipv6Addr::LOCALHOST)]
# trusted_proxies = []

# [network.sync.header_map]
# memory_limit = "256MB"

Expand Down
19 changes: 16 additions & 3 deletions util/app-config/src/configs/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ use ckb_types::{H256, U256};
use multiaddr::Multiaddr;
use rand::Rng;
use serde::{Deserialize, Serialize};
use std::fs;
use std::io::{Error, ErrorKind, Read, Write};
use std::path::PathBuf;
use std::{
fs,
io::{Error, ErrorKind, Read, Write},
net::{IpAddr, Ipv4Addr, Ipv6Addr},
path::PathBuf,
};
use ubyte::ByteUnit;

// Max data size in send buffer: 24MB (a little larger than max frame length)
Expand Down Expand Up @@ -91,6 +94,9 @@ pub struct Config {
pub disable_block_relay_only_connection: bool,
/// Tentacle inner channel_size.
pub channel_size: Option<usize>,
/// A list of trusted proxies' IP addresses.
#[serde(default = "default_trusted_proxies")]
pub trusted_proxies: Vec<IpAddr>,
#[cfg(target_family = "wasm")]
#[serde(skip)]
pub secret_key: [u8; 32],
Expand Down Expand Up @@ -158,6 +164,13 @@ fn default_onion_external_port() -> u16 {
8115
}

fn default_trusted_proxies() -> Vec<IpAddr> {
vec![
IpAddr::V4(Ipv4Addr::LOCALHOST),
IpAddr::V6(Ipv6Addr::LOCALHOST),
]
}

/// Chain synchronization config options.
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
#[serde(deny_unknown_fields)]
Expand Down
Loading