Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to gRPC API of Concordium node version 8 #106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
## Unreleased changes

## 6.0.0

- Support for Concordium Node version 8 API changes:
- Expand enum `ProtocolVersion` with `P8` variant.
- Introduce `IsSuspended` field on `AccountBaker` and `BakerPoolStatus`.
- Introduce new baker events `BakerSuspended` and `BakerResumed` for when a validator choose to suspend.
- Introduce `ChainParametersV3` with `ValidatorScoreParameters`.
- Introduce `Parameter` field for `ContractInitializedEvent`.
- Introduce `EffectValidatorScoreParameters` for pending updates to `ValidatorScoreParameters`.
- Introduce `ValidatorScoreParametersUpdate` and `UpdateType.ValidatorScoreParametersUpdate` for update payloads.
- Introduce `ValidatorPrimedForSuspension` and `ValidatorSuspended` as `ISpecialEvent`.

## 5.0.0

- Added
Expand Down
2 changes: 1 addition & 1 deletion concordium-base
Submodule concordium-base updated 105 files
2 changes: 1 addition & 1 deletion src/Concordium.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageTags>concordium;concordium-net-sdk;blockchain;sdk;</PackageTags>
<Company>Concordium</Company>
<PackageId>ConcordiumNetSdk</PackageId>
<Version>5.0.0</Version>
<Version>6.0.0</Version>
<PackageIcon>icon.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>MPL-2.0</PackageLicenseExpression>
Expand Down
6 changes: 4 additions & 2 deletions src/Types/AccountStakingInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public sealed record AccountBaker(
CcdAmount StakedAmount,
BakerInfo BakerInfo,
AccountBakerPendingChange? PendingChange,
BakerPoolInfo? BakerPoolInfo
BakerPoolInfo? BakerPoolInfo,
bool IsSuspended
) : IAccountStakingInfo
{
internal static AccountBaker From(Grpc.V2.AccountStakingInfo.Types.Baker stakeBaker) =>
Expand All @@ -52,7 +53,8 @@ internal static AccountBaker From(Grpc.V2.AccountStakingInfo.Types.Baker stakeBa
PendingChange: AccountBakerPendingChange.From(stakeBaker.PendingChange),
RestakeEarnings: stakeBaker.RestakeEarnings,
StakedAmount: CcdAmount.From(stakeBaker.StakedAmount),
BakerPoolInfo: BakerPoolInfo.From(stakeBaker.PoolInfo)
BakerPoolInfo: BakerPoolInfo.From(stakeBaker.PoolInfo),
IsSuspended: stakeBaker.IsSuspended
);

/// <summary>
Expand Down
14 changes: 14 additions & 0 deletions src/Types/BakerEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal static IBakerEvent From(BakerEvent bakerEvent) =>
AmountFraction.From(bakerEvent.BakerSetFinalizationRewardCommission.FinalizationRewardCommission)
),
BakerEvent.EventOneofCase.DelegationRemoved => new BakerEventDelegationRemoved(DelegatorId.From(bakerEvent.DelegationRemoved.DelegatorId)),
BakerEvent.EventOneofCase.BakerSuspended => new BakerEventSuspended(BakerId.From(bakerEvent.BakerSuspended.BakerId)),
BakerEvent.EventOneofCase.BakerResumed => new BakerEventResumed(BakerId.From(bakerEvent.BakerResumed.BakerId)),
BakerEvent.EventOneofCase.None =>
throw new MissingEnumException<BakerEvent.EventOneofCase>(bakerEvent.EventCase),
_ => throw new MissingEnumException<BakerEvent.EventOneofCase>(bakerEvent.EventCase)
Expand Down Expand Up @@ -142,3 +144,15 @@ public sealed record BakerSetFinalizationRewardCommissionEvent(BakerId BakerId,
/// </summary>
/// <param name="DelegatorId">Delegator's id</param>
public sealed record BakerEventDelegationRemoved(DelegatorId DelegatorId) : IBakerEvent;

/// <summary>
/// A baker has been suspended.
/// </summary>
/// <param name="BakerId">Suspended baker's id</param>
public sealed record BakerEventSuspended(BakerId BakerId) : IBakerEvent;

/// <summary>
/// A baker has been resumed.
/// </summary>
/// <param name="BakerId">The resumed baker's id</param>
public sealed record BakerEventResumed(BakerId BakerId) : IBakerEvent;
13 changes: 10 additions & 3 deletions src/Types/BakerPoolStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ namespace Concordium.Sdk.Types;
/// </param>
/// <param name="BakerStakePendingChange">Any pending change to the baker's stake.</param>
/// <param name="AllPoolTotalCapital">Total capital staked across all pools.</param>
/// <param name="IsSuspended">
/// A flag indicating whether the pool owner is suspended.
/// Also `False` if the protocol version does not support validator suspension or the pool is removed.
/// </param>
public sealed record BakerPoolStatus(
BakerId BakerId,
AccountAddress BakerAddress,
Expand All @@ -40,7 +44,9 @@ public sealed record BakerPoolStatus(
BakerPoolInfo? PoolInfo,
CurrentPaydayBakerPoolStatus? CurrentPaydayStatus,
CcdAmount AllPoolTotalCapital,
BakerPoolPendingChange? BakerStakePendingChange)
BakerPoolPendingChange? BakerStakePendingChange,
bool IsSuspended
)
{
internal static BakerPoolStatus From(Grpc.V2.PoolInfoResponse poolInfoResponse) =>
new(
Expand All @@ -52,6 +58,7 @@ internal static BakerPoolStatus From(Grpc.V2.PoolInfoResponse poolInfoResponse)
poolInfoResponse.PoolInfo != null ? BakerPoolInfo.From(poolInfoResponse.PoolInfo) : null,
CurrentPaydayBakerPoolStatus.From(poolInfoResponse.CurrentPaydayInfo),
CcdAmount.From(poolInfoResponse.AllPoolTotalCapital),
BakerPoolPendingChange.From(poolInfoResponse.EquityPendingChange)
);
BakerPoolPendingChange.From(poolInfoResponse.EquityPendingChange),
poolInfoResponse.IsSuspended
);
}
71 changes: 70 additions & 1 deletion src/Types/ChainParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ internal static IChainParameters From(ChainParameters chainParameters) =>
ChainParametersV1.From(chainParameters.V1),
ChainParameters.ParametersOneofCase.V2 =>
ChainParametersV2.From(chainParameters.V2),
ChainParameters.ParametersOneofCase.V3 =>
ChainParametersV3.From(chainParameters.V3),
ChainParameters.ParametersOneofCase.None =>
throw new MissingEnumException<ChainParameters.ParametersOneofCase>(chainParameters.ParametersCase),
_ => throw new MissingEnumException<ChainParameters.ParametersOneofCase>(chainParameters.ParametersCase)
Expand All @@ -29,7 +31,74 @@ internal static IChainParameters From(ChainParameters chainParameters) =>

/// <summary>
/// Values of chain parameters that can be updated via chain updates.
/// This applies to protocol version 6 and up.
/// This applies to protocol version 8 and up.
/// </summary>
/// <param name="TimeoutParameters">Consensus protocol version 2 timeout parameters.</param>
/// <param name="MinBlockTime">Minimum time interval between blocks.</param>
/// <param name="BlockEnergyLimit">Maximum energy allowed per block.</param>
/// <param name="EuroPerEnergy">Euro per energy exchange rate.</param>
/// <param name="MicroCcdPerEuro">Micro ccd per euro exchange rate.</param>
/// <param name="CooldownParameters">Parameters related to cooldowns when staking.</param>
/// <param name="TimeParameters">Parameters related mint rate and reward period.</param>
/// <param name="AccountCreationLimit">The limit for the number of account creations in a block.</param>
/// <param name="MintDistribution">Parameters related to the distribution of newly minted CCD.</param>
/// <param name="TransactionFeeDistribution">Parameters related to the distribution of transaction fees.</param>
/// <param name="GasRewards">Parameters related to the distribution from the GAS account.</param>
/// <param name="FoundationAccount">Address of the foundation account.</param>
/// <param name="PoolParameters">Parameters for baker pools.</param>
/// <param name="FinalizationCommitteeParameters">The finalization committee parameters.</param>
/// <param name="ValidatorScoreParameters">Validator score parameters.</param>
/// <param name="RootKeys">Root Keys</param>
/// <param name="Level1Keys">Level 1 Keys</param>
/// <param name="Level2Keys">Level 2 Keys</param>
public sealed record ChainParametersV3(
TimeoutParameters TimeoutParameters,
TimeSpan MinBlockTime,
EnergyAmount BlockEnergyLimit,
ExchangeRate EuroPerEnergy,
ExchangeRate MicroCcdPerEuro,
CooldownParameters CooldownParameters,
TimeParameters TimeParameters,
CredentialsPerBlockLimit AccountCreationLimit,
MintDistributionCpv1 MintDistribution,
TransactionFeeDistribution TransactionFeeDistribution,
GasRewardsCpv2 GasRewards,
AccountAddress FoundationAccount,
PoolParameters PoolParameters,
FinalizationCommitteeParameters FinalizationCommitteeParameters,
ValidatorScoreParameters ValidatorScoreParameters,
HigherLevelKeys RootKeys,
HigherLevelKeys Level1Keys,
AuthorizationsV1 Level2Keys
) : IChainParameters
{
internal static ChainParametersV3 From(Grpc.V2.ChainParametersV3 chainParams) =>
new(
TimeoutParameters.From(chainParams.ConsensusParameters.TimeoutParameters),
TimeSpan.FromMilliseconds(chainParams.ConsensusParameters.MinBlockTime.Value),
EnergyAmount.From(chainParams.ConsensusParameters.BlockEnergyLimit),
ExchangeRate.From(chainParams.EuroPerEnergy),
ExchangeRate.From(chainParams.MicroCcdPerEuro),
CooldownParameters.From(chainParams.CooldownParameters),
TimeParameters.From(chainParams.TimeParameters),
CredentialsPerBlockLimit.From(chainParams.AccountCreationLimit),
MintDistributionCpv1.From(chainParams.MintDistribution),
TransactionFeeDistribution.From(chainParams.TransactionFeeDistribution),
GasRewardsCpv2.From(chainParams.GasRewards),
AccountAddress.From(chainParams.FoundationAccount),
PoolParameters.From(chainParams.PoolParameters),
FinalizationCommitteeParameters.From(chainParams.FinalizationCommitteeParameters),
ValidatorScoreParameters.From(chainParams.ValidatorScoreParameters),
Types.RootKeys.From(chainParams.RootKeys),
Types.Level1Keys.From(chainParams.Level1Keys),
AuthorizationsV1.From(chainParams.Level2Keys)
);
}


/// <summary>
/// Values of chain parameters that can be updated via chain updates.
/// This applies to protocol version 6 and 7.
/// </summary>
/// <param name="TimeoutParameters">Consensus protocol version 2 timeout parameters.</param>
/// <param name="MinBlockTime">Minimum time interval between blocks.</param>
Expand Down
7 changes: 5 additions & 2 deletions src/Types/ContractInitializedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ namespace Concordium.Sdk.Types;
/// <param name="Amount">Represent the CCD amount the contract instance was initialized with.</param>
/// <param name="InitName">The name of the contract.</param>
/// <param name="Events">A list of events generated by a smart contract.</param>
/// <param name="Parameter">The parameter passed to the initializer (introduced by Concordium Node v8 and up).</param>
public sealed record ContractInitializedEvent(
ContractVersion ContractVersion,
ModuleReference ModuleReference,
ContractAddress ContractAddress,
CcdAmount Amount,
ContractName InitName,
IList<ContractEvent> Events
IList<ContractEvent> Events,
Parameter? Parameter
)
{
/// <summary>
Expand All @@ -36,8 +38,9 @@ internal static ContractInitializedEvent From(Grpc.V2.ContractInitializedEvent i
var events = initializedEvent.Events
.Select(e => new ContractEvent(e.Value.ToByteArray()))
.ToList();
var parameter = initializedEvent.Parameter == null ? null : Parameter.From(initializedEvent.Parameter);
return new ContractInitializedEvent(contractVersion, moduleReference, contractAddress, amount,
initName, events);
initName, events, parameter);
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions src/Types/PendingUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ internal static PendingUpdate From(Grpc.V2.PendingUpdate pendingUpdate) =>
GrpcEffect.MinBlockTime => new EffectMinBlockTime(TimeSpan.FromMilliseconds(pendingUpdate.MinBlockTime.Value)),
GrpcEffect.BlockEnergyLimit => new EffectBlockEnergyLimit(EnergyAmount.From(pendingUpdate.BlockEnergyLimit)),
GrpcEffect.FinalizationCommitteeParameters => new EffectFinalizationCommitteeParameters(FinalizationCommitteeParameters.From(pendingUpdate.FinalizationCommitteeParameters)),
GrpcEffect.ValidatorScoreParameters =>
new EffectValidatorScoreParameters(ValidatorScoreParameters.From(pendingUpdate.ValidatorScoreParameters)),
GrpcEffect.None => throw new NotImplementedException(),
_ => throw new MissingEnumException<GrpcEffect>(pendingUpdate.EffectCase),
}
Expand Down Expand Up @@ -104,3 +106,5 @@ public sealed record EffectMinBlockTime(TimeSpan MinBlockTime) : IEffect;
public sealed record EffectBlockEnergyLimit(EnergyAmount BlockEnergyLimit) : IEffect;
/// <summary>Updates to the finalization committee for for chain parameters version 2.</summary>
public sealed record EffectFinalizationCommitteeParameters(FinalizationCommitteeParameters FinalizationCommitteeParameters) : IEffect;
/// <summary>Updates to the validator score for chain parameters version 3.</summary>
public sealed record EffectValidatorScoreParameters(ValidatorScoreParameters ValidatorScoreParameters) : IEffect;
8 changes: 8 additions & 0 deletions src/Types/ProtocolVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public enum ProtocolVersion
/// implements tokenomics changes.
/// </summary>
P7,
/// <summary>
/// Protocol `P8` supports suspending inactive validators automatically
/// when they consistently fail to participate in the consensus protocol.
/// Suspended validators can be reactivated manually by a transaction
/// from the validator's account.
/// </summary>
P8,
}


Expand All @@ -66,6 +73,7 @@ internal static ProtocolVersion Into(this Grpc.V2.ProtocolVersion protocolVersio
Grpc.V2.ProtocolVersion._5 => ProtocolVersion.P5,
Grpc.V2.ProtocolVersion._6 => ProtocolVersion.P6,
Grpc.V2.ProtocolVersion._7 => ProtocolVersion.P7,
Grpc.V2.ProtocolVersion._8 => ProtocolVersion.P8,
_ => throw new MissingEnumException<Grpc.V2.ProtocolVersion>(protocolVersion)
};
}
38 changes: 38 additions & 0 deletions src/Types/SpecialEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ internal static ISpecialEvent From(BlockSpecialEvent specialEvent) =>
BlockAccrueReward.From(specialEvent.BlockAccrueReward),
BlockSpecialEvent.EventOneofCase.PaydayPoolReward =>
PaydayPoolReward.From(specialEvent.PaydayPoolReward),
BlockSpecialEvent.EventOneofCase.ValidatorPrimedForSuspension =>
ValidatorPrimedForSuspension.From(specialEvent.ValidatorPrimedForSuspension),
BlockSpecialEvent.EventOneofCase.ValidatorSuspended =>
ValidatorSuspended.From(specialEvent.ValidatorSuspended),
BlockSpecialEvent.EventOneofCase.None => throw new MissingEnumException<BlockSpecialEvent.EventOneofCase>(specialEvent.EventCase),
_ => throw new MissingEnumException<BlockSpecialEvent.EventOneofCase>(specialEvent.EventCase)
};
Expand Down Expand Up @@ -233,3 +237,37 @@ internal static PaydayPoolReward From(BlockSpecialEvent.Types.PaydayPoolReward p
);
}

/// <summary>
/// A validator that is primed for suspension at the next snapshot epoch due to too
/// many missed rounds.
/// </summary>
/// <param name="BakerId">The id of the primed validator.</param>
/// <param name="Account">The account of the primed validator.</param>
public sealed record ValidatorPrimedForSuspension(
BakerId BakerId,
AccountAddress Account
) : ISpecialEvent
{
internal static ValidatorPrimedForSuspension From(BlockSpecialEvent.Types.ValidatorPrimedForSuspension primed) =>
new(
BakerId: BakerId.From(primed.BakerId),
Account: AccountAddress.From(primed.Account)
);
}

/// <summary>
/// The id of a validator that got suspended due to too many missed rounds.
/// </summary>
/// <param name="BakerId">The id of the suspended validator.</param>
/// <param name="Account">The account of the suspended validator.</param>
public sealed record ValidatorSuspended(
BakerId BakerId,
AccountAddress Account
) : ISpecialEvent
{
internal static ValidatorSuspended From(BlockSpecialEvent.Types.ValidatorSuspended suspended) =>
new(
BakerId: BakerId.From(suspended.BakerId),
Account: AccountAddress.From(suspended.Account)
);
}
13 changes: 13 additions & 0 deletions src/Types/UpdatePayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public enum UpdateType
BlockEnergyLimitUpdate,
/// <summary> Update of finalization committee parameters. </summary>
FinalizationCommitteeParametersUpdate,
/// <summary> Update of validator score parameters. </summary>
ValidatorScoreParametersUpdate,
}

/// <summary>
Expand Down Expand Up @@ -99,6 +101,7 @@ public static UpdateType From(IUpdatePayload payload) =>
TimeoutParametersUpdate => UpdateType.TimeoutParametersUpdate,
TimeParametersCpv1Update => UpdateType.TimeParametersCpv1Update,
TransactionFeeDistributionUpdate => UpdateType.TransactionFeeDistributionUpdate,
ValidatorScoreParametersUpdate => UpdateType.ValidatorScoreParametersUpdate,
_ => throw new MissingTypeException<IUpdatePayload>(payload)
};

Expand Down Expand Up @@ -149,6 +152,8 @@ internal static IUpdatePayload From(UpdatePayload payload) =>
BlockEnergyLimitUpdate.From(payload.BlockEnergyLimitUpdate),
UpdatePayload.PayloadOneofCase.FinalizationCommitteeParametersUpdate =>
FinalizationCommitteeParametersUpdate.From(payload.FinalizationCommitteeParametersUpdate),
UpdatePayload.PayloadOneofCase.ValidatorScoreParametersUpdate =>
ValidatorScoreParametersUpdate.From(payload.ValidatorScoreParametersUpdate),
UpdatePayload.PayloadOneofCase.None =>
throw new MissingEnumException<UpdatePayload.PayloadOneofCase>(payload.PayloadCase),
_ => throw new MissingEnumException<UpdatePayload.PayloadOneofCase>(payload.PayloadCase)
Expand Down Expand Up @@ -370,3 +375,11 @@ public sealed record FinalizationCommitteeParametersUpdate
internal static FinalizationCommitteeParametersUpdate From(Grpc.V2.FinalizationCommitteeParameters parameters) => new(FinalizationCommitteeParameters.From(parameters));
}

/// <summary>
/// Finalization committee parameters (chain parameters version 2).
/// </summary>
public sealed record ValidatorScoreParametersUpdate
(ValidatorScoreParameters ValidatorScoreParameters) : IUpdatePayload
{
internal static ValidatorScoreParametersUpdate From(Grpc.V2.ValidatorScoreParameters parameters) => new(ValidatorScoreParameters.From(parameters));
}
13 changes: 13 additions & 0 deletions src/Types/ValidatorScoreParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Concordium.Sdk.Types;

/// <summary>
/// Validator score parameters (introduced in Concordium Protocol 8).
/// </summary>
/// <param name="MaximumMissedRounds">The maximal number of missed rounds before a validator gets suspended.</param>
public sealed record ValidatorScoreParameters(
ulong MaximumMissedRounds
)
{
internal static ValidatorScoreParameters From(Grpc.V2.ValidatorScoreParameters param) =>
new(param.MaximumMissedRounds);
}
4 changes: 3 additions & 1 deletion tests/UnitTests/Types/ContractInitializedEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public void WhenGetDeserializedEventsFromContractInitializedEvent_ThenReturnPars
new ContractAddress(1, 0),
CcdAmount.Zero,
result.ContractName!,
new List<ContractEvent> { new(Convert.FromHexString(eventMessage)) });
new List<ContractEvent> { new(Convert.FromHexString(eventMessage)) },
Parameter.Empty()
);

// Act
var events = contractInitializedEvent.GetDeserializedEvents(versionedModuleSchema);
Expand Down