Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.05 integration testing: exact costs matching in miner and follower: #2913 #2916

Merged
merged 42 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
49b4fdf
fix: add sqlite_open(), which sets the usual pragmas and busy handler…
jcnelson Oct 18, 2021
9cef3d3
fix: use rusqlite's new Connection::pragma method instead of query_ro…
jcnelson Oct 18, 2021
2a35aa7
fix: typo
jcnelson Oct 18, 2021
92c99b5
chore: unit test for sqlite_open() to verify that it sets pragmas
jcnelson Oct 22, 2021
3d47711
Merge branch 'develop' into fix/2885
jcnelson Oct 22, 2021
34777d1
chore: remove set_wal_mode -- it's not used
jcnelson Oct 22, 2021
3eac1fd
fix: merge artifact
jcnelson Oct 22, 2021
3b64620
Merge pull request #2887 from blockstack/fix/2885
jcnelson Oct 25, 2021
2a1b5bf
feat: vendor ctrlc package and add support for SIGBUS. Also, have the…
jcnelson Oct 26, 2021
d202d26
feat: add nix crate (to support vendored ctrlc package) and add the c…
jcnelson Oct 26, 2021
c55a6e4
refactor: db_mkdirs() now only returns one argument
jcnelson Oct 26, 2021
fd962c3
chore: give credit where credit is due for ctrlc
jcnelson Oct 26, 2021
c76a7f5
chore: expose ctrlc vendored package
jcnelson Oct 26, 2021
4cef87b
feat: expose ctrlc crate, with OS-specific packages
jcnelson Oct 26, 2021
36b2743
feat: use mmap by default in sqlite connections (256MB)
jcnelson Oct 26, 2021
0511532
chore: no longer need ctrlc
jcnelson Oct 26, 2021
4ef95f9
refactor: use deps/ctrlc now
jcnelson Oct 26, 2021
ede6334
fix: update docstrings to use deps::ctrlc
jcnelson Oct 26, 2021
0cde87c
fix: use move in docstring and use new arg
jcnelson Oct 26, 2021
cef19e6
fix: add unix and windows deps for vendored ctrlc package to libclarity
jcnelson Oct 26, 2021
9943a4b
fix: don't panic if we set a signal handler multiple times when testi…
jcnelson Oct 26, 2021
88185e0
refactor: only MARF databases will use mmap
jcnelson Oct 26, 2021
c5a276f
refactor: expose test module
jcnelson Oct 26, 2021
1e1d7c9
refactor: run original ctrlc tests as a unit test
jcnelson Oct 26, 2021
13eb05e
fix: don't mmap on sqlite_open()
jcnelson Oct 26, 2021
0a46823
fix: crash and burn on SIGBUS, and use async-safe (but rust unsafe) l…
jcnelson Oct 26, 2021
34f2cbf
fix: use proper libc types
jcnelson Oct 26, 2021
7062a02
chore: new Cargo lockfile
jcnelson Oct 26, 2021
684e8c9
chore: remove needless docstring example
jcnelson Oct 26, 2021
1ff6075
fix: have clarity target use nix and winapi for platform-specific nee…
jcnelson Oct 26, 2021
7403620
chore: updated cargo.lock
jcnelson Oct 27, 2021
0ae09f8
fix: windows-specific call to libc::write, because windows inexplicab…
jcnelson Oct 27, 2021
8303d22
chore: add CHANGELOG entry about mmap'ed connections
jcnelson Oct 27, 2021
75f6328
Merge pull request #2900 from blockstack/fix/2869
jcnelson Oct 27, 2021
5d021a9
chore: prepare changelog for release
kantai Nov 8, 2021
fcc717d
Merge branch 'develop' into next-costs
kantai Nov 9, 2021
7abd0c2
chore: fix merge artifacts in unit tests
kantai Nov 9, 2021
f688e8c
test: start of testing for #2913. adds a mined_block event to the dis…
kantai Nov 9, 2021
9ee9101
fix: issue raised in #2913
kantai Nov 10, 2021
b1291da
docs: add reference for the event dispatcher changes
kantai Nov 10, 2021
342a498
test: fix the assertion in runtime_overflow_unconfirmed_microblocks_i…
kantai Nov 11, 2021
e9c6d49
ci: add new test to github workflow
kantai Nov 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to the versioning scheme outlined in the [README.md](README.md).

## [Not yet released]
## [2.0.11.4.0]

This software update is a point-release to change the transaction
selection logic in the default miner to prioritize by an estimated fee
rate instead of raw fee. This release's chainstate directory is
compatible with chainstate directories from 2.0.11.3.0.

## Added

Expand All @@ -18,6 +23,8 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
## Changed

- Prioritize transaction inclusion in blocks by estimated fee rates (#2859).
- MARF sqlite connections will now use `mmap`'ed connections with up to 256MB
space (#2869).

## [2.0.11.3.0]

Expand Down
41 changes: 22 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ slog-json = { version = "2.3.0", optional = true }
chrono = "0.4.19"
libc = "0.2.82"

[target.'cfg(unix)'.dependencies]
nix = "0.23"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["consoleapi", "handleapi", "synchapi", "winbase"] }

[target.'cfg(windows)'.dev-dependencies]
winapi = { version = "0.3", features = ["fileapi", "processenv", "winnt"] }

[dependencies.serde_json]
version = "1.0"
features = ["arbitrary_precision", "unbounded_depth"]
Expand Down
9 changes: 9 additions & 0 deletions clarity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ slog-json = { version = "2.3.0", optional = true }
chrono = "0.4.19"
libc = "0.2.82"

[target.'cfg(unix)'.dependencies]
nix = "0.23"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["consoleapi", "handleapi", "synchapi", "winbase"] }

[target.'cfg(windows)'.dev-dependencies]
winapi = { version = "0.3", features = ["fileapi", "processenv", "winnt"] }

[dependencies.serde_json]
version = "1.0"
features = ["arbitrary_precision", "unbounded_depth"]
Expand Down
50 changes: 49 additions & 1 deletion docs/event-dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,21 @@ Example:
"from_stacks_block_hash": "0xf5d4ce0efe1d42c963d615ce57f0d014f263a985175e4ece766eceff10e0a358",
"from_index_block_hash": "0x329efcbcc6daf5ac3f264522e0df50eddb5be85df6ee8a9fc2384c54274d7afc",
}
]
],
"anchored_cost": {
"runtime": 100,
"read_count": 10,
"write_count": 5,
"read_length": 150,
"write_length": 75
},
"confirmed_microblocks_cost": {
"runtime": 100,
"read_count": 10,
"write_count": 5,
"read_length": 150,
"write_length": 75
}
}
```

Expand Down Expand Up @@ -216,3 +230,37 @@ Reason can be one of:
* `ReplaceAcrossFork` - replaced by a transaction with the same nonce but in the canonical fork
* `TooExpensive` - the transaction is too expensive to include in a block
* `StaleGarbageCollect` - transaction was dropped because it became stale

### `POST /mined_block`

This payload includes data related to block mined by this Stacks node. This
will never be invoked if the node is configured only as a follower. This is invoked
when the miner **assembles** the block; this block may or may not win the sortition.

This endpoint will only broadcast events to observers that explicitly register for
`MinedBlocks` events, `AnyEvent` observers will not receive the events by default.

Example:

```json
{
"block_hash": "0x4eaabcd105865e471f697eff5dd5bd85d47ecb5a26a3379d74fae0ae87c40904",
"staks_height": 3,
"target_burn_height": 745000,
"block_size": 145000,
"anchored_cost": {
"runtime": 100,
"read_count": 10,
"write_count": 5,
"read_length": 150,
"write_length": 75
},
"confirmed_microblocks_cost": {
"runtime": 100,
"read_count": 10,
"write_count": 5,
"read_length": 150,
"write_length": 75
}
}
```
11 changes: 4 additions & 7 deletions src/burnchains/bitcoin/spv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use rusqlite::Transaction;
use rusqlite::{Connection, OpenFlags, NO_PARAMS};

use util::db::{
query_row, query_rows, tx_begin_immediate, tx_busy_handler, u64_to_sql, DBConn, DBTx,
Error as db_error, FromColumn, FromRow,
query_row, query_rows, sqlite_open, tx_begin_immediate, tx_busy_handler, u64_to_sql, DBConn,
DBTx, Error as db_error, FromColumn, FromRow,
};
use util::get_epoch_time_secs;
use util::hash::{hex_bytes, to_hex};
Expand Down Expand Up @@ -212,11 +212,8 @@ impl SpvClient {
}
};

let mut conn =
Connection::open_with_flags(headers_path, open_flags).map_err(db_error::SqliteError)?;

conn.busy_handler(Some(tx_busy_handler))
.map_err(db_error::SqliteError)?;
let mut conn = sqlite_open(headers_path, open_flags, false)
.map_err(|e| btc_error::DBError(db_error::SqliteError(e)))?;

if create_flag {
SpvClient::db_instantiate(&mut conn)?;
Expand Down
15 changes: 4 additions & 11 deletions src/burnchains/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use burnchains::{Burnchain, BurnchainBlock, BurnchainBlockHeader, Error as Burnc
use chainstate::burn::operations::BlockstackOperationType;
use chainstate::stacks::index::MarfTrieId;
use util::db::{
query_row, query_rows, sql_pragma, tx_begin_immediate, tx_busy_handler, u64_to_sql,
Error as DBError, FromColumn, FromRow,
query_row, query_rows, sql_pragma, sqlite_open, tx_begin_immediate, tx_busy_handler,
u64_to_sql, Error as DBError, FromColumn, FromRow,
};

use crate::types::chainstate::BurnchainHeaderHash;
Expand Down Expand Up @@ -209,16 +209,11 @@ impl BurnchainDB {
}
};

let conn = Connection::open_with_flags(path, open_flags)
.expect(&format!("FAILED to open: {}", path));

conn.busy_handler(Some(tx_busy_handler))?;

let conn = sqlite_open(path, open_flags, true)?;
let mut db = BurnchainDB { conn };

if create_flag {
let db_tx = db.tx_begin()?;
sql_pragma(&db_tx.sql_tx, "PRAGMA journal_mode = WAL;")?;
db_tx.sql_tx.execute_batch(BURNCHAIN_DB_INITIAL_SCHEMA)?;

db_tx.sql_tx.execute(
Expand Down Expand Up @@ -247,9 +242,7 @@ impl BurnchainDB {
} else {
OpenFlags::SQLITE_OPEN_READ_ONLY
};
let conn = Connection::open_with_flags(path, open_flags)?;
conn.busy_handler(Some(tx_busy_handler))?;

let conn = sqlite_open(path, open_flags, true)?;
Ok(BurnchainDB { conn })
}

Expand Down
29 changes: 15 additions & 14 deletions src/chainstate/burn/db/sortdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2011,17 +2011,18 @@ impl SortitionDB {

fn open_index(index_path: &str) -> Result<MARF<SortitionId>, db_error> {
test_debug!("Open index at {}", index_path);
MARF::from_path(index_path).map_err(|_e| db_error::Corruption)
let marf = MARF::from_path(index_path).map_err(|_e| db_error::Corruption)?;
sql_pragma(marf.sqlite_conn(), "foreign_keys", &true)?;
Ok(marf)
}

/// Open the database on disk. It must already exist and be instantiated.
/// It's best not to call this if you are able to call connect(). If you must call this, do so
/// after you call connect() somewhere else, since connect() performs additional validations.
pub fn open(path: &str, readwrite: bool) -> Result<SortitionDB, db_error> {
let (db_path, index_path) = db_mkdirs(path)?;
let index_path = db_mkdirs(path)?;
debug!(
"Open sortdb '{}' as '{}', with index as '{}'",
db_path,
"Open sortdb as '{}', with index as '{}'",
if readwrite { "readwrite" } else { "readonly" },
index_path
);
Expand Down Expand Up @@ -2066,11 +2067,10 @@ impl SortitionDB {
Ok(_md) => false,
};

let (db_path, index_path) = db_mkdirs(path)?;
let index_path = db_mkdirs(path)?;
debug!(
"Connect/Open {} sortdb '{}' as '{}', with index as '{}'",
"Connect/Open {} sortdb as '{}', with index as '{}'",
if create_flag { "(create)" } else { "" },
db_path,
if readwrite { "readwrite" } else { "readonly" },
index_path
);
Expand Down Expand Up @@ -2154,13 +2154,12 @@ impl SortitionDB {
Ok(_md) => false,
};

let (db_path, index_path) = db_mkdirs(path)?;
let index_path = db_mkdirs(path)?;
debug!(
"Connect/Open {} sortdb '{}' as '{}', with index as '{}'",
"Connect/Open {} sortdb '{}' as '{}'",
if create_flag { "(create)" } else { "" },
db_path,
if readwrite { "readwrite" } else { "readonly" },
index_path
index_path,
if readwrite { "readwrite" } else { "readonly" }
);

let marf = SortitionDB::open_index(&index_path)?;
Expand Down Expand Up @@ -2242,7 +2241,8 @@ impl SortitionDB {
) -> Result<(), db_error> {
debug!("Instantiate SortDB");

sql_pragma(self.conn(), "PRAGMA journal_mode = WAL;")?;
sql_pragma(self.conn(), "journal_mode", &"WAL")?;
sql_pragma(self.conn(), "foreign_keys", &true)?;

let mut db_tx = SortitionHandleTx::begin(self, &SortitionId::sentinel())?;

Expand Down Expand Up @@ -2313,7 +2313,8 @@ impl SortitionDB {
) -> Result<(), db_error> {
debug!("Instantiate SortDB");

sql_pragma(self.conn(), "PRAGMA journal_mode = WAL;")?;
sql_pragma(self.conn(), "journal_mode", &"WAL")?;
sql_pragma(self.conn(), "foreign_keys", &true)?;

let mut db_tx = SortitionHandleTx::begin(self, &SortitionId::sentinel())?;

Expand Down
4 changes: 4 additions & 0 deletions src/chainstate/coordinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub trait BlockEventDispatcher {
parent_burn_block_hash: BurnchainHeaderHash,
parent_burn_block_height: u32,
parent_burn_block_timestamp: u64,
anchored_consumed: &ExecutionCost,
mblock_confirmed_consumed: &ExecutionCost,
);

/// called whenever a burn block is about to be
Expand Down Expand Up @@ -833,6 +835,8 @@ impl<
block_receipt.parent_burn_block_hash,
block_receipt.parent_burn_block_height,
block_receipt.parent_burn_block_timestamp,
&block_receipt.anchored_block_cost,
&block_receipt.parent_microblocks_cost,
);
}

Expand Down
Loading