Skip to content
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
6 changes: 4 additions & 2 deletions node/common/src/service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ impl node::service::TransitionFrontierGenesisService for NodeServiceCommon {
fn load_genesis(&mut self, config: Arc<GenesisConfig>) {
let res = match config.load() {
Err(err) => Err(err.to_string()),
Ok((mask, data)) => {
self.ledger_manager.insert_genesis_ledger(mask);
Ok((masks, data)) => {
masks
.into_iter()
.for_each(|mask| self.ledger_manager.insert_genesis_ledger(mask));
Ok(data)
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use mina_p2p_messages::v2::{
ConsensusProofOfStakeDataEpochDataStakingValueVersionedValueStableV1, LedgerHash,
};
use openmina_core::action_info;
use openmina_core::action_trace;
use openmina_core::block::ArcBlockWithHash;
use openmina_core::ActionEvent;
use serde::{Deserialize, Serialize};
Expand All @@ -27,7 +28,7 @@ pub type BlockProducerVrfEvaluatorActionWithMetaRef<'a> =
#[action_event(level = info)]
pub enum BlockProducerVrfEvaluatorAction {
/// Vrf Evaluation requested.
#[action_event(fields(debug(vrp_input)))]
#[action_event(level = trace, fields(debug(vrp_input)))]
EvaluateSlot { vrf_input: VrfEvaluatorInput },
/// Evaluation successful.
#[action_event(expr(log_vrf_output(context, vrf_output)))]
Expand Down Expand Up @@ -255,7 +256,7 @@ where
vrf_output = display(vrf_output)
),
VrfEvaluationOutput::SlotLost(_) => {
action_info!(context, summary = "Slot evaluation result - lost slot")
action_trace!(context, summary = "Slot evaluation result - lost slot")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub enum GenesisConfigError {
}

impl GenesisConfig {
pub fn load(&self) -> Result<(ledger::Mask, GenesisConfigLoaded), GenesisConfigError> {
pub fn load(&self) -> Result<(Vec<ledger::Mask>, GenesisConfigLoaded), GenesisConfigError> {
Ok(match self {
Self::Counts {
whales,
Expand Down Expand Up @@ -117,15 +117,16 @@ impl GenesisConfig {
constants: constants.clone(),
genesis_ledger_hash: genesis_ledger_hash.clone(),
genesis_total_currency,
genesis_producer_stake_proof: genesis_producer_stake_proof(&mask),
genesis_producer_stake_proof: create_genesis_producer_stake_proof(&mask),
staking_epoch_ledger_hash: genesis_ledger_hash.clone(),
staking_epoch_total_currency,
next_epoch_ledger_hash: genesis_ledger_hash,
next_epoch_total_currency,
staking_epoch_seed,
next_epoch_seed,
};
(mask, load_result)
let masks = vec![mask];
(masks, load_result)
}
Self::BalancesDelegateTable { table, constants } => {
let table = table.iter().map(|(bp_balance, delegators)| {
Expand All @@ -144,21 +145,23 @@ impl GenesisConfig {
constants: constants.clone(),
genesis_ledger_hash: genesis_ledger_hash.clone(),
genesis_total_currency,
genesis_producer_stake_proof: genesis_producer_stake_proof(&mask),
genesis_producer_stake_proof: create_genesis_producer_stake_proof(&mask),
staking_epoch_ledger_hash: genesis_ledger_hash.clone(),
staking_epoch_total_currency,
next_epoch_ledger_hash: genesis_ledger_hash,
next_epoch_total_currency,
staking_epoch_seed,
next_epoch_seed,
};
(mask, load_result)
let masks = vec![mask];
(masks, load_result)
}
Self::Prebuilt(bytes) => {
let prebuilt = PrebuiltGenesisConfig::read(&mut bytes.as_ref())?;
prebuilt.load()
}
Self::DaemonJson(config) => {
let mut masks = Vec::new();
let constants = config
.genesis
.as_ref()
Expand All @@ -172,6 +175,7 @@ impl GenesisConfig {
let (mask, total_currency, genesis_ledger_hash) =
Self::build_or_load_ledger(ledger.ledger_name(), accounts.into_iter())?;

masks.push(mask.clone());
if let Some(expected_hash) = config.ledger.as_ref().and_then(|l| l.hash.as_ref()) {
if expected_hash != &genesis_ledger_hash.to_string() {
return Err(GenesisConfigError::LedgerHashMismatch {
Expand All @@ -187,6 +191,7 @@ impl GenesisConfig {
let next_epoch_ledger_hash;
let next_epoch_total_currency;
let next_epoch_seed: v2::EpochSeed;
let genesis_producer_stake_proof: v2::MinaBaseSparseLedgerBaseStableV2;
// TODO(devnet): handle other cases here, right now this works
// only for the post-fork genesis
if let Some(data) = &config.epoch_data {
Expand All @@ -198,13 +203,16 @@ impl GenesisConfig {
.iter()
.map(daemon_json::Account::to_account)
.collect::<Result<Vec<_>, _>>()?;
let (mut _mask, total_currency, hash) = Self::build_or_load_ledger(
let (staking_ledger_mask, total_currency, hash) = Self::build_or_load_ledger(
data.staking.ledger_name(),
accounts.into_iter(),
)?;
staking_epoch_ledger_hash = hash;
staking_epoch_total_currency = total_currency;
staking_epoch_seed = v2::EpochSeed::from_str(&data.staking.seed).unwrap();
genesis_producer_stake_proof =
create_genesis_producer_stake_proof(&staking_ledger_mask);
masks.push(staking_ledger_mask);

let next = data.next.as_ref().unwrap();
let accounts = next
Expand All @@ -227,21 +235,22 @@ impl GenesisConfig {
next_epoch_ledger_hash = genesis_ledger_hash.clone();
next_epoch_total_currency = total_currency.clone();
next_epoch_seed = v2::EpochSeed::zero();
genesis_producer_stake_proof = create_genesis_producer_stake_proof(&mask);
}

let result = GenesisConfigLoaded {
constants,
genesis_ledger_hash,
genesis_total_currency: total_currency,
genesis_producer_stake_proof: genesis_producer_stake_proof(&mask),
genesis_producer_stake_proof,
staking_epoch_ledger_hash,
staking_epoch_total_currency,
next_epoch_ledger_hash,
next_epoch_total_currency,
staking_epoch_seed,
next_epoch_seed,
};
(mask, result)
(masks, result)
}
Self::DaemonJsonFile(path) => {
let reader = File::open(path)?;
Expand Down Expand Up @@ -391,7 +400,9 @@ fn genesis_account_iter() -> impl Iterator<Item = ledger::Account> {
})
}

fn genesis_producer_stake_proof(mask: &ledger::Mask) -> v2::MinaBaseSparseLedgerBaseStableV2 {
fn create_genesis_producer_stake_proof(
mask: &ledger::Mask,
) -> v2::MinaBaseSparseLedgerBaseStableV2 {
let producer = AccountSecretKey::genesis_producer().public_key();
let producer_id = ledger::AccountId::new(producer.into(), ledger::TokenId::default());
let sparse_ledger =
Expand Down Expand Up @@ -448,15 +459,17 @@ impl PrebuiltGenesisConfig {
self.binprot_write(&mut writer)
}

pub fn load(self) -> (ledger::Mask, GenesisConfigLoaded) {
pub fn load(self) -> (Vec<ledger::Mask>, GenesisConfigLoaded) {
let mut masks = Vec::new();
let (mask, genesis_total_currency) = GenesisConfig::build_ledger_from_accounts_and_hashes(
self.accounts.into_iter().map(|acc| (&acc).into()),
self.hashes
.into_iter()
.map(|(n, h)| (n, h.to_field()))
.collect::<Vec<_>>(),
);
let (_mask, staking_epoch_total_currency) =
masks.push(mask);
let (staking_ledger_mask, staking_epoch_total_currency) =
GenesisConfig::build_ledger_from_accounts_and_hashes(
self.staking_epoch_data
.accounts
Expand Down Expand Up @@ -485,15 +498,16 @@ impl PrebuiltGenesisConfig {
constants: self.constants,
genesis_ledger_hash: self.ledger_hash,
genesis_total_currency,
genesis_producer_stake_proof: genesis_producer_stake_proof(&mask),
genesis_producer_stake_proof: create_genesis_producer_stake_proof(&staking_ledger_mask),
staking_epoch_ledger_hash: self.staking_epoch_data.ledger_hash.clone(),
staking_epoch_total_currency,
next_epoch_ledger_hash: self.next_epoch_data.ledger_hash.clone(),
next_epoch_total_currency,
staking_epoch_seed: self.staking_epoch_data.seed,
next_epoch_seed: self.next_epoch_data.seed,
};
(mask, load_result)
masks.push(staking_ledger_mask);
(masks, load_result)
}
}

Expand Down