Skip to content

Commit d6a40dc

Browse files
committed
Address review comments
1 parent 51d69e5 commit d6a40dc

File tree

6 files changed

+24
-87
lines changed

6 files changed

+24
-87
lines changed

backend-rust/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ To run the services, the following dependencies are required to be available on
1818
## Run the Indexer Service
1919

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

2324
For instructions on how to use the indexer run:

backend-rust/migrations/0001_initialize.up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ CREATE TABLE current_chain_parameters(
9393
epoch_duration
9494
BIGINT
9595
NOT NULL,
96-
-- Number of epochs between reward payouts to happen.
96+
-- Number of epochs between reward payouts.
9797
-- E.g. This value is 24 for testnet in protocol version 7 or above. This means after 24 hours
9898
-- a new payday block is happening on testnet with reward payouts.
9999
reward_period_length

backend-rust/src/graphql_api.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ macro_rules! todo_api {
2424
pub(crate) use todo_api;
2525

2626
use crate::{
27-
scalar_types::{BlockHeight, DateTime, RewardPeriodLength, TimeSpan},
27+
scalar_types::{BlockHeight, DateTime, TimeSpan, UnsignedLong},
2828
transaction_event::smart_contracts::InvalidContractVersionError,
2929
};
3030
use account::Account;
3131
use anyhow::Context as _;
3232
use async_graphql::{
3333
http::GraphiQLSource,
3434
types::{self, connection},
35-
Context, EmptyMutation, Enum, MergedObject, Object, Schema, SimpleObject, Subscription,
35+
Context, EmptyMutation, Enum, MergedObject, Object, Schema, SimpleObject, Subscription, Union,
3636
};
3737
use async_graphql_axum::GraphQLSubscription;
3838
use block::Block;
@@ -501,9 +501,12 @@ impl BaseQuery {
501501
.await?
502502
.ok_or(ApiError::NotFound)?;
503503

504-
Ok(LatestChainParameters {
505-
reward_period_length,
506-
})
504+
// Future improvement (breaking changes): remove `ChainParametersV1` and just
505+
// use the `reward_period_length` from the current consensus algorithm
506+
// directly.
507+
Ok(LatestChainParameters::ChainParametersV1(ChainParametersV1 {
508+
reward_period_length: reward_period_length.try_into()?,
509+
}))
507510
}
508511

509512
async fn tokens(
@@ -767,9 +770,16 @@ struct ImportState {
767770
epoch_duration: TimeSpan,
768771
}
769772

773+
// Future improvement (breaking changes): remove `ChainParametersV1` and just
774+
// use the `reward_period_length` from the current consensus algorithm directly.
775+
#[derive(Union)]
776+
pub enum LatestChainParameters {
777+
ChainParametersV1(ChainParametersV1),
778+
}
779+
770780
#[derive(SimpleObject)]
771-
struct LatestChainParameters {
772-
reward_period_length: RewardPeriodLength,
781+
pub struct ChainParametersV1 {
782+
pub reward_period_length: UnsignedLong,
773783
}
774784

775785
#[derive(SimpleObject)]

backend-rust/src/graphql_api/block.rs

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use crate::{
44
graphql_api::Transaction,
55
scalar_types::{Amount, BakerId, BlockHash, BlockHeight, DateTime},
66
};
7-
use async_graphql::{
8-
connection, types, ComplexObject, Context, Enum, Interface, Object, SimpleObject, Union,
9-
};
7+
use async_graphql::{connection, types, ComplexObject, Context, Enum, Object, SimpleObject, Union};
108

119
#[derive(Default)]
1210
pub(crate) struct QueryBlocks;
@@ -447,80 +445,6 @@ struct BalanceStatistics {
447445
gas_account: Amount,
448446
}
449447

450-
#[derive(Interface)]
451-
#[allow(clippy::duplicated_attributes)]
452-
#[graphql(
453-
field(name = "euro_per_energy", ty = "&ExchangeRate"),
454-
field(name = "micro_ccd_per_euro", ty = "&ExchangeRate"),
455-
field(name = "account_creation_limit", ty = "&i32"),
456-
field(name = "foundation_account_address", ty = "&AccountAddress")
457-
)]
458-
enum ChainParameters {
459-
ChainParametersV0(ChainParametersV0),
460-
ChainParametersV1(ChainParametersV1),
461-
ChainParametersV2(ChainParametersV2),
462-
}
463-
464-
#[derive(SimpleObject)]
465-
struct ChainParametersV0 {
466-
// TODO
467-
// electionDifficulty: Decimal!
468-
// bakerCooldownEpochs: UnsignedLong!
469-
// rewardParameters: RewardParametersV0!
470-
// minimumThresholdForBaking: UnsignedLong!
471-
euro_per_energy: ExchangeRate,
472-
micro_ccd_per_euro: ExchangeRate,
473-
account_creation_limit: i32,
474-
foundation_account_address: AccountAddress,
475-
}
476-
477-
#[derive(SimpleObject)]
478-
struct ChainParametersV1 {
479-
// TODO
480-
// electionDifficulty: Decimal!
481-
// poolOwnerCooldown: UnsignedLong!
482-
// delegatorCooldown: UnsignedLong!
483-
// rewardPeriodLength: UnsignedLong!
484-
// mintPerPayday: Decimal!
485-
// rewardParameters: RewardParametersV1!
486-
// passiveFinalizationCommission: Decimal!
487-
// passiveBakingCommission: Decimal!
488-
// passiveTransactionCommission: Decimal!
489-
// finalizationCommissionRange: CommissionRange!
490-
// bakingCommissionRange: CommissionRange!
491-
// transactionCommissionRange: CommissionRange!
492-
// minimumEquityCapital: UnsignedLong!
493-
// capitalBound: Decimal!
494-
// leverageBound: LeverageFactor!
495-
euro_per_energy: ExchangeRate,
496-
micro_ccd_per_euro: ExchangeRate,
497-
account_creation_limit: i32,
498-
foundation_account_address: AccountAddress,
499-
}
500-
501-
#[derive(SimpleObject)]
502-
struct ChainParametersV2 {
503-
// TODO
504-
// poolOwnerCooldown: UnsignedLong!
505-
// delegatorCooldown: UnsignedLong!
506-
// rewardPeriodLength: UnsignedLong!
507-
// mintPerPayday: Decimal!
508-
// rewardParameters: RewardParametersV2!
509-
// passiveFinalizationCommission: Decimal!
510-
// passiveBakingCommission: Decimal!
511-
// passiveTransactionCommission: Decimal!
512-
// finalizationCommissionRange: CommissionRange!
513-
// bakingCommissionRange: CommissionRange!
514-
// transactionCommissionRange: CommissionRange!
515-
// minimumEquityCapital: UnsignedLong!
516-
// capitalBound: Decimal!
517-
// leverageBound: LeverageFactor!
518-
euro_per_energy: ExchangeRate,
519-
micro_ccd_per_euro: ExchangeRate,
520-
account_creation_limit: i32,
521-
foundation_account_address: AccountAddress,
522-
}
523-
524448
#[derive(SimpleObject)]
525449
struct ExchangeRate {
526450
numerator: u64,

backend-rust/src/indexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ async fn save_genesis_data(endpoint: v2::Endpoint, pool: &PgPool) -> anyhow::Res
737737
ChainParameters::V1(chain_parameters_v1) => {
738738
chain_parameters_v1.time_parameters.reward_period_length
739739
}
740-
_ => todo!(
740+
ChainParameters::V0(_) => unimplemented!(
741741
"Expect the chain to have caught up enought for the `reward_period_length` value \
742742
being available."
743743
),

frontend/src/queries/useBakerQuery.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ const BakerQuery = gql<BakerResponse>`
3737
3838
latestChainParameters {
3939
__typename
40-
rewardPeriodLength
40+
... on ChainParametersV1 {
41+
rewardPeriodLength
42+
}
4143
}
4244
4345
importState {

0 commit comments

Comments
 (0)