Skip to content

Commit

Permalink
Merge pull request #397 from Concordium/p8-conformance
Browse files Browse the repository at this point in the history
P8 conformance
  • Loading branch information
soerenbf authored Jan 13, 2025
2 parents c4e665a + 19e407d commit 5f968c9
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 10 deletions.
2 changes: 1 addition & 1 deletion deps/concordium-base
Submodule concordium-base updated 109 files
11 changes: 11 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## Unreleased

### Breaking changes

- Protocol version 8:
- Add `isSuspended` field to `AccountBakerDetails`.
- Add `BakerSuspendedEvent` and `BakerResumedEvent` to `BakerEvent` union type.
- Add `BlockSpecialEventValidatorSuspended` and `BlockSpecialEventValidatorPrimedForSuspension` to `BlockSpecialEvent` union type.
- Add `PendingValidatorScoreUpdate` to `UpdateInstructionPayload` union type.
- Add `ChainParametersV3` to `ChainParameters` union type.

## 8.1.0

### Added
Expand Down
58 changes: 54 additions & 4 deletions packages/sdk/src/grpc/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ function trOpenStatus(openStatus: v2.OpenStatus | undefined): v1.OpenStatusText

function trBaker(baker: v2.AccountStakingInfo_Baker): v1.AccountBakerDetails {
const bakerInfo = baker.bakerInfo;
const isSuspended = baker.isSuspended;

const v0: v1.AccountBakerDetails = {
version: 0,
Expand All @@ -228,6 +229,7 @@ function trBaker(baker: v2.AccountStakingInfo_Baker): v1.AccountBakerDetails {
...(baker.pendingChange && {
pendingChange: trPendingChange(baker.pendingChange),
}),
isSuspended,
};

if (baker.poolInfo === undefined) {
Expand Down Expand Up @@ -324,6 +326,8 @@ function transPaydayStatus(status: v2.PoolCurrentPaydayInfo): v1.CurrentPaydayBa
bakerEquityCapital: CcdAmount.fromProto(unwrap(status.bakerEquityCapital)),
delegatedCapital: CcdAmount.fromProto(unwrap(status.delegatedCapital)),
commissionRates: trCommissionRates(status.commissionRates),
isPrimedForSuspension: status.isPrimedForSuspension ?? false,
missedRounds: status.missedRounds ?? 0n,
};
}

Expand Down Expand Up @@ -499,7 +503,7 @@ function trChainParametersV1(params: v2.ChainParametersV1): v1.ChainParametersV1
};
}

function trChainParametersV2(params: v2.ChainParametersV2): v1.ChainParametersV2 {
function trChainParametersV2(params: v2.ChainParametersV2 | v2.ChainParametersV3): v1.ChainParametersV2 {
const common = translateChainParametersCommon(params);
const commonRewardParameters = translateRewardParametersCommon(params);

Expand Down Expand Up @@ -548,8 +552,22 @@ function trChainParametersV2(params: v2.ChainParametersV2): v1.ChainParametersV2
};
}

function trChainParametersV3(params: v2.ChainParametersV3): v1.ChainParametersV3 {
const { version, ...common } = trChainParametersV2(params);
return {
...common,
version: 3,
validatorScoreParameters: {
maxMissedRounds: unwrap(params.validatorScoreParameters?.maximumMissedRounds),
},
};
}

export function blockChainParameters(params: v2.ChainParameters): v1.ChainParameters {
switch (params.parameters.oneofKind) {
case 'v3': {
return trChainParametersV3(params.parameters.v3);
}
case 'v2': {
return trChainParametersV2(params.parameters.v2);
}
Expand All @@ -559,7 +577,7 @@ export function blockChainParameters(params: v2.ChainParameters): v1.ChainParame
case 'v0': {
return trChainParametersV0(params.parameters.v0);
}
default:
case undefined:
throw new Error('Missing chain parameters');
}
}
Expand All @@ -578,6 +596,7 @@ export function bakerPoolInfo(info: v2.PoolInfoResponse): v1.BakerPoolStatus {
currentPaydayStatus:
info.currentPaydayInfo !== undefined ? transPaydayStatus(info.currentPaydayInfo) : undefined,
allPoolTotalCapital: CcdAmount.fromProto(unwrap(info.allPoolTotalCapital)),
isSuspended: info.isSuspended ?? false,
};
}

Expand Down Expand Up @@ -876,6 +895,18 @@ function trBakerEvent(bakerEvent: v2.BakerEvent, account: AccountAddress.Type):
delegatorId: unwrap(event.delegationRemoved.delegatorId?.id?.value),
};
}
case 'bakerSuspended': {
return {
tag: v1.TransactionEventTag.BakerSuspended,
bakerId: unwrap(event.bakerSuspended.bakerId?.value),
};
}
case 'bakerResumed': {
return {
tag: v1.TransactionEventTag.BakerResumed,
bakerId: unwrap(event.bakerResumed.bakerId?.value),
};
}
case undefined:
throw Error('Unrecognized event type. This should be impossible.');
}
Expand Down Expand Up @@ -1436,10 +1467,15 @@ export function trPendingUpdateEffect(pendingUpdate: v2.PendingUpdate): v1.Pendi
updatePayload: trAuthorizationsV1(effect.level2KeysCpv1),
},
};
case 'validatorScoreParameters':
return {
updateType: v1.UpdateType.ValidatorScoreParameters,
update: {
maxMissedRounds: effect.validatorScoreParameters.maximumMissedRounds,
},
};
case undefined:
throw Error('Unexpected missing pending update');
default:
throw Error(`Unsupported update: ${effect}`);
}
}

Expand Down Expand Up @@ -2408,6 +2444,20 @@ export function blockSpecialEvent(specialEvent: v2.BlockSpecialEvent): v1.BlockS
...(poolOwner !== undefined && { poolOwner }),
};
}
case 'validatorSuspended': {
return {
tag: 'validatorSuspended',
account: AccountAddress.fromProto(unwrap(event.validatorSuspended.account)),
bakerId: unwrap(event.validatorSuspended.bakerId?.value),
};
}
case 'validatorPrimedForSuspension': {
return {
tag: 'validatorPrimedForSuspension',
account: AccountAddress.fromProto(unwrap(event.validatorPrimedForSuspension.account)),
bakerId: unwrap(event.validatorPrimedForSuspension.bakerId?.value),
};
}
case undefined: {
throw Error('Error translating BlockSpecialEvent: unexpected undefined');
}
Expand Down
44 changes: 42 additions & 2 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export type ChainParametersV1 = ChainParametersCommon &
level2Keys: AuthorizationsV1;
};

/** Chain parameters used from protocol version 6 */
/** Chain parameters used in protocol version 6 and 7 */
export type ChainParametersV2 = ChainParametersCommon &
CooldownParametersV1 &
TimeParametersV1 &
Expand All @@ -468,8 +468,24 @@ export type ChainParametersV2 = ChainParametersCommon &
level2Keys: AuthorizationsV1;
};

/**
* Validator score parameters. These parameters control the threshold of
* maximal missed rounds before a validator gets suspended.
*/
export interface ValidatorScoreParameters {
/** Maximal number of missed rounds before a validator gets suspended. */
maxMissedRounds: bigint;
}

/** Chain parameters used from protocol version 8 */
export type ChainParametersV3 = Omit<ChainParametersV2, 'version'> & {
version: 3;
/** The current validator score parameters */
validatorScoreParameters: ValidatorScoreParameters;
};

/** Union of all chain parameters across all protocol versions */
export type ChainParameters = ChainParametersV0 | ChainParametersV1 | ChainParametersV2;
export type ChainParameters = ChainParametersV0 | ChainParametersV1 | ChainParametersV2 | ChainParametersV3;

export interface Authorization {
threshold: number;
Expand Down Expand Up @@ -875,15 +891,28 @@ export interface CommissionRates {
finalizationCommission: number;
}

/** Information about a baker pool in the current reward period. */
export interface CurrentPaydayBakerPoolStatus {
/** The number of blocks baked in the current reward period. */
blocksBaked: bigint;
/** The number of blocks baked in the current reward period. */
finalizationLive: boolean;
/** The transaction fees accruing to the pool in the current reward period. */
transactionFeesEarned: CcdAmount.Type;
/** The effective stake of the baker in the current reward period. */
effectiveStake: CcdAmount.Type;
/** The lottery power of the baker in the current reward period. */
lotteryPower: number;
/** The effective equity capital of the baker for the current reward period. */
bakerEquityCapital: CcdAmount.Type;
/** The effective delegated capital to the pool for the current reward period. */
delegatedCapital: CcdAmount.Type;
/** The commission rates that apply for the current reward period. */
commissionRates: CommissionRates;
/** A flag indicating whether the pool owner is primed for suspension. Will always be `false` if the protocol version does not support validator suspension. */
isPrimedForSuspension: boolean;
/** The number of missed rounds in the current reward period. Will always be `0n` if the protocol version does not support validator suspension. */
missedRounds: bigint;
}

export enum BakerPoolPendingChangeType {
Expand Down Expand Up @@ -963,6 +992,11 @@ export interface BakerPoolStatusDetails {
currentPaydayStatus?: CurrentPaydayBakerPoolStatus;
/** Total capital staked across all pools, including passive delegation. */
allPoolTotalCapital: CcdAmount.Type;
/**
* A flag indicating whether the pool owner is suspended.
* Will always be `false` if the protocol version does not support validator suspension.
*/
isSuspended: boolean;
}

/**
Expand Down Expand Up @@ -1029,6 +1063,12 @@ interface AccountBakerDetailsCommon {
bakerSignatureVerifyKey: string;
stakedAmount: CcdAmount.Type;
pendingChange?: StakePendingChange;
/**
* A flag indicating whether the validator is currently suspended or not.
* In protocol versions prior to protocol version 8, this will always be `false`.
* A suspended validator will not be included in the validator committee the next time it is calculated.
*/
isSuspended: boolean;
}

/** Protocol version 1-3. */
Expand Down
33 changes: 32 additions & 1 deletion packages/sdk/src/types/BlockSpecialEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type { BakerId } from '../types.js';
import * as AccountAddress from './AccountAddress.js';
import * as CcdAmount from './CcdAmount.js';

/**
* A union of all the different "special events" that can be part of a block.
*/
export type BlockSpecialEvent =
| BlockSpecialEventBakingRewards
| BlockSpecialEventMint
Expand All @@ -10,7 +13,9 @@ export type BlockSpecialEvent =
| BlockSpecialEventPaydayFoundationReward
| BlockSpecialEventPaydayAccountReward
| BlockSpecialEventBlockAccrueReward
| BlockSpecialEventPaydayPoolReward;
| BlockSpecialEventPaydayPoolReward
| BlockSpecialEventValidatorSuspended
| BlockSpecialEventValidatorPrimedForSuspension;

export interface BlockSpecialEventBakingRewards {
tag: 'bakingRewards';
Expand Down Expand Up @@ -115,6 +120,29 @@ export interface BlockSpecialEventAccountAmount {
amount: CcdAmount.Type;
}

/**
* A validator was suspended due to too many missed rounds.
*/
export interface BlockSpecialEventValidatorSuspended {
tag: 'validatorSuspended';
/** The validator that was suspended. */
bakerId: BakerId;
/** The account address of the validator. */
account: AccountAddress.Type;
}

/**
* A validator was primed to be suspended at the next snapshot epoch due to
* too many missed rounds.
*/
export interface BlockSpecialEventValidatorPrimedForSuspension {
tag: 'validatorPrimedForSuspension';
/** The validator that was primed for suspension. */
bakerId: BakerId;
/** The account address of the validator. */
account: AccountAddress.Type;
}

/**
* Gets a list of {@link AccountAddress.Type} account addresses affected the {@link BlockSpecialEvent}.
*
Expand Down Expand Up @@ -146,6 +174,9 @@ export function specialEventAffectedAccounts(event: BlockSpecialEvent): AccountA
}
return [event.baker, event.foundationAccount];
}
case 'validatorSuspended':
case 'validatorPrimedForSuspension':
return [event.account];
default:
return [];
}
Expand Down
8 changes: 7 additions & 1 deletion packages/sdk/src/types/chainUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
MintRate,
TimeoutParameters,
TransactionFeeDistribution,
ValidatorScoreParameters,
VerifyKey,
} from '../types.js';
import type * as CcdAmount from './CcdAmount.js';
Expand Down Expand Up @@ -103,6 +104,9 @@ export type PendingHigherLevelKeyUpdate = ChainUpdate<UpdateType.HigherLevelKeyU
/** A pending update to authorization keys */
export type PendingAuthorizationKeysUpdate = ChainUpdate<UpdateType.AuthorizationKeysUpdate, AuthorizationKeysUpdate>;

/** A pending update to validator score parameters */
export type PendingValidatorScoreUpdate = ChainUpdate<UpdateType.ValidatorScoreParameters, ValidatorScoreParameters>;

/** A union of chain updates, barring key updates */
export type CommonUpdate =
| MicroGtuPerEuroUpdate
Expand All @@ -123,7 +127,8 @@ export type CommonUpdate =
| TimeoutParametersUpdate
| MinBlockTimeUpdate
| BlockEnergyLimitUpdate
| FinalizationCommitteeParametersUpdate;
| FinalizationCommitteeParametersUpdate
| PendingValidatorScoreUpdate;

/** A union of chain updates */
export type UpdateInstructionPayload = CommonUpdate | RootUpdate | Level1Update;
Expand Down Expand Up @@ -166,6 +171,7 @@ export enum UpdateType {
MinBlockTime = 'minBlockTime',
BlockEnergyLimit = 'blockEnergyLimit',
FinalizationCommitteeParameters = 'finalizationCommitteeParameters',
ValidatorScoreParameters = 'validatorScoreParameters',
}

export type KeyUpdate = HigherLevelKeyUpdate | AuthorizationKeysUpdate;
Expand Down
16 changes: 15 additions & 1 deletion packages/sdk/src/types/transactionEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export enum TransactionEventTag {
BakerSetBakingRewardCommission = 'BakerSetBakingRewardCommission',
BakerSetFinalizationRewardCommission = 'BakerSetFinalizationRewardCommission',
BakerDelegationRemoved = 'BakerDelegationRemoved',
BakerSuspended = 'BakerSuspended',
BakerResumed = 'BakerResumed',
DelegationStakeIncreased = 'DelegationStakeIncreased',
DelegationStakeDecreased = 'DelegationStakeDecreased',
DelegationSetRestakeEarnings = 'DelegationSetRestakeEarnings',
Expand Down Expand Up @@ -336,6 +338,16 @@ export interface BakerDelegationRemovedEvent {
delegatorId: DelegatorId;
}

export interface BakerSuspendedEvent {
tag: TransactionEventTag.BakerSuspended;
bakerId: BakerId;
}

export interface BakerResumedEvent {
tag: TransactionEventTag.BakerResumed;
bakerId: BakerId;
}

export interface UpdateEnqueuedEvent {
tag: TransactionEventTag.UpdateEnqueued;
effectiveTime: number;
Expand All @@ -354,7 +366,9 @@ export type BakerEvent =
| BakerAddedEvent
| BakerRemovedEvent
| BakerKeysUpdatedEvent
| BakerDelegationRemovedEvent;
| BakerDelegationRemovedEvent
| BakerSuspendedEvent
| BakerResumedEvent;
export type DelegationEvent =
| DelegatorEvent
| DelegationSetDelegationTargetEvent
Expand Down
Loading

0 comments on commit 5f968c9

Please sign in to comment.