Skip to content

Commit 3477059

Browse files
committed
perf: improve next_ready_nakamoto_block
* add an index for the SQLite lookup that the routine requires. this improves block processing speeds.
1 parent e9be296 commit 3477059

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1010
### Changed
1111

1212
- Reduce the default `block_rejection_timeout_steps` configuration so that miners will retry faster when blocks fail to reach 70% approved or 30% rejected.
13+
- Added index for `next_ready_nakamoto_block()` which improves block processing performance.
1314

1415
## [3.1.0.0.8]
1516

stackslib/src/chainstate/nakamoto/staging_blocks.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ pub const NAKAMOTO_STAGING_DB_SCHEMA_3: &[&str] = &[
160160
r#"UPDATE db_version SET version = 3"#,
161161
];
162162

163-
pub const NAKAMOTO_STAGING_DB_SCHEMA_LATEST: u32 = 3;
163+
pub const NAKAMOTO_STAGING_DB_SCHEMA_4: &[&str] = &[
164+
r#"CREATE INDEX nakamoto_staging_blocks_by_ready_and_height ON nakamoto_staging_blocks(burn_attachable, orphaned, processed, height);"#,
165+
r#"UPDATE db_version SET version = 4"#,
166+
];
167+
168+
pub const NAKAMOTO_STAGING_DB_SCHEMA_LATEST: u32 = 4;
164169

165170
pub struct NakamotoStagingBlocksConn(rusqlite::Connection);
166171

@@ -796,6 +801,15 @@ impl StacksChainState {
796801
assert_eq!(version, 3, "Nakamoto staging DB migration failure");
797802
debug!("Migrated Nakamoto staging blocks DB to schema 3");
798803
}
804+
3 => {
805+
debug!("Migrate Nakamoto staging blocks DB to schema 3");
806+
for cmd in NAKAMOTO_STAGING_DB_SCHEMA_4.iter() {
807+
conn.execute(cmd, NO_PARAMS)?;
808+
}
809+
let version = Self::get_nakamoto_staging_blocks_db_version(conn)?;
810+
assert_eq!(version, 4, "Nakamoto staging DB migration failure");
811+
debug!("Migrated Nakamoto staging blocks DB to schema 3");
812+
}
799813
NAKAMOTO_STAGING_DB_SCHEMA_LATEST => {
800814
break;
801815
}

0 commit comments

Comments
 (0)