Skip to content

Commit

Permalink
fixup! feat(consensus): Add basic VRF block validation
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewWestberg committed Oct 17, 2024
1 parent 733a992 commit a2cc334
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ resolver = "2"
members = [
"amaru-common",
"amaru-consensus",
"amaru-node",
"amaru",
]
24 changes: 16 additions & 8 deletions amaru-common/src/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@ pub enum Error {
/// The sigma value of a pool. This is a rational number that represents the total value of the
/// delegated stake in the pool over the total value of the active stake in the network. This value
/// is tracked in the ledger state and recorded as a snapshot value at each epoch.
pub type Sigma = RationalNumber;
pub type PoolSigma = RationalNumber;

/// Performs a lookup of a pool_id to its sigma value. This usually represents a different set of
/// sigma snapshot data depending on whether we need to look up the pool_id in the current epoch
/// or in the future.
/// The pool info trait provides a lookup mechanism for pool data. This is sourced from the ledger
#[automock]
pub trait PoolInfo: Send + Sync {
fn sigma(&self, pool_id: &PoolId) -> Result<Sigma, Error>;
/// Performs a lookup of a pool_id to its sigma value. This usually represents a different set of
/// sigma snapshot data depending on whether we need to look up the pool_id in the current epoch
/// or in the future.
fn sigma(&self, pool_id: &PoolId) -> Result<PoolSigma, Error>;

/// Hashes the vrf vkey of a pool.
fn vrf_vkey_hash(&self, pool_id: &PoolId) -> Result<[u8; 32], Error>;
}

/// Performs a lookup of the first slot number in the epoch given an absolute slot number.
/// This requires knowledge of the genesis values and the shelley transition epoch value when
/// we left the byron era.
/// The slot calculator trait provides a mechanism for calculating slot and epoch information based
/// on the state of the ledger.
#[automock]
pub trait SlotCalculator: Send + Sync {
/// Performs a lookup of the first slot number in the epoch given an absolute slot number.
/// This requires knowledge of the genesis values and the shelley transition epoch value when
/// we left the byron era.
fn first_slot_in_epoch(&self, absolute_slot: u64) -> u64;

/// Performs a lookup of the epoch number given an absolute slot number. This requires knowledge
/// of the genesis values and the shelley transition epoch value when we left the byron era.
fn epoch_for_slot(&self, absolute_slot: u64) -> u64;
}
11 changes: 0 additions & 11 deletions amaru-consensus/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,8 @@ use pallas_crypto::vrf::{
};
use pallas_math::math::{ExpOrdering, FixedDecimal, FixedPrecision};
use pallas_traverse::MultiEraHeader;
use std::ops::Deref;
use std::sync::LazyLock;
use tracing::{error, span, trace, warn};

// The certified natural max value represents 2^256 in babbage and beyond
static CERTIFIED_NATURAL_MAX: LazyLock<FixedDecimal> = LazyLock::new(|| {
FixedDecimal::from_str(
"1157920892373161954235709850086879078532699846656405640394575840079131296399360000000000000000000000000000000000",
34,
)
.expect("Infallible")
});

struct BlockValidator<'b> {
multi_era_header: &'b MultiEraHeader<'b>,
pool_info: &'b dyn PoolInfo,
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion amaru-node/src/main.rs → amaru/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tracing::info;
#[tokio::main]
async fn main() {
init_logging();
info!("Hello, amaru-node!");
info!("Hello, amaru!");
}

fn init_logging() {
Expand Down

0 comments on commit a2cc334

Please sign in to comment.