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

[Backport] merge several fixes into 118 for next rc release #4616

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6be1671
Fix the possible cycling attack in RBF
chenyukang Jul 31, 2024
158cfa9
code refactor
chenyukang Jul 31, 2024
db66275
cleanup and add assertion for process_rbf
chenyukang Aug 1, 2024
2c2b1f1
add verify log for monitor
chenyukang Aug 20, 2024
fbe63f4
Integration Test: wait find unverified blocks finish for all specs
eval-exec Aug 22, 2024
47dc5ed
add ignore item in deny.toml.
EthanYuan Aug 22, 2024
83ac99f
Merge pull request #4605 from eval-exec/exec/fix-ci-2
eval-exec Aug 22, 2024
2c057db
Fix SendLargeCyclesTxToRelay on slow machine
chenyukang Aug 22, 2024
0ceb6f8
Merge pull request #4606 from chenyukang/yukang-fix-relay-ci-issue
chenyukang Aug 22, 2024
3bd5fed
Merge pull request #4600 from chenyukang/yukang-add-verify-log
chenyukang Aug 23, 2024
7bfc1e1
add clear verify queue rpc
chenyukang Aug 23, 2024
ce41807
verify worker exit when signal_exit is_cancelled
chenyukang Aug 24, 2024
dc20e94
Make sure the uncle block timestamp is different from the next block …
chenyukang Aug 25, 2024
76ebab4
Merge pull request #4611 from chenyukang/yukang-debug-chain-fork-spec
chenyukang Aug 25, 2024
8744829
Merge pull request #4612 from chenyukang/yukang-fix-verify-queue-exit
chenyukang Aug 25, 2024
6ee85c3
Merge pull request #4609 from chenyukang/yukang-clear-verify-queue
chenyukang Aug 26, 2024
e48f664
Do not start BlockDownload thread if ckb has received exit signal
eval-exec Aug 26, 2024
7304ea7
Merge pull request #4615 from eval-exec/exec/exit-blockdownload-if-Bl…
chenyukang Aug 27, 2024
47f92ff
Early return init_load_unverified thread when no unverified blocks fo…
eval-exec Aug 27, 2024
d28bde6
Integration Test: add more log for SyncChurn
eval-exec Aug 27, 2024
3675433
Merge pull request #4617 from eval-exec/exec/early-return-init-load-u…
driftluo Aug 27, 2024
48c09c2
Integration Test: kill_gracefully on RandomlyKill
eval-exec Aug 28, 2024
50b74a2
Merge pull request #4622 from eval-exec/exec/kill-gracefully-on-integ…
eval-exec Aug 28, 2024
3a40e37
Do not kill gracefully on windows
eval-exec Aug 29, 2024
f9c3c70
Merge pull request #4624 from eval-exec/exec/fix/widnows-ci
eval-exec Aug 29, 2024
258676a
fix: fix atomic ordering in multi-thread
driftluo Aug 28, 2024
114a11f
test
eval-exec Aug 29, 2024
7749bcb
Merge pull request #4625 from eval-exec/exec/ci/windows
eval-exec Aug 30, 2024
2fb17ab
Merge pull request #4623 from driftluo/fix-atomic-ordering
eval-exec Aug 30, 2024
c789b83
Rename ckb_chain::consume_unverified to ckb_chain::verify
eval-exec Aug 30, 2024
b86e176
test: add check relax ordering on ci
driftluo Aug 30, 2024
b30e378
Merge branch 'develop' into yukang-fix-cycling-attack-rbf
chenyukang Aug 30, 2024
3d78da8
chore: remove all relax order
driftluo Aug 30, 2024
a73b7f4
Merge pull request #4561 from chenyukang/yukang-fix-cycling-attack-rbf
quake Sep 2, 2024
6332b10
add retry for git clone in cli_test
chenyukang Sep 2, 2024
9d8e976
CI: windows integration use windows-latest
eval-exec Sep 2, 2024
ea3651f
Merge branch 'develop' into ci-check-relaxed
chenyukang Sep 2, 2024
4919219
Merge pull request #4626 from eval-exec/exec/rename-consume-unverifie…
eval-exec Sep 2, 2024
6fa274e
Merge pull request #4631 from eval-exec/exec/ci/windows-2022
eval-exec Sep 2, 2024
0e99a2a
Merge pull request #4627 from driftluo/ci-check-relaxed
eval-exec Sep 2, 2024
72b735c
Merge pull request #4630 from chenyukang/yukang-add-retry-for-ci
chenyukang Sep 2, 2024
d398e5a
Fix script test error
chenyukang Aug 12, 2024
cf78552
enlarge spec wait time
chenyukang Aug 13, 2024
2e100d8
add logs for script test
chenyukang Aug 13, 2024
0274984
Merge pull request #4581 from chenyukang/yukang-fix-script-test
eval-exec Sep 2, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci_integration_tests_windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
ci_integration_tests_windows:
name: ci_integration_tests_windows
needs: prologue
runs-on: ${{ needs.prologue.outputs.windows_runner_label }}
runs-on: windows-latest
timeout-minutes: 140
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions chain/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

//! Bootstrap InitLoadUnverified, PreloadUnverifiedBlock, ChainService and ConsumeUnverified threads.
use crate::chain_service::ChainService;
use crate::consume_unverified::ConsumeUnverifiedBlocks;
use crate::init_load_unverified::InitLoadUnverified;
use crate::orphan_broker::OrphanBroker;
use crate::preload_unverified_blocks_channel::PreloadUnverifiedBlocksChannel;
use crate::utils::orphan_block_pool::OrphanBlockPool;
use crate::verify::ConsumeUnverifiedBlocks;
use crate::{chain_controller::ChainController, LonelyBlockHash, UnverifiedBlock};
use ckb_channel::{self as channel, SendError};
use ckb_constant::sync::BLOCK_DOWNLOAD_WINDOW;
Expand Down Expand Up @@ -37,7 +37,7 @@ pub fn start_chain_services(builder: ChainServicesBuilder) -> ChainController {
let is_pending_verify: Arc<DashSet<Byte32>> = Arc::new(DashSet::new());

let consumer_unverified_thread = thread::Builder::new()
.name("consume_unverified_blocks".into())
.name("verify_blocks".into())
.spawn({
let shared = builder.shared.clone();
let is_pending_verify = Arc::clone(&is_pending_verify);
Expand Down
9 changes: 9 additions & 0 deletions chain/src/init_load_unverified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ impl InitLoadUnverified {
let unverified_hashes: Vec<packed::Byte32> =
self.find_unverified_block_hashes(check_unverified_number);

if check_unverified_number > tip_number && unverified_hashes.is_empty() {
info!(
"no unverified blocks found after tip, current tip: {}-{}",
tip_number,
self.shared.snapshot().tip_hash()
);
return;
}

for unverified_hash in unverified_hashes {
f(&unverified_hash);
}
Expand Down
2 changes: 1 addition & 1 deletion chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ use std::sync::Arc;

mod chain_controller;
mod chain_service;
pub mod consume_unverified;
mod init;
mod init_load_unverified;
mod orphan_broker;
mod preload_unverified_blocks_channel;
#[cfg(test)]
mod tests;
mod utils;
pub mod verify;

pub use chain_controller::ChainController;
use ckb_logger::{error, info};
Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/find_fork.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::consume_unverified::ConsumeUnverifiedBlockProcessor;
use crate::utils::forkchanges::ForkChanges;
use crate::verify::ConsumeUnverifiedBlockProcessor;
use crate::{start_chain_services, UnverifiedBlock};
use ckb_chain_spec::consensus::{Consensus, ProposalWindow};
use ckb_proposal_table::ProposalTable;
Expand Down
2 changes: 1 addition & 1 deletion chain/src/consume_unverified.rs → chain/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl ConsumeUnverifiedBlocks {
},
},
recv(self.stop_rx) -> _ => {
info!("consume_unverified_blocks thread received exit signal, exit now");
info!("verify_blocks thread received exit signal, exit now");
break;
}

Expand Down
4 changes: 4 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ feature-depth = 1
# A list of advisory IDs to ignore. Note that ignored advisories will still
# output a note when they are encountered.
ignore = [
# https://rustsec.org/advisories/RUSTSEC-2024-0363
# https://github.com/launchbadge/sqlx/issues/3440
# The queries for the rich indexer receive input parameters via RPC, and the data size is far less than 4GB, so this issue can be temporarily ignored while waiting for sqlx to be fixed.
"RUSTSEC-2024-0363",
# https://rustsec.org/advisories/RUSTSEC-2022-0090
# It was sometimes possible for SQLite versions >= 1.0.12, < 3.39.2 to allow an array-bounds overflow when large string were input into SQLite's `printf` function.
"RUSTSEC-2022-0090",
Expand Down
40 changes: 40 additions & 0 deletions devtools/ci/check-relaxed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -euo pipefail

case "$OSTYPE" in
darwin*)
if ! type gsed &>/dev/null || ! type ggrep &>/dev/null; then
echo "GNU sed and grep not found! You can install via Homebrew" >&2
echo >&2
echo " brew install grep gnu-sed" >&2
exit 1
fi

SED=gsed
GREP=ggrep
;;
*)
SED=sed
GREP=grep
;;
esac

function main() {
local res=$(find ./ -not -path '*/target/*' -type f -name "*.rs" | xargs grep -H "Relaxed")

if [ -z "${res}" ]; then
echo "ok"
exit 0
else
echo "find use Relaxed on code, please check"

for file in ${res}; do
printf ${file}
done

exit 1
fi
}

main "$@"
1 change: 1 addition & 0 deletions devtools/ci/ci_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ case $GITHUB_WORKFLOW in
make check-dirty-rpc-doc
make check-dirty-hashes-toml
devtools/ci/check-cyclic-dependencies.py
devtools/ci/check-relaxed.sh
;;
ci_aarch64_build*)
echo "ci_aarch64_build"
Expand Down
4 changes: 2 additions & 2 deletions network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ impl NetworkState {

/// Network message processing controller, default is true, if false, discard any received messages
pub fn is_active(&self) -> bool {
self.active.load(Ordering::Relaxed)
self.active.load(Ordering::Acquire)
}
}

Expand Down Expand Up @@ -1368,7 +1368,7 @@ impl NetworkController {

/// Change active status, if set false discard any received messages
pub fn set_active(&self, active: bool) {
self.network_state.active.store(active, Ordering::Relaxed);
self.network_state.active.store(active, Ordering::Release);
}

/// Return all connected peers' protocols info
Expand Down
32 changes: 32 additions & 0 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1.
* [Method `remove_transaction`](#pool-remove_transaction)
* [Method `tx_pool_info`](#pool-tx_pool_info)
* [Method `clear_tx_pool`](#pool-clear_tx_pool)
* [Method `clear_tx_verify_queue`](#pool-clear_tx_verify_queue)
* [Method `get_raw_tx_pool`](#pool-get_raw_tx_pool)
* [Method `get_pool_tx_detail_info`](#pool-get_pool_tx_detail_info)
* [Method `tx_pool_ready`](#pool-tx_pool_ready)
Expand Down Expand Up @@ -4748,6 +4749,37 @@ Response
}
```

<a id="pool-clear_tx_verify_queue"></a>
#### Method `clear_tx_verify_queue`
* `clear_tx_verify_queue()`

* result: `null`

Removes all transactions from the verification queue.

###### Examples

Request

```json
{
"id": 42,
"jsonrpc": "2.0",
"method": "clear_tx_verify_queue",
"params": []
}
```

Response

```json
{
"id": 42,
"jsonrpc": "2.0",
"result": null
}
```

<a id="pool-get_raw_tx_pool"></a>
#### Method `get_raw_tx_pool`
* `get_raw_tx_pool(verbose)`
Expand Down
36 changes: 36 additions & 0 deletions rpc/src/module/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,33 @@ pub trait PoolRpc {
#[rpc(name = "clear_tx_pool")]
fn clear_tx_pool(&self) -> Result<()>;

/// Removes all transactions from the verification queue.
///
/// ## Examples
///
/// Request
///
/// ```json
/// {
/// "id": 42,
/// "jsonrpc": "2.0",
/// "method": "clear_tx_verify_queue",
/// "params": []
/// }
/// ```
///
/// Response
///
/// ```json
/// {
/// "id": 42,
/// "jsonrpc": "2.0",
/// "result": null
/// }
/// ```
#[rpc(name = "clear_tx_verify_queue")]
fn clear_tx_verify_queue(&self) -> Result<()>;

/// Returns all transaction ids in tx pool as a json array of string transaction ids.
/// ## Params
///
Expand Down Expand Up @@ -662,6 +689,15 @@ impl PoolRpc for PoolRpcImpl {
Ok(())
}

fn clear_tx_verify_queue(&self) -> Result<()> {
let tx_pool = self.shared.tx_pool_controller();
tx_pool
.clear_verify_queue()
.map_err(|err| RPCError::custom(RPCError::Invalid, err.to_string()))?;

Ok(())
}

fn get_raw_tx_pool(&self, verbose: Option<bool>) -> Result<RawTxPool> {
let tx_pool = self.shared.tx_pool_controller();

Expand Down
10 changes: 6 additions & 4 deletions script/src/verify/tests/ckb_latest/features_since_v2021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,10 +835,12 @@ fn _check_typical_secp256k1_blake160_2_in_2_out_tx_with_state(step_cycles: Cycle
let mut cycles = 0;
let verifier = TransactionScriptsVerifierWithEnv::new();
let result = verifier.verify_map(script_version, &rtx, |verifier| {
#[allow(unused_assignments)]
let mut init_state: Option<TransactionState> = None;

if let VerifyResult::Suspended(state) = verifier.resumable_verify(step_cycles).unwrap() {
init_state = Some(state);
match verifier.resumable_verify(step_cycles).unwrap() {
VerifyResult::Suspended(state) => init_state = Some(state),
VerifyResult::Completed(cycle) => return Ok(cycle),
}

loop {
Expand Down Expand Up @@ -948,12 +950,12 @@ fn _check_typical_secp256k1_blake160_2_in_2_out_tx_with_snap(step_cycles: Cycle)
if script_version == crate::ScriptVersion::V2 {
assert!(
cycles >= TWO_IN_TWO_OUT_CYCLES - V2_CYCLE_BOUND,
"step_cycles {step_cycles}"
"cycles {cycles} step_cycles {step_cycles}"
);
} else {
assert!(
cycles >= TWO_IN_TWO_OUT_CYCLES - CYCLE_BOUND,
"step_cycles {step_cycles}"
"cycles {cycles} step_cycles {step_cycles}"
);
}
assert_eq!(cycles, cycles_once, "step_cycles {step_cycles}");
Expand Down
4 changes: 2 additions & 2 deletions shared/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,14 @@ impl Shared {
/// Return whether chain is in initial block download
pub fn is_initial_block_download(&self) -> bool {
// Once this function has returned false, it must remain false.
if self.ibd_finished.load(Ordering::Relaxed) {
if self.ibd_finished.load(Ordering::Acquire) {
false
} else if unix_time_as_millis().saturating_sub(self.snapshot().tip_header().timestamp())
> MAX_TIP_AGE
{
true
} else {
self.ibd_finished.store(true, Ordering::Relaxed);
self.ibd_finished.store(true, Ordering::Release);
false
}
}
Expand Down
4 changes: 2 additions & 2 deletions shared/src/types/header_map/kernel_lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ where
self.stats().tick_primary_delete();
}
// If IBD is not finished, don't shrink memory map
let allow_shrink_to_fit = self.ibd_finished.load(Ordering::Relaxed);
let allow_shrink_to_fit = self.ibd_finished.load(Ordering::Acquire);
self.memory.remove(hash, allow_shrink_to_fit);
if self.backend.is_empty() {
return;
Expand All @@ -175,7 +175,7 @@ where
});

// If IBD is not finished, don't shrink memory map
let allow_shrink_to_fit = self.ibd_finished.load(Ordering::Relaxed);
let allow_shrink_to_fit = self.ibd_finished.load(Ordering::Acquire);
self.memory
.remove_batch(values.iter().map(|value| value.hash()), allow_shrink_to_fit);
}
Expand Down
5 changes: 5 additions & 0 deletions sync/src/synchronizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,11 @@ impl Synchronizer {
return;
}

if ckb_stop_handler::has_received_stop_signal() {
info!("received stop signal, stop find_blocks_to_fetch");
return;
}

let unverified_tip = self.shared.active_chain().unverified_tip_number();

let disconnect_list = {
Expand Down
9 changes: 6 additions & 3 deletions sync/src/tests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use ckb_types::{
use rand::{thread_rng, Rng};
use std::{
collections::{BTreeMap, HashMap},
sync::atomic::{AtomicUsize, Ordering::Relaxed},
sync::atomic::{
AtomicUsize,
Ordering::{Acquire, SeqCst},
},
};

use crate::types::{TtlFilter, FILTER_TTL};
Expand Down Expand Up @@ -64,15 +67,15 @@ fn test_get_ancestor_use_skip_list() {
0,
b,
|hash, _| {
count.fetch_add(1, Relaxed);
count.fetch_add(1, SeqCst);
header_map.get(hash).cloned()
},
|_, _| None,
)
.unwrap();

// Search must finished in <limit> steps
assert!(count.load(Relaxed) <= limit);
assert!(count.load(Acquire) <= limit);

header
};
Expand Down
1 change: 1 addition & 0 deletions test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ fn all_specs() -> Vec<Box<dyn Spec>> {
Box::new(RbfReplaceProposedSuccess),
Box::new(RbfConcurrency),
Box::new(RbfCellDepsCheck),
Box::new(RbfCyclingAttack),
Box::new(CompactBlockEmpty),
Box::new(CompactBlockEmptyParentUnknown),
Box::new(CompactBlockPrefilled),
Expand Down
Loading
Loading