Skip to content

Commit 02a0c91

Browse files
authored
Merge branch 'develop' into zhangsoledad/fix-txpool-proposal
2 parents 677b6b1 + 696455d commit 02a0c91

File tree

17 files changed

+339
-93
lines changed

17 files changed

+339
-93
lines changed

.github/workflows/release-plz.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ jobs:
1414
contents: write
1515
id-token: write
1616
steps:
17+
- &free-up-disk-space
18+
name: Free up disk space
19+
if: github.repository_owner != 'nervosnetwork'
20+
run: |
21+
sudo rm -rf /usr/share/dotnet
22+
sudo rm -rf /usr/local/lib/android
23+
sudo rm -rf /opt/ghc
24+
sudo rm -rf /opt/hostedtoolcache/CodeQL
25+
sudo docker image prune --all --force
1726
- &checkout
1827
name: Checkout repository
1928
uses: actions/checkout@v6
@@ -51,6 +60,7 @@ jobs:
5160
group: release-plz-${{ github.ref }}
5261
cancel-in-progress: false
5362
steps:
63+
- *free-up-disk-space
5464
- *checkout
5565
- *install-rust
5666
- *generate-token

Cargo.lock

Lines changed: 12 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ repository = "https://github.com/nervosnetwork/ckb"
1111
rust-version = "1.92.0"
1212
default-run = "ckb"
1313

14+
[package.metadata.binstall]
15+
bin-dir = "{ name }_v{ version }_{ target }/{ bin }{ binary-ext }"
16+
1417
[[bin]]
1518
name = "ckb"
1619
path = "src/main.rs"
@@ -134,7 +137,7 @@ blake2b-ref = "0.3"
134137
bloom-filters = "0.1"
135138
bs58 = "0.5.0"
136139
byteorder = "1.3.1"
137-
bytes = "1"
140+
bytes = "1.11.1"
138141
cfg-if = "1.0"
139142
ckb-app-config = { path = "util/app-config", version = "1" }
140143
ckb-async-runtime = { path = "util/runtime", version = "1" }

ckb-bin/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ ckb-async-runtime.workspace = true
4040
ckb-migrate.workspace = true
4141
ckb-launcher.workspace = true
4242
ckb-constant.workspace = true
43+
ckb-logger-config.workspace = true
4344
base64.workspace = true
4445
tempfile.workspace = true
4546
rayon.workspace = true
@@ -48,6 +49,7 @@ is-terminal.workspace = true
4849
fdlimit.workspace = true
4950
ckb-stop-handler.workspace = true
5051
tokio = { workspace = true, features = ["sync"] }
52+
time = { workspace = true }
5153

5254
[target.'cfg(not(target_os="windows"))'.dependencies]
5355
daemonize-me = { version = "2" }

ckb-bin/src/lib.rs

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ mod tests;
1212
use ckb_app_config::ExitCode;
1313
use ckb_async_runtime::new_global_runtime;
1414
use ckb_build_info::Version;
15-
use ckb_logger::{debug, info};
15+
use ckb_logger::debug;
1616
use ckb_network::tokio;
1717
use clap::ArgMatches;
1818
use helper::raise_fd_limit;
1919
use setup::Setup;
2020
use setup_guard::SetupGuard;
21+
use time::OffsetDateTime;
2122

2223
#[cfg(not(target_os = "windows"))]
2324
use colored::Colorize;
@@ -28,6 +29,26 @@ use subcommand::check_process;
2829
#[cfg(feature = "with_sentry")]
2930
pub(crate) const LOG_TARGET_SENTRY: &str = "sentry";
3031

32+
/// Print a log-like message to stderr.
33+
/// Format: `YYYY-MM-DD HH:MM:SS.mmm +00:00 thread_name INFO module message`
34+
fn log_println(message: &str) {
35+
let now = OffsetDateTime::now_utc();
36+
let thread = std::thread::current();
37+
let thread_name = thread.name().unwrap_or("main");
38+
eprintln!(
39+
"{:04}-{:02}-{:02} {:02}:{:02}:{:02}.{:03} +00:00 {} INFO ckb_bin {}",
40+
now.year(),
41+
now.month() as u8,
42+
now.day(),
43+
now.hour(),
44+
now.minute(),
45+
now.second(),
46+
now.millisecond(),
47+
thread_name,
48+
message
49+
);
50+
}
51+
3152
/// The executable main entry.
3253
///
3354
/// It returns `Ok` when the process exist normally, otherwise the `ExitCode` is converted to the
@@ -109,11 +130,11 @@ fn run_app_in_daemon(
109130

110131
match daemon.start() {
111132
Ok(_) => {
112-
info!("Success, daemonized ...");
133+
ckb_logger::info!("Success, daemonized ...");
113134
run_app_inner(version, bin_name, cmd, matches)
114135
}
115136
Err(e) => {
116-
info!("daemonize error: {}", e);
137+
ckb_logger::info!("daemonize error: {}", e);
117138
Err(ExitCode::Failure)
118139
}
119140
}
@@ -128,12 +149,21 @@ fn run_app_inner(
128149
let is_silent_logging = is_silent_logging(cmd);
129150
let (mut handle, mut handle_stop_rx, _runtime) = new_global_runtime(None);
130151
let setup = Setup::from_matches(bin_name, cmd, matches)?;
131-
let _guard = SetupGuard::from_setup(&setup, &version, handle.clone(), is_silent_logging)?;
152+
// Disable logging here if the user is executing `ckb run`.
153+
// Logs subscription of RPC service requires access to `struct Shared`,
154+
// so logger of `ckb run` will be initialized in `subcommand::run`.
155+
let (_guard, log_config) = SetupGuard::from_setup(
156+
&setup,
157+
&version,
158+
handle.clone(),
159+
is_silent_logging,
160+
cmd != cli::CMD_RUN,
161+
)?;
132162

133163
raise_fd_limit();
134164

135165
let ret = match cmd {
136-
cli::CMD_RUN => subcommand::run(setup.run(matches)?, version, handle.clone()),
166+
cli::CMD_RUN => subcommand::run(setup.run(matches)?, version, handle.clone(), log_config),
137167
cli::CMD_MINER => subcommand::miner(setup.miner(matches)?, handle.clone()),
138168
cli::CMD_REPLAY => subcommand::replay(setup.replay(matches)?, handle.clone()),
139169
cli::CMD_EXPORT => subcommand::export(setup.export(matches)?, handle.clone()),
@@ -150,9 +180,18 @@ fn run_app_inner(
150180
handle.drop_guard();
151181

152182
tokio::task::block_in_place(|| {
153-
info!("Waiting for all tokio tasks to exit...");
183+
// Here we use `log_println` instead of `info!` because the Logger has already been
184+
// shut down when `subcommand::run()` returned (LoggerGuard was dropped there).
185+
//
186+
// We cannot simply extend the LoggerGuard's lifetime to here because it would cause
187+
// a deadlock: NotifyController (held by Logger's background thread) contains a clone
188+
// of Handle, which holds a clone of `guard` (Sender). If LoggerGuard is not dropped
189+
// before `handle_stop_rx.blocking_recv()`, the Logger thread won't terminate, and
190+
// the Sender inside NotifyController won't be dropped, causing blocking_recv() to
191+
// wait forever.
192+
log_println("Waiting for all tokio tasks to exit...");
154193
handle_stop_rx.blocking_recv();
155-
info!("All tokio tasks and threads have exited. CKB shutdown");
194+
log_println("All tokio tasks and threads have exited. CKB shutdown");
156195
});
157196
}
158197

ckb-bin/src/setup_guard.rs

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use ckb_metrics_service::{self, Guard as MetricsInitGuard};
66

77
use crate::setup::Setup;
88

9-
const CKB_LOG_ENV: &str = "CKB_LOG";
9+
pub const CKB_LOG_ENV: &str = "CKB_LOG";
1010

1111
pub struct SetupGuard {
12-
_logger_guard: LoggerInitGuard,
12+
_logger_guard: Option<LoggerInitGuard>,
1313
#[cfg(feature = "with_sentry")]
1414
_sentry_guard: Option<sentry::ClientInitGuard>,
1515
_metrics_guard: MetricsInitGuard,
@@ -22,18 +22,23 @@ impl SetupGuard {
2222
version: &Version,
2323
async_handle: Handle,
2424
silent_logging: bool,
25-
) -> Result<Self, ExitCode> {
25+
enable_logging: bool,
26+
) -> Result<(Self, ckb_logger_config::Config), ExitCode> {
2627
// Initialization of logger must do before sentry, since `logger::init()` and
2728
// `sentry_config::init()` both registers custom panic hooks, but `logger::init()`
2829
// replaces all hooks previously registered.
29-
let logger_guard = if silent_logging {
30-
ckb_logger_service::init_silent()?
30+
let logger_guard = if enable_logging {
31+
Some(if silent_logging {
32+
ckb_logger_service::init_silent()?
33+
} else {
34+
let mut logger_config = setup.config.logger().to_owned();
35+
if logger_config.emit_sentry_breadcrumbs.is_none() {
36+
logger_config.emit_sentry_breadcrumbs = Some(setup.is_sentry_enabled);
37+
}
38+
ckb_logger_service::init(Some(CKB_LOG_ENV), logger_config, None)?
39+
})
3140
} else {
32-
let mut logger_config = setup.config.logger().to_owned();
33-
if logger_config.emit_sentry_breadcrumbs.is_none() {
34-
logger_config.emit_sentry_breadcrumbs = Some(setup.is_sentry_enabled);
35-
}
36-
ckb_logger_service::init(Some(CKB_LOG_ENV), logger_config)?
41+
None
3742
};
3843

3944
let sentry_guard = if setup.is_sentry_enabled {
@@ -67,11 +72,14 @@ impl SetupGuard {
6772
ExitCode::Config
6873
})?;
6974

70-
Ok(Self {
71-
_logger_guard: logger_guard,
72-
_sentry_guard: sentry_guard,
73-
_metrics_guard: metrics_guard,
74-
})
75+
Ok((
76+
Self {
77+
_logger_guard: logger_guard,
78+
_sentry_guard: sentry_guard,
79+
_metrics_guard: metrics_guard,
80+
},
81+
setup.config.logger().to_owned(),
82+
))
7583
}
7684

7785
#[cfg(not(feature = "with_sentry"))]
@@ -80,12 +88,18 @@ impl SetupGuard {
8088
_version: &Version,
8189
async_handle: Handle,
8290
silent_logging: bool,
83-
) -> Result<Self, ExitCode> {
84-
let logger_guard = if silent_logging {
85-
ckb_logger_service::init_silent()?
91+
// For ckb run, logging can be disabled here, since it requires `Shared` to create a logger that will be used for `ckb run`
92+
enable_logging: bool,
93+
) -> Result<(Self, ckb_logger_config::Config), ExitCode> {
94+
let logger_guard = if enable_logging {
95+
Some(if silent_logging {
96+
ckb_logger_service::init_silent()?
97+
} else {
98+
let logger_config = setup.config.logger().to_owned();
99+
ckb_logger_service::init(Some(CKB_LOG_ENV), logger_config, None)?
100+
})
86101
} else {
87-
let logger_config = setup.config.logger().to_owned();
88-
ckb_logger_service::init(Some(CKB_LOG_ENV), logger_config)?
102+
None
89103
};
90104

91105
let metrics_config = setup.config.metrics().to_owned();
@@ -95,9 +109,12 @@ impl SetupGuard {
95109
ExitCode::Config
96110
})?;
97111

98-
Ok(Self {
99-
_logger_guard: logger_guard,
100-
_metrics_guard: metrics_guard,
101-
})
112+
Ok((
113+
Self {
114+
_logger_guard: logger_guard,
115+
_metrics_guard: metrics_guard,
116+
},
117+
setup.config.logger().to_owned(),
118+
))
102119
}
103120
}

0 commit comments

Comments
 (0)