Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/concordium-base
Submodule concordium-base updated 109 files
4 changes: 4 additions & 0 deletions examples/nodejs/client/getAccountInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,9 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
if (accountInfo.type === AccountInfoType.Delegator) {
console.log('Delegated stake amount:', accountInfo.accountDelegation.stakedAmount);
}

if (accountInfo.type === AccountInfoType.Baker) {
console.log('Validator pool info:', accountInfo.accountBaker);
}
// #endregion documentation-snippet
})();
2 changes: 2 additions & 0 deletions examples/nodejs/client/getPoolInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
);
console.log('Total capital in CCD of ALL pools:', CcdAmount.toCcd(bakerPool.allPoolTotalCapital));
console.log('Pool commision rates:', bakerPool.poolInfo?.commissionRates);
console.log('Is suspended:', bakerPool.isSuspended);
console.log('Current payday status:', bakerPool.currentPaydayStatus);
// #endregion documentation-snippet
})();
4 changes: 2 additions & 2 deletions examples/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"devDependencies": {
"@types/node": "^20.12.13",
"eslint": "8",
"ts-node": "10.9",
"tsx": "^4.19.2",
"typescript": "^5.2.2"
},
"scripts": {
Expand All @@ -30,6 +30,6 @@
"fmt": "yarn prettier --write",
"fmt-check": "yarn prettier --check",
"build": "tsc --noEmit",
"run-example": "ts-node"
"run-example": "tsx"
}
}
2 changes: 1 addition & 1 deletion examples/reactnative/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -716,4 +716,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: c70448f9d8b13c40c47391af88ee9f69ffe85d63

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
14 changes: 14 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

## Unreleased

## 9.0.0

### Breaking changes

- Protocol version 8:
- Add `isSuspended` field to `AccountBakerDetails` and `BakerPoolStatusDetails`.
- 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.
- Add `isPrimedForSuspension` and `missedRounds` fields to `CurrentPaydayBakerPoolStatus`.
- Add suspended field to the `ConfigureBakerPayload`.
- Add `validatorScoreParameters` to `NextUpdateSequenceNumbers`.

## 8.1.1

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@concordium/web-sdk",
"version": "8.1.1",
"version": "9.0.0",
"license": "Apache-2.0",
"engines": {
"node": ">=16"
Expand Down
70 changes: 64 additions & 6 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 @@ -1502,10 +1538,16 @@ function trUpdatePayload(updatePayload: v2.UpdatePayload | undefined): v1.Update
update: keyUpdate,
};
}
case 'validatorScoreParametersUpdate': {
return {
updateType: v1.UpdateType.ValidatorScoreParameters,
update: {
maxMissedRounds: payload.validatorScoreParametersUpdate.maximumMissedRounds,
},
};
}
case undefined:
throw new Error('Unexpected missing update payload');
default:
throw Error(`Unsupported update payload type: ${payload}`);
}
}

Expand Down Expand Up @@ -2190,6 +2232,8 @@ export function nextUpdateSequenceNumbers(nextNums: v2.NextUpdateSequenceNumbers
minBlockTime: unwrap(nextNums.minBlockTime?.value),
blockEnergyLimit: unwrap(nextNums.blockEnergyLimit?.value),
finalizationCommiteeParameters: unwrap(nextNums.finalizationCommitteeParameters?.value),
// We fall back to be backwards compatible.
validatorScoreParameters: nextNums.validatorScoreParameters?.value ?? 1n,
};
}

Expand Down Expand Up @@ -2408,6 +2452,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
1 change: 1 addition & 0 deletions packages/sdk/src/serializationHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ const configureBakerSerializationSpec: SerializationSpec<ConfigureBakerPayload>
transactionFeeCommission: orUndefined(encodeWord32),
bakingRewardCommission: orUndefined(encodeWord32),
finalizationRewardCommission: orUndefined(encodeWord32),
suspended: orUndefined(encodeBool),
};

const getSerializedConfigureBakerBitmap = (payload: ConfigureBakerPayload): Buffer =>
Expand Down
54 changes: 50 additions & 4 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 Expand Up @@ -1187,6 +1227,7 @@ export interface NextUpdateSequenceNumbers {
minBlockTime: bigint;
blockEnergyLimit: bigint;
finalizationCommiteeParameters: bigint;
validatorScoreParameters: bigint;
}

export type BlockFinalizationSummary = BlockFinalizationSummary_None | BlockFinalizationSummary_Record;
Expand Down Expand Up @@ -1382,16 +1423,21 @@ export type BakerKeysWithProofs = PublicBakerKeys & BakerKeyProofs;
export type GenerateBakerKeysOutput = PublicBakerKeys & PrivateBakerKeys & BakerKeyProofs;

export interface ConfigureBakerPayload {
/* stake to bake. if set to 0, this removes the account as a baker */
/** stake to bake. if set to 0, this removes the account as a baker */
stake?: CcdAmount.Type;
/* should earnings from baking be added to staked amount */
/** should earnings from baking be added to staked amount */
restakeEarnings?: boolean;
openForDelegation?: OpenStatus;
keys?: BakerKeysWithProofs;
metadataUrl?: UrlString;
transactionFeeCommission?: number;
bakingRewardCommission?: number;
finalizationRewardCommission?: number;
/**
* Describes whether the validator should change its suspended status. This field is only from protocol version 8
* and later.
*/
suspended?: boolean;
}

export interface ConfigureDelegationPayload {
Expand Down
Loading