Skip to content

Commit

Permalink
Merge pull request #217 from Concordium/inactive-validators
Browse files Browse the repository at this point in the history
Support for inactive validator events.
  • Loading branch information
td202 authored Dec 6, 2024
2 parents 9b9f22b + f8894dd commit eb4a3ea
Show file tree
Hide file tree
Showing 10 changed files with 944 additions and 18 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
## Unreleased changes

- Add functionality for generating, and verifying account signatures.
- Support for protocol version 8 functionality:
- `ConfigureBakerPayload` supports the optional `suspend` flag.
- `BakerEvent` has new cases for `BakerSuspended` and `BakerResumed` when the flag is set in a
`ConfigureBaker` transaction.
- `SpecialTransactionOutcome` has new cases for `ValidatorSuspended` and
`ValidatorPrimedForSuspension`, which occur when a validator is (or potentially will be)
suspended.
- New `UpdatePayload` type `ValidatorScoreParametersCPV3`, which updates the maximum number of
consecutive failures a validator can have before it faces suspension.

## 5.0.0

Expand Down
2 changes: 1 addition & 1 deletion concordium-base
Submodule concordium-base updated 104 files
1 change: 1 addition & 0 deletions examples/v2_update_exchange_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async fn main() -> anyhow::Result<()> {
v2::ChainParameters::V0(v0) => v0.micro_ccd_per_euro,
v2::ChainParameters::V1(v1) => v1.micro_ccd_per_euro,
v2::ChainParameters::V2(v2) => v2.micro_ccd_per_euro,
v2::ChainParameters::V3(v3) => v3.micro_ccd_per_euro,
};

let effective_time = 0.into(); // immediate effect
Expand Down
38 changes: 38 additions & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ pub enum AccountStakingInfo {
baker_info: Box<BakerInfo>,
pending_change: Option<StakePendingChange>,
pool_info: Option<BakerPoolInfo>,
/// A flag indicating whether the baker is currently suspended or not.
/// The flag will always be `false` for protocol versions before version
/// 8. A suspended validator will not be included in the validator
/// committee the next time it is calculated.
is_suspended: bool,
},
/// The account is delegating stake to a baker.
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -891,6 +896,23 @@ pub enum SpecialTransactionOutcome {
/// Accrued finalization rewards for pool.
finalization_reward: Amount,
},
/// A validator was suspended due to too many missed rounds.
#[serde(rename_all = "camelCase")]
ValidatorSuspended {
/// The validator that was suspended.
baker_id: BakerId,
/// The account address of the validator.
account: AccountAddress,
},
/// A validator was primed to be suspended at the next snapshot epoch due to
/// too many missed rounds.
#[serde(rename_all = "camelCase")]
ValidatorPrimedForSuspension {
/// The validator that was primed for suspension.
baker_id: BakerId,
/// The account address of the validator.
account: AccountAddress,
},
}

impl SpecialTransactionOutcome {
Expand Down Expand Up @@ -923,6 +945,12 @@ impl SpecialTransactionOutcome {
SpecialTransactionOutcome::PaydayAccountReward { account, .. } => vec![*account],
SpecialTransactionOutcome::BlockAccrueReward { .. } => Vec::new(),
SpecialTransactionOutcome::PaydayPoolReward { .. } => Vec::new(),
SpecialTransactionOutcome::ValidatorSuspended { account, .. } => {
vec![*account]
}
SpecialTransactionOutcome::ValidatorPrimedForSuspension { account, .. } => {
vec![*account]
}
}
}
}
Expand Down Expand Up @@ -2111,6 +2139,16 @@ pub enum BakerEvent {
/// from the account immediately.
delegator_id: DelegatorId,
},
/// The baker was suspended.
BakerSuspended {
// Baker's id
baker_id: BakerId,
},
/// The baker was suspended.
BakerResumed {
// Baker's id
baker_id: BakerId,
},
}

#[derive(Debug, Clone)]
Expand Down
2 changes: 2 additions & 0 deletions src/types/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ pub enum PendingUpdateEffect {
BlockEnergyLimit(Energy),
#[serde(rename = "finalizationCommitteeParameters")]
FinalizationCommitteeParameters(FinalizationCommitteeParameters),
#[serde(rename = "validatorScoreParameters")]
ValidatorScoreParameters(ValidatorScoreParameters),
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
Expand Down
26 changes: 26 additions & 0 deletions src/types/summary_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,20 @@ pub(crate) enum Event {
/// The new module reference that is in effect after the upgrade.
to: smart_contracts::ModuleReference,
},
#[serde(rename_all = "camelCase")]
BakerSuspended {
/// Baker's id
baker_id: BakerId,
/// Baker account
account: AccountAddress,
},
#[serde(rename_all = "camelCase")]
BakerResumed {
/// Baker's id
baker_id: BakerId,
/// Baker account
account: AccountAddress,
},
}

impl From<super::ContractTraceElement> for Event {
Expand Down Expand Up @@ -693,6 +707,18 @@ impl From<super::BlockItemSummary> for BlockItemSummary {
account: sender,
}
}
super::BakerEvent::BakerSuspended { baker_id } => {
Event::BakerSuspended {
baker_id,
account: sender,
}
}
super::BakerEvent::BakerResumed { baker_id } => {
Event::BakerResumed {
baker_id,
account: sender,
}
}
})
.collect();
(Some(ty), BlockItemResult::Success { events })
Expand Down
78 changes: 78 additions & 0 deletions src/v2/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ impl From<ProtocolVersion> for super::types::ProtocolVersion {
ProtocolVersion::ProtocolVersion5 => super::types::ProtocolVersion::P5,
ProtocolVersion::ProtocolVersion6 => super::types::ProtocolVersion::P6,
ProtocolVersion::ProtocolVersion7 => super::types::ProtocolVersion::P7,
ProtocolVersion::ProtocolVersion8 => super::types::ProtocolVersion::P8,
}
}
}
Expand All @@ -461,6 +462,7 @@ impl From<super::types::ProtocolVersion> for ProtocolVersion {
super::types::ProtocolVersion::P5 => ProtocolVersion::ProtocolVersion5,
super::types::ProtocolVersion::P6 => ProtocolVersion::ProtocolVersion6,
super::types::ProtocolVersion::P7 => ProtocolVersion::ProtocolVersion7,
super::types::ProtocolVersion::P8 => ProtocolVersion::ProtocolVersion8,
}
}
}
Expand Down Expand Up @@ -560,12 +562,14 @@ impl TryFrom<AccountStakingInfo> for super::types::AccountStakingInfo {
None => None,
Some(bi) => Some(bi.try_into()?),
};
let is_suspended = bsi.is_suspended;
Ok(Self::Baker {
staked_amount,
restake_earnings,
baker_info: Box::new(baker_info),
pending_change,
pool_info,
is_suspended,
})
}
account_staking_info::StakingInfo::Delegator(dsi) => {
Expand Down Expand Up @@ -1417,6 +1421,9 @@ impl TryFrom<UpdatePayload> for super::types::UpdatePayload {
update_payload::Payload::FinalizationCommitteeParametersUpdate(v) => {
Self::FinalizationCommitteeParametersCPV2(v.try_into()?)
}
update_payload::Payload::ValidatorScoreParametersUpdate(v) => {
Self::ValidatorScoreParametersCPV3(v.try_into()?)
}
})
}
}
Expand Down Expand Up @@ -1941,6 +1948,12 @@ impl TryFrom<BakerEvent> for super::types::BakerEvent {
baker_event::Event::DelegationRemoved(v) => Self::DelegationRemoved {
delegator_id: v.delegator_id.require()?.try_into()?,
},
baker_event::Event::BakerSuspended(v) => Self::BakerSuspended {
baker_id: v.baker_id.require()?.into(),
},
baker_event::Event::BakerResumed(v) => Self::BakerResumed {
baker_id: v.baker_id.require()?.into(),
},
})
}
}
Expand Down Expand Up @@ -2445,6 +2458,46 @@ impl TryFrom<ChainParametersV2> for super::ChainParametersV2 {
}
}

impl TryFrom<ChainParametersV3> for super::ChainParametersV3 {
type Error = tonic::Status;

fn try_from(value: ChainParametersV3) -> Result<Self, Self::Error> {
let consensus_parameters = value.consensus_parameters.require()?;

Ok(Self {
timeout_parameters: consensus_parameters
.timeout_parameters
.require()?
.try_into()?,
min_block_time: consensus_parameters.min_block_time.require()?.into(),
block_energy_limit: consensus_parameters.block_energy_limit.require()?.into(),
euro_per_energy: value.euro_per_energy.require()?.try_into()?,
micro_ccd_per_euro: value.micro_ccd_per_euro.require()?.try_into()?,
pool_parameters: value.pool_parameters.require()?.try_into()?,
account_creation_limit: value.account_creation_limit.require()?.try_into()?,
mint_distribution: value.mint_distribution.require()?.try_into()?,
transaction_fee_distribution: value
.transaction_fee_distribution
.require()?
.try_into()?,
gas_rewards: value.gas_rewards.require()?.try_into()?,
foundation_account: value.foundation_account.require()?.try_into()?,
time_parameters: value.time_parameters.require()?.try_into()?,
cooldown_parameters: value.cooldown_parameters.require()?.try_into()?,
finalization_committee_parameters: value
.finalization_committee_parameters
.require()?
.try_into()?,
validator_score_parameters: value.validator_score_parameters.require()?.try_into()?,
keys: UpdateKeysCollectionSkeleton {
root_keys: value.root_keys.require()?.try_into()?,
level_1_keys: value.level1_keys.require()?.try_into()?,
level_2_keys: value.level2_keys.require()?.try_into()?,
},
})
}
}

impl TryFrom<ChainParameters> for super::ChainParameters {
type Error = tonic::Status;

Expand All @@ -2453,6 +2506,7 @@ impl TryFrom<ChainParameters> for super::ChainParameters {
chain_parameters::Parameters::V0(v0) => Ok(Self::V0(v0.try_into()?)),
chain_parameters::Parameters::V1(v1) => Ok(Self::V1(v1.try_into()?)),
chain_parameters::Parameters::V2(v2) => Ok(Self::V2(v2.try_into()?)),
chain_parameters::Parameters::V3(v3) => Ok(Self::V3(v3.try_into()?)),
}
}
}
Expand Down Expand Up @@ -2864,6 +2918,16 @@ impl TryFrom<BlockSpecialEvent> for super::types::SpecialTransactionOutcome {
baker_reward: event.baker_reward.require()?.into(),
finalization_reward: event.finalization_reward.require()?.into(),
},
block_special_event::Event::ValidatorSuspended(event) => Self::ValidatorSuspended {
baker_id: event.baker_id.require()?.into(),
account: event.account.require()?.try_into()?,
},
block_special_event::Event::ValidatorPrimedForSuspension(event) => {
Self::ValidatorPrimedForSuspension {
baker_id: event.baker_id.require()?.into(),
account: event.account.require()?.try_into()?,
}
}
};
Ok(event)
}
Expand Down Expand Up @@ -3006,6 +3070,16 @@ impl TryFrom<FinalizationCommitteeParameters> for updates::FinalizationCommittee
}
}

impl TryFrom<ValidatorScoreParameters> for updates::ValidatorScoreParameters {
type Error = tonic::Status;

fn try_from(value: ValidatorScoreParameters) -> Result<Self, Self::Error> {
Ok(Self {
max_missed_rounds: value.maximum_missed_rounds,
})
}
}

impl TryFrom<PoolParametersCpv1> for updates::PoolParameters {
type Error = tonic::Status;

Expand Down Expand Up @@ -3213,6 +3287,10 @@ impl TryFrom<PendingUpdate> for super::types::queries::PendingUpdate {
effective_time,
effect: PendingUpdateEffect::FinalizationCommitteeParameters(update.try_into()?),
}),
pending_update::Effect::ValidatorScoreParameters(update) => Ok(Self {
effective_time,
effect: PendingUpdateEffect::ValidatorScoreParameters(update.try_into()?),
}),
}
}
}
Expand Down
Loading

0 comments on commit eb4a3ea

Please sign in to comment.