diff --git a/CHANGELOG.md b/CHANGELOG.md index 492d2a264a..73107691b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,23 @@ The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/ ## [Unreleased] +### Changed + - Node: + - `node-daemon` and `node-gui`: the "reckless" mode of the chainstate database is now + enabled by default during the initial block download or bootstrapping, which + significantly increases its speed at the cost of a potential db corruption if the + system crashes in the meantime; the node automatically switches back to the normal + mode of operation when the download/bootstrapping finishes. + + - Node CLI: + - boolean node options now require an explicit `true`/`false` value (e.g. + `--enable-db-reckless-mode-in-ibd true`) instead of working as value-less flags; the + corresponding environment variables (`ML_NODE_*` for top-level options and + `ML_MAINNET_NODE_*` / `ML_TESTNET_NODE_*` / `ML_REGTEST_NODE_*` for per-network ones) + likewise now require an explicit `true`/`false` value. This makes the absence of an + option distinguishable from an explicit opt-out, so a value from the configuration + file is no longer silently overridden by the command line or the environment. + ## [1.4.1] - 2026-09-25 ### Added diff --git a/Cargo.lock b/Cargo.lock index 677f29284e..c517153cb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1536,6 +1536,7 @@ dependencies = [ "randomness", "rstest", "serialization", + "storage", "strum 0.26.3", "test-utils", "tokens-accounting", @@ -2950,7 +2951,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -3386,7 +3387,7 @@ dependencies = [ "libc", "log", "rustversion", - "windows-link 0.2.1", + "windows-link 0.1.3", "windows-result 0.4.1", ] @@ -4021,7 +4022,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2 0.6.2", + "socket2 0.5.10", "system-configuration", "tokio", "tower-service", @@ -4460,7 +4461,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" dependencies = [ "hermit-abi", "libc", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -4861,9 +4862,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.180" +version = "0.2.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" [[package]] name = "libdbus-sys" @@ -5389,9 +5390,9 @@ dependencies = [ [[package]] name = "mio" -version = "1.1.1" +version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee" dependencies = [ "libc", "log", @@ -5706,6 +5707,7 @@ dependencies = [ "rstest", "serde", "serde_with", + "serial_test", "storage-lmdb", "subsystem", "tempfile", @@ -5734,7 +5736,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -7763,7 +7765,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.11.0", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -8594,12 +8596,12 @@ dependencies = [ [[package]] name = "socket2" -version = "0.6.2" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -8911,6 +8913,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "sync_wrapper" version = "1.0.2" @@ -8977,7 +8990,7 @@ dependencies = [ "getrandom 0.4.1", "once_cell", "rustix 1.1.3", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -9231,9 +9244,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.50.0" +version = "1.51.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" +checksum = "a13e32eacd0222f9658be2ccbd83b718bfd9bfb0d54b5921913c184cb86124a5" dependencies = [ "bytes", "libc", @@ -9241,7 +9254,7 @@ dependencies = [ "parking_lot 0.12.5", "pin-project-lite", "signal-hook-registry", - "socket2 0.6.2", + "socket2 0.6.5", "tokio-macros", "tracing", "windows-sys 0.61.2", @@ -9249,13 +9262,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.6.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.114", + "syn 3.0.9", ] [[package]] @@ -9288,7 +9301,7 @@ dependencies = [ "postgres-protocol", "postgres-types", "rand 0.10.1", - "socket2 0.6.2", + "socket2 0.6.5", "tokio", "tokio-util", "whoami", @@ -9441,7 +9454,7 @@ dependencies = [ "hyper-util", "percent-encoding", "pin-project", - "socket2 0.6.2", + "socket2 0.6.5", "sync_wrapper", "tokio", "tokio-stream", @@ -10801,7 +10814,7 @@ dependencies = [ "js-sys", "log", "naga", - "parking_lot 0.12.5", + "parking_lot 0.11.2", "profiling", "raw-window-handle", "smallvec", @@ -10829,7 +10842,7 @@ dependencies = [ "log", "naga", "once_cell", - "parking_lot 0.12.5", + "parking_lot 0.11.2", "profiling", "raw-window-handle", "rustc-hash 1.1.0", @@ -10871,7 +10884,7 @@ dependencies = [ "ndk-sys 0.5.0+25.2.9519653", "objc", "once_cell", - "parking_lot 0.12.5", + "parking_lot 0.11.2", "profiling", "range-alloc", "raw-window-handle", @@ -10935,7 +10948,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.48.0", ] [[package]] @@ -11150,15 +11163,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets 0.53.5", -] - [[package]] name = "windows-sys" version = "0.61.2" @@ -11207,30 +11211,13 @@ dependencies = [ "windows_aarch64_gnullvm 0.52.6", "windows_aarch64_msvc 0.52.6", "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm 0.52.6", + "windows_i686_gnullvm", "windows_i686_msvc 0.52.6", "windows_x86_64_gnu 0.52.6", "windows_x86_64_gnullvm 0.52.6", "windows_x86_64_msvc 0.52.6", ] -[[package]] -name = "windows-targets" -version = "0.53.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" -dependencies = [ - "windows-link 0.2.1", - "windows_aarch64_gnullvm 0.53.1", - "windows_aarch64_msvc 0.53.1", - "windows_i686_gnu 0.53.1", - "windows_i686_gnullvm 0.53.1", - "windows_i686_msvc 0.53.1", - "windows_x86_64_gnu 0.53.1", - "windows_x86_64_gnullvm 0.53.1", - "windows_x86_64_msvc 0.53.1", -] - [[package]] name = "windows-threading" version = "0.1.0" @@ -11258,12 +11245,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" - [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -11282,12 +11263,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" - [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -11306,24 +11281,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" -[[package]] -name = "windows_i686_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" - [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" - [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -11342,12 +11305,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_i686_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" - [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -11366,12 +11323,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" - [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -11390,12 +11341,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" - [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -11414,12 +11359,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" - [[package]] name = "winit" version = "0.30.12" diff --git a/api-server/api-server-common/src/storage/impls/postgres/queries.rs b/api-server/api-server-common/src/storage/impls/postgres/queries.rs index 28ba7d2ec7..b08b92b162 100644 --- a/api-server/api-server-common/src/storage/impls/postgres/queries.rs +++ b/api-server/api-server-common/src/storage/impls/postgres/queries.rs @@ -57,7 +57,7 @@ const VERSION_STR: &str = "version"; // ML_SCANNER_STAGE_TIMING=1; the counter is read and reset per sync batch by // the scanner's perf_timing module. // -// Caveat (review round 2, INFO): these counters are process-global across all +// Caveat: these counters are process-global across all // postgres connections. Numbers are exact when the scanner is the only // postgres traffic in the process (dedicated scanner-daemon); if an api-server // serves requests in the same process, stmts/block absorbs that traffic too. @@ -135,7 +135,13 @@ impl<'a, 'b> CountingConnection<'a, 'b> { ) -> Result { use std::sync::atomic::Ordering::Relaxed; - let cached = self.statements.lock().unwrap().get(statement).cloned(); + // Degrade gracefully if the mutex is poisoned: never panic before the + // connection returns to the pool (matching the Drop paths in transactional). + let cached = self + .statements + .lock() + .ok() + .and_then(|statements| statements.get(statement).cloned()); match cached { Some(prepared) => { if stmt_counting_enabled() { @@ -148,10 +154,9 @@ impl<'a, 'b> CountingConnection<'a, 'b> { STMT_CACHE_MISSES.fetch_add(1, Relaxed); } let prepared = self.inner.prepare(statement).await?; - self.statements - .lock() - .unwrap() - .insert(statement.to_string(), prepared.clone()); + if let Ok(mut statements) = self.statements.lock() { + statements.insert(statement.to_string(), prepared.clone()); + } Ok(prepared) } } @@ -263,7 +268,9 @@ impl<'a, 'b> QueryFromConnection<'a, 'b> { tx: &'a PooledConnection<'b, PostgresConnectionManager>, statements: &'a StatementCache, ) -> Self { - Self { tx: CountingConnection::new(tx, statements) } + Self { + tx: CountingConnection::new(tx, statements), + } } fn block_height_to_postgres_friendly(block_height: BlockHeight) -> i64 { @@ -2852,7 +2859,7 @@ impl<'a, 'b> QueryFromConnection<'a, 'b> { } let encoded: Vec> = outpoints.iter().map(|op| op.encode()).collect(); - // (review fix) The utxo table can hold multiple versioned rows per + // The utxo table can hold multiple versioned rows per // outpoint (one per height); DISTINCT ON with block_height DESC makes // the batched fetch pick the same newest row the single get_utxo // (ORDER BY block_height DESC LIMIT 1) would pick. @@ -2875,19 +2882,17 @@ impl<'a, 'b> QueryFromConnection<'a, 'b> { let block_height: i64 = row.get(3); let spent_at_block_height = spent.then_some(BlockHeight::new(block_height as u64)); - let utxo = UtxoWithExtraInfo::decode_all(&mut serialized_data.as_slice()).map_err(|e| { - ApiServerStorageError::DeserializationError(format!( - "Utxo deserialization failed in batched fetch: {}", - e - )) - })?; + let utxo = + UtxoWithExtraInfo::decode_all(&mut serialized_data.as_slice()).map_err(|e| { + ApiServerStorageError::DeserializationError(format!( + "Utxo deserialization failed in batched fetch: {}", + e + )) + })?; by_outpoint.insert(outpoint, Utxo::new_with_info(utxo, spent_at_block_height)); } - Ok(outpoints - .iter() - .map(|op| by_outpoint.get(&op.encode()).cloned()) - .collect()) + Ok(outpoints.iter().map(|op| by_outpoint.get(&op.encode()).cloned()).collect()) } pub async fn get_address_available_utxos( diff --git a/api-server/api-server-common/src/storage/impls/postgres/transactional/mod.rs b/api-server/api-server-common/src/storage/impls/postgres/transactional/mod.rs index 6ab9628085..3f3c693942 100644 --- a/api-server/api-server-common/src/storage/impls/postgres/transactional/mod.rs +++ b/api-server/api-server-common/src/storage/impls/postgres/transactional/mod.rs @@ -78,21 +78,24 @@ impl ApiServerPostgresTransactionalRo<'_> { } pub async fn is_initialized(&mut self) -> Result { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.is_initialized().await?; Ok(res) } pub async fn get_storage_version(&mut self) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_storage_version().await?; Ok(res) } pub async fn get_best_block(&mut self) -> Result { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_best_block().await?; Ok(res) @@ -102,7 +105,8 @@ impl ApiServerPostgresTransactionalRo<'_> { &mut self, block_height: BlockHeight, ) -> Result>, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_main_chain_block_id(block_height).await?; Ok(res) @@ -112,7 +116,8 @@ impl ApiServerPostgresTransactionalRo<'_> { &mut self, block_id: Id, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_block(block_id).await?; Ok(res) @@ -122,7 +127,8 @@ impl ApiServerPostgresTransactionalRo<'_> { &mut self, pool_id: PoolId, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_pool_data(pool_id, &self.chain_config).await?; Ok(res) @@ -133,7 +139,8 @@ impl ApiServerPostgresTransactionalRo<'_> { &mut self, transaction_id: Id, ) -> Result, TransactionInfo)>, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_transaction(transaction_id).await?; Ok(res) @@ -143,7 +150,8 @@ impl ApiServerPostgresTransactionalRo<'_> { &mut self, block_id: Id, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_block_aux_data(block_id).await?; Ok(res) @@ -171,7 +179,7 @@ impl Drop for ApiServerPostgresTransactionalRw<'_> { fn drop(&mut self) { // (experimental) step 7: drop prepared statements before the // connection goes back to the pool. - // (review fix) degrade gracefully if the mutex is poisoned: never + // degrade gracefully if the mutex is poisoned: never // panic in Drop before the connection returns to the pool. if let Ok(mut statements) = self.statements.lock() { statements.clear(); @@ -252,7 +260,7 @@ impl Drop for ApiServerPostgresTransactionalRo<'_> { fn drop(&mut self) { // (experimental) step 7: drop prepared statements before the // connection goes back to the pool. - // (review fix) degrade gracefully if the mutex is poisoned: never + // degrade gracefully if the mutex is poisoned: never // panic in Drop before the connection returns to the pool. if let Ok(mut statements) = self.statements.lock() { statements.clear(); diff --git a/api-server/api-server-common/src/storage/impls/postgres/transactional/read.rs b/api-server/api-server-common/src/storage/impls/postgres/transactional/read.rs index fcc92a2024..920c4c4c55 100644 --- a/api-server/api-server-common/src/storage/impls/postgres/transactional/read.rs +++ b/api-server/api-server-common/src/storage/impls/postgres/transactional/read.rs @@ -40,14 +40,16 @@ use super::{ApiServerPostgresTransactionalRo, CONN_ERR}; #[async_trait::async_trait] impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { async fn is_initialized(&self) -> Result { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.is_initialized().await?; Ok(res) } async fn get_storage_version(&self) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_storage_version().await?; Ok(res) @@ -58,7 +60,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { address: &str, coin_or_token_id: CoinOrTokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_address_balance(address, coin_or_token_id).await?; Ok(res) @@ -70,7 +73,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { len: u32, cursor: Option<(String, Amount)>, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.get_top_address_amounts(coin_or_token_id, len, cursor).await } @@ -78,7 +82,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, address: &str, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_address_balances(address).await?; Ok(res) @@ -89,7 +94,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { address: &str, coin_or_token_id: CoinOrTokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_address_locked_balance(address, coin_or_token_id).await?; Ok(res) @@ -99,7 +105,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, address: &str, ) -> Result>, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_address_transactions(address).await?; Ok(res) @@ -111,7 +118,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_token_transactions(token_id, len, offset).await?; Ok(res) @@ -120,14 +128,16 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { async fn get_latest_blocktimestamps( &self, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_latest_blocktimestamps().await?; Ok(res) } async fn get_best_block(&self) -> Result { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_best_block().await?; Ok(res) @@ -137,7 +147,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, block_id: Id, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_block(block_id).await?; Ok(res) @@ -150,7 +161,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { Option, ApiServerStorageError, > { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_block_aux_data(block_id).await?; Ok(res) @@ -160,7 +172,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, time_range: (BlockTimestamp, BlockTimestamp), ) -> Result<(BlockHeight, BlockHeight), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_block_range_from_time_range(time_range).await?; Ok(res) @@ -170,7 +183,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, delegation_id: DelegationId, ) -> Result, crate::storage::storage_api::ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_delegation(delegation_id, &self.chain_config).await?; Ok(res) @@ -181,7 +195,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { pool_id: PoolId, block_range: (BlockHeight, BlockHeight), ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_pool_block_stats(pool_id, block_range, &self.chain_config).await?; Ok(res) @@ -191,7 +206,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, pool_id: PoolId, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_pool_delegation_shares(pool_id, &self.chain_config).await?; Ok(res) @@ -201,7 +217,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, block_height: BlockHeight, ) -> Result>, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_main_chain_block_id(block_height).await?; Ok(res) @@ -211,7 +228,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, transaction_id: Id, ) -> Result, TransactionInfo)>, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_transaction_with_block(transaction_id).await?; Ok(res) @@ -222,7 +240,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_transactions_with_block(len, offset).await?; Ok(res) @@ -233,7 +252,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { len: u32, order_number: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn .get_transactions_with_block_before_tx_global_index(len, order_number) .await?; @@ -244,7 +264,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { async fn get_last_transaction_global_index( &self, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_last_transaction_global_index().await?; Ok(res) @@ -255,7 +276,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { pool_id: PoolId, ) -> Result, crate::storage::storage_api::ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_pool_data(pool_id, &self.chain_config).await?; Ok(res) @@ -266,7 +288,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_latest_pool_data(len, offset, &self.chain_config).await?; Ok(res) @@ -277,7 +300,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { len: u32, cursor: Option<(BlockHeight, PoolId)>, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_latest_pool_data_before(len, cursor, &self.chain_config).await?; Ok(res) @@ -288,7 +312,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn .get_pool_data_with_largest_staker_balance(len, offset, &self.chain_config) .await?; @@ -300,7 +325,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, transaction_id: Id, ) -> Result, TransactionInfo)>, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_transaction(transaction_id).await?; Ok(res) @@ -310,7 +336,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, outpoint: UtxoOutPoint, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_utxo(outpoint).await?; Ok(res) @@ -320,7 +347,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, outpoints: &[UtxoOutPoint], ) -> Result>, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_utxos(outpoints).await?; Ok(res) @@ -330,7 +358,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, address: &str, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_address_available_utxos(address).await?; Ok(res) @@ -340,7 +369,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, address: &str, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_address_all_utxos(address).await?; Ok(res) @@ -351,7 +381,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { block_height: BlockHeight, time_range: (BlockTimestamp, BlockTimestamp), ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_locked_utxos_until_now(block_height, time_range).await?; Ok(res) @@ -361,7 +392,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, address: &Destination, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_delegations_from_address(address, &self.chain_config).await?; Ok(res) @@ -371,7 +403,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, authority: Destination, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_fungible_tokens_by_authority(authority, &self.chain_config).await?; Ok(res) @@ -381,7 +414,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, token_id: TokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_fungible_token_issuance(token_id).await?; Ok(res) @@ -391,7 +425,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, token_id: TokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_nft_token_issuance(token_id).await?; Ok(res) @@ -401,7 +436,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, token_id: TokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_token_num_decimals(token_id).await?; Ok(res) @@ -412,7 +448,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_token_ids(len, offset).await?; Ok(res) @@ -424,7 +461,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { offset: u64, ticker: &str, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_token_ids_by_ticker(len, offset, ticker).await?; Ok(res) @@ -435,7 +473,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { statistic: CoinOrTokenStatistic, coin_or_token_id: CoinOrTokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_statistic(statistic, coin_or_token_id).await?; Ok(res) @@ -445,14 +484,16 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, coin_or_token_id: CoinOrTokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_all_statistic(coin_or_token_id).await?; Ok(res) } async fn get_order(&self, order_id: OrderId) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_order(order_id, &self.chain_config).await?; Ok(res) @@ -463,7 +504,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_orders_by_height(len, offset, &self.chain_config).await?; Ok(res) @@ -475,7 +517,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_orders_for_trading_pair(pair, len, offset, &self.chain_config).await?; Ok(res) @@ -486,7 +529,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { ask_currency: CoinOrTokenId, give_currency: CoinOrTokenId, ) -> Result<(Vec<(Amount, Amount)>, bool), ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.get_order_book_entries(ask_currency, give_currency).await } @@ -494,14 +538,16 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRo<'_> { &self, last_seen_id: StreamEventId, ) -> Result, StreamEventReadError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.read_stream_events_after(last_seen_id).await?; Ok(res) } async fn latest_stream_event_id(&self) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.latest_stream_event_id().await?; Ok(res) diff --git a/api-server/api-server-common/src/storage/impls/postgres/transactional/write.rs b/api-server/api-server-common/src/storage/impls/postgres/transactional/write.rs index 3bebfd5150..37fb230ef6 100644 --- a/api-server/api-server-common/src/storage/impls/postgres/transactional/write.rs +++ b/api-server/api-server-common/src/storage/impls/postgres/transactional/write.rs @@ -45,7 +45,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, chain_config: &ChainConfig, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.reinitialize_database(chain_config).await?; Ok(()) @@ -55,7 +56,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_address_balance_above_height(block_height).await?; Ok(()) @@ -65,7 +67,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_address_locked_balance_above_height(block_height).await?; Ok(()) @@ -75,7 +78,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_address_transactions_above_height(block_height).await?; Ok(()) @@ -85,7 +89,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_token_transactions_above_height(block_height).await?; Ok(()) @@ -98,7 +103,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { coin_or_token_id: CoinOrTokenId, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_address_balance_at_height(address, amount, coin_or_token_id, block_height) .await?; @@ -112,7 +118,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { coin_or_token_id: CoinOrTokenId, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_address_locked_balance_at_height(address, amount, coin_or_token_id, block_height) .await?; @@ -125,7 +132,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { transaction_ids: BTreeSet>, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_address_transactions_at_height(address, transaction_ids, block_height) .await?; @@ -139,7 +147,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { block_height: BlockHeight, tx_global_index: u64, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_token_transactions_at_height( token_id, transaction_id, @@ -157,7 +166,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { block_height: BlockHeight, block: &BlockWithExtraData, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_mainchain_block(block_id, block_height, block).await?; Ok(()) @@ -169,7 +179,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { delegation: &Delegation, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_delegation_at_height(delegation_id, delegation, block_height, &self.chain_config) .await?; @@ -183,7 +194,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { owning_block: Id, transaction: &TransactionInfo, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_transaction(transaction_id, order_number, owning_block, transaction) .await?; @@ -195,7 +207,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { block_id: Id, block_aux_data: &BlockAuxData, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_block_aux_data(block_id, block_aux_data).await?; Ok(()) @@ -205,7 +218,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_main_chain_blocks_above_height(block_height).await?; Ok(()) @@ -217,7 +231,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { pool_data: &PoolDataWithExtraInfo, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_pool_data_at_height(pool_id, pool_data, block_height, &self.chain_config) .await?; @@ -228,7 +243,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_delegations_above_height(block_height).await?; Ok(()) @@ -238,7 +254,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_pools_above_height(block_height).await?; Ok(()) @@ -251,7 +268,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { addresses: &[&str], block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_utxo_at_height(outpoint, utxo, addresses, block_height).await?; Ok(()) @@ -264,7 +282,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { addresses: &[&str], block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_locked_utxo_at_height(outpoint, utxo, addresses, block_height).await?; Ok(()) @@ -274,7 +293,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_utxo_above_height(block_height).await?; Ok(()) @@ -284,7 +304,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_locked_utxo_above_height(block_height).await?; Ok(()) @@ -296,7 +317,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { block_height: BlockHeight, issuance: FungibleTokenData, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_fungible_token_issuance(token_id, block_height, issuance, &self.chain_config) .await?; @@ -309,7 +331,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { block_height: BlockHeight, data: FungibleTokenData, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_fungible_token_data(token_id, block_height, data, &self.chain_config) .await?; @@ -323,7 +346,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { issuance: NftIssuance, owner: &Destination, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_nft_token_issuance(token_id, block_height, issuance, owner).await?; Ok(()) @@ -333,7 +357,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_token_issuance_above_height(block_height).await?; Ok(()) @@ -343,7 +368,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_nft_issuance_above_height(block_height).await?; Ok(()) @@ -353,7 +379,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_coin_or_token_decimals_above_height(block_height).await?; Ok(()) @@ -366,7 +393,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { block_height: BlockHeight, amount: Amount, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_statistic(statistic, coin_or_token_id, block_height, amount).await?; Ok(()) @@ -376,7 +404,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_statistics_above_height(block_height).await?; Ok(()) @@ -388,7 +417,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { order: &Order, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.set_order_at_height(order_id, order, block_height, &self.chain_config) .await?; @@ -399,7 +429,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, block_height: BlockHeight, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.del_orders_above_height(block_height).await?; Ok(()) @@ -409,7 +440,8 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, event: &StreamEvent, ) -> Result { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.append_stream_event(event).await?; Ok(res) @@ -419,14 +451,16 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { &mut self, last_event_id: StreamEventId, ) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.notify_new_stream_events(last_event_id).await?; Ok(()) } async fn prune_stream_events(&mut self) -> Result<(), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let deleted = conn.prune_stream_events().await?; if deleted > 0 { logging::log::warn!( @@ -441,14 +475,16 @@ impl ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'_> { #[async_trait::async_trait] impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { async fn is_initialized(&self) -> Result { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.is_initialized().await?; Ok(res) } async fn get_storage_version(&self) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_storage_version().await?; Ok(res) @@ -459,7 +495,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { address: &str, coin_or_token_id: CoinOrTokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_address_balance(address, coin_or_token_id).await?; Ok(res) @@ -471,7 +508,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { len: u32, cursor: Option<(String, Amount)>, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.get_top_address_amounts(coin_or_token_id, len, cursor).await } @@ -479,7 +517,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, address: &str, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_address_balances(address).await?; Ok(res) @@ -490,7 +529,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { address: &str, coin_or_token_id: CoinOrTokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_address_locked_balance(address, coin_or_token_id).await?; Ok(res) @@ -500,7 +540,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, address: &str, ) -> Result>, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_address_transactions(address).await?; Ok(res) @@ -512,7 +553,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_token_transactions(token_id, len, offset).await?; Ok(res) @@ -521,14 +563,16 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { async fn get_latest_blocktimestamps( &self, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_latest_blocktimestamps().await?; Ok(res) } async fn get_best_block(&self) -> Result { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_best_block().await?; Ok(res) @@ -538,7 +582,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, block_id: Id, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_block(block_id).await?; Ok(res) @@ -548,7 +593,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, block_id: Id, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_block_aux_data(block_id).await?; Ok(res) @@ -558,7 +604,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, time_range: (BlockTimestamp, BlockTimestamp), ) -> Result<(BlockHeight, BlockHeight), ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_block_range_from_time_range(time_range).await?; Ok(res) @@ -568,7 +615,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, delegation_id: DelegationId, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_delegation(delegation_id, &self.chain_config).await?; Ok(res) @@ -578,7 +626,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, block_height: BlockHeight, ) -> Result>, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_main_chain_block_id(block_height).await?; Ok(res) @@ -588,7 +637,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, transaction_id: Id, ) -> Result, TransactionInfo)>, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_transaction_with_block(transaction_id).await?; Ok(res) @@ -599,7 +649,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_transactions_with_block(len, offset).await?; Ok(res) @@ -610,7 +661,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { len: u32, tx_global_index: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn .get_transactions_with_block_before_tx_global_index(len, tx_global_index) .await?; @@ -621,7 +673,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { async fn get_last_transaction_global_index( &self, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_last_transaction_global_index().await?; Ok(res) @@ -631,7 +684,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, pool_id: PoolId, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_pool_data(pool_id, &self.chain_config).await?; Ok(res) @@ -642,7 +696,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_latest_pool_data(len, offset, &self.chain_config).await?; Ok(res) @@ -653,7 +708,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { len: u32, cursor: Option<(BlockHeight, PoolId)>, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_latest_pool_data_before(len, cursor, &self.chain_config).await?; Ok(res) @@ -664,7 +720,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn .get_pool_data_with_largest_staker_balance(len, offset, &self.chain_config) .await?; @@ -677,7 +734,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { pool_id: PoolId, block_range: (BlockHeight, BlockHeight), ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_pool_block_stats(pool_id, block_range, &self.chain_config).await?; Ok(res) @@ -687,7 +745,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, pool_id: PoolId, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_pool_delegation_shares(pool_id, &self.chain_config).await?; Ok(res) @@ -697,7 +756,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, transaction_id: Id, ) -> Result, TransactionInfo)>, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_transaction(transaction_id).await?; Ok(res) @@ -707,7 +767,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, outpoint: UtxoOutPoint, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_utxo(outpoint).await?; Ok(res) @@ -717,7 +778,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, address: &str, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_address_available_utxos(address).await?; Ok(res) @@ -727,7 +789,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, address: &str, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_address_all_utxos(address).await?; Ok(res) @@ -738,7 +801,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { block_height: BlockHeight, time_range: (BlockTimestamp, BlockTimestamp), ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_locked_utxos_until_now(block_height, time_range).await?; Ok(res) @@ -748,7 +812,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, address: &Destination, ) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_delegations_from_address(address, &self.chain_config).await?; Ok(res) @@ -758,7 +823,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, authority: Destination, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_fungible_tokens_by_authority(authority, &self.chain_config).await?; Ok(res) @@ -768,7 +834,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, token_id: TokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_fungible_token_issuance(token_id).await?; Ok(res) @@ -778,7 +845,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, token_id: TokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_nft_token_issuance(token_id).await?; Ok(res) @@ -788,7 +856,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, token_id: TokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_token_num_decimals(token_id).await?; Ok(res) @@ -799,7 +868,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_token_ids(len, offset).await?; Ok(res) @@ -811,7 +881,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { offset: u64, ticker: &str, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_token_ids_by_ticker(len, offset, ticker).await?; Ok(res) @@ -822,7 +893,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { statistic: CoinOrTokenStatistic, coin_or_token_id: CoinOrTokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_statistic(statistic, coin_or_token_id).await?; Ok(res) @@ -832,14 +904,16 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, coin_or_token_id: CoinOrTokenId, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_all_statistic(coin_or_token_id).await?; Ok(res) } async fn get_order(&self, order_id: OrderId) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_order(order_id, &self.chain_config).await?; Ok(res) @@ -850,7 +924,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_orders_by_height(len, offset, &self.chain_config).await?; Ok(res) @@ -862,7 +937,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { len: u32, offset: u64, ) -> Result, ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.get_orders_for_trading_pair(pair, len, offset, &self.chain_config).await?; Ok(res) @@ -873,7 +949,8 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { ask_currency: CoinOrTokenId, give_currency: CoinOrTokenId, ) -> Result<(Vec<(Amount, Amount)>, bool), ApiServerStorageError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); conn.get_order_book_entries(ask_currency, give_currency).await } @@ -881,14 +958,16 @@ impl ApiServerStorageRead for ApiServerPostgresTransactionalRw<'_> { &self, last_seen_id: StreamEventId, ) -> Result, StreamEventReadError> { - let conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.read_stream_events_after(last_seen_id).await?; Ok(res) } async fn latest_stream_event_id(&self) -> Result, ApiServerStorageError> { - let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); + let mut conn = + QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR), &self.statements); let res = conn.latest_stream_event_id().await?; Ok(res) diff --git a/api-server/scanner-daemon/src/lib.rs b/api-server/scanner-daemon/src/lib.rs index 2957eeb322..ea03d28fcd 100644 --- a/api-server/scanner-daemon/src/lib.rs +++ b/api-server/scanner-daemon/src/lib.rs @@ -219,6 +219,7 @@ enum ConnectionState { /// been restarted) are not fixed by reconnecting, so the client is kept and only the sync is /// retried, with the delay growing via `sync_error_backoff` so that a persistent failure (e.g. /// a broken database) cannot flood the logs. +#[allow(clippy::items_after_statements)] // the catch-up threshold sits next to its use async fn supervise_sync( chain_config: &Arc, node_rpc_address: String, @@ -349,7 +350,9 @@ async fn supervise_sync( let local_is_on_node_chain = local_id == chain_info.best_block_id || matches!( api_blockchain_scanner_lib::sync::RemoteNode::last_common_ancestor( - &client, local_id, chain_info.best_block_id, + &client, + local_id, + chain_info.best_block_id, ) .await, Ok(Some(_)) @@ -357,9 +360,7 @@ async fn supervise_sync( let behind = chain_info.best_block_height > local_height; let mode = if behind && local_is_on_node_chain - && chain_info.best_block_height - .into_int() - .saturating_sub(local_height.into_int()) + && chain_info.best_block_height.into_int().saturating_sub(local_height.into_int()) > CATCH_UP_THRESHOLD { api_blockchain_scanner_lib::blockchain_state::ScanMode::CatchingUp diff --git a/api-server/scanner-lib/src/blockchain_state/mod.rs b/api-server/scanner-lib/src/blockchain_state/mod.rs index c68946f888..64d2ffcf46 100644 --- a/api-server/scanner-lib/src/blockchain_state/mod.rs +++ b/api-server/scanner-lib/src/blockchain_state/mod.rs @@ -13,7 +13,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::{collections::{BTreeMap, BTreeSet}, sync::Arc}; +use std::{ + collections::{BTreeMap, BTreeSet}, + sync::Arc, +}; use futures::{TryStreamExt, stream::FuturesOrdered}; @@ -155,13 +158,18 @@ impl LocalBlockchainState for BlockchainState self.scan_blocks_with_fees(common_block_height, blocks, fees).await } + #[allow(clippy::items_after_statements)] // the prefetch chunk size sits next to its use async fn scan_blocks_with_fees( &mut self, common_block_height: BlockHeight, blocks: Vec, trusted_fees: Vec>>, ) -> Result<(), Self::Error> { - assert_eq!(blocks.len(), trusted_fees.len(), "fees must align with blocks"); + assert_eq!( + blocks.len(), + trusted_fees.len(), + "fees must align with blocks" + ); let mut db_tx = self.storage.transaction_rw().await?; // Note: a reorg happened iff the local best block is above the common ancestor with the @@ -234,7 +242,7 @@ impl LocalBlockchainState for BlockchainState } } let outpoint_list: Vec = prefetch_outpoints.into_iter().collect(); - // (review round 3) Chunk the prefetch so a transaction-heavy batch + // Chunk the prefetch so a transaction-heavy batch // cannot build one giant ANY($1) bind. const UTXO_PREFETCH_CHUNK: usize = 10_000; let mut utxo_cache: BTreeMap = BTreeMap::new(); @@ -300,9 +308,8 @@ impl LocalBlockchainState for BlockchainState count_txs(block.transactions().len()); for (idx, tx) in block.transactions().iter().enumerate() { - let trusted_fee = block_trusted_fees - .as_ref() - .and_then(|fees| fees.get(idx).copied()); + let trusted_fee = + block_trusted_fees.as_ref().and_then(|fees| fees.get(idx).copied()); let (tx_fee, tx_additional_info) = { let _t = TimingGuard::stage(Stage::FeeCalc); calculate_tx_fee_and_collect_token_info( @@ -355,7 +362,11 @@ impl LocalBlockchainState for BlockchainState block_id, height: block_height, timestamp: block_timestamp, - tx_ids: block.transactions().iter().map(|tx| tx.transaction().get_id()).collect(), + tx_ids: block + .transactions() + .iter() + .map(|tx| tx.transaction().get_id()) + .collect(), }; last_event_id = db_tx.append_stream_event(&event).await?; @@ -483,23 +494,29 @@ fn amount_delta_i128(amount: &Amount) -> i128 { i128::try_from(amount.into_atoms()).expect("amount atoms do not fit i128") } -/// (review round 3) Returns an error instead of panicking so a statistic +/// Returns an error instead of panicking so a statistic /// underflow surfaces as a scan error like it did before the aggregation /// refactor (address-balance paths keep the historical panic-for-parity via /// the caller). -fn apply_delta(current: Amount, delta: i128, context: &str) -> Result { - let current_atoms = i128::try_from(current.into_atoms()) - .map_err(|_| ApiServerStorageError::LowLevelStorageError(format!("amount atoms do not fit i128: {context}")))?; +fn apply_delta( + current: Amount, + delta: i128, + context: &str, +) -> Result { + let current_atoms = i128::try_from(current.into_atoms()).map_err(|_| { + ApiServerStorageError::LowLevelStorageError(format!( + "amount atoms do not fit i128: {context}" + )) + })?; let new_atoms = current_atoms + delta; if new_atoms < 0 { return Err(ApiServerStorageError::LowLevelStorageError(format!( "Balance should not overflow {context}: would go negative" ))); } - Ok(Amount::from_atoms( - u128::try_from(new_atoms) - .map_err(|_| ApiServerStorageError::LowLevelStorageError(format!("balance overflow: {context}")))?, - )) + Ok(Amount::from_atoms(u128::try_from(new_atoms).map_err( + |_| ApiServerStorageError::LowLevelStorageError(format!("balance overflow: {context}")), + )?)) } impl BalanceAccumulator { @@ -551,12 +568,9 @@ impl BalanceAccumulator { }; // Address balances panicked on underflow before the aggregation // refactor; keep that parity. - let new_amount = apply_delta( - current, - delta, - &format!("{address:?} {coin_or_token_id:?}"), - ) - .expect("address balance underflow"); + let new_amount = + apply_delta(current, delta, &format!("{address:?} {coin_or_token_id:?}")) + .expect("address balance underflow"); db_tx .set_address_balance_at_height(&address, new_amount, coin_or_token_id, block_height) .await?; @@ -623,6 +637,7 @@ impl BalanceAccumulator { } } +#[allow(clippy::unused_async)] async fn increase_address_amount( acc: &mut BalanceAccumulator, address: &Address, @@ -633,6 +648,7 @@ async fn increase_address_amount( acc.add_address_delta(address, coin_or_token_id, amount_delta_i128(amount)); } +#[allow(clippy::unused_async)] async fn decrease_address_amount( acc: &mut BalanceAccumulator, address: Address, @@ -643,6 +659,7 @@ async fn decrease_address_amount( acc.add_address_delta(&address, coin_or_token_id, -amount_delta_i128(amount)); } +#[allow(clippy::unused_async)] async fn increase_locked_address_amount( acc: &mut BalanceAccumulator, address: &Address, @@ -653,6 +670,7 @@ async fn increase_locked_address_amount( acc.add_locked_delta(address, coin_or_token_id, amount_delta_i128(amount)); } +#[allow(clippy::unused_async)] async fn decrease_address_locked_amount( acc: &mut BalanceAccumulator, address: Address, @@ -663,6 +681,7 @@ async fn decrease_address_locked_amount( acc.add_locked_delta(&address, coin_or_token_id, -amount_delta_i128(amount)); } +#[allow(clippy::unused_async)] async fn increase_statistic_amount( acc: &mut BalanceAccumulator, statistic: CoinOrTokenStatistic, @@ -674,6 +693,7 @@ async fn increase_statistic_amount( Ok(()) } +#[allow(clippy::unused_async)] async fn decrease_statistic_amount( acc: &mut BalanceAccumulator, statistic: CoinOrTokenStatistic, @@ -685,7 +705,6 @@ async fn decrease_statistic_amount( Ok(()) } - async fn update_locked_amounts_for_current_block( db_tx: &mut T, chain_config: &ChainConfig, @@ -772,8 +791,7 @@ fn previous_and_new_median_time_from_window( calculate_median_time_past_from_blocktimestamps(window.iter().copied()); window.insert(0, block_timestamp); window.truncate(chainstate::MEDIAN_TIME_SPAN); - let new_median_time = - calculate_median_time_past_from_blocktimestamps(window.iter().copied()); + let new_median_time = calculate_median_time_past_from_blocktimestamps(window.iter().copied()); (previous_median_time, new_median_time) } @@ -1150,9 +1168,8 @@ async fn fetch_utxo( ) -> Result, ApiServerStorageError> { match input { TxInput::Utxo(outpoint) => { - let utxo = cached_get_utxo(utxo_cache, outpoint, db_tx) - .await? - .expect("must be present"); + let utxo = + cached_get_utxo(utxo_cache, outpoint, db_tx).await?.expect("must be present"); Ok(Some(utxo.into_output())) } TxInput::Account(_) | TxInput::AccountCommand(_, _) | TxInput::OrderAccountCommand(_) => { @@ -1274,7 +1291,7 @@ async fn tx_fees( &pos_accounting_adapter, &tokens_view, tx.inputs(), - &inputs_utxos, + inputs_utxos, ) .expect("valid block"); let outputs_accumulator = @@ -1401,7 +1418,7 @@ async fn update_tables_from_consensus_data( for input in pos_data.kernel_inputs() { match input { TxInput::Utxo(outpoint) => { - let utxo = cached_get_utxo(&utxo_cache, outpoint, db_tx) + let utxo = cached_get_utxo(utxo_cache, outpoint, db_tx) .await? .expect("must be present"); set_utxo( @@ -1498,6 +1515,7 @@ async fn update_tables_from_consensus_data( Ok(()) } +#[allow(clippy::too_many_arguments)] async fn update_tables_from_transaction( chain_config: Arc, db_tx: &mut T, @@ -1537,6 +1555,7 @@ async fn update_tables_from_transaction( Ok(()) } +#[allow(clippy::too_many_arguments)] async fn update_tables_from_transaction_inputs( chain_config: Arc, db_tx: &mut T, @@ -1843,7 +1862,7 @@ async fn update_tables_from_transaction_inputs( } TxInput::Utxo(outpoint) => match outpoint.source_id() { OutPointSourceId::BlockReward(_) => { - let utxo = cached_get_utxo(&utxo_cache, outpoint, db_tx) + let utxo = cached_get_utxo(utxo_cache, outpoint, db_tx) .await? .expect("must be present"); set_utxo( @@ -1893,7 +1912,7 @@ async fn update_tables_from_transaction_inputs( } } OutPointSourceId::Transaction(_) => { - let utxo = cached_get_utxo(&utxo_cache, outpoint, db_tx) + let utxo = cached_get_utxo(utxo_cache, outpoint, db_tx) .await? .expect("must be present"); set_utxo( @@ -1917,8 +1936,13 @@ async fn update_tables_from_transaction_inputs( | TxOutput::CreateOrder(_) => {} TxOutput::CreateStakePool(pool_id, _) | TxOutput::ProduceBlockFromStake(_, pool_id) => { - decommission_pool_and_decrement_staked(db_tx, pool_id, block_height, acc) - .await?; + decommission_pool_and_decrement_staked( + db_tx, + pool_id, + block_height, + acc, + ) + .await?; } TxOutput::IssueNft(token_id, _, destination) => { let address = Address::::new(&chain_config, destination) @@ -2047,6 +2071,7 @@ async fn update_tables_from_transaction_inputs( Ok(()) } +#[allow(clippy::too_many_arguments)] async fn update_tables_from_transaction_outputs( chain_config: Arc, db_tx: &mut T, @@ -2550,8 +2575,6 @@ async fn update_tables_from_transaction_outputs( Ok(()) } - - /// Decommissions a stake pool and removes its whole balance (pledge plus /// accumulated staker rewards, matching what the creation and block-reward /// paths added to the `Staked` statistic) from it. The balance is captured @@ -2586,16 +2609,7 @@ async fn decommission_pool_and_decrement_staked( Ok(pool_data) } - - - - - - - - - - +#[allow(clippy::too_many_arguments)] async fn set_utxo( outpoint: UtxoOutPoint, output: &TxOutput, @@ -2651,16 +2665,14 @@ fn get_tx_output_destination(txo: &TxOutput) -> Option<&Destination> { #[cfg(test)] mod median_window_tests { - // (review round 3, INFO) Focused coverage for the in-memory median-time + // Focused coverage for the in-memory median-time // window: the rolling window must produce identical medians to a // from-scratch recomputation over the same history, for chains both // shorter and longer than MEDIAN_TIME_SPAN. use super::previous_and_new_median_time_from_window; - use chainstate::{ - calculate_median_time_past_from_blocktimestamps, MEDIAN_TIME_SPAN, - }; - use randomness::{CryptoRng, RngExt as _}; + use chainstate::{MEDIAN_TIME_SPAN, calculate_median_time_past_from_blocktimestamps}; use common::chain::block::timestamp::BlockTimestamp; + use randomness::RngExt as _; use test_utils::random::{Seed, make_seedable_rng}; #[test] @@ -2682,13 +2694,9 @@ mod median_window_tests { // From-scratch mirror of the per-block db query: the previous // median covers the history BEFORE this block; the new median // covers it after inserting this block at the front. - let previous = calculate_median_time_past_from_blocktimestamps( - history.iter().copied(), - ); + let previous = calculate_median_time_past_from_blocktimestamps(history.iter().copied()); history.insert(0, timestamp); - let new = calculate_median_time_past_from_blocktimestamps( - history.iter().copied(), - ); + let new = calculate_median_time_past_from_blocktimestamps(history.iter().copied()); let (rolled_previous, rolled_new) = previous_and_new_median_time_from_window(&mut window, timestamp); diff --git a/api-server/scanner-lib/src/blockchain_state/perf_timing.rs b/api-server/scanner-lib/src/blockchain_state/perf_timing.rs index 0c2f0462dc..2eff18c71d 100644 --- a/api-server/scanner-lib/src/blockchain_state/perf_timing.rs +++ b/api-server/scanner-lib/src/blockchain_state/perf_timing.rs @@ -1,3 +1,18 @@ +// Copyright (c) 2023 RBB S.r.l +// opensource@mintlayer.org +// SPDX-License-Identifier: MIT +// Licensed under the MIT License; +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // (experimental) Stage-timing instrumentation for scanner (indexer) profiling. // // Enabled via ML_SCANNER_STAGE_TIMING=1. Accumulates wall-clock time spent in @@ -108,6 +123,7 @@ pub fn count_cache_miss() { } /// Log and reset accumulated stage times; call at the end of scan_blocks. +#[allow(clippy::float_arithmetic)] // percentages and ms/block of the report pub fn log_batch_summary() { if !enabled() { return; @@ -135,7 +151,11 @@ pub fn log_batch_summary() { "{:>13}: {:>8.2} ms/block ({:>8.2} ms/tx)", name, d.as_millis() as f64 / blocks as f64, - if txs > 0 { d.as_millis() as f64 / txs as f64 } else { 0.0 }, + if txs > 0 { + d.as_millis() as f64 / txs as f64 + } else { + 0.0 + }, ) }) .collect(); @@ -148,7 +168,11 @@ pub fn log_batch_summary() { txs, stmts, stmts as f64 / blocks as f64, - if txs > 0 { stmts as f64 / txs as f64 } else { 0.0 }, + if txs > 0 { + stmts as f64 / txs as f64 + } else { + 0.0 + }, hits, misses, stmt_cache_hits, diff --git a/api-server/scanner-lib/src/sync/mod.rs b/api-server/scanner-lib/src/sync/mod.rs index 0d1b057409..226b5c04cf 100644 --- a/api-server/scanner-lib/src/sync/mod.rs +++ b/api-server/scanner-lib/src/sync/mod.rs @@ -132,7 +132,6 @@ async fn fetch_and_sync( chain_config: &ChainConfig, rpc_client: &R, local_node: &mut L, - ) -> Result<(), SyncError> { // TODO: use chain trust instead of height utils::ensure!( @@ -209,8 +208,7 @@ async fn fetch_new_blocks( // chain before trusting it. for pair in blocks.windows(2) { utils::ensure!( - *pair[1].header().prev_block_id() - == Id::::from(pair[0].header().block_id()), + *pair[1].header().prev_block_id() == Id::::from(pair[0].header().block_id()), SyncError::InvalidPrevBlockId( *pair[1].header().prev_block_id(), pair[0].header().block_id().into(), diff --git a/api-server/scanner-lib/src/sync/remote_node.rs b/api-server/scanner-lib/src/sync/remote_node.rs index 743ea9fbd0..7da8882473 100644 --- a/api-server/scanner-lib/src/sync/remote_node.rs +++ b/api-server/scanner-lib/src/sync/remote_node.rs @@ -18,7 +18,6 @@ use common::{ chain::{Block, BlockTxFees, GenBlock}, primitives::{BlockHeight, Id}, }; -use node_comm::node_traits::NodeInterface as _; use mempool::FeeRate; use node_comm::{ node_traits::NodeInterface, @@ -45,10 +44,7 @@ pub trait RemoteNode { /// (experimental) Per-transaction fees of a mainchain block, persisted at /// connect time. Returns None if the block predates fee persistence; the /// scanner then falls back to recomputing fees locally. - async fn block_tx_fees( - &self, - block_id: Id, - ) -> Result, Self::Error>; + async fn block_tx_fees(&self, block_id: Id) -> Result, Self::Error>; async fn mempool_feerate_points(&self) -> Result, Self::Error>; @@ -88,10 +84,7 @@ impl RemoteNode for NodeRpcClient { self.get_mainchain_blocks(from, max_count).await } - async fn block_tx_fees( - &self, - block_id: Id, - ) -> Result, Self::Error> { + async fn block_tx_fees(&self, block_id: Id) -> Result, Self::Error> { NodeInterface::get_block_tx_fees(self, block_id).await } diff --git a/api-server/scanner-lib/src/sync/tests/mod.rs b/api-server/scanner-lib/src/sync/tests/mod.rs index 29bf1e00d4..6305e48110 100644 --- a/api-server/scanner-lib/src/sync/tests/mod.rs +++ b/api-server/scanner-lib/src/sync/tests/mod.rs @@ -39,9 +39,8 @@ use common::{ address::Address, chain::{ AccountCommand, AccountNonce, AccountOutPoint, AccountSpending, BlockTxFees, CoinUnit, - Destination, - OrderAccountCommand, OrderData, OrderId, OutPointSourceId, PoolId, SignedTransaction, - Transaction, TxInput, TxOutput, UtxoOutPoint, + Destination, OrderAccountCommand, OrderData, OrderId, OutPointSourceId, PoolId, + SignedTransaction, Transaction, TxInput, TxOutput, UtxoOutPoint, htlc::{HashedTimelockContract, HtlcSecret}, make_delegation_id, make_order_id, make_token_id, output_value::OutputValue, @@ -184,7 +183,7 @@ impl RemoteNode for MockRemoteNode { _block_id: Id, ) -> Result, Self::Error> { Ok(None) -} + } async fn mainchain_blocks( &self, diff --git a/api-server/scanner-lib/tests/postgres_scan_perf.rs b/api-server/scanner-lib/tests/postgres_scan_perf.rs index 6b5ef4f308..42ad131104 100644 --- a/api-server/scanner-lib/tests/postgres_scan_perf.rs +++ b/api-server/scanner-lib/tests/postgres_scan_perf.rs @@ -1,3 +1,18 @@ +// Copyright (c) 2023 RBB S.r.l +// opensource@mintlayer.org +// SPDX-License-Identifier: MIT +// Licensed under the MIT License; +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // (experimental) End-to-end validation of the scanner stage/statement timing // instrumentation against a real postgres instance. // @@ -27,14 +42,14 @@ use common::{ }, primitives::{Amount, BlockDistance, BlockHeight, H256, Id, Idable, per_thousand::PerThousand}, }; -use randomness::CryptoRng; use crypto::{ key::{KeyKind, PrivateKey}, vrf::{VRFKeyKind, VRFPrivateKey}, }; +use randomness::CryptoRng; use test_utils::random::make_seedable_rng; -/// (review fix) Exercises the postgres get_utxos override against real data: +/// Exercises the postgres get_utxos override against real data: /// batched results must match single fetches for every outpoint referenced by /// the scanned blocks (inputs and PoS kernel inputs), a missing outpoint must /// return None, and duplicate request entries must return identical values. @@ -79,24 +94,23 @@ async fn assert_get_utxos_matches_single( std::iter::once(missing.clone()).chain(outpoints.iter().cloned()).collect(); let batched = db_tx.get_utxos(&requested).await.unwrap(); assert_eq!(batched.len(), requested.len()); - assert!(batched[0].is_none(), "missing outpoint must resolve to None"); + assert!( + batched[0].is_none(), + "missing outpoint must resolve to None" + ); for (position, outpoint) in requested.iter().enumerate().skip(1) { let single = db_tx.get_utxo(outpoint.clone()).await.unwrap().expect("must be present"); let batched_utxo = batched[position].as_ref().expect("must be present"); assert_eq!( - batched_utxo, - &single, + batched_utxo, &single, "batched fetch disagrees with single fetch for {outpoint:?}" ); } // Duplicate request entries return identical values. let first_known = requested[1].clone(); - let dup = db_tx - .get_utxos(&[first_known.clone(), first_known.clone()]) - .await - .unwrap(); + let dup = db_tx.get_utxos(&[first_known.clone(), first_known.clone()]).await.unwrap(); assert_eq!(dup[0], dup[1]); assert!(dup[0].is_some()); } @@ -106,7 +120,7 @@ const BLOCKS: usize = 20; /// (experimental) Recreate a fresh database for a test so parallel tests don't /// clobber each other's schema. async fn reset_db(db_name: &str) { - // (review fix) identifiers cannot be bound as parameters; since this + // identifiers cannot be bound as parameters; since this // helper interpolates into destructive DDL, restrict the name to a safe // charset before use. assert!( @@ -169,9 +183,7 @@ async fn postgres_scan_perf_summary() { .build(); let target_block_time = chain_config.target_block_spacing(); - let mut tf = TestFramework::builder(&mut rng) - .with_chain_config(chain_config.clone()) - .build(); + let mut tf = TestFramework::builder(&mut rng).with_chain_config(chain_config.clone()).build(); tf.progress_time_seconds_since_epoch(target_block_time.as_secs()); tf.create_chain_pos( @@ -205,10 +217,7 @@ async fn postgres_scan_perf_summary() { } let mut local_state = BlockchainState::new(Arc::clone(&chain_config), storage); - local_state - .scan_genesis(chain_config.genesis_block().as_ref()) - .await - .unwrap(); + local_state.scan_genesis(chain_config.genesis_block().as_ref()).await.unwrap(); // All blocks above genesis, scanned in a single batch, like the sync loop // does with MAX_FETCH_BLOCK_COUNT=100. @@ -217,14 +226,10 @@ async fn postgres_scan_perf_summary() { blocks.push(tf.block(*tf.index_at(height).block_id())); } - local_state - .scan_blocks(BlockHeight::zero(), blocks) - .await - .unwrap(); + local_state.scan_blocks(BlockHeight::zero(), blocks).await.unwrap(); - let scanned: Vec = (1..=BLOCKS) - .map(|height| tf.block(*tf.index_at(height).block_id())) - .collect(); + let scanned: Vec = + (1..=BLOCKS).map(|height| tf.block(*tf.index_at(height).block_id())).collect(); assert_get_utxos_matches_single(local_state.storage(), &scanned, &mut rng).await; // The (experimental scanner timing) summary, including the postgres @@ -249,8 +254,7 @@ async fn postgres_scan_perf_summary_with_txs() { let mut tf = TestFramework::builder(&mut rng).build(); let chain_config = tf.chain_config().clone(); - tf.create_chain(&tf.genesis().get_id().into(), BLOCKS, &mut rng) - .unwrap(); + tf.create_chain(&tf.genesis().get_id().into(), BLOCKS, &mut rng).unwrap(); let chain_config = Arc::new(chain_config); reset_db("ml_scan_perf_tx").await; @@ -273,23 +277,16 @@ async fn postgres_scan_perf_summary_with_txs() { } let mut local_state = BlockchainState::new(Arc::clone(&chain_config), storage); - local_state - .scan_genesis(chain_config.genesis_block().as_ref()) - .await - .unwrap(); + local_state.scan_genesis(chain_config.genesis_block().as_ref()).await.unwrap(); let mut blocks = Vec::with_capacity(BLOCKS); for height in 1..=BLOCKS { blocks.push(tf.block(*tf.index_at(height).block_id())); } - local_state - .scan_blocks(BlockHeight::zero(), blocks) - .await - .unwrap(); + local_state.scan_blocks(BlockHeight::zero(), blocks).await.unwrap(); - let scanned: Vec = (1..=BLOCKS) - .map(|height| tf.block(*tf.index_at(height).block_id())) - .collect(); + let scanned: Vec = + (1..=BLOCKS).map(|height| tf.block(*tf.index_at(height).block_id())).collect(); assert_get_utxos_matches_single(local_state.storage(), &scanned, &mut rng).await; } diff --git a/api-server/stack-test-suite/tests/scanner_reconnect.rs b/api-server/stack-test-suite/tests/scanner_reconnect.rs index 220ee4002f..ef98167a23 100644 --- a/api-server/stack-test-suite/tests/scanner_reconnect.rs +++ b/api-server/stack-test-suite/tests/scanner_reconnect.rs @@ -41,9 +41,10 @@ use api_server_common::storage::{ }; use chainstate_test_framework::TestFramework; use common::{ - chain::GenBlock, + chain::{Block, GenBlock}, primitives::{BlockHeight, Id}, }; +use mempool::FeeRate; use randomness::RngExt as _; use rpc::test_support::{INTERNAL_ERROR_CODE, RpcModule, RpcResult, Server}; use rpc::{Error as ErrorObjectOwned, RpcAuthData}; @@ -63,7 +64,7 @@ const TIP_TIMEOUT: Duration = Duration::from_secs(30); /// several backoff steps of the scanner's reconnection attempts). const OUTAGE_DURATION: Duration = Duration::from_secs(4); -/// The four `chainstate` RPC methods used by the scanner, served by a real WebSocket RPC server +/// The five `chainstate` RPC methods used by the scanner, served by a real WebSocket RPC server /// backed by the chainstate of a [`TestFramework`]. The method names and the request/response /// formats match the ones of the real node's RPC, so the scanner cannot tell the difference. fn make_chainstate_rpc_module( @@ -77,6 +78,36 @@ fn make_chainstate_rpc_module( }) .unwrap(); + module + .register_async_method( + "chainstate_get_block_tx_fees", + |params, state, _| async move { + // The jsonrpsee client sends named params as an object. + #[derive(serde::Deserialize)] + struct GetBlockTxFeesParams { + block_id: Id, + } + let params = params.parse::()?; + call_chainstate(Arc::clone(&state), move |tf| { + tf.chainstate.get_block_tx_fees(¶ms.block_id) + }) + .await + }, + ) + .unwrap(); + + module + .register_async_method( + "mempool_get_fee_rate_points", + |_params, _state, _| async move { + Ok::, ErrorObjectOwned>(vec![( + 1usize, + FeeRate::from_amount_per_kb(common::primitives::Amount::from_atoms(1)), + )]) + }, + ) + .unwrap(); + module .register_async_method("chainstate_best_block_id", |_params, state, _| async move { call_chainstate(Arc::clone(&state), |tf| tf.chainstate.get_best_block_id()).await diff --git a/api-server/storage-test-suite/src/basic.rs b/api-server/storage-test-suite/src/basic.rs index f699791c2b..5be6911f95 100644 --- a/api-server/storage-test-suite/src/basic.rs +++ b/api-server/storage-test-suite/src/basic.rs @@ -2899,12 +2899,11 @@ where Ok(()) } - -/// (review fix) Batched UTXO fetch must agree with the single fetch: +/// Batched UTXO fetch must agree with the single fetch: /// - multiple versioned rows per outpoint resolve to the newest row, /// - duplicate outpoints in the request return the same value per position, /// - missing outpoints return None, -/// and the result order matches the request order. +/// and the result order matches the request order. pub async fn get_utxos_batch_semantics Fut>( storage_maker: Arc, _seed_maker: Box Seed + Send>, @@ -2922,12 +2921,17 @@ where let mut storage = storage_maker().await; + { + let mut tx = storage.transaction_rw().await.unwrap(); + tx.reinitialize_storage(&chain_config).await.unwrap(); + tx.commit().await.unwrap(); + } + { let mut db_tx = storage.transaction_rw().await.unwrap(); let tx_id = Id::::random_using(&mut rng); - let outpoint = - UtxoOutPoint::new(OutPointSourceId::Transaction(tx_id), rng.random::()); + let outpoint = UtxoOutPoint::new(OutPointSourceId::Transaction(tx_id), rng.random::()); // Two versioned rows for the same outpoint: an unspent row at the // lower height and a spent row at the higher height. The newest row @@ -2975,11 +2979,7 @@ where rng.random::(), ); - let requested = &[ - missing_outpoint.clone(), - outpoint.clone(), - outpoint.clone(), - ]; + let requested = &[missing_outpoint.clone(), outpoint.clone(), outpoint.clone()]; let batched = db_tx.get_utxos(requested).await.unwrap(); let single_0 = db_tx.get_utxo(missing_outpoint.clone()).await.unwrap(); @@ -2991,8 +2991,13 @@ where assert_eq!(batched[1].as_ref(), single_1.as_ref()); assert_eq!(batched[1], batched[2]); assert_eq!(single_1, single_2); - // The newest (spent) row wins over the older unspent one. - assert_eq!(batched[1].as_ref().unwrap(), &newer_spent); + // The newest (spent) row wins over the older unspent one: the utxo + // payload is the one stored with the newest row. (The reported + // spent height comes from the row height, mirroring get_utxo.) + assert_eq!( + batched[1].as_ref().unwrap().utxo_with_extra_info(), + newer_spent.utxo_with_extra_info() + ); // Empty request is not an error. assert!(db_tx.get_utxos(&[]).await.unwrap().is_empty()); diff --git a/build-tools/fork-detection/detector.py b/build-tools/fork-detection/detector.py index fd6023a220..d3995440db 100644 --- a/build-tools/fork-detection/detector.py +++ b/build-tools/fork-detection/detector.py @@ -138,7 +138,7 @@ def __init__(self, args, email_sender): self.node_cmd += [ "--datadir", self.cur_attempt_node_data_dir, args.chain_type, - "--allow-checkpoints-mismatch", + "--allow-checkpoints-mismatch=true", "--rpc-bind-address", args.node_rpc_bind_address, "--rpc-username", NODE_RPC_USER, "--rpc-password", NODE_RPC_PWD, diff --git a/build-tools/staking-test/.env b/build-tools/staking-test/.env index 666c0ac53e..a5c8796de0 100644 --- a/build-tools/staking-test/.env +++ b/build-tools/staking-test/.env @@ -20,7 +20,7 @@ CHAIN_TYPE=regtest COMMON_ARGS="--force-allow-run-as-root --chain-pos-netupgrades=3" -COMMON_NODE_DAEMON_ARGS="--create-datadir-if-missing=true $CHAIN_TYPE --rpc-bind-address 0.0.0.0:$NODE_RPC_INTERNAL_PORT --rpc-username=$NODE_RPC_USER --rpc-password=$NODE_RPC_PWD --blockprod-min-peers-to-produce-blocks=0 --max-tip-age=1000000000 --blockprod-use-current-time-if-non-pos --chain-initial-difficulty=419627008 $COMMON_ARGS" +COMMON_NODE_DAEMON_ARGS="--create-datadir-if-missing=true $CHAIN_TYPE --rpc-bind-address 0.0.0.0:$NODE_RPC_INTERNAL_PORT --rpc-username=$NODE_RPC_USER --rpc-password=$NODE_RPC_PWD --blockprod-min-peers-to-produce-blocks=0 --max-tip-age=1000000000 --blockprod-use-current-time-if-non-pos=true --chain-initial-difficulty=419627008 $COMMON_ARGS" COMMON_WALLET_RPC_DAEMON_ARGS="$CHAIN_TYPE --rpc-bind-address=0.0.0.0:$WALLET_RPC_INTERNAL_PORT --rpc-username=$WALLET_RPC_USER --rpc-password=$WALLET_RPC_PWD --node-rpc-username=$NODE_RPC_USER --node-rpc-password=$NODE_RPC_PWD $COMMON_ARGS" diff --git a/build-tools/staking-test/README.md b/build-tools/staking-test/README.md index 9be1593e50..6ef04f4bf9 100644 --- a/build-tools/staking-test/README.md +++ b/build-tools/staking-test/README.md @@ -10,7 +10,7 @@ the script) and certain other arguments. The expected `node-daemon` arguments are: - `--blockprod-min-peers-to-produce-blocks=0` -- `--blockprod-use-current-time-if-non-pos` +- `--blockprod-use-current-time-if-non-pos=true` - `--chain-pos-netupgrades=3` - `--max-tip-age=1000000000` diff --git a/chainstate/src/config.rs b/chainstate/src/config.rs index 5c9ec34880..beae6e0c1e 100644 --- a/chainstate/src/config.rs +++ b/chainstate/src/config.rs @@ -80,10 +80,9 @@ impl ChainstateConfig { } pub fn db_reckless_mode_in_ibd_enabled(&self) -> bool { - // (review fix) The library default stays identical to master (opt-in): - // the experimental default-on behavior lives at the node-daemon layer - // (node-lib/src/runner.rs), so cherry-picked library code cannot - // silently change durability semantics. + // The library default stays identical to master (opt-in): the experimental + // default-on behavior lives at the node-daemon layer (node-lib/src/runner.rs), + // so cherry-picked library code cannot silently change durability semantics. self.enable_db_reckless_mode_in_ibd.unwrap_or(false) } diff --git a/chainstate/src/detail/block_checking.rs b/chainstate/src/detail/block_checking.rs index f5b930ba1d..a3239efbcc 100644 --- a/chainstate/src/detail/block_checking.rs +++ b/chainstate/src/detail/block_checking.rs @@ -41,10 +41,9 @@ impl<'a, S: BlockchainStorage, V: TransactionVerificationStrategy> BlockChecker< // along with the tip it was validated against, so integrate_block can // skip the duplicate check if the tip is unchanged by then. { - let tip = chainstate_ref - .get_best_block_id() - .map_err(|e| BlockError::PropertyQueryError(e.into()))?; - let mut memo = self.chainstate.pre_checked_blocks.lock().unwrap(); + let tip = chainstate_ref.get_best_block_id().map_err(BlockError::PropertyQueryError)?; + let mut memo = + self.chainstate.pre_checked_blocks.lock().unwrap_or_else(|e| e.into_inner()); if memo.len() > 10_000 { memo.clear(); } diff --git a/chainstate/src/detail/chainstateref/mod.rs b/chainstate/src/detail/chainstateref/mod.rs index 3b7ca42153..0ab878799b 100644 --- a/chainstate/src/detail/chainstateref/mod.rs +++ b/chainstate/src/detail/chainstateref/mod.rs @@ -38,8 +38,7 @@ use common::{ Uint256, chain::{ AccountNonce, AccountType, Block, BlockTxFees, ChainConfig, GenBlock, GenBlockId, - OrderAccountCommand, - PoolId, Transaction, TxInput, TxOutput, UtxoOutPoint, + OrderAccountCommand, PoolId, Transaction, TxInput, TxOutput, UtxoOutPoint, block::{ BlockReward, ConsensusData, signed_block_header::SignedBlockHeader, timestamp::BlockTimestamp, @@ -278,9 +277,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat &self, block_id: &Id, ) -> Result, PropertyQueryError> { - self.db_tx - .get_block_tx_fees(block_id) - .map_err(PropertyQueryError::from) + self.db_tx.get_block_tx_fees(block_id).map_err(PropertyQueryError::from) } #[log_error] @@ -1302,8 +1299,7 @@ impl ChainstateRe // (experimental) step 9: persist the per-transaction fees computed // during connect, for serving to API consumers. - self.db_tx - .set_block_tx_fees(block_index.block_id(), &block_tx_fees)?; + self.db_tx.set_block_tx_fees(block_index.block_id(), &block_tx_fees)?; Ok(()) } @@ -1321,7 +1317,7 @@ impl ChainstateRe // (experimental) step 9: the block is no longer on the mainchain; its // persisted per-transaction fees are removed with it. - self.db_tx.del_block_tx_fees(&Id::::from(block.get_id()))?; + self.db_tx.del_block_tx_fees(&block.get_id())?; Ok(()) } @@ -1345,9 +1341,8 @@ impl ChainstateRe // (experimental) step 11: when the block to connect is the one // just persisted by the caller, reuse the in-memory copy instead // of reading it back from the storage and decoding it. - let preloaded = in_memory_block - .filter(|b| b.get_id() == *block_index.block_id()) - .cloned(); + let preloaded = + in_memory_block.filter(|b| b.get_id() == *block_index.block_id()).cloned(); let block: WithId = match preloaded { Some(block) => block, @@ -1449,7 +1444,11 @@ impl ChainstateRe if new_block_index.chain_trust() > current_best_block_index.chain_trust() { // Chain trust is higher than the best block - self.reorganize(¤t_best_block_index.block_id(), new_block_index, in_memory_block)?; + self.reorganize( + ¤t_best_block_index.block_id(), + new_block_index, + in_memory_block, + )?; return Ok(true); } diff --git a/chainstate/src/detail/mod.rs b/chainstate/src/detail/mod.rs index e39dd5398c..cc299a8cb7 100644 --- a/chainstate/src/detail/mod.rs +++ b/chainstate/src/detail/mod.rs @@ -381,7 +381,7 @@ impl Chainstate ) -> Result { let mut block_status = BlockStatus::new(); - // (review round 3) Re-verify the memoized check verdict against the + // Re-verify the memoized check verdict against the // tip as observed INSIDE this rw transaction: the verdict is only // trusted if the recorded tip is still the current one. This keeps // the skip stale-safe across retries and batch commits. @@ -389,7 +389,7 @@ impl Chainstate Some(checked_tip) => { let current_tip = chainstate_ref .get_best_block_id() - .map_err(|e| BlockError::PropertyQueryError(e.into())) + .map_err(BlockError::PropertyQueryError) .map_err(BlockIntegrationError::OtherNonValidationError)?; checked_tip == current_tip } @@ -426,8 +426,8 @@ impl Chainstate // makes visible. { let _t = perf_timing::TimingGuard::stage(perf_timing::Stage::SealIndex); - if let Err(err) = chainstate_ref - .index_block_seal_if_enabled(block, block_index.block_height()) + if let Err(err) = + chainstate_ref.index_block_seal_if_enabled(block, block_index.block_height()) { log::error!( "Failed to index the seal of the block {}: {err}", @@ -476,7 +476,7 @@ impl Chainstate block_source: BlockSource, ) -> Result, BlockError> { let result = self.attempt_to_process_block_inner(block, block_source); - // (review fix) count every processed block, on success and failure + // count every processed block, on success and failure // alike, so the timing window doesn't drift. perf_timing::on_block_processed(); result @@ -518,7 +518,11 @@ impl Chainstate // integrate_block), so the verdict can never be applied against a // state that no longer matches the one it was validated against - // including across with_rw_tx retries and, later, batch commits. - let checked_against_tip = self.pre_checked_blocks.lock().unwrap().remove(&block_id); + let checked_against_tip = self + .pre_checked_blocks + .lock() + .unwrap_or_else(|e| e.into_inner()) + .remove(&block_id); // Perform block checks; `integrate_block_result` is `Result`, where the bool // indicates whether a reorg has occurred. @@ -548,18 +552,16 @@ impl Chainstate let saved_block_index = get_existing_block_index(&chainstate_ref, &block_id)?; assert!(saved_block_index.status().is_ok()); - return Ok(reorg_occurred.then_some(saved_block_index)); + Ok(reorg_occurred.then_some(saved_block_index)) } Err(BlockIntegrationError::BlockCommitError(block_id, attempts_count, db_err)) => { - return Err(BlockError::DbCommitError( + Err(BlockError::DbCommitError( attempts_count, db_err, DbCommittingContext::Block(block_id), - )); - } - Err(BlockIntegrationError::OtherNonValidationError(err)) => { - return Err(err); + )) } + Err(BlockIntegrationError::OtherNonValidationError(err)) => Err(err), Err(BlockIntegrationError::ConnectBlockErrorDuringReorg( err, status, @@ -598,12 +600,12 @@ impl Chainstate ); // Don't save an "ok" status for a block that hasn't been persisted. } - return Err(err); + Err(err) } Err(BlockIntegrationError::OtherReorgError(err, _status)) => { log::warn!("An error occurred during reorg, but none of the blocks can be blamed"); // Don't save an "ok" status for a block that hasn't been persisted. - return Err(err); + Err(err) } Err(BlockIntegrationError::BlockCheckError(err, status)) => { // The failure occurred during the integration of the new block itself. @@ -626,9 +628,9 @@ impl Chainstate ); // Don't save an "ok" status for a block that hasn't been persisted. } - return Err(err); + Err(err) } - }; + } } /// If heavy checks are enabled, perform block index consistency check; panic if it's violated. @@ -726,6 +728,11 @@ impl Chainstate if let Some(best_block_index) = &best_block_index_opt { let best_block_index_ref = GenBlockIndexRef::Block(best_block_index); + // Note: while IBD is finishing, this can fail if the closing reckless-mode + // switch-off (forced db sync) keeps failing; the `?` then also skips the new + // tip event for this block. That is conservative degradation on a failing + // disk: the flag stays unset for retry, and tip events resume (including + // the pending block) once a sync succeeds. self.update_initial_block_download_flag(best_block_index_ref, false)?; self.broadcast_new_tip_event(best_block_index_ref, self.is_initial_block_download()); @@ -942,12 +949,15 @@ impl Chainstate .inc(&self.chainstate_config, &self.chainstate_storage)?; } } else { - self.is_initial_block_download_finished.set(); - + // Decrement before consuming the set-once flag: if the forced sync inside `dec` + // fails (e.g. EIO/ENOSPC right after a big IBD), the error propagates and a + // later tip update will retry the transition. Setting the flag first would + // strand the node in reckless mode (no fsync on commit) permanently. if !initial_update { self.reckless_mode_counter .dec(&self.chainstate_config, &self.chainstate_storage)?; } + self.is_initial_block_download_finished.set(); } Ok(()) @@ -1129,12 +1139,20 @@ impl DbRecklessModeCounter { storage: &S, ) -> Result<(), chainstate_storage::Error> { if config.db_reckless_mode_in_ibd_enabled() { - self.counter = self.counter.checked_sub(1).unwrap_or_else(|| { - debug_panic_or_log!("Reckless mode counter underflow"); - self.counter - }); + if self.counter == 1 { + // Switch the mode off first and only decrement on success, so that a + // failed sync (e.g. EIO/ENOSPC right after a big IBD) can be retried + // on a later call without underflowing the counter. + storage.set_reckless_mode(false)?; + } - if self.counter == 0 { + if self.counter > 0 { + self.counter -= 1; + } else { + // Underflow: recover by attempting the switch-off anyway, so that a + // previously failed switch-off cannot leave the node in reckless mode + // indefinitely. + log::warn!("Reckless mode counter underflow; retrying the switch-off"); storage.set_reckless_mode(false)?; } } diff --git a/chainstate/src/detail/perf_timing.rs b/chainstate/src/detail/perf_timing.rs index b7452d0621..de223f7c7c 100644 --- a/chainstate/src/detail/perf_timing.rs +++ b/chainstate/src/detail/perf_timing.rs @@ -1,3 +1,18 @@ +// Copyright (c) 2023 RBB S.r.l +// opensource@mintlayer.org +// SPDX-License-Identifier: MIT +// Licensed under the MIT License; +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // (experimental) Stage-timing instrumentation for IBD profiling. // // Enabled via ML_IBD_STAGE_TIMING=1. Accumulates wall-clock time spent in @@ -27,7 +42,8 @@ static ENABLED: std::sync::OnceLock = std::sync::OnceLock::new(); fn enabled() -> bool { *ENABLED.get_or_init(|| { - std::env::var("ML_IBD_STAGE_TIMING").is_ok_and(|v| v != "0" && !v.eq_ignore_ascii_case("false")) + std::env::var("ML_IBD_STAGE_TIMING") + .is_ok_and(|v| v != "0" && !v.eq_ignore_ascii_case("false")) }) } @@ -129,6 +145,7 @@ impl Drop for WindowGuard { } } +#[allow(clippy::float_arithmetic)] // percentages and ms/block of the report fn log_summary(window_blocks: usize, window: Duration) { let mut accounted_ns = 0u64; let stage_lines: Vec = STAGES diff --git a/chainstate/src/detail/test.rs b/chainstate/src/detail/test.rs index 7f01ef8df6..21dc94f922 100644 --- a/chainstate/src/detail/test.rs +++ b/chainstate/src/detail/test.rs @@ -109,3 +109,74 @@ fn empty_chainstate_no_genesis() { let _ = chainstate.query().unwrap().get_best_block_id(); }) } + +/// A failed switch-off of the reckless mode (e.g. an IO error during the forced sync +/// right after a large IBD) must not consume the counter nor panic on retry: the next +/// `dec` must retry the switch-off, and a spurious extra decrement must recover instead +/// of underflowing. +#[test] +fn reckless_mode_counter_retry_after_failed_switch_off() { + use chainstate_storage::mock::MockStore; + use std::sync::atomic::{AtomicBool, Ordering}; + + let config = crate::config::ChainstateConfig { + enable_db_reckless_mode_in_ibd: Some(true), + ..Default::default() + }; + + let mut storage = MockStore::default(); + let fail_next_switch_off = AtomicBool::new(true); + let mut seq = mockall::Sequence::new(); + + // inc: switch the mode on + storage + .expect_set_reckless_mode() + .times(1) + .in_sequence(&mut seq) + .returning(|set: bool| { + assert!(set); + Ok(()) + }); + // dec #1: the forced sync fails, simulating an IO error after a big IBD + storage.expect_set_reckless_mode().times(1).in_sequence(&mut seq).returning( + move |_set: bool| { + if fail_next_switch_off.swap(false, Ordering::SeqCst) { + Err(chainstate_storage::Error::Storage( + storage::error::Recoverable::TransactionFailed, + )) + } else { + Ok(()) + } + }, + ); + // dec #2: the retry succeeds + storage + .expect_set_reckless_mode() + .times(1) + .in_sequence(&mut seq) + .returning(|_set: bool| Ok(())); + // dec #3: a spurious extra decrement attempts the (idempotent) switch-off again + storage + .expect_set_reckless_mode() + .times(1) + .in_sequence(&mut seq) + .returning(|_set: bool| Ok(())); + + let mut counter = DbRecklessModeCounter::new(); + + counter.inc(&config, &storage).unwrap(); + assert_eq!(counter.counter, 1); + + // The failed switch-off must propagate its error without decrementing the counter. + assert!(counter.dec(&config, &storage).is_err()); + assert_eq!(counter.counter, 1); + + // The retry must succeed and empty the counter. + counter.dec(&config, &storage).unwrap(); + assert_eq!(counter.counter, 0); + + // A spurious extra decrement must not panic (including debug builds) and must + // attempt the switch-off again. + counter.dec(&config, &storage).unwrap(); + assert_eq!(counter.counter, 0); +} diff --git a/chainstate/src/detail/tx_verification_strategy/mod.rs b/chainstate/src/detail/tx_verification_strategy/mod.rs index 1e2df7cee1..c0a708a5d9 100644 --- a/chainstate/src/detail/tx_verification_strategy/mod.rs +++ b/chainstate/src/detail/tx_verification_strategy/mod.rs @@ -46,6 +46,11 @@ impl TransactionVerifierMakerFn for F whe } /// A trait that specifies how a block will be verified +/// The output of [`TransactionVerificationStrategy::connect_block`]: the +/// transaction verifier for the connected block, and the per-transaction +/// fees of the block. +type ConnectBlockOutput = (TransactionVerifier, BlockTxFees); + pub trait TransactionVerificationStrategy: Sized + Send { /// Connect the transactions given by block and block_index, /// and return a TransactionVerifier with an internal state @@ -62,7 +67,7 @@ pub trait TransactionVerificationStrategy: Sized + Send { block_index: &BlockIndex, block: &WithId, median_time_past: BlockTimestamp, - ) -> Result<(TransactionVerifier, BlockTxFees), ConnectTransactionError> + ) -> Result, ConnectTransactionError> where S: TransactionVerifierStorageRef, U: UtxosView, diff --git a/chainstate/src/interface/chainstate_interface_impl_delegation.rs b/chainstate/src/interface/chainstate_interface_impl_delegation.rs index 3df9ace6b7..a3e02d2995 100644 --- a/chainstate/src/interface/chainstate_interface_impl_delegation.rs +++ b/chainstate/src/interface/chainstate_interface_impl_delegation.rs @@ -23,9 +23,8 @@ use std::{ use chainstate_types::{BlockIndex, EpochData, GenBlockIndex, Locator}; use common::{ chain::{ - AccountNonce, AccountType, Block, BlockTxFees, Currency, DelegationId, GenBlock, - OrderId, PoolId, - RpcOrderInfo, Transaction, TxInput, UtxoOutPoint, + AccountNonce, AccountType, Block, BlockTxFees, Currency, DelegationId, GenBlock, OrderId, + PoolId, RpcOrderInfo, Transaction, TxInput, UtxoOutPoint, block::{BlockReward, signed_block_header::SignedBlockHeader, timestamp::BlockTimestamp}, config::ChainConfig, tokens::{RPCTokenInfo, TokenAuxiliaryData, TokenId}, diff --git a/chainstate/src/rpc/mod.rs b/chainstate/src/rpc/mod.rs index c971d61e7a..66d36c2892 100644 --- a/chainstate/src/rpc/mod.rs +++ b/chainstate/src/rpc/mod.rs @@ -331,9 +331,7 @@ impl ChainstateRpcServer for super::ChainstateHandle { } async fn get_block_tx_fees(&self, block_id: Id) -> RpcResult> { - rpc::handle_result( - self.call(move |this| this.get_block_tx_fees(&block_id)).await, - ) + rpc::handle_result(self.call(move |this| this.get_block_tx_fees(&block_id)).await) } async fn submit_block(&self, block: HexEncoded) -> RpcResult<()> { diff --git a/chainstate/storage/src/internal/blockchain_storage.rs b/chainstate/storage/src/internal/blockchain_storage.rs index eb92ab8342..842f9c98fc 100644 --- a/chainstate/storage/src/internal/blockchain_storage.rs +++ b/chainstate/storage/src/internal/blockchain_storage.rs @@ -41,12 +41,13 @@ pub trait BlockchainStorage: for<'tx> Transactional<'tx> + Send { #[cfg(feature = "lmdb")] impl BlockchainStorageBackendImpl for LmdbImpl { fn set_reckless_mode(&self, set: bool) -> crate::Result<()> { - // When switching the reckless mode off, do a sync immediately. - let force_sync = self.in_reckless_mode()? && !set; - + // Note: when switching the reckless mode off, always do a sync immediately, even + // if a previous switch-off attempt already cleared `no_sync_on_commit` but failed + // to sync (e.g. because of an IO error): the sync is idempotent, and skipping it + // would leave the database unsynced while reporting success. self.set_no_sync_on_commit(set); - if force_sync { + if !set { self.force_sync()?; } diff --git a/chainstate/storage/src/mock/mock_impl.rs b/chainstate/storage/src/mock/mock_impl.rs index dc55b1e2d3..289934d54b 100644 --- a/chainstate/storage/src/mock/mock_impl.rs +++ b/chainstate/storage/src/mock/mock_impl.rs @@ -22,8 +22,9 @@ use chainstate_types::{ seal::{BlockSeal, DuplicateSealEvidence, SealIndexEntry}, }; use common::{ - chain::{ BlockTxFees, - AccountNonce, AccountType, Block, DelegationId, GenBlock, OrderId, PoolId, UtxoOutPoint, + chain::{ + AccountNonce, AccountType, Block, BlockTxFees, DelegationId, GenBlock, OrderId, PoolId, + UtxoOutPoint, block::{BlockReward, signed_block_header::SignedBlockHeader}, config::{EpochIndex, MagicBytes}, tokens::{TokenAuxiliaryData, TokenId}, diff --git a/chainstate/storage/src/schema.rs b/chainstate/storage/src/schema.rs index 4a524d2d37..3fa59bd771 100644 --- a/chainstate/storage/src/schema.rs +++ b/chainstate/storage/src/schema.rs @@ -21,9 +21,8 @@ use chainstate_types::{ }; use common::{ chain::{ - AccountNonce, AccountType, Block, DelegationId, GenBlock, OrderId, PoolId, Transaction, - BlockTxFees, - UtxoOutPoint, + AccountNonce, AccountType, Block, BlockTxFees, DelegationId, GenBlock, OrderId, PoolId, + Transaction, UtxoOutPoint, config::EpochIndex, tokens::{TokenAuxiliaryData, TokenId}, }, diff --git a/chainstate/test-suite/benches/benches.rs b/chainstate/test-suite/benches/benches.rs index acc01b5b27..192442cef4 100644 --- a/chainstate/test-suite/benches/benches.rs +++ b/chainstate/test-suite/benches/benches.rs @@ -88,7 +88,7 @@ pub fn pos_ibd_linear_connect(c: &mut Criterion) { tf.create_chain_pos( &mut rng, &tf.genesis().get_id().into(), - 5, + 5, genesis_pool_id, &staking_sk, &vrf_sk, diff --git a/chainstate/test-suite/src/tests/bootstrap.rs b/chainstate/test-suite/src/tests/bootstrap.rs index 758038450c..9d4d23d00e 100644 --- a/chainstate/test-suite/src/tests/bootstrap.rs +++ b/chainstate/test-suite/src/tests/bootstrap.rs @@ -749,7 +749,7 @@ fn check_reckless_mode( pos_seal_duplication_tracking: Default::default(), }) .build(); - // (review fix) library default stays opt-in, matching master. + // library default stays opt-in, matching master. let use_reckless_mode = enable_db_reckless_mode_in_ibd.unwrap_or(false); let dest_tf_store = dest_tf.storage.clone(); diff --git a/chainstate/test-suite/src/tests/homomorphism.rs b/chainstate/test-suite/src/tests/homomorphism.rs index 383879313c..5ce80d7ab0 100644 --- a/chainstate/test-suite/src/tests/homomorphism.rs +++ b/chainstate/test-suite/src/tests/homomorphism.rs @@ -15,22 +15,22 @@ use super::*; use chainstate_storage::Transactional; +use chainstate_storage::schema::{DBBlockTxFees, Schema}; use chainstate_test_framework::{ TestFramework, TestStore, TransactionBuilder, TxVerificationStrategy, anyonecanspend_address, create_stake_pool_data_with_all_reward_to_staker, empty_witness, }; use common::{ chain::{ - AccountCommand, AccountNonce, BlockTxFees, Destination, OutPointSourceId, PoolId, TxInput, - TxOutput, UtxoOutPoint, make_delegation_id, make_token_id, output_value::OutputValue, + AccountCommand, AccountNonce, Destination, OutPointSourceId, PoolId, TxInput, TxOutput, + UtxoOutPoint, make_delegation_id, make_token_id, output_value::OutputValue, timelock::OutputTimeLock, tokens::TokenIssuance, }, primitives::{Amount, Idable}, }; +use crypto::vrf::{VRFKeyKind, VRFPrivateKey}; use storage::StorageContents; use storage::schema::HasDbMap; -use chainstate_storage::schema::{DBBlockTxFees, Schema}; -use crypto::vrf::{VRFKeyKind, VRFPrivateKey}; use test_utils::token_utils::random_token_issuance_v1; // These tests prove that TransactionVerifiers hierarchy has homomorphic property: f(ab) == f(a)f(b) @@ -411,12 +411,8 @@ fn pos_accounting_homomorphism(#[case] seed: Seed) { /// (experimental step 9) Compare the full raw dumps of the two storages, /// excluding the strategy-dependent per-transaction fee records (the /// Disposable strategy skips full verification and cannot produce fees). -fn assert_dumps_equal_excluding_fees( - storage1: &TestStore, - storage2: &TestStore, -) { - let fee_map_index = - >::INDEX; +fn assert_dumps_equal_excluding_fees(storage1: &TestStore, storage2: &TestStore) { + let fee_map_index = >::INDEX; let filter = |dump: &mut StorageContents| { dump.retain(|map_id, _| map_id.as_core() != fee_map_index); }; diff --git a/chainstate/test-suite/src/tests/pos_accounting_reorg.rs b/chainstate/test-suite/src/tests/pos_accounting_reorg.rs index 0504d48840..216c6e83fd 100644 --- a/chainstate/test-suite/src/tests/pos_accounting_reorg.rs +++ b/chainstate/test-suite/src/tests/pos_accounting_reorg.rs @@ -19,7 +19,6 @@ use super::helpers::new_pub_key_destination; use accounting::{DataDelta, DeltaAmountCollection, DeltaDataCollection}; use chainstate::BlockSource; -use storage::StorageContents; use chainstate_storage::{BlockchainStorageWrite, TransactionRw, Transactional}; use chainstate_test_framework::{ TestFramework, TestStore, TransactionBuilder, anyonecanspend_address, diff --git a/chainstate/test-suite/src/tests/syncing_tests.rs b/chainstate/test-suite/src/tests/syncing_tests.rs index 652d5ba221..72908f28ce 100644 --- a/chainstate/test-suite/src/tests/syncing_tests.rs +++ b/chainstate/test-suite/src/tests/syncing_tests.rs @@ -749,7 +749,7 @@ fn initial_block_download( }) .with_initial_time_since_genesis(2) .build(); - // (review fix) library default stays opt-in, matching master. + // library default stays opt-in, matching master. let use_reckless_mode = enable_db_reckless_mode_in_ibd.unwrap_or(false); // We are two seconds after genesis timestamp, so in the IBD state diff --git a/chainstate/test-suite/src/tests/tx_verification_simulation.rs b/chainstate/test-suite/src/tests/tx_verification_simulation.rs index 5eb91a8f93..75d9af62a8 100644 --- a/chainstate/test-suite/src/tests/tx_verification_simulation.rs +++ b/chainstate/test-suite/src/tests/tx_verification_simulation.rs @@ -1,4 +1,3 @@ -use storage::StorageContents; // Copyright (c) 2022 RBB S.r.l // opensource@mintlayer.org // SPDX-License-Identifier: MIT diff --git a/chainstate/test-suite/tests/pos_ibd_perf.rs b/chainstate/test-suite/tests/pos_ibd_perf.rs index d967bdb285..25741285e1 100644 --- a/chainstate/test-suite/tests/pos_ibd_perf.rs +++ b/chainstate/test-suite/tests/pos_ibd_perf.rs @@ -1,3 +1,18 @@ +// Copyright (c) 2023 RBB S.r.l +// opensource@mintlayer.org +// SPDX-License-Identifier: MIT +// Licensed under the MIT License; +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // (experimental) Decomposes PoS block cost into building vs chainstate processing. // Run: cargo test -p chainstate-test-suite --release --test pos_ibd_perf -- --ignored --nocapture // diff --git a/common/src/chain/block/mod.rs b/common/src/chain/block/mod.rs index 2cabf282e9..0ba03559bc 100644 --- a/common/src/chain/block/mod.rs +++ b/common/src/chain/block/mod.rs @@ -25,10 +25,11 @@ pub use crate::chain::{ pub mod block_body; pub mod block_header; pub mod block_size; -pub mod tx_fees; pub mod consensus_data; pub mod signed_block_header; pub mod timestamp; +pub mod tx_fees; +pub use tx_fees::BlockTxFees; mod block_reward; mod block_v1; @@ -469,5 +470,3 @@ mod tests { check_block_tag(&block); } } - -pub use tx_fees::BlockTxFees; diff --git a/common/src/chain/block/tx_fees.rs b/common/src/chain/block/tx_fees.rs index b7a7e43a40..2d0a8e4280 100644 --- a/common/src/chain/block/tx_fees.rs +++ b/common/src/chain/block/tx_fees.rs @@ -32,6 +32,4 @@ impl rpc_description::HasValueHint for BlockTxFees { const HINT_DE: rpc_description::ValueHint = rpc_description::ValueHint::GENERIC_OBJECT; } -impl BlockTxFees { - -} +impl BlockTxFees {} diff --git a/common/src/primitives/mod.rs b/common/src/primitives/mod.rs index 292bc53a97..26cfe655a0 100644 --- a/common/src/primitives/mod.rs +++ b/common/src/primitives/mod.rs @@ -37,7 +37,19 @@ pub use version_tag::VersionTag; use crate::chain::{output_value::OutputValue, tokens::TokenId}; use serialization::{Decode, Encode}; -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encode, Decode, serde::Serialize, serde::Deserialize)] +#[derive( + Debug, + Copy, + Clone, + PartialEq, + Eq, + PartialOrd, + Ord, + Encode, + Decode, + serde::Serialize, + serde::Deserialize, +)] pub struct Fee(pub Amount); impl rpc_description::HasValueHint for Fee { diff --git a/deny.toml b/deny.toml index c41817824c..b6d431259f 100644 --- a/deny.toml +++ b/deny.toml @@ -52,4 +52,11 @@ ignore = [ # the 0.26.x line (pulled in via `rustls-platform-verifier`) has no # release with the root removed yet. "RUSTSEC-2026-0383", + + # "pin-utils" is unmaintained: the upstream repository was archived in + # October 2026 (shortly after releasing 0.1.1) and the advisory covers + # every published version, so no lockfile update can clear it. The crate + # is pulled in transitively by "futures", which requires the 0.1.x line; + # this entry can go away when "futures" drops the dependency. + "RUSTSEC-2026-0441", ] diff --git a/mocks/src/chainstate.rs b/mocks/src/chainstate.rs index bf617f2939..7587a81474 100644 --- a/mocks/src/chainstate.rs +++ b/mocks/src/chainstate.rs @@ -26,8 +26,7 @@ use chainstate_types::{BlockIndex, EpochData, GenBlockIndex}; use common::{ chain::{ AccountNonce, AccountType, BlockTxFees, ChainConfig, Currency, DelegationId, OrderId, - PoolId, - RpcOrderInfo, TxInput, UtxoOutPoint, + PoolId, RpcOrderInfo, TxInput, UtxoOutPoint, block::{ Block, BlockReward, GenBlock, signed_block_header::SignedBlockHeader, timestamp::BlockTimestamp, diff --git a/node-daemon/docs/RPC.md b/node-daemon/docs/RPC.md index aa593bd902..1e46b0a219 100644 --- a/node-daemon/docs/RPC.md +++ b/node-daemon/docs/RPC.md @@ -200,6 +200,27 @@ EITHER OF 2) null ``` +### Method `chainstate_get_block_tx_fees` + +(experimental) Returns the per-transaction fees of a mainchain block, +ordered by transaction index within the block. Fees are computed and +persisted by the consensus layer at block connection time. + +Returns `None` (null) if the block predates fee persistence. + + +Parameters: +``` +{ "block_id": hex string } +``` + +Returns: +``` +EITHER OF + 1) object + 2) null +``` + ### Method `chainstate_submit_block` Submit a block to be included in the blockchain. diff --git a/node-lib/Cargo.toml b/node-lib/Cargo.toml index 09b97fa39b..70caffc54b 100644 --- a/node-lib/Cargo.toml +++ b/node-lib/Cargo.toml @@ -43,6 +43,7 @@ randomness = { path = "../randomness" } ctor.workspace = true rstest.workspace = true tempfile.workspace = true +serial_test.workspace = true [build-dependencies] build_utils = { path = "../utils/build_utils" } diff --git a/node-lib/src/options.rs b/node-lib/src/options.rs index 1e227649bb..f79d3c5797 100644 --- a/node-lib/src/options.rs +++ b/node-lib/src/options.rs @@ -128,7 +128,7 @@ pub struct TopLevelOptions { /// Create the data directory if it is missing; the default value depends on whether /// a custom data directory is used (false for a custom directory, true for the default one). - #[clap(long = "create-datadir-if-missing", value_name = "VAL")] + #[clap(long = "create-datadir-if-missing", value_name = "true|false", action = clap::ArgAction::Set)] pub create_data_dir_if_missing: Option, /// Log to a file. @@ -139,7 +139,7 @@ pub struct TopLevelOptions { /// The log level used in this case doesn't depend on the RUST_LOG env variable and is always INFO. /// /// By default, the option is enabled for node-gui and disabled for node-daemon. - #[clap(long, action = clap::ArgAction::Set)] + #[clap(long, value_name = "true|false", action = clap::ArgAction::Set)] pub log_to_file: Option, /// If specified, the application will clean the data directory and exit immediately. @@ -334,12 +334,12 @@ pub struct RunOptions { /// Genesis. If used on a node that is not starting from Genesis, /// the node may produce blocks from the past, which will lead /// to being banned by the network. - #[clap(long, action = clap::ArgAction::SetTrue)] + #[clap(long, action = clap::ArgAction::Set, value_name = "true|false")] pub blockprod_skip_ibd_check: Option, /// If true, blocks with non-PoS consensus types will always be created with timestamps /// bigger than or equal to the current time. - #[clap(long, action = clap::ArgAction::SetTrue)] + #[clap(long, action = clap::ArgAction::Set, value_name = "true|false")] #[arg(hide = true)] pub blockprod_use_current_time_if_non_pos: Option, @@ -373,7 +373,15 @@ pub struct RunOptions { /// Additionally, the corruption may not be detectable by the db engine, in which case you'll /// end up having a malfunctioning node. Therefore, if you are using the reckless mode and /// the system crashes in the process, always delete the db and re-sync, just in case. - #[clap(long, action = clap::ArgAction::SetTrue)] + /// + /// Note: the value must be explicit (`true`/`false`) because the node daemon enables the + /// reckless mode by default when this option is not set anywhere; a value-less boolean + /// flag would make the flag's absence look like an explicit opt-out. + // Implementation note: an explicit `ArgAction::Set` is what makes the absence of the + // flag yield `None`. clap's `SetTrue` action on an `Option` materializes `Some(false)` + // for an absent flag, which would look like an explicit `false` to the code below and + // would defeat the daemon's default-on behavior as well as config-file values. + #[clap(long, action = clap::ArgAction::Set, value_name = "true|false")] pub enable_db_reckless_mode_in_ibd: Option, /// The maximum capacity of the orphan blocks pool in blocks. @@ -389,7 +397,7 @@ pub struct RunOptions { pub mempool_max_cluster_size_bytes: Option, /// Whether p2p networking should be enabled. - #[clap(long, value_name = "VAL")] + #[clap(long, value_name = "true|false", action = clap::ArgAction::Set)] pub p2p_networking_enabled: Option, /// Addresses to bind P2P to. @@ -402,7 +410,7 @@ pub struct RunOptions { pub p2p_socks5_proxy: Option, /// Disable p2p encryption (for tests only). - #[clap(long, action = clap::ArgAction::SetTrue)] + #[clap(long, action = clap::ArgAction::Set, value_name = "true|false")] #[arg(hide = true)] pub p2p_disable_noise: Option, @@ -459,7 +467,7 @@ pub struct RunOptions { // remove them. /// If true, the node will perform an early dns query if the peer db doesn't contain /// any global addresses at startup. - #[clap(long, action = clap::ArgAction::SetTrue)] + #[clap(long, action = clap::ArgAction::Set, value_name = "true|false")] #[arg(hide = true)] pub p2p_force_dns_query_if_no_global_addresses_known: Option, @@ -485,7 +493,7 @@ pub struct RunOptions { pub rpc_bind_address: Option, /// Enable/Disable http RPC. - #[clap(long, value_name = "VAL")] + #[clap(long, value_name = "true|false", action = clap::ArgAction::Set)] pub rpc_enabled: Option, /// Username for RPC server basic authorization. @@ -512,11 +520,11 @@ pub struct RunOptions { /// If true, additional computationally-expensive consistency checks will be performed by the chainstate. /// Defaults to true for regtest and false in other cases. - #[clap(long, value_name = "VAL")] + #[clap(long, value_name = "true|false", action = clap::ArgAction::Set)] pub enable_chainstate_heavy_checks: Option, /// If true, blocks and block headers will not be rejected if checkpoints mismatch is detected. - #[clap(long, action = clap::ArgAction::SetTrue, hide = true)] + #[clap(long, action = clap::ArgAction::Set, value_name = "true|false", hide = true)] pub allow_checkpoints_mismatch: Option, /// Path to a CSV file with custom checkpoints that must be used instead of the predefined ones. @@ -667,6 +675,122 @@ mod tests { } } +#[cfg(test)] +mod reckless_mode_option_tests { + use super::*; + + const RECKLESS_MODE_ENV_VAR: &str = "ML_MAINNET_NODE_ENABLE_DB_RECKLESS_MODE_IN_IBD"; + + /// Clears the variable on construction (so an ambient environment cannot interfere + /// with a test) and on drop (so a failing assertion cannot leak it into sibling + /// tests). Must only be used from `#[serial_test::serial]`-serialized tests. + struct EnvVarGuard(&'static str); + + impl EnvVarGuard { + fn cleared(name: &'static str) -> Self { + // SAFETY: the tests using this guard are `#[serial_test::serial]`-serialized. + unsafe { std::env::remove_var(name) }; + Self(name) + } + + fn set(&self, value: &str) { + // SAFETY: see `cleared`. + unsafe { std::env::set_var(self.0, value) }; + } + } + + impl Drop for EnvVarGuard { + fn drop(&mut self) { + // SAFETY: see `cleared`. + unsafe { std::env::remove_var(self.0) }; + } + } + + fn parse_mainnet_run_options(args: &[&str]) -> RunOptions { + let full_args = std::iter::once("mintlayerd").chain(args.iter().copied()); + let options = ::try_parse_from(full_args) + .unwrap_or_else(|err| panic!("arguments must parse: {err}")); + match options.with_resolved_command().command { + Command::Mainnet(run_options) => run_options, + _ => panic!("expected the mainnet subcommand"), + } + } + + // Regression: `--enable-db-reckless-mode-in-ibd` used to be a value-less flag + // (`ArgAction::SetTrue`), so not passing it produced `Some(false)`, which the node + // runner treats as an explicit opt-out from the reckless-mode-by-default IBD + // behavior. The flag now requires an explicit value, so its absence must yield + // `None` for the default to kick in. + // These tests parse arguments, and parsing reads `ML_*` environment variables, so + // they must not run concurrently with the tests that set those variables. + #[test] + #[serial_test::serial] + fn reckless_mode_flag_absent_yields_none() { + let _env_guard = EnvVarGuard::cleared(RECKLESS_MODE_ENV_VAR); + let run_options = parse_mainnet_run_options(&["mainnet"]); + assert_eq!(run_options.enable_db_reckless_mode_in_ibd, None); + // The other boolean options use the same explicit-value pattern; their absence must + // also yield `None` so that a value from the configuration file can take precedence. + assert_eq!(run_options.blockprod_skip_ibd_check, None); + assert_eq!(run_options.blockprod_use_current_time_if_non_pos, None); + assert_eq!(run_options.p2p_disable_noise, None); + assert_eq!( + run_options.p2p_force_dns_query_if_no_global_addresses_known, + None + ); + assert_eq!(run_options.allow_checkpoints_mismatch, None); + } + + #[test] + #[serial_test::serial] + fn reckless_mode_flag_accepts_explicit_values() { + let _env_guard = EnvVarGuard::cleared(RECKLESS_MODE_ENV_VAR); + let run_options = + parse_mainnet_run_options(&["mainnet", "--enable-db-reckless-mode-in-ibd", "true"]); + assert_eq!(run_options.enable_db_reckless_mode_in_ibd, Some(true)); + + let run_options = + parse_mainnet_run_options(&["mainnet", "--enable-db-reckless-mode-in-ibd", "false"]); + assert_eq!(run_options.enable_db_reckless_mode_in_ibd, Some(false)); + } + + #[test] + #[serial_test::serial] + fn reckless_mode_flag_without_a_value_is_rejected() { + let _env_guard = EnvVarGuard::cleared(RECKLESS_MODE_ENV_VAR); + let full_args = ["mintlayerd", "mainnet", "--enable-db-reckless-mode-in-ibd"]; + assert!(::try_parse_from(full_args).is_err()); + } + + #[test] + #[serial_test::serial] + fn reckless_mode_env_var_value_reaches_parsing() { + // The env var name is derived from the long option name by + // `clap_utils::env_adder`; the env layer of the precedence chain must keep + // working: an env var with a valid value wins when the CLI flag is absent, + // and an invalid value must be rejected. + let env_guard = EnvVarGuard::cleared(RECKLESS_MODE_ENV_VAR); + + env_guard.set("true"); + let run_options = parse_mainnet_run_options(&["mainnet"]); + assert_eq!(run_options.enable_db_reckless_mode_in_ibd, Some(true)); + + env_guard.set("false"); + let run_options = parse_mainnet_run_options(&["mainnet"]); + assert_eq!(run_options.enable_db_reckless_mode_in_ibd, Some(false)); + } + + #[test] + #[serial_test::serial] + fn reckless_mode_env_var_with_invalid_value_is_rejected() { + let env_guard = EnvVarGuard::cleared(RECKLESS_MODE_ENV_VAR); + + env_guard.set("not-a-bool"); + let result = ::try_parse_from(["mintlayerd", "mainnet"]); + assert!(result.is_err()); + } +} + #[cfg(test)] mod redacted_tests { use super::*; diff --git a/node-lib/src/runner.rs b/node-lib/src/runner.rs index 2c7e287e48..82811ca167 100644 --- a/node-lib/src/runner.rs +++ b/node-lib/src/runner.rs @@ -96,11 +96,11 @@ async fn initialize( // user configured it explicitly. The library default remains opt-in, so // this branch's behavior cannot leak through cherry-picked library code. let mut chainstate_config = node_config.chainstate.clone().unwrap_or_default(); - if chainstate_config - .chainstate_config - .enable_db_reckless_mode_in_ibd - .is_none() - { + if chainstate_config.chainstate_config.enable_db_reckless_mode_in_ibd.is_none() { + log::info!( + "db reckless mode enabled by default during IBD (db sync disabled); \ + set --enable-db-reckless-mode-in-ibd=false to opt out" + ); chainstate_config.chainstate_config.enable_db_reckless_mode_in_ibd = Some(true); } let chainstate_maker = chainstate_launcher::create_chainstate_maker( diff --git a/node-lib/tests/cli.rs b/node-lib/tests/cli.rs index e969ad12e4..d05aab844d 100644 --- a/node-lib/tests/cli.rs +++ b/node-lib/tests/cli.rs @@ -339,3 +339,42 @@ fn read_config_override_values() { assert_eq!(config.chainstate.unwrap().storage_backend, backend_type); } + +// Regression: a boolean option set in the config file must survive when the corresponding +// command-line flag is absent. This pins the end-to-end path: clap leaves the flag as `None` +// when it is absent (it used to materialize `Some(false)`, silently overruling the config +// file), and the `or()` merge chain then lets the config file value win. +#[test] +fn config_file_boolean_value_survives_when_cli_flag_absent() { + // Parsing reads `ML_*` environment variables; clear the one this test is about so + // an ambient environment cannot interfere. + // SAFETY: this test binary never sets environment variables, so there is no + // concurrent mutation to serialize against. + unsafe { std::env::remove_var("ML_MAINNET_NODE_ENABLE_DB_RECKLESS_MODE_IN_IBD") }; + + let data_dir = TempDir::new().unwrap(); + + let config_path = data_dir.path().join(CONFIG_NAME); + std::fs::write( + &config_path, + "[chainstate]\nenable_db_reckless_mode_in_ibd = true\n", + ) + .unwrap(); + + let chain_config = create_testnet(); + let options = + match ::try_parse_from(["mintlayerd", "mainnet"]) + .unwrap() + .with_resolved_command() + .command + { + node_lib::Command::Mainnet(run_options) => run_options, + _ => unreachable!("the mainnet subcommand was requested"), + }; + let config = NodeConfigFile::read(&chain_config, &config_path, &options).unwrap(); + + assert_eq!( + config.chainstate.unwrap().chainstate_config.enable_db_reckless_mode_in_ibd, + Some(true) + ); +} diff --git a/storage/src/lib.rs b/storage/src/lib.rs index a40ebc014b..90627d950b 100644 --- a/storage/src/lib.rs +++ b/storage/src/lib.rs @@ -105,8 +105,8 @@ pub use storage_core::{ }; // Re-export the interface types -pub use database::*; pub use database::StorageContents; +pub use database::*; #[cfg(test)] mod test; diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index 3cf4fb9c56..00160da8ef 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -1,7 +1,10 @@ # cargo-vet audits file -[audits] +[[audits.libc]] +criteria = "safe-to-deploy" +delta = "0.2.180 -> 0.2.183" +notes = """Reviewed the 0.2.180...0.2.183 diff: new platform constant and FFI declarations (linux_uapi can/pidfd, netbsd, qurt), fuchsia updates, and test additions; no new unsafe semantics beyond the crate's standard extern "C" declarations.""" [[trusted.aead]] criteria = "safe-to-deploy" diff --git a/supply-chain/config.toml b/supply-chain/config.toml index 6f06d188c0..d087a0cebe 100644 --- a/supply-chain/config.toml +++ b/supply-chain/config.toml @@ -211,10 +211,6 @@ criteria = "safe-to-deploy" version = "1.1.0" criteria = "safe-to-deploy" -[[exemptions.chacha20]] -version = "0.10.2" -criteria = "safe-to-deploy" - [[exemptions.clap_complete]] version = "4.6.9" criteria = "safe-to-deploy" @@ -1135,10 +1131,6 @@ criteria = "safe-to-deploy" version = "0.10.0" criteria = "safe-to-deploy" -[[exemptions.rand_core]] -version = "0.10.1" -criteria = "safe-to-deploy" - [[exemptions.range-alloc]] version = "0.1.4" criteria = "safe-to-deploy" @@ -1187,10 +1179,6 @@ criteria = "safe-to-deploy" version = "0.15.4" criteria = "safe-to-deploy" -[[exemptions.ring]] -version = "0.17.14" -criteria = "safe-to-deploy" - [[exemptions.rkyv]] version = "0.7.46" criteria = "safe-to-deploy" @@ -1403,10 +1391,6 @@ criteria = "safe-to-deploy" version = "0.1.19" criteria = "safe-to-deploy" -[[exemptions.sync_wrapper]] -version = "1.0.2" -criteria = "safe-to-deploy" - [[exemptions.sys-locale]] version = "0.3.2" criteria = "safe-to-deploy" @@ -1487,10 +1471,6 @@ criteria = "safe-to-deploy" version = "0.2.0" criteria = "safe-to-deploy" -[[exemptions.untrusted]] -version = "0.9.0" -criteria = "safe-to-deploy" - [[exemptions.unwrap-infallible]] version = "1.0.0" criteria = "safe-to-deploy" @@ -1587,10 +1567,6 @@ criteria = "safe-to-deploy" version = "0.3.85" criteria = "safe-to-deploy" -[[exemptions.web-time]] -version = "1.1.0" -criteria = "safe-to-deploy" - [[exemptions.wgpu]] version = "0.19.4" criteria = "safe-to-deploy" diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index fd907d50e1..2a37de8d3a 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -996,8 +996,8 @@ user-login = "seanmonstar" user-name = "Sean McArthur" [[publisher.mio]] -version = "1.1.1" -when = "2025-12-04" +version = "1.2.4" +when = "2026-10-03" user-id = 6025 user-login = "Thomasdezeeuw" user-name = "Thomas de Zeeuw" @@ -1330,6 +1330,13 @@ user-id = 359 user-login = "seanmonstar" user-name = "Sean McArthur" +[[publisher.ring]] +version = "0.17.11" +when = "2025-02-22" +user-id = 2751 +user-login = "ctz" +user-name = "Joe Birr-Pixton" + [[publisher.ripemd]] version = "0.1.3" when = "2022-09-23" @@ -1562,8 +1569,8 @@ user-login = "Thomasdezeeuw" user-name = "Thomas de Zeeuw" [[publisher.socket2]] -version = "0.6.2" -when = "2026-01-23" +version = "0.6.5" +when = "2026-07-13" user-id = 6025 user-login = "Thomasdezeeuw" user-name = "Thomas de Zeeuw" @@ -1589,6 +1596,13 @@ user-id = 3618 user-login = "dtolnay" user-name = "David Tolnay" +[[publisher.syn]] +version = "3.0.9" +when = "2026-10-12" +user-id = 3618 +user-login = "dtolnay" +user-name = "David Tolnay" + [[publisher.termcolor]] version = "1.4.1" when = "2024-01-10" @@ -1646,15 +1660,15 @@ user-login = "Manishearth" user-name = "Manish Goregaokar" [[publisher.tokio]] -version = "1.50.0" -when = "2026-03-03" +version = "1.51.6" +when = "2026-10-13" user-id = 6741 user-login = "Darksonn" user-name = "Alice Ryhl" [[publisher.tokio-macros]] -version = "2.6.1" -when = "2026-03-02" +version = "2.7.2" +when = "2026-07-29" user-id = 6741 user-login = "Darksonn" user-name = "Alice Ryhl" @@ -2109,13 +2123,6 @@ user-id = 64539 user-login = "kennykerr" user-name = "Kenny Kerr" -[[publisher.windows-sys]] -version = "0.60.2" -when = "2025-06-12" -user-id = 64539 -user-login = "kennykerr" -user-name = "Kenny Kerr" - [[publisher.windows-sys]] version = "0.61.2" when = "2025-10-06" @@ -2144,13 +2151,6 @@ user-id = 64539 user-login = "kennykerr" user-name = "Kenny Kerr" -[[publisher.windows-targets]] -version = "0.53.5" -when = "2025-10-06" -user-id = 64539 -user-login = "kennykerr" -user-name = "Kenny Kerr" - [[publisher.windows-threading]] version = "0.1.0" when = "2025-05-15" @@ -2179,13 +2179,6 @@ user-id = 64539 user-login = "kennykerr" user-name = "Kenny Kerr" -[[publisher.windows_aarch64_gnullvm]] -version = "0.53.1" -when = "2025-10-06" -user-id = 64539 -user-login = "kennykerr" -user-name = "Kenny Kerr" - [[publisher.windows_aarch64_msvc]] version = "0.42.2" when = "2023-03-13" @@ -2207,13 +2200,6 @@ user-id = 64539 user-login = "kennykerr" user-name = "Kenny Kerr" -[[publisher.windows_aarch64_msvc]] -version = "0.53.1" -when = "2025-10-06" -user-id = 64539 -user-login = "kennykerr" -user-name = "Kenny Kerr" - [[publisher.windows_i686_gnu]] version = "0.42.2" when = "2023-03-13" @@ -2235,13 +2221,6 @@ user-id = 64539 user-login = "kennykerr" user-name = "Kenny Kerr" -[[publisher.windows_i686_gnu]] -version = "0.53.1" -when = "2025-10-06" -user-id = 64539 -user-login = "kennykerr" -user-name = "Kenny Kerr" - [[publisher.windows_i686_gnullvm]] version = "0.52.6" when = "2024-07-03" @@ -2249,13 +2228,6 @@ user-id = 64539 user-login = "kennykerr" user-name = "Kenny Kerr" -[[publisher.windows_i686_gnullvm]] -version = "0.53.1" -when = "2025-10-06" -user-id = 64539 -user-login = "kennykerr" -user-name = "Kenny Kerr" - [[publisher.windows_i686_msvc]] version = "0.42.2" when = "2023-03-13" @@ -2277,13 +2249,6 @@ user-id = 64539 user-login = "kennykerr" user-name = "Kenny Kerr" -[[publisher.windows_i686_msvc]] -version = "0.53.1" -when = "2025-10-06" -user-id = 64539 -user-login = "kennykerr" -user-name = "Kenny Kerr" - [[publisher.windows_x86_64_gnu]] version = "0.42.2" when = "2023-03-13" @@ -2305,13 +2270,6 @@ user-id = 64539 user-login = "kennykerr" user-name = "Kenny Kerr" -[[publisher.windows_x86_64_gnu]] -version = "0.53.1" -when = "2025-10-06" -user-id = 64539 -user-login = "kennykerr" -user-name = "Kenny Kerr" - [[publisher.windows_x86_64_gnullvm]] version = "0.42.2" when = "2023-03-13" @@ -2333,13 +2291,6 @@ user-id = 64539 user-login = "kennykerr" user-name = "Kenny Kerr" -[[publisher.windows_x86_64_gnullvm]] -version = "0.53.1" -when = "2025-10-06" -user-id = 64539 -user-login = "kennykerr" -user-name = "Kenny Kerr" - [[publisher.windows_x86_64_msvc]] version = "0.42.2" when = "2023-03-13" @@ -2361,13 +2312,6 @@ user-id = 64539 user-login = "kennykerr" user-name = "Kenny Kerr" -[[publisher.windows_x86_64_msvc]] -version = "0.53.1" -when = "2025-10-06" -user-id = 64539 -user-login = "kennykerr" -user-name = "Kenny Kerr" - [[publisher.winnow]] version = "0.7.14" when = "2025-11-26" @@ -4135,6 +4079,11 @@ who = "David Cook " criteria = "safe-to-deploy" version = "0.9.0" +[[audits.isrg.audits.chacha20]] +who = "David Cook " +criteria = "safe-to-deploy" +version = "0.10.0" + [[audits.isrg.audits.cpufeatures]] who = "David Cook " criteria = "safe-to-deploy" @@ -4285,6 +4234,11 @@ who = "J.C. Jones " criteria = "safe-to-deploy" delta = "0.9.3 -> 0.9.5" +[[audits.isrg.audits.rand_core]] +who = "David Cook " +criteria = "safe-to-deploy" +delta = "0.9.5 -> 0.10.0" + [[audits.isrg.audits.rayon]] who = "Brandon Pitman " criteria = "safe-to-deploy" @@ -4379,6 +4333,11 @@ who = "David Cook " criteria = "safe-to-deploy" delta = "0.5.0 -> 0.5.1" +[[audits.isrg.audits.untrusted]] +who = "David Cook " +criteria = "safe-to-deploy" +version = "0.7.1" + [[audits.mozilla.wildcard-audits.core-foundation]] who = "Bobby Holley " criteria = "safe-to-deploy" @@ -4463,12 +4422,12 @@ notes = "All code written or reviewed by Manish" aggregated-from = "https://raw.githubusercontent.com/mozilla-firefox/firefox/main/supply-chain/audits.toml" [[audits.mozilla.wildcard-audits.utf8_iter]] -who = "Makoto Kato " +who = "Henri Sivonen " criteria = "safe-to-deploy" user-id = 4484 # Henri Sivonen (hsivonen) start = "2022-04-19" -end = "2024-06-16" -notes = "Maintained by Henri Sivonen who works at Mozilla." +end = "2027-10-30" +notes = "I wrote this crate." aggregated-from = "https://raw.githubusercontent.com/mozilla-firefox/firefox/main/supply-chain/audits.toml" [[audits.mozilla.audits.allocator-api2]] @@ -4610,6 +4569,12 @@ delta = "0.1.1 -> 0.2.1" notes = "Very minor changes." aggregated-from = "https://raw.githubusercontent.com/mozilla-firefox/firefox/main/supply-chain/audits.toml" +[[audits.mozilla.audits.chacha20]] +who = "Alex Franchuk " +criteria = "safe-to-deploy" +delta = "0.10.0 -> 0.10.2" +aggregated-from = "https://raw.githubusercontent.com/mozilla/cargo-vet/main/supply-chain/audits.toml" + [[audits.mozilla.audits.core-foundation]] who = "Teodor Tanasoaia " criteria = "safe-to-deploy" @@ -5172,6 +5137,12 @@ feature. No new dependencies or unsafe code. """ aggregated-from = "https://raw.githubusercontent.com/mozilla-firefox/firefox/main/supply-chain/audits.toml" +[[audits.mozilla.audits.rand_core]] +who = "Alex Franchuk " +criteria = "safe-to-deploy" +delta = "0.10.0 -> 0.10.1" +aggregated-from = "https://raw.githubusercontent.com/mozilla/cargo-vet/main/supply-chain/audits.toml" + [[audits.mozilla.audits.raw-window-handle]] who = "Jim Blandy " criteria = "safe-to-deploy" @@ -5210,6 +5181,13 @@ criteria = "safe-to-deploy" delta = "1.5.3 -> 1.6.1" aggregated-from = "https://raw.githubusercontent.com/mozilla-firefox/firefox/main/supply-chain/audits.toml" +[[audits.mozilla.audits.ring]] +who = "Alex Franchuk " +criteria = "safe-to-deploy" +delta = "0.17.11 -> 0.17.14" +notes = "Generated code changes based on Perl scripts taken from BoringSSL. Portions are superficial in nature: deprecating/renaming modules and functions. New unsafe code is necessary to call out to assembly." +aggregated-from = "https://raw.githubusercontent.com/mozilla/cargo-vet/main/supply-chain/audits.toml" + [[audits.mozilla.audits.rustc-hash]] who = "Bobby Holley " criteria = "safe-to-deploy" @@ -5309,6 +5287,13 @@ version = "2.5.0" notes = "The goal is to provide some constant-time correctness for cryptographic implementations. The approach is reasonable, it is known to be insufficient but this is pointed out in the documentation." aggregated-from = "https://raw.githubusercontent.com/mozilla-firefox/firefox/main/supply-chain/audits.toml" +[[audits.mozilla.audits.sync_wrapper]] +who = "Alex Franchuk " +criteria = "safe-to-deploy" +version = "1.0.2" +notes = "Simple crate, nothing out of the ordinary." +aggregated-from = "https://raw.githubusercontent.com/mozilla/cargo-vet/main/supply-chain/audits.toml" + [[audits.mozilla.audits.synstructure]] who = "Nika Layzell " criteria = "safe-to-deploy" @@ -5352,12 +5337,26 @@ version = "0.7.5+spec-1.1.0" notes = "Pure data type crate with some datetime parsing. No unsafe." aggregated-from = "https://raw.githubusercontent.com/mozilla/glean/main/supply-chain/audits.toml" +[[audits.mozilla.audits.untrusted]] +who = "Alex Franchuk " +criteria = "safe-to-deploy" +delta = "0.7.1 -> 0.9.0" +notes = "Mostly a refactor of existing code. No use of std, no unsafe, no dependencies." +aggregated-from = "https://raw.githubusercontent.com/mozilla/cargo-vet/main/supply-chain/audits.toml" + [[audits.mozilla.audits.utf8parse]] who = "Nika Layzell " criteria = "safe-to-deploy" delta = "0.2.1 -> 0.2.2" aggregated-from = "https://raw.githubusercontent.com/mozilla/cargo-vet/main/supply-chain/audits.toml" +[[audits.mozilla.audits.web-time]] +who = "Alex Franchuk " +criteria = "safe-to-deploy" +version = "1.1.0" +notes = "Reasonable dependencies, unsafe code denied. The only use of std is to forward std::time when used on non-wasm targets and to reuse a few std::time things that are still applicable." +aggregated-from = "https://raw.githubusercontent.com/mozilla/cargo-vet/main/supply-chain/audits.toml" + [[audits.mozilla.audits.wgpu-types]] who = "Dzmitry Malyshau " criteria = "safe-to-deploy" diff --git a/test/functional/blockprod_ibd_genesis.py b/test/functional/blockprod_ibd_genesis.py index 693737258e..d2bcf3ed4e 100755 --- a/test/functional/blockprod_ibd_genesis.py +++ b/test/functional/blockprod_ibd_genesis.py @@ -66,7 +66,7 @@ def set_test_params(self): "--blockprod-min-peers-to-produce-blocks=0", "--max-tip-age={}".format(MAX_TIP_AGE), "--chain-genesis-block-timestamp=0", - "--blockprod-skip-ibd-check", + "--blockprod-skip-ibd-check=true", ]] def run_test(self): diff --git a/test/functional/p2p_ping.py b/test/functional/p2p_ping.py index 492032fae5..b0ea8622ae 100755 --- a/test/functional/p2p_ping.py +++ b/test/functional/p2p_ping.py @@ -40,7 +40,7 @@ def set_test_params(self): self.extra_args = [[ '--p2p-ping-timeout={}'.format(TIMEOUT_INTERVAL), '--p2p-ping-check-period={}'.format(PING_INTERVAL), - '--p2p-disable-noise', + '--p2p-disable-noise=true', '--p2p-sync-stalling-timeout={}'.format(SYNC_TIMEOUT) ]] diff --git a/test/functional/p2p_submit_orphan.py b/test/functional/p2p_submit_orphan.py index 2e57b3872c..a3ab6aefa9 100644 --- a/test/functional/p2p_submit_orphan.py +++ b/test/functional/p2p_submit_orphan.py @@ -31,7 +31,7 @@ class MempoolOrphanSubmissionTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True self.num_nodes = 3 - self.extra_args = self.num_nodes * [['--p2p-disable-noise']] + self.extra_args = self.num_nodes * [['--p2p-disable-noise=true']] def setup_network(self): self.setup_nodes() diff --git a/wallet/wallet-controller/src/sync/tests/mod.rs b/wallet/wallet-controller/src/sync/tests/mod.rs index 579489538b..a8cff2249b 100644 --- a/wallet/wallet-controller/src/sync/tests/mod.rs +++ b/wallet/wallet-controller/src/sync/tests/mod.rs @@ -29,8 +29,8 @@ use chainstate::ChainInfo; use chainstate_test_framework::TestFramework; use common::{ chain::{ - Currency, DelegationId, Destination, OrderId, PoolId, RpcOrderInfo, SignedTransaction, - Transaction, + BlockTxFees, Currency, DelegationId, Destination, OrderId, PoolId, RpcOrderInfo, + SignedTransaction, Transaction, tokens::{RPCTokenInfo, TokenId}, }, primitives::{Amount, time::Time}, @@ -217,6 +217,12 @@ impl NodeInterface for MockNode { async fn get_block(&self, block_id: Id) -> Result, Self::Error> { Ok(self.tf.lock().unwrap().chainstate.get_block(&block_id).unwrap()) } + async fn get_block_tx_fees( + &self, + _block_id: Id, + ) -> Result, Self::Error> { + unreachable!() + } async fn get_mainchain_blocks( &self, from: BlockHeight, diff --git a/wallet/wallet-node-client/src/handles_client/mod.rs b/wallet/wallet-node-client/src/handles_client/mod.rs index 466e117275..59bac9679b 100644 --- a/wallet/wallet-node-client/src/handles_client/mod.rs +++ b/wallet/wallet-node-client/src/handles_client/mod.rs @@ -26,8 +26,7 @@ use chainstate::{BlockSource, ChainInfo, ChainstateError, ChainstateHandle}; use common::{ chain::{ Block, BlockTxFees, Currency, DelegationId, Destination, GenBlock, OrderId, PoolId, - RpcOrderInfo, - SignedTransaction, Transaction, + RpcOrderInfo, SignedTransaction, Transaction, tokens::{RPCTokenInfo, TokenId}, }, primitives::{Amount, BlockHeight, Id, time::Time}, @@ -210,10 +209,7 @@ impl NodeInterface for WalletHandlesClient { &self, block_id: Id, ) -> Result, Self::Error> { - let fees = self - .chainstate - .call(move |this| this.get_block_tx_fees(&block_id)) - .await??; + let fees = self.chainstate.call(move |this| this.get_block_tx_fees(&block_id)).await??; Ok(fees) } diff --git a/wallet/wallet-node-client/src/mock.rs b/wallet/wallet-node-client/src/mock.rs index b203e7bbf6..b9769efee0 100644 --- a/wallet/wallet-node-client/src/mock.rs +++ b/wallet/wallet-node-client/src/mock.rs @@ -26,8 +26,7 @@ use chainstate::ChainInfo; use common::{ chain::{ Block, BlockTxFees, Currency, DelegationId, Destination, GenBlock, OrderId, PoolId, - RpcOrderInfo, - SignedTransaction, Transaction, TxOutput, UtxoOutPoint, + RpcOrderInfo, SignedTransaction, Transaction, TxOutput, UtxoOutPoint, tokens::{RPCTokenInfo, TokenId}, }, primitives::{Amount, BlockHeight, Id, time::Time}, diff --git a/wallet/wallet-node-client/src/node_traits.rs b/wallet/wallet-node-client/src/node_traits.rs index ee75ebe3f6..b988121f6c 100644 --- a/wallet/wallet-node-client/src/node_traits.rs +++ b/wallet/wallet-node-client/src/node_traits.rs @@ -24,9 +24,8 @@ use futures::stream::Stream; use chainstate::ChainInfo; use common::{ chain::{ - Block, BlockTxFees, Currency, DelegationId, Destination, GenBlock, OrderId, - PoolId, RpcOrderInfo, - SignedTransaction, Transaction, TxOutput, UtxoOutPoint, + Block, BlockTxFees, Currency, DelegationId, Destination, GenBlock, OrderId, PoolId, + RpcOrderInfo, SignedTransaction, Transaction, TxOutput, UtxoOutPoint, tokens::{RPCTokenInfo, TokenId}, }, primitives::{Amount, BlockHeight, Id, time::Time}, diff --git a/wallet/wallet-node-client/src/rpc_client/client_impl.rs b/wallet/wallet-node-client/src/rpc_client/client_impl.rs index 8f21295aaa..5dcff54a04 100644 --- a/wallet/wallet-node-client/src/rpc_client/client_impl.rs +++ b/wallet/wallet-node-client/src/rpc_client/client_impl.rs @@ -27,8 +27,7 @@ use common::{ address::Address, chain::{ Block, BlockTxFees, Currency, DelegationId, Destination, GenBlock, OrderId, PoolId, - RpcOrderInfo, - SignedTransaction, Transaction, TxOutput, UtxoOutPoint, + RpcOrderInfo, SignedTransaction, Transaction, TxOutput, UtxoOutPoint, tokens::{RPCTokenInfo, TokenId}, }, primitives::{Amount, BlockHeight, Id, time::Time}, diff --git a/wallet/wallet-node-client/src/rpc_client/cold_wallet_client.rs b/wallet/wallet-node-client/src/rpc_client/cold_wallet_client.rs index 8d2090bbde..3f4fc0a21e 100644 --- a/wallet/wallet-node-client/src/rpc_client/cold_wallet_client.rs +++ b/wallet/wallet-node-client/src/rpc_client/cold_wallet_client.rs @@ -23,9 +23,8 @@ use blockprod::TimestampSearchData; use chainstate::ChainInfo; use common::{ chain::{ - Block, BlockTxFees, Currency, DelegationId, Destination, GenBlock, OrderId, - PoolId, RpcOrderInfo, - SignedTransaction, Transaction, + Block, BlockTxFees, Currency, DelegationId, Destination, GenBlock, OrderId, PoolId, + RpcOrderInfo, SignedTransaction, Transaction, tokens::{RPCTokenInfo, TokenId}, }, primitives::{Amount, BlockHeight, Id, time::Time},