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

Build up to date state from pruning proof #96

Merged
merged 18 commits into from
Jan 30, 2023
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ web-root
/rust-toolchain
/.vscode/
**/db-*
/consensus/tests/testdata/goref-1.6M-tx-10K-blocks.json.gz
/consensus/tests/testdata/dags_for_json_tests/goref-mainnet
/consensus/tests/testdata/dags_for_json_tests/goref-1.6M-tx-10K-blocks
analyzer-target
8 changes: 5 additions & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ criterion = { version = "0.4", default-features = false }
indexmap = "1.9.1"
smallvec = { version = "1.10.0", features = ["serde"] }
borsh = "0.9.3"
clap = { version = "4.0.23", features = ["derive"] }
async-std = { version = "1.12.0", features = ['attributes'] }
clap = { version = "4.0.23", features = ["derive", "string"] }
async-channel = "1.8.0"
derive_more = { version = "0.99" }
log = "0.4"
cfg-if = "1.0.0"
3 changes: 3 additions & 0 deletions consensus/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod merkle;
pub mod muhash;
pub mod networktype;
pub mod notify;
pub mod pruning;
pub mod sign;
pub mod subnets;
pub mod tx;
Expand Down Expand Up @@ -101,6 +102,8 @@ impl BuildHasher for BlockHasher {
}
}

pub type BlockLevel = u8;

#[cfg(test)]
mod tests {
use super::BlockHasher;
Expand Down
11 changes: 8 additions & 3 deletions consensus/core/src/muhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use muhash::MuHash;

pub trait MuHashExtensions {
fn add_transaction(&mut self, tx: &impl VerifiableTransaction, block_daa_score: u64);
fn add_utxo(&mut self, outpoint: &TransactionOutpoint, entry: &UtxoEntry);
}

impl MuHashExtensions for MuHash {
Expand All @@ -20,11 +21,15 @@ impl MuHashExtensions for MuHash {
for (i, output) in tx.outputs().iter().enumerate() {
let outpoint = TransactionOutpoint::new(tx_id, i as u32);
let entry = UtxoEntry::new(output.value, output.script_public_key.clone(), block_daa_score, tx.is_coinbase());
let mut writer = self.add_element_builder();
write_utxo(&mut writer, &entry, &outpoint);
writer.finalize();
self.add_utxo(&outpoint, &entry);
}
}

fn add_utxo(&mut self, outpoint: &TransactionOutpoint, entry: &UtxoEntry) {
let mut writer = self.add_element_builder();
write_utxo(&mut writer, entry, outpoint);
writer.finalize();
}
}

fn write_utxo(writer: &mut impl HasherBase, entry: &UtxoEntry, outpoint: &TransactionOutpoint) {
Expand Down
5 changes: 5 additions & 0 deletions consensus/core/src/pruning.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use std::sync::Arc;

use crate::header::Header;

pub type PruningPointProof = Vec<Vec<Arc<Header>>>;
82 changes: 82 additions & 0 deletions consensus/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use std::ops::Deref;

use crate::{
constants::perf::{PerfParams, PERF_PARAMS},
params::Params,
};

/// Various consensus configurations all bundled up under a single struct. Use `Config::new` for directly building from
/// a `Params` instance. For anything more complex it is recommended to use `ConfigBuilder`. NOTE: this struct can be
/// implicitly de-refed into `Params`
#[derive(Clone)]
pub struct Config {
/// Consensus params
pub params: Params,
/// Performance params
pub perf: PerfParams,

//
// Additional consensus configuration arguments which are not consensus sensitive
//
pub process_genesis: bool,
// TODO:
// is_archival: bool,
// enable_sanity_check_pruning_utxoset: bool,
}

impl Config {
pub fn new(params: Params) -> Self {
Self { params, perf: PERF_PARAMS, process_genesis: true }
}
}

impl AsRef<Params> for Config {
fn as_ref(&self) -> &Params {
&self.params
}
}

impl Deref for Config {
type Target = Params;

fn deref(&self) -> &Self::Target {
&self.params
}
}

pub struct ConfigBuilder {
config: Config,
}

impl ConfigBuilder {
pub fn new(params: Params) -> Self {
Self { config: Config::new(params) }
}

pub fn set_perf_params(mut self, perf: PerfParams) -> Self {
self.config.perf = perf;
self
}

pub fn edit_consensus_params<F>(mut self, edit_func: F) -> Self
where
F: Fn(&mut Params),
{
edit_func(&mut self.config.params);
self
}

pub fn skip_proof_of_work(mut self) -> Self {
self.config.params.skip_proof_of_work = true;
self
}

pub fn skip_adding_genesis(mut self) -> Self {
self.config.process_genesis = false;
self
}

pub fn build(self) -> Config {
self.config
}
}
Loading