Skip to content

Commit 7f6eab9

Browse files
committed
Merge branch 'develop' into refactor/add-epoch-index
2 parents 7e57af9 + d11ed3c commit 7f6eab9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2708
-3531
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
77

88
## [Unreleased]
99

10+
### Changed
11+
- Add index for StacksBlockId to nakamoto block headers table (improves node performance)
12+
- Remove the panic for reporting DB deadlocks (just error and continue waiting)
13+
1014
## [3.0.0.0.0]
1115

1216
### Added

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rand = "0.8"
2121
rand_chacha = "0.3.1"
2222
tikv-jemallocator = "0.5.4"
2323
rusqlite = { version = "0.31.0", features = ["blob", "serde_json", "i128_blob", "bundled", "trace"] }
24+
thiserror = { version = "1.0.65" }
2425

2526
# Use a bit more than default optimization for
2627
# dev builds to speed up test execution

clarity/src/vm/docs/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,17 +1775,17 @@ this value is less than or equal to the value for `miner-spend-total` at the sam
17751775
const GET_BURN_BLOCK_INFO_API: SpecialAPI = SpecialAPI {
17761776
input_type: "BurnBlockInfoPropertyName, uint",
17771777
output_type: "(optional buff) | (optional (tuple (addrs (list 2 (tuple (hashbytes (buff 32)) (version (buff 1))))) (payout uint)))",
1778-
snippet: "get-burn-block-info? ${1:prop} ${2:block-height}",
1779-
signature: "(get-burn-block-info? prop-name block-height)",
1778+
snippet: "get-burn-block-info? ${1:prop} ${2:burn-block-height}",
1779+
signature: "(get-burn-block-info? prop-name burn-block-height)",
17801780
description: "The `get-burn-block-info?` function fetches data for a block of the given *burnchain* block height. The
1781-
value and type returned are determined by the specified `BlockInfoPropertyName`. Valid values for `block-height` only
1781+
value and type returned are determined by the specified `BlockInfoPropertyName`. Valid values for `burn-block-height` only
17821782
include heights between the burnchain height at the time the Stacks chain was launched, and the last-processed burnchain
1783-
block. If the `block-height` argument falls outside of this range, then `none` shall be returned.
1783+
block. If the `burn-block-height` argument falls outside of this range, then `none` shall be returned.
17841784
17851785
The following `BlockInfoPropertyName` values are defined:
17861786
17871787
* The `header-hash` property returns a 32-byte buffer representing the header hash of the burnchain block at
1788-
burnchain height `block-height`.
1788+
burnchain height `burn-block-height`.
17891789
17901790
* The `pox-addrs` property returns a tuple with two items: a list of up to two PoX addresses that received a PoX payout at that block height, and the amount of burnchain
17911791
tokens paid to each address (note that per the blockchain consensus rules, each PoX payout will be the same for each address in the block-commit transaction).
@@ -1811,11 +1811,11 @@ The `addrs` list contains the same PoX address values passed into the PoX smart
18111811

18121812
const GET_STACKS_BLOCK_INFO_API: SpecialAPI = SpecialAPI {
18131813
input_type: "StacksBlockInfoPropertyName, uint",
1814-
snippet: "get-stacks-block-info? ${1:prop} ${2:block-height}",
1814+
snippet: "get-stacks-block-info? ${1:prop} ${2:stacks-block-height}",
18151815
output_type: "(optional buff) | (optional uint)",
1816-
signature: "(get-stacks-block-info? prop-name block-height)",
1816+
signature: "(get-stacks-block-info? prop-name stacks-block-height)",
18171817
description: "The `get-stacks-block-info?` function fetches data for a block of the given *Stacks* block height. The
1818-
value and type returned are determined by the specified `StacksBlockInfoPropertyName`. If the provided `block-height` does
1818+
value and type returned are determined by the specified `StacksBlockInfoPropertyName`. If the provided `stacks-block-height` does
18191819
not correspond to an existing block prior to the current block, the function returns `none`. The currently available property names
18201820
are as follows:
18211821
@@ -1840,11 +1840,11 @@ the mining of this block started, but is not guaranteed to be accurate. This tim
18401840

18411841
const GET_TENURE_INFO_API: SpecialAPI = SpecialAPI {
18421842
input_type: "TenureInfoPropertyName, uint",
1843-
snippet: "get-tenure-info? ${1:prop} ${2:block-height}",
1843+
snippet: "get-tenure-info? ${1:prop} ${2:stacks-block-height}",
18441844
output_type: "(optional buff) | (optional uint)",
1845-
signature: "(get-tenure-info? prop-name block-height)",
1845+
signature: "(get-tenure-info? prop-name stacks-block-height)",
18461846
description: "The `get-tenure-info?` function fetches data for the tenure at the given block height. The
1847-
value and type returned are determined by the specified `TenureInfoPropertyName`. If the provided `block-height` does
1847+
value and type returned are determined by the specified `TenureInfoPropertyName`. If the provided `stacks-block-height` does
18481848
not correspond to an existing block prior to the current block, the function returns `none`. The currently available property names
18491849
are as follows:
18501850

libsigner/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ slog-term = "2.6.0"
3030
slog-json = { version = "2.3.0", optional = true }
3131
stacks-common = { path = "../stacks-common" }
3232
stackslib = { path = "../stackslib"}
33-
thiserror = "1.0"
33+
thiserror = { workspace = true }
3434
tiny_http = "0.12"
3535

3636
[dev-dependencies]

stacks-common/src/util/db.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,25 @@ pub fn update_lock_table(conn: &Connection) {
5151
/// Called by `rusqlite` if we are waiting too long on a database lock
5252
/// If called too many times, will assume a deadlock and panic
5353
pub fn tx_busy_handler(run_count: i32) -> bool {
54-
const TIMEOUT: Duration = Duration::from_secs(300);
5554
const AVG_SLEEP_TIME_MS: u64 = 100;
5655

56+
// Every ~5min, report an error with a backtrace
57+
// 5min * 60s/min * 1_000ms/s / 100ms
58+
const ERROR_COUNT: u32 = 3_000;
59+
5760
// First, check if this is taking unreasonably long. If so, it's probably a deadlock
5861
let run_count = run_count.unsigned_abs();
59-
let approx_time_elapsed =
60-
Duration::from_millis(AVG_SLEEP_TIME_MS.saturating_mul(u64::from(run_count)));
61-
if approx_time_elapsed > TIMEOUT {
62-
error!("Deadlock detected. Waited {} seconds (estimated) for database lock. Giving up", approx_time_elapsed.as_secs();
62+
if run_count > 0 && run_count % ERROR_COUNT == 0 {
63+
error!("Deadlock detected. Waited 5 minutes (estimated) for database lock.";
6364
"run_count" => run_count,
6465
"backtrace" => ?Backtrace::capture()
6566
);
6667
for (k, v) in LOCK_TABLE.lock().unwrap().iter() {
6768
error!("Database '{k}' last locked by {v}");
6869
}
69-
panic!("Deadlock in thread {:?}", thread::current().name());
7070
}
7171

7272
let mut sleep_time_ms = 2u64.saturating_pow(run_count);
73-
7473
sleep_time_ms = sleep_time_ms.saturating_add(thread_rng().gen_range(0..sleep_time_ms));
7574

7675
if sleep_time_ms > AVG_SLEEP_TIME_MS {

stacks-common/src/util/log.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,13 @@ fn make_json_logger() -> Logger {
215215
panic!("Tried to construct JSON logger, but stacks-blockchain built without slog_json feature enabled.")
216216
}
217217

218-
#[cfg(not(any(test, feature = "testing")))]
219218
fn make_logger() -> Logger {
220219
if env::var("STACKS_LOG_JSON") == Ok("1".into()) {
221220
make_json_logger()
222221
} else {
223222
let debug = env::var("STACKS_LOG_DEBUG") == Ok("1".into());
224223
let pretty_print = env::var("STACKS_LOG_PP") == Ok("1".into());
225-
let decorator = slog_term::PlainSyncDecorator::new(std::io::stderr());
224+
let decorator = get_decorator();
226225
let atty = isatty(Stream::Stderr);
227226
let drain = TermFormat::new(decorator, pretty_print, debug, atty);
228227
let logger = Logger::root(drain.ignore_res(), o!());
@@ -231,17 +230,13 @@ fn make_logger() -> Logger {
231230
}
232231

233232
#[cfg(any(test, feature = "testing"))]
234-
fn make_logger() -> Logger {
235-
if env::var("STACKS_LOG_JSON") == Ok("1".into()) {
236-
make_json_logger()
237-
} else {
238-
let debug = env::var("STACKS_LOG_DEBUG") == Ok("1".into());
239-
let plain = slog_term::PlainSyncDecorator::new(slog_term::TestStdoutWriter);
240-
let isatty = isatty(Stream::Stdout);
241-
let drain = TermFormat::new(plain, false, debug, isatty);
242-
let logger = Logger::root(drain.ignore_res(), o!());
243-
logger
244-
}
233+
fn get_decorator() -> slog_term::PlainSyncDecorator<slog_term::TestStdoutWriter> {
234+
slog_term::PlainSyncDecorator::new(slog_term::TestStdoutWriter)
235+
}
236+
237+
#[cfg(not(any(test, feature = "testing")))]
238+
fn get_decorator() -> slog_term::PlainSyncDecorator<std::io::Stderr> {
239+
slog_term::PlainSyncDecorator::new(std::io::stderr())
245240
}
246241

247242
fn inner_get_loglevel() -> slog::Level {

stacks-signer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ slog-json = { version = "2.3.0", optional = true }
3838
slog-term = "2.6.0"
3939
stacks-common = { path = "../stacks-common" }
4040
stackslib = { path = "../stackslib" }
41-
thiserror = "1.0"
41+
thiserror = { workspace = true }
4242
tiny_http = { version = "0.12", optional = true }
4343
toml = "0.5.6"
4444
tracing = "0.1.37"

stacks-signer/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use stacks_common::util::hash::Hash160;
3434
use crate::client::SignerSlotID;
3535

3636
const EVENT_TIMEOUT_MS: u64 = 5000;
37-
const BLOCK_PROPOSAL_TIMEOUT_MS: u64 = 45_000;
37+
const BLOCK_PROPOSAL_TIMEOUT_MS: u64 = 600_000;
3838
const DEFAULT_FIRST_PROPOSAL_BURN_BLOCK_TIMING_SECS: u64 = 60;
3939

4040
#[derive(thiserror::Error, Debug)]
@@ -335,7 +335,7 @@ Metrics endpoint: {metrics_endpoint}
335335

336336
/// Get the chain ID for the network
337337
pub fn to_chain_id(&self) -> u32 {
338-
self.chain_id.unwrap_or_else(|| match self.network {
338+
self.chain_id.unwrap_or(match self.network {
339339
Network::Mainnet => CHAIN_ID_MAINNET,
340340
Network::Testnet | Network::Mocknet => CHAIN_ID_TESTNET,
341341
})

stacks-signer/src/main.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,7 @@ fn handle_generate_stacking_signature(
157157

158158
fn handle_check_config(args: RunSignerArgs) {
159159
let config = GlobalConfig::try_from(&args.config).unwrap();
160-
println!(
161-
"Signer version: {}\nConfig: \n{}",
162-
VERSION_STRING.to_string(),
163-
config
164-
);
160+
println!("Signer version: {}\nConfig: \n{}", *VERSION_STRING, config);
165161
}
166162

167163
fn handle_generate_vote(args: GenerateVoteArgs, do_print: bool) -> MessageSignature {

0 commit comments

Comments
 (0)