Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! Refactor and use pallas nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewWestberg committed Sep 18, 2024
1 parent 3d55f8b commit df123fa
Show file tree
Hide file tree
Showing 12 changed files with 390 additions and 814 deletions.
74 changes: 66 additions & 8 deletions Cargo.lock

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

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "cncli"
version = "6.3.1"
authors = ["Andrew Westberg <[email protected]>"]
edition = "2021"
build = "build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -11,10 +12,10 @@ async-std = "1.13"
bech32 = "0.11"
bincode = "1.3.3"
byteorder = "1.5"
pallas-crypto = { git = "https://github.com/txpipe/pallas", rev = "85919762a93167d1e2187f828037251addbf07a8" }
pallas-math = { git = "https://github.com/txpipe/pallas", rev = "85919762a93167d1e2187f828037251addbf07a8" }
pallas-network = { git = "https://github.com/txpipe/pallas", rev = "85919762a93167d1e2187f828037251addbf07a8" }
pallas-traverse = { git = "https://github.com/txpipe/pallas", rev = "85919762a93167d1e2187f828037251addbf07a8" }
pallas-crypto = { git = "https://github.com/txpipe/pallas", rev = "224636230a5a29e597a46055de2a001dc33ccb58" }
pallas-math = { git = "https://github.com/txpipe/pallas", rev = "224636230a5a29e597a46055de2a001dc33ccb58" }
pallas-network = { git = "https://github.com/txpipe/pallas", rev = "224636230a5a29e597a46055de2a001dc33ccb58" }
pallas-traverse = { git = "https://github.com/txpipe/pallas", rev = "224636230a5a29e597a46055de2a001dc33ccb58" }
#pallas-crypto = "0.30"
#pallas-network = "0.30"
#pallas-traverse = "0.30"
Expand Down Expand Up @@ -43,3 +44,6 @@ thiserror = "1.0"
tracing = "0.1"
tracing-subscriber = "0.3"
uuid = { version = "1", features = ["v7"] }

[build-dependencies]
built = { version = "0.7", features = ["git2"] }
9 changes: 9 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::env;
use std::path::Path;
use std::process::Command;

fn main() {
built::write_built_file().expect("Failed to acquire build-time information");

println!("cargo:rerun-if-changed=build.rs");
}
2 changes: 0 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ async fn main() {
set_var("RUST_LOG", "info");
}
}
pretty_env_logger::init_timed();

let tracing_filter = match var("RUST_LOG") {
Ok(level) => match level.to_lowercase().as_str() {
"error" => tracing::Level::ERROR,
Expand Down
12 changes: 2 additions & 10 deletions src/nodeclient/blockstore/redb.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::io::Read;
use std::path::Path;
use std::str::FromStr;
use itertools::Itertools;
use pallas_crypto::hash::{Hash, Hasher};
use pallas_crypto::nonce::NonceGenerator;
use pallas_crypto::nonce::rolling_nonce::RollingNonceGenerator;
use pallas_crypto::nonce::generate_rolling_nonce;
use redb::{Builder, Database, MultimapTableDefinition, MultimapValue, ReadableMultimapTable, ReadableTable, RepairSession, TableDefinition, TypeName, Value};
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -38,9 +35,6 @@ pub enum Error {
#[error("Redb storage error: {0}")]
RedbStorage(#[from] redb::StorageError),

#[error("Nonce error: {0}")]
Nonce(#[from] pallas_crypto::nonce::Error),

#[error("FromHex error: {0}")]
FromHex(#[from] hex::FromHexError),

Expand Down Expand Up @@ -228,9 +222,7 @@ impl RedbBlockStore {
let pool_id = Hasher::<224>::hash(block.node_vkey.as_slice());

// calculate rolling nonce (eta_v)
let mut rolling_nonce_generator = RollingNonceGenerator::new(prev_eta_v);
rolling_nonce_generator.apply_block(&block.eta_vrf_0)?;
let eta_v = rolling_nonce_generator.finalize()?;
let eta_v = generate_rolling_nonce(prev_eta_v, &block.eta_vrf_0);

let chain_record = ChainRecord {
block_number: block.block_number,
Expand Down
13 changes: 3 additions & 10 deletions src/nodeclient/blockstore/sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use log::{debug, error, info};
use pallas_crypto::hash::{Hash, Hasher};
use pallas_crypto::nonce::rolling_nonce::RollingNonceGenerator;
use pallas_crypto::nonce::NonceGenerator;
use pallas_crypto::nonce::generate_rolling_nonce;
use rusqlite::{named_params, Connection};
use std::path::Path;
use std::str::FromStr;
use thiserror::Error;

use tracing::{debug, error, info};
use crate::nodeclient::blockstore;
use crate::nodeclient::blockstore::{Block, BlockStore};
use crate::nodeclient::sync::BlockHeader;
Expand All @@ -16,9 +14,6 @@ pub enum Error {
#[error("SQLite error: {0}")]
Sqlite(#[from] rusqlite::Error),

#[error("Nonce error: {0}")]
Nonce(#[from] pallas_crypto::nonce::Error),

#[error("FromHex error: {0}")]
FromHex(#[from] hex::FromHexError),
}
Expand Down Expand Up @@ -278,9 +273,7 @@ impl SqLiteBlockStore {
);
}
// calculate rolling nonce (eta_v)
let mut rolling_nonce_generator = RollingNonceGenerator::new(prev_eta_v);
rolling_nonce_generator.apply_block(&block.eta_vrf_0)?;
let eta_v = rolling_nonce_generator.finalize()?;
let eta_v = generate_rolling_nonce(prev_eta_v, &block.eta_vrf_0);

// blake2b 224 of node_vkey is the pool_id
let pool_id = hex::encode(Hasher::<224>::hash(&block.node_vkey));
Expand Down
Loading

0 comments on commit df123fa

Please sign in to comment.