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

start a tool to validate aspects of the blockchain database #792

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/chia-consensus/src/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub const TEST_CONSTANTS: ConsensusConstants = ConsensusConstants {
max_future_time2: 2 * 60,
number_of_timestamps: 11,
genesis_challenge: Bytes32::new(hex!(
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
"ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb"
)),
agg_sig_me_additional_data: Bytes32::new(hex!(
"ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb"
Expand Down
6 changes: 6 additions & 0 deletions crates/chia-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ clap = { workspace = true, features = ["derive"] }
zstd = { workspace = true }
blocking-threadpool = { workspace = true }
hex = { workspace = true }
hex-literal = { workspace = true }

[lib]
name = "chia_tools"
Expand Down Expand Up @@ -69,3 +70,8 @@ bench = false
name = "get-generator"
test = false
bench = false

[[bin]]
name = "validate-blockchain-db"
test = false
bench = false
7 changes: 5 additions & 2 deletions crates/chia-tools/src/bin/analyze-chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::time::SystemTime;
use chia_consensus::consensus_constants::TEST_CONSTANTS;
use chia_consensus::gen::flags::{ALLOW_BACKREFS, MEMPOOL_MODE};
use chia_consensus::gen::run_block_generator::{run_block_generator, run_block_generator2};
use chia_tools::iterate_tx_blocks;
use chia_tools::iterate_blocks;
use clvmr::Allocator;

/// Analyze the blocks in a chia blockchain database
Expand Down Expand Up @@ -42,11 +42,14 @@ fn main() {
let mut a = Allocator::new_limited(500_000_000);
let allocator_checkpoint = a.checkpoint();
let mut prev_timestamp = 0;
iterate_tx_blocks(
iterate_blocks(
&args.file,
args.start,
Some(args.end),
|height, block, block_refs| {
if block.transactions_generator.is_none() {
AmineKhaldi marked this conversation as resolved.
Show resolved Hide resolved
return;
}
// after the hard fork, we run blocks without paying for the
// CLVM generator ROM
let block_runner = if height >= 5_496_000 {
Expand Down
7 changes: 5 additions & 2 deletions crates/chia-tools/src/bin/gen-corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use clap::Parser;

use chia_tools::{iterate_tx_blocks, visit_spends};
use chia_tools::{iterate_blocks, visit_spends};
use chia_traits::streamable::Streamable;

use chia_bls::G2Element;
Expand Down Expand Up @@ -78,11 +78,14 @@ fn main() {
let mut last_height = 0;
let mut last_time = Instant::now();
let corpus_counter = Arc::new(AtomicUsize::new(0));
iterate_tx_blocks(
iterate_blocks(
&args.file,
args.start_height,
args.max_height,
|height, block, block_refs| {
if block.transactions_generator.is_none() {
return;
}
// this is called for each transaction block
let max_cost = block.transactions_info.unwrap().cost;
let prg = block.transactions_generator.unwrap();
Expand Down
7 changes: 5 additions & 2 deletions crates/chia-tools/src/bin/test-block-generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use chia_consensus::consensus_constants::TEST_CONSTANTS;
use chia_consensus::gen::conditions::{NewCoin, SpendBundleConditions, SpendConditions};
use chia_consensus::gen::flags::{ALLOW_BACKREFS, DONT_VALIDATE_SIGNATURE, MEMPOOL_MODE};
use chia_consensus::gen::run_block_generator::{run_block_generator, run_block_generator2};
use chia_tools::iterate_tx_blocks;
use chia_tools::iterate_blocks;
use clvmr::allocator::NodePtr;
use clvmr::Allocator;
use std::collections::HashSet;
Expand Down Expand Up @@ -165,11 +165,14 @@ fn main() {
let mut last_height = args.start_height;
let mut last_time = Instant::now();
println!("opening blockchain database file: {}", args.file);
iterate_tx_blocks(
iterate_blocks(
&args.file,
args.start_height,
max_height,
|height, block, block_refs| {
if block.transactions_generator.is_none() {
return;
}
pool.execute(move || {
let mut a = Allocator::new_limited(500_000_000);

Expand Down
Loading
Loading