Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Jan 23, 2025
1 parent 51d69e5 commit b066c88
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 89 deletions.
1 change: 1 addition & 0 deletions backend-rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ To run the services, the following dependencies are required to be available on
## Run the Indexer Service

The indexer talks to a Concordium node in order to gather data about the chain, which it then inserts into a PostgreSQL database.
Note that the connected Concordium node needs to be caught-up to protocol 7 or above.
Note that only one instance of the indexer may run at any one time, as multiple instances would conflict with each other.

For instructions on how to use the indexer run:
Expand Down
2 changes: 1 addition & 1 deletion backend-rust/migrations/0001_initialize.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ CREATE TABLE current_chain_parameters(
epoch_duration
BIGINT
NOT NULL,
-- Number of epochs between reward payouts to happen.
-- Number of epochs between reward payouts.
-- E.g. This value is 24 for testnet in protocol version 7 or above. This means after 24 hours
-- a new payday block is happening on testnet with reward payouts.
reward_period_length
Expand Down
24 changes: 17 additions & 7 deletions backend-rust/src/graphql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ macro_rules! todo_api {
pub(crate) use todo_api;

use crate::{
scalar_types::{BlockHeight, DateTime, RewardPeriodLength, TimeSpan},
scalar_types::{BlockHeight, DateTime, TimeSpan, UnsignedLong},
transaction_event::smart_contracts::InvalidContractVersionError,
};
use account::Account;
use anyhow::Context as _;
use async_graphql::{
http::GraphiQLSource,
types::{self, connection},
Context, EmptyMutation, Enum, MergedObject, Object, Schema, SimpleObject, Subscription,
Context, EmptyMutation, Enum, MergedObject, Object, Schema, SimpleObject, Subscription, Union,
};
use async_graphql_axum::GraphQLSubscription;
use block::Block;
Expand Down Expand Up @@ -501,9 +501,12 @@ impl BaseQuery {
.await?
.ok_or(ApiError::NotFound)?;

Ok(LatestChainParameters {
reward_period_length,
})
// Future improvement (breaking changes): remove `ChainParametersV1` and just
// use the `reward_period_length` from the current consensus algorithm
// directly.
Ok(LatestChainParameters::ChainParametersV1(ChainParametersV1 {
reward_period_length: reward_period_length.try_into()?,
}))
}

async fn tokens(
Expand Down Expand Up @@ -767,9 +770,16 @@ struct ImportState {
epoch_duration: TimeSpan,
}

// Future improvement (breaking changes): remove `ChainParametersV1` and just
// use the `reward_period_length` from the current consensus algorithm directly.
#[derive(Union)]
pub enum LatestChainParameters {
ChainParametersV1(ChainParametersV1),
}

#[derive(SimpleObject)]
struct LatestChainParameters {
reward_period_length: RewardPeriodLength,
pub struct ChainParametersV1 {
pub reward_period_length: UnsignedLong,
}

#[derive(SimpleObject)]
Expand Down
78 changes: 1 addition & 77 deletions backend-rust/src/graphql_api/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use crate::{
graphql_api::Transaction,
scalar_types::{Amount, BakerId, BlockHash, BlockHeight, DateTime},
};
use async_graphql::{
connection, types, ComplexObject, Context, Enum, Interface, Object, SimpleObject, Union,
};
use async_graphql::{connection, types, ComplexObject, Context, Enum, Object, SimpleObject, Union};

#[derive(Default)]
pub(crate) struct QueryBlocks;
Expand Down Expand Up @@ -447,80 +445,6 @@ struct BalanceStatistics {
gas_account: Amount,
}

#[derive(Interface)]
#[allow(clippy::duplicated_attributes)]
#[graphql(
field(name = "euro_per_energy", ty = "&ExchangeRate"),
field(name = "micro_ccd_per_euro", ty = "&ExchangeRate"),
field(name = "account_creation_limit", ty = "&i32"),
field(name = "foundation_account_address", ty = "&AccountAddress")
)]
enum ChainParameters {
ChainParametersV0(ChainParametersV0),
ChainParametersV1(ChainParametersV1),
ChainParametersV2(ChainParametersV2),
}

#[derive(SimpleObject)]
struct ChainParametersV0 {
// TODO
// electionDifficulty: Decimal!
// bakerCooldownEpochs: UnsignedLong!
// rewardParameters: RewardParametersV0!
// minimumThresholdForBaking: UnsignedLong!
euro_per_energy: ExchangeRate,
micro_ccd_per_euro: ExchangeRate,
account_creation_limit: i32,
foundation_account_address: AccountAddress,
}

#[derive(SimpleObject)]
struct ChainParametersV1 {
// TODO
// electionDifficulty: Decimal!
// poolOwnerCooldown: UnsignedLong!
// delegatorCooldown: UnsignedLong!
// rewardPeriodLength: UnsignedLong!
// mintPerPayday: Decimal!
// rewardParameters: RewardParametersV1!
// passiveFinalizationCommission: Decimal!
// passiveBakingCommission: Decimal!
// passiveTransactionCommission: Decimal!
// finalizationCommissionRange: CommissionRange!
// bakingCommissionRange: CommissionRange!
// transactionCommissionRange: CommissionRange!
// minimumEquityCapital: UnsignedLong!
// capitalBound: Decimal!
// leverageBound: LeverageFactor!
euro_per_energy: ExchangeRate,
micro_ccd_per_euro: ExchangeRate,
account_creation_limit: i32,
foundation_account_address: AccountAddress,
}

#[derive(SimpleObject)]
struct ChainParametersV2 {
// TODO
// poolOwnerCooldown: UnsignedLong!
// delegatorCooldown: UnsignedLong!
// rewardPeriodLength: UnsignedLong!
// mintPerPayday: Decimal!
// rewardParameters: RewardParametersV2!
// passiveFinalizationCommission: Decimal!
// passiveBakingCommission: Decimal!
// passiveTransactionCommission: Decimal!
// finalizationCommissionRange: CommissionRange!
// bakingCommissionRange: CommissionRange!
// transactionCommissionRange: CommissionRange!
// minimumEquityCapital: UnsignedLong!
// capitalBound: Decimal!
// leverageBound: LeverageFactor!
euro_per_energy: ExchangeRate,
micro_ccd_per_euro: ExchangeRate,
account_creation_limit: i32,
foundation_account_address: AccountAddress,
}

#[derive(SimpleObject)]
struct ExchangeRate {
numerator: u64,
Expand Down
4 changes: 2 additions & 2 deletions backend-rust/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,8 @@ async fn save_genesis_data(endpoint: v2::Endpoint, pool: &PgPool) -> anyhow::Res
ChainParameters::V1(chain_parameters_v1) => {
chain_parameters_v1.time_parameters.reward_period_length
}
_ => todo!(
"Expect the chain to have caught up enought for the `reward_period_length` value \
ChainParameters::V0(_) => unimplemented!(
"Expect the node to have caught up enought for the `reward_period_length` value \
being available."
),
};
Expand Down
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@
},
"volta": {
"node": "18.18.2"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
4 changes: 3 additions & 1 deletion frontend/src/queries/useBakerQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const BakerQuery = gql<BakerResponse>`
latestChainParameters {
__typename
rewardPeriodLength
... on ChainParametersV1 {
rewardPeriodLength
}
}
importState {
Expand Down

0 comments on commit b066c88

Please sign in to comment.