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

Feat/lw 9927 review protocol params update #1212

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions packages/core/src/Cardano/types/Governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Crypto from '@cardano-sdk/crypto';
import { Credential, CredentialType, RewardAccount } from '../Address';
import { EpochNo, Fraction, ProtocolVersion, TransactionId } from '.';
import { Lovelace } from './Value';
import { ProtocolParametersUpdate } from './ProtocolParameters';
import { ProtocolParametersUpdateConway } from './ProtocolParameters';

export type Anchor = {
url: string;
Expand Down Expand Up @@ -43,7 +43,7 @@ export type Constitution = {
export type ParameterChangeAction = {
__typename: GovernanceActionType.parameter_change_action;
governanceActionId: GovernanceActionId | null;
protocolParamUpdate: ProtocolParametersUpdate;
protocolParamUpdate: ProtocolParametersUpdateConway;
policyHash: Crypto.Hash28ByteBase16 | null;
};

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/Cardano/types/ProtocolParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ type NewProtocolParamsInConway = {
minFeeRefScriptCostPerByte: string;
};

type ConwayProtocolParameters = BabbageProtocolParameters & NewProtocolParamsInConway;

export type ProtocolParameters = ConwayProtocolParameters;
export type ProtocolParameters = BabbageProtocolParameters & NewProtocolParamsInConway;
export type ConwayProtocolParameters = Omit<ProtocolParameters, 'protocolVersion'>;

// Even tho extraEntropy was deprecated on babbage era, and protocolVersion was deprecated in conway era,
// they are still present in the ProtocolParametersUpdate structure since this structure is backward compatible with all eras.
export type ProtocolParametersUpdate = Partial<ProtocolParameters & Pick<AlonzoProtocolParams, 'extraEntropy'>>;
export type ProtocolParametersUpdateConway = Partial<ConwayProtocolParameters>;

export type GenesisDelegateKeyHash = Crypto.Hash28ByteBase16;
export type ProposedProtocolParameterUpdates = Map<GenesisDelegateKeyHash, ProtocolParametersUpdate>;
Expand Down
14 changes: 9 additions & 5 deletions packages/core/src/Serialization/Update/ProtocolParamUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ export class ProtocolParamUpdate {
*
* @param parametersUpdate core parametersUpdate object.
*/
static fromCore(parametersUpdate: Cardano.ProtocolParametersUpdate) {
static fromCore<T extends Cardano.ProtocolParametersUpdateConway = Cardano.ProtocolParametersUpdate>(
parametersUpdate: T
) {
const params = new ProtocolParamUpdate();

params.#minFeeA = parametersUpdate.minFeeCoefficient ? BigInt(parametersUpdate.minFeeCoefficient) : undefined;
Expand All @@ -470,14 +472,10 @@ export class ProtocolParamUpdate {
? UnitInterval.fromFloat(Number(parametersUpdate.decentralizationParameter))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decentralizationParameter was also removed in conway era.
I am investigating this and a few other serialization issues on the conway-era branch.
I will update this PR once the implementation is stable.

Copy link
Member

@AngelCastilloB AngelCastilloB Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decentralizationParameter was actually deprecated in babbage era, but there shouldn't be a need to remove this, that way the serialization utils can be use to serialize/deserialize older transactions too. When this fields are deprecated their key is no longer used (in this case I believe is 12), but no other field can take its place, so there is no harm on leaving them there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my particular case (e2e test), the raw txBuilder is passing a manually built protocol params to a conway params update proposal.
I am trying to prevent this by building the typesafe version of the fromCore when called via conway governance.
Otherwise, the effect is that txbuilder will build the tx for you, even if those protocol params were deprecated.
But the change will not cripple the ser/des part, it will only make it more restrictive when called from the gov path

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats a pretty good solution 🚀

: undefined;
params.#minPoolCost = parametersUpdate.minPoolCost ? BigInt(parametersUpdate.minPoolCost) : undefined;
params.#protocolVersion = parametersUpdate.protocolVersion
? ProtocolVersion.fromCore(parametersUpdate.protocolVersion)
: undefined;
params.#maxValueSize = parametersUpdate.maxValueSize;
params.#maxTxSize = parametersUpdate.maxTxSize;
params.#collateralPercentage = parametersUpdate.collateralPercentage;
params.#maxCollateralInputs = parametersUpdate.maxCollateralInputs;
params.#extraEntropy = parametersUpdate.extraEntropy ? HexBlob(parametersUpdate.extraEntropy) : undefined;
params.#costModels = parametersUpdate.costModels ? Costmdls.fromCore(parametersUpdate.costModels) : undefined;
params.#executionCosts = parametersUpdate.prices ? ExUnitPrices.fromCore(parametersUpdate.prices) : undefined;
params.#maxTxExUnits = parametersUpdate.maxExecutionUnitsPerTransaction
Expand All @@ -503,6 +501,12 @@ export class ProtocolParamUpdate {
? UnitInterval.fromFloat(Number(parametersUpdate.minFeeRefScriptCostPerByte))
: undefined;

const { protocolVersion, extraEntropy } = parametersUpdate as unknown as Cardano.ProtocolParametersUpdate;
if (protocolVersion !== undefined || extraEntropy !== undefined) {
params.#protocolVersion = protocolVersion ? ProtocolVersion.fromCore(protocolVersion) : undefined;
params.#extraEntropy = extraEntropy ? HexBlob(extraEntropy) : undefined;
}

return params;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ParameterChangeAction } from '../../../../src/Serialization';

// Test data used in the following tests was generated with the cardano-serialization-lib
const cbor = HexBlob(
'8400825820000000000000000000000000000000000000000000000000000000000000000003b8200018640118c80219012c03190190041901f4051a001e8480061a0bebc200071903200819038409d81e8201020ad81e8201030bd81e8201040cd81e8201050d8201582000000000000000000000000000000000000000000000000000000000000000000e820103101903e8111988b812a20098a61a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0374f693194a1f0a0198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a1382d81e820102d81e82010214821b00000001000000001b000000010000000015821b00000001000000001b0000000100000000161903ba1719035418181864181985d81e820000d81e820101d81e820202d81e820303d81e820101181a8ad81e820000d81e820101d81e820202d81e820303d81e820404d81e820505d81e820606d81e820707d81e820808d81e820909181b1864181c18c8181d19012c181e1903e8181f1907d01820191388581c8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'
'8400825820000000000000000000000000000000000000000000000000000000000000000003b81f0018640118c80219012c03190190041901f4051a001e8480061a0bebc200071903200819038409d81e8201020ad81e8201030bd81e8201040cd81e8201050d820158200000000000000000000000000000000000000000000000000000000000000000101903e8111988b812a20098a61a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0374f693194a1f0a0198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a1382d81e820102d81e82010214821b00000001000000001b000000010000000015821b00000001000000001b0000000100000000161903ba1719035418181864181985d81e820000d81e820101d81e820202d81e820303d81e820101181a8ad81e820000d81e820101d81e820202d81e820303d81e820404d81e820505d81e820606d81e820707d81e820808d81e820909181b1864181c18c8181d19012c181e1903e8181f1907d01820191388581c8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'
);

const vasilPlutusV1Costmdls = [
Expand Down Expand Up @@ -36,12 +36,15 @@ const vasilPlutusV2Costmdls = [

const core = {
__typename: Cardano.GovernanceActionType.parameter_change_action,
governanceActionId: { actionIndex: 3, id: '0000000000000000000000000000000000000000000000000000000000000000' },
governanceActionId: {
actionIndex: 3,
id: Cardano.TransactionId('0000000000000000000000000000000000000000000000000000000000000000')
},
policyHash: Hash28ByteBase16('8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'),
protocolParamUpdate: {
coinsPerUtxoByte: 35_000,
collateralPercentage: 852,
committeeTermLimit: 200,
committeeTermLimit: Cardano.EpochNo(200),
costModels: new Map([
[PlutusLanguageVersion.V1, vasilPlutusV1Costmdls],
[PlutusLanguageVersion.V2, vasilPlutusV2Costmdls]
Expand Down Expand Up @@ -88,7 +91,6 @@ const core = {
securityRelevantParamVotingThreshold: { denominator: 1, numerator: 1 }
},
prices: { memory: 0.5, steps: 0.5 },
protocolVersion: { major: 1, minor: 3 },
stakeKeyDeposit: 2_000_000,
treasuryExpansion: '0.25'
}
Expand Down
2 changes: 1 addition & 1 deletion packages/util-dev/src/mockProviders/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const protocolParameters = {
prices: { memory: 0.0577, steps: 0.000_007_21 },
protocolVersion: { major: 5, minor: 0 },
stakeKeyDeposit: 2_000_000
} as Cardano.ProtocolParameters;
} as Required<Cardano.ProtocolParametersUpdate>;

export const epochRewards = [
{
Expand Down
Loading