Skip to content

Commit

Permalink
feat: use max block time
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszjasiuk committed Aug 21, 2024
1 parent 8c733f3 commit 808e89e
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions orm/migrations/2024-05-31-125032_chain_parameters/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CREATE TABLE chain_parameters (
epochs_per_year INT NOT NULL,
min_num_of_blocks INT NOT NULL,
min_duration INT NOT NULL,
max_block_time INT NOT NULL,
apr VARCHAR NOT NULL,
native_token_address VARCHAR NOT NULL,
chain_id VARCHAR NOT NULL,
Expand Down
3 changes: 3 additions & 0 deletions orm/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct ParametersInsertDb {
pub epochs_per_year: i32,
pub min_num_of_blocks: i32,
pub min_duration: i32,
pub max_block_time: i32,
pub apr: String,
pub native_token_address: String,
pub chain_id: String,
Expand All @@ -36,6 +37,7 @@ pub struct ParametersDb {
pub epochs_per_year: i32,
pub min_num_of_blocks: i32,
pub min_duration: i32,
pub max_block_time: i32,
pub apr: String,
pub native_token_address: String,
pub chain_id: String,
Expand All @@ -61,6 +63,7 @@ impl From<(Parameters, Genesis, Checksums, EpochSwitchBlocksDelay)>
epochs_per_year: parameters.epochs_per_year as i32,
min_num_of_blocks: parameters.min_num_of_blocks as i32,
min_duration: parameters.min_duration as i32,
max_block_time: parameters.max_block_time as i32,
apr: parameters.apr,
native_token_address: parameters.native_token_address,
chain_id: genesis.chain_id,
Expand Down
1 change: 1 addition & 0 deletions orm/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ diesel::table! {
epochs_per_year -> Int4,
min_num_of_blocks -> Int4,
min_duration -> Int4,
max_block_time -> Int4,
apr -> Varchar,
native_token_address -> Varchar,
chain_id -> Varchar,
Expand Down
4 changes: 3 additions & 1 deletion parameters/src/services/namada.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ pub async fn get_parameters(
.native_token(client)
.await
.context("Failed to query native token")?;
tracing::info!("Native token address: {:?}", native_token_address);

let max_block_time = RPC.shell().max_block_time(client).await?;

let apr = calc_apr(
client,
Expand All @@ -102,6 +103,7 @@ pub async fn get_parameters(
epochs_per_year,
min_num_of_blocks: epoch_duration.min_num_of_blocks,
min_duration: epoch_duration.min_duration.0,
max_block_time: max_block_time.0,
apr,
native_token_address: native_token_address.to_string(),
})
Expand Down
1 change: 1 addition & 0 deletions shared/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub struct Parameters {
pub pipeline_length: u64,
pub epochs_per_year: u64,
pub min_num_of_blocks: u64,
pub max_block_time: u64,
pub min_duration: u64,
pub apr: String,
pub native_token_address: String,
Expand Down
4 changes: 3 additions & 1 deletion webserver/src/response/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ impl Proposal {
pub fn from_proposal_db(
value: GovernanceProposalDb,
chain_state: &ChainCrawlerStateDb,
min_num_of_blocks: i32,
max_block_time: i32,
min_duration: i32,
) -> Self {
let min_num_of_blocks = min_duration / max_block_time;

let epoch_progress = epoch_progress(
chain_state.last_processed_block,
chain_state.first_block_in_epoch,
Expand Down
4 changes: 3 additions & 1 deletion webserver/src/response/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ impl Unbond {
withdraw_epoch: i32,
db_validator: ValidatorDb,
chain_state: &ChainCrawlerStateDb,
min_num_of_blocks: i32,
max_block_time: i32,
min_duration: i32,
) -> Self {
let min_num_of_blocks = min_duration / max_block_time;

let epoch_progress = epoch_progress(
chain_state.last_processed_block,
chain_state.first_block_in_epoch,
Expand Down
6 changes: 3 additions & 3 deletions webserver/src/service/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl GovernanceService {
Proposal::from_proposal_db(
p,
&chain_state,
parameters.min_num_of_blocks,
parameters.max_block_time,
parameters.min_duration,
)
})
Expand Down Expand Up @@ -101,7 +101,7 @@ impl GovernanceService {
Proposal::from_proposal_db(
p,
&chain_state,
parameters.min_num_of_blocks,
parameters.max_block_time,
parameters.min_duration,
)
})
Expand Down Expand Up @@ -134,7 +134,7 @@ impl GovernanceService {
Proposal::from_proposal_db(
p,
&chain_state,
parameters.min_num_of_blocks,
parameters.max_block_time,
parameters.min_duration,
)
}))
Expand Down
2 changes: 1 addition & 1 deletion webserver/src/service/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl PosService {
withdraw_epoch,
validator,
&chain_state,
parameters.min_num_of_blocks,
parameters.max_block_time,
parameters.min_duration,
);
Unbond {
Expand Down

0 comments on commit 808e89e

Please sign in to comment.