Skip to content

Commit

Permalink
staking: 🔊 log genesis validators after parsing (#3916)
Browse files Browse the repository at this point in the history
cherry-picked from #3902.
  • Loading branch information
cratelyn authored Mar 1, 2024
1 parent f410d39 commit fc6e9d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
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.

1 change: 1 addition & 0 deletions crates/core/component/stake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ serde = {workspace = true, features = ["derive"]}
serde_unit_struct = {workspace = true}
serde_with = {workspace = true}
sha2 = {workspace = true}
tap = {workspace = true}
tendermint = {workspace = true, default-features = true}
tokio = {workspace = true, features = ["full", "tracing"], optional = true}
tonic = {workspace = true, optional = true}
Expand Down
18 changes: 13 additions & 5 deletions crates/core/component/stake/src/component/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ use sha2::{Digest, Sha256};
use std::pin::Pin;
use std::str::FromStr;
use std::{collections::BTreeMap, sync::Arc};
use tap::Tap;
use tendermint::v0_37::abci;
use tendermint::validator::Update;
use tendermint::{block, PublicKey};
use tracing::instrument;
use tracing::{instrument, trace};

use crate::component::epoch_handler::EpochHandler;
use crate::component::validator_handler::{ValidatorDataRead, ValidatorManager};
Expand All @@ -48,11 +49,13 @@ impl Component for Staking {
let starting_height = state
.get_block_height()
.await
.expect("should be able to get initial block height");
.expect("should be able to get initial block height")
.tap(|height| trace!(%height,"found initial block height"));
let starting_epoch = state
.get_epoch_by_height(starting_height)
.await
.expect("should be able to get initial epoch");
.expect("should be able to get initial epoch")
.tap(|epoch| trace!(?epoch, "found initial epoch"));
let epoch_index = starting_epoch.index;

let genesis_base_rate = BaseRateData {
Expand All @@ -61,17 +64,22 @@ impl Component for Staking {
base_exchange_rate: 1_0000_0000u128.into(),
};
state.set_base_rate(genesis_base_rate.clone());
trace!(?genesis_base_rate, "set base rate");

let mut genesis_allocations = BTreeMap::<_, Amount>::new();
for allocation in &sp_genesis.allocations {
let value = allocation.value();
*genesis_allocations.entry(value.asset_id).or_default() += value.amount;
}

for validator in &staking_genesis.validators {
trace!("parsing genesis validators");
for (i, validator) in staking_genesis.validators.iter().enumerate() {
// Parse the proto into a domain type.
let validator = Validator::try_from(validator.clone())
.expect("should be able to parse genesis validator");
.expect("should be able to parse genesis validator")
.tap(|Validator { name, enabled, .. }|
trace!(%i, %name, %enabled, "parsed genesis validator")
);

state
.add_genesis_validator(&genesis_allocations, &genesis_base_rate, validator)
Expand Down

0 comments on commit fc6e9d2

Please sign in to comment.