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 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ export const toProtocolParams = ({
governance_action_validity_period,
governance_action_deposit,
drep_deposit,
drep_inactivity_period
drep_inactivity_period,
min_fee_ref_script_cost_per_byte
}: ProtocolParamsModel): Cardano.ProtocolParameters => ({
coinsPerUtxoByte: Number(coins_per_utxo_size),
collateralPercentage: collateral_percent,
committeeTermLimit: Number(committee_term_limit),
committeeTermLimit: Cardano.EpochNo(committee_term_limit),
costModels: mapCostModels(costs),
dRepDeposit: Number(drep_deposit),
dRepInactivityPeriod: Cardano.EpochNo(drep_inactivity_period),
Expand All @@ -96,6 +97,7 @@ export const toProtocolParams = ({
minCommitteeSize: Number(min_committee_size),
minFeeCoefficient: min_fee_a,
minFeeConstant: min_fee_b,
minFeeRefScriptCostPerByte: String(min_fee_ref_script_cost_per_byte),
minPoolCost: Number(min_pool_cost),
monetaryExpansion: String(monetary_expand_rate),
poolDeposit: Number(pool_deposit),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface ProtocolParamsModel {
max_bh_size: number;
optimal_pool_count: number;
influence: number;
min_fee_ref_script_cost_per_byte: number;
monetary_expand_rate: number;
treasury_growth_rate: number;
decentralisation: number;
Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/Cardano/types/ProtocolParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ export interface PoolVotingThresholds {
committeeNormal: Fraction;
commiteeNoConfidence: Fraction;
hardForkInitiation: Fraction;
securityRelevantParamVotingThreshold: Fraction;
}

export interface DelegateRepresentativeThresholds extends PoolVotingThresholds {
export interface DelegateRepresentativeThresholds
extends Omit<PoolVotingThresholds, 'securityRelevantParamVotingThreshold'> {
updateConstitution: Fraction;
ppNetworkGroup: Fraction;
ppEconomicGroup: Fraction;
Expand All @@ -127,19 +129,20 @@ type NewProtocolParamsInConway = {
poolVotingThresholds: PoolVotingThresholds;
dRepVotingThresholds: DelegateRepresentativeThresholds;
minCommitteeSize: number;
committeeTermLimit: number;
committeeTermLimit: EpochNo;
governanceActionValidityPeriod: EpochNo;
governanceActionDeposit: number;
dRepDeposit: number;
dRepInactivityPeriod: EpochNo;
minFeeRefScriptCostPerByte: string;
};

type ConwayProtocolParameters = BabbageProtocolParameters & NewProtocolParamsInConway;

export type ProtocolParameters = ConwayProtocolParameters;

// Even tho extraEntropy was deprecated on babbage era, it is still present in the ProtocolParametersUpdate structure
// since this structure is backward compatible with all eras.
// 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 GenesisDelegateKeyHash = Crypto.Hash28ByteBase16;
Expand Down
30 changes: 24 additions & 6 deletions packages/core/src/Serialization/Update/PoolVotingThresholds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CborReader, CborWriter } from '../CBOR';
import { HexBlob, InvalidArgumentError } from '@cardano-sdk/util';
import { UnitInterval } from '../Common';

const POOL_VOTING_THRESHOLDS_SIZE = 4;
const POOL_VOTING_THRESHOLDS_SIZE = 5;

/**
* Governance actions are ratified through on-chain voting. Different
Expand All @@ -17,6 +17,7 @@ export class PoolVotingThresholds {
#committeeNormal: UnitInterval;
#committeeNoConfidence: UnitInterval;
#hardForkInitiation: UnitInterval;
#securityRelevantParamVotingThreshold: UnitInterval;
#originalBytes: HexBlob | undefined = undefined;

/**
Expand All @@ -35,12 +36,14 @@ export class PoolVotingThresholds {
motionNoConfidence: UnitInterval,
committeeNormal: UnitInterval,
committeeNoConfidence: UnitInterval,
hardForkInitiation: UnitInterval
hardForkInitiation: UnitInterval,
securityRelevantParamVotingThreshold: UnitInterval
) {
this.#motionNoConfidence = motionNoConfidence;
this.#committeeNormal = committeeNormal;
this.#committeeNoConfidence = committeeNoConfidence;
this.#hardForkInitiation = hardForkInitiation;
this.#securityRelevantParamVotingThreshold = securityRelevantParamVotingThreshold;
}

/**
Expand All @@ -59,13 +62,15 @@ export class PoolVotingThresholds {
// , unit_interval ; committee normal
// , unit_interval ; committee no confidence
// , unit_interval ; hard fork initiation
// , unit_interval ; security relevant parameter voting threshold
// ]
writer.writeStartArray(POOL_VOTING_THRESHOLDS_SIZE);

writer.writeEncodedValue(Buffer.from(this.#motionNoConfidence.toCbor(), 'hex'));
writer.writeEncodedValue(Buffer.from(this.#committeeNormal.toCbor(), 'hex'));
writer.writeEncodedValue(Buffer.from(this.#committeeNoConfidence.toCbor(), 'hex'));
writer.writeEncodedValue(Buffer.from(this.#hardForkInitiation.toCbor(), 'hex'));
writer.writeEncodedValue(Buffer.from(this.#securityRelevantParamVotingThreshold.toCbor(), 'hex'));

return writer.encodeAsHex();
}
Expand All @@ -91,14 +96,16 @@ export class PoolVotingThresholds {
const committeeNormal = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
const committeeNoConfidence = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
const hardForkInitiation = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
const securityRelevantParamVotingThreshold = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));

reader.readEndArray();

const thresholds = new PoolVotingThresholds(
motionNoConfidence,
committeeNormal,
committeeNoConfidence,
hardForkInitiation
hardForkInitiation,
securityRelevantParamVotingThreshold
);

thresholds.#originalBytes = cbor;
Expand All @@ -107,7 +114,7 @@ export class PoolVotingThresholds {
}

/**
* Creates a Core PoolVotingThresholdsSHOLDS_SIZE object from the current PoolVotingThresholds object.
* Creates a Core PoolVotingThresholds object from the current PoolVotingThresholds object.
*
* @returns The Core Prices object.
*/
Expand All @@ -116,7 +123,8 @@ export class PoolVotingThresholds {
commiteeNoConfidence: this.#committeeNoConfidence.toCore(),
committeeNormal: this.#committeeNormal.toCore(),
hardForkInitiation: this.#hardForkInitiation.toCore(),
motionNoConfidence: this.#motionNoConfidence.toCore()
motionNoConfidence: this.#motionNoConfidence.toCore(),
securityRelevantParamVotingThreshold: this.#securityRelevantParamVotingThreshold.toCore()
};
}

Expand All @@ -130,7 +138,8 @@ export class PoolVotingThresholds {
UnitInterval.fromCore(core.motionNoConfidence),
UnitInterval.fromCore(core.committeeNormal),
UnitInterval.fromCore(core.commiteeNoConfidence),
UnitInterval.fromCore(core.hardForkInitiation)
UnitInterval.fromCore(core.hardForkInitiation),
UnitInterval.fromCore(core.securityRelevantParamVotingThreshold)
);
}

Expand Down Expand Up @@ -223,4 +232,13 @@ export class PoolVotingThresholds {
hardForkInitiation(): UnitInterval {
return this.#hardForkInitiation;
}

/**
* Gets the security relevant parameter voting threshold
*
* @returns security relevant parameter voting threshold.
*/
securityRelevantParamVotingThreshold(): UnitInterval {
return this.#securityRelevantParamVotingThreshold;
}
}
24 changes: 23 additions & 1 deletion packages/core/src/Serialization/Update/ProtocolParamUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class ProtocolParamUpdate {
#governanceActionDeposit: number | undefined;
#drepDeposit: number | undefined;
#drepInactivityPeriod: number | undefined;
#minFeeRefScriptCostPerByte: UnitInterval | undefined;
#originalBytes: HexBlob | undefined = undefined;

/**
Expand Down Expand Up @@ -90,6 +91,7 @@ export class ProtocolParamUpdate {
// , ? 30: coin ; governance action deposit
// , ? 31: coin ; DRep deposit
// , ? 32: epoch ; DRep inactivity period
// , ? 33: nonnegative_interval ; MinFee RefScriptCostPerByte
// }
writer.writeStartMap(this.#getMapSize());

Expand Down Expand Up @@ -254,6 +256,12 @@ export class ProtocolParamUpdate {
writer.writeInt(32n);
writer.writeInt(this.#drepInactivityPeriod);
}

if (this.#minFeeRefScriptCostPerByte) {
writer.writeInt(33n);
writer.writeEncodedValue(Buffer.from(this.#minFeeRefScriptCostPerByte.toCbor(), 'hex'));
}

return writer.encodeAsHex();
}

Expand Down Expand Up @@ -373,6 +381,9 @@ export class ProtocolParamUpdate {
case 32n:
params.#drepInactivityPeriod = Number(reader.readInt());
break;
case 33n:
params.#minFeeRefScriptCostPerByte = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
}
}

Expand All @@ -392,7 +403,7 @@ export class ProtocolParamUpdate {
return {
coinsPerUtxoByte: this.#adaPerUtxoByte ? Number(this.#adaPerUtxoByte) : undefined,
collateralPercentage: this.#collateralPercentage,
committeeTermLimit: this.#committeeTermLimit,
committeeTermLimit: this.#committeeTermLimit ? Cardano.EpochNo(this.#committeeTermLimit) : undefined,
costModels: this.#costModels?.toCore(),
dRepDeposit: this.#drepDeposit,
dRepInactivityPeriod: this.#drepInactivityPeriod ? Cardano.EpochNo(this.#drepInactivityPeriod) : undefined,
Expand All @@ -414,6 +425,9 @@ export class ProtocolParamUpdate {
minCommitteeSize: this.#minCommitteeSize,
minFeeCoefficient: this.#minFeeA ? Number(this.#minFeeA) : undefined,
minFeeConstant: this.#minFeeB ? Number(this.#minFeeB) : undefined,
minFeeRefScriptCostPerByte: this.#minFeeRefScriptCostPerByte
? this.#minFeeRefScriptCostPerByte.toFloat().toString()
: undefined,
minPoolCost: this.#minPoolCost ? Number(this.#minPoolCost) : undefined,
monetaryExpansion: this.#expansionRate ? this.#expansionRate.toFloat().toString() : undefined,
poolDeposit: this.#poolDeposit ? Number(this.#poolDeposit) : undefined,
Expand Down Expand Up @@ -485,6 +499,9 @@ export class ProtocolParamUpdate {
params.#governanceActionDeposit = parametersUpdate.governanceActionDeposit;
params.#drepDeposit = parametersUpdate.dRepDeposit;
params.#drepInactivityPeriod = parametersUpdate.dRepInactivityPeriod;
params.#minFeeRefScriptCostPerByte = parametersUpdate.minFeeRefScriptCostPerByte
? UnitInterval.fromFloat(Number(parametersUpdate.minFeeRefScriptCostPerByte))
: undefined;

return params;
}
Expand Down Expand Up @@ -1177,6 +1194,10 @@ export class ProtocolParamUpdate {
return this.#drepInactivityPeriod;
}

minFeeRefScriptCostPerByte(): UnitInterval | undefined {
return this.#minFeeRefScriptCostPerByte;
}

/**
* Gets the size of the serialized map.
*
Expand Down Expand Up @@ -1217,6 +1238,7 @@ export class ProtocolParamUpdate {
if (this.#governanceActionDeposit !== undefined) ++mapSize;
if (this.#drepDeposit !== undefined) ++mapSize;
if (this.#drepInactivityPeriod !== undefined) ++mapSize;
if (this.#minFeeRefScriptCostPerByte !== undefined) ++mapSize;

return mapSize;
}
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(
'8400825820000000000000000000000000000000000000000000000000000000000000000003b8200018640118c80219012c03190190041901f4051a001e8480061a0bebc200071903200819038409d81e8201020ad81e8201030bd81e8201040cd81e8201050d8201582000000000000000000000000000000000000000000000000000000000000000000e820103101903e8111988b812a20098a61a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0374f693194a1f0a0198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a1382d81e820102d81e82010214821b00000001000000001b000000010000000015821b00000001000000001b0000000100000000161903ba1719035418181864181984d81e820000d81e820101d81e820202d81e820303181a8ad81e820000d81e820101d81e820202d81e820303d81e820404d81e820505d81e820606d81e820707d81e820808d81e820909181b1864181c18c8181d19012c181e1903e8181f1907d01820191388581c8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'
'8400825820000000000000000000000000000000000000000000000000000000000000000003b8200018640118c80219012c03190190041901f4051a001e8480061a0bebc200071903200819038409d81e8201020ad81e8201030bd81e8201040cd81e8201050d8201582000000000000000000000000000000000000000000000000000000000000000000e820103101903e8111988b812a20098a61a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0374f693194a1f0a0198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a1382d81e820102d81e82010214821b00000001000000001b000000010000000015821b00000001000000001b0000000100000000161903ba1719035418181864181985d81e820000d81e820101d81e820202d81e820303d81e820101181a8ad81e820000d81e820101d81e820202d81e820303d81e820404d81e820505d81e820606d81e820707d81e820808d81e820909181b1864181c18c8181d19012c181e1903e8181f1907d01820191388581c8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'
);

const vasilPlutusV1Costmdls = [
Expand Down Expand Up @@ -84,7 +84,8 @@ const core = {
commiteeNoConfidence: { denominator: 2, numerator: 2 },
committeeNormal: { denominator: 1, numerator: 1 },
hardForkInitiation: { denominator: 3, numerator: 3 },
motionNoConfidence: { denominator: 0, numerator: 0 }
motionNoConfidence: { denominator: 0, numerator: 0 },
securityRelevantParamVotingThreshold: { denominator: 1, numerator: 1 }
},
prices: { memory: 0.5, steps: 0.5 },
protocolVersion: { major: 1, minor: 3 },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/* eslint-disable sonarjs/no-duplicate-string */
import { Cardano } from '../../../src';
import { HexBlob } from '@cardano-sdk/util';
import { PoolVotingThresholds } from '../../../src/Serialization';

// Test data used in the following tests was generated with the cardano-serialization-lib

const cbor = HexBlob('84d81e820000d81e820101d81e820202d81e820303');
const cbor = HexBlob('85d81e820000d81e820101d81e820202d81e820303d81e820101');

const core = {
const core: Cardano.PoolVotingThresholds = {
commiteeNoConfidence: { denominator: 2, numerator: 2 },
committeeNormal: { denominator: 1, numerator: 1 },
hardForkInitiation: { denominator: 3, numerator: 3 },
motionNoConfidence: { denominator: 0, numerator: 0 }
motionNoConfidence: { denominator: 0, numerator: 0 },
securityRelevantParamVotingThreshold: { denominator: 1, numerator: 1 }
};

describe('PoolVotingThresholds', () => {
Expand All @@ -21,6 +23,9 @@ describe('PoolVotingThresholds', () => {
expect(thresholds.committeeNormal().toCore()).toEqual(core.committeeNormal);
expect(thresholds.hardForkInitiation().toCore()).toEqual(core.hardForkInitiation);
expect(thresholds.motionNoConfidence().toCore()).toEqual(core.motionNoConfidence);
expect(thresholds.securityRelevantParamVotingThreshold().toCore()).toEqual(
core.securityRelevantParamVotingThreshold
);
});

it('can decode PoolVotingThresholds from Core', () => {
Expand All @@ -30,6 +35,9 @@ describe('PoolVotingThresholds', () => {
expect(thresholds.committeeNormal().toCore()).toEqual(core.committeeNormal);
expect(thresholds.hardForkInitiation().toCore()).toEqual(core.hardForkInitiation);
expect(thresholds.motionNoConfidence().toCore()).toEqual(core.motionNoConfidence);
expect(thresholds.securityRelevantParamVotingThreshold().toCore()).toEqual(
core.securityRelevantParamVotingThreshold
);
});

it('can encode PoolVotingThresholds to CBOR', () => {
Expand Down
Loading
Loading