From 72d6cdb888901a8bdd76c22347c43e36e8c6b53c Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Wed, 17 Jul 2024 21:02:13 -0500 Subject: [PATCH] feat: support for Conway protocol parameter updates (#673) Fixes #592 --- ledger/conway.go | 51 +++++++++++++++++++++++++++++- protocol/localstatequery/client.go | 12 ++++--- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/ledger/conway.go b/ledger/conway.go index 8dd9ea49..31e631f2 100644 --- a/ledger/conway.go +++ b/ledger/conway.go @@ -206,6 +206,55 @@ func (b *ConwayTransactionBody) Donation() uint64 { return b.TxDonation } +type ConwayProtocolParameters struct { + BabbageProtocolParameters + PoolVotingThresholds PoolVotingThresholds + DRepVotingThresholds DRepVotingThresholds + MinCommitteeSize uint + CommitteeTermLimit uint64 + GovActionValidityPeriod uint64 + GovActionDeposit uint64 + DRepDeposit uint64 + DRepInactivityPeriod uint64 + MinFeeRefScriptCostPerByte *cbor.Rat +} + +type ConwayProtocolParameterUpdate struct { + BabbageProtocolParameterUpdate + PoolVotingThresholds PoolVotingThresholds `cbor:"25,keyasint"` + DRepVotingThresholds DRepVotingThresholds `cbor:"26,keyasint"` + MinCommitteeSize uint `cbor:"27,keyasint"` + CommitteeTermLimit uint64 `cbor:"28,keyasint"` + GovActionValidityPeriod uint64 `cbor:"29,keyasint"` + GovActionDeposit uint64 `cbor:"30,keyasint"` + DRepDeposit uint64 `cbor:"31,keyasint"` + DRepInactivityPeriod uint64 `cbor:"32,keyasint"` + MinFeeRefScriptCostPerByte *cbor.Rat `cbor:"33,keyasint"` +} + +type PoolVotingThresholds struct { + cbor.StructAsArray + MotionNoConfidence cbor.Rat + CommitteeNormal cbor.Rat + CommitteeNoConfidence cbor.Rat + HardForkInitiation cbor.Rat + SecurityRelevantParameterVotingThreshold cbor.Rat +} + +type DRepVotingThresholds struct { + cbor.StructAsArray + MotionNoConfidence cbor.Rat + CommitteeNormal cbor.Rat + CommitteeNoConfidence cbor.Rat + UpdateConstitution cbor.Rat + HardForkInitiation cbor.Rat + PPNetworkGroup cbor.Rat + PPEconomicGroup cbor.Rat + PPTechnicalGroup cbor.Rat + PPGovGroup cbor.Rat + TreasureWithdrawal cbor.Rat +} + // VotingProcedures is a convenience type to avoid needing to duplicate the full type definition everywhere type VotingProcedures map[*Voter]map[*GovActionId]VotingProcedure @@ -316,7 +365,7 @@ type ParameterChangeGovAction struct { cbor.StructAsArray Type uint ActionId *GovActionId - ParamUpdate BabbageProtocolParameterUpdate // TODO: use Conway params update type + ParamUpdate ConwayProtocolParameterUpdate PolicyHash []byte } diff --git a/protocol/localstatequery/client.go b/protocol/localstatequery/client.go index a056f454..9578c747 100644 --- a/protocol/localstatequery/client.go +++ b/protocol/localstatequery/client.go @@ -348,6 +348,12 @@ func (c *Client) GetCurrentProtocolParams() (CurrentProtocolParamsResult, error) QueryTypeShelleyCurrentProtocolParams, ) switch currentEra { + case ledger.EraIdConway: + result := []ledger.ConwayProtocolParameters{} + if err := c.runQuery(query, &result); err != nil { + return nil, err + } + return result[0], nil case ledger.EraIdBabbage: result := []ledger.BabbageProtocolParameters{} if err := c.runQuery(query, &result); err != nil { @@ -379,11 +385,7 @@ func (c *Client) GetCurrentProtocolParams() (CurrentProtocolParamsResult, error) } return result[0], nil default: - result := []any{} - if err := c.runQuery(query, &result); err != nil { - return nil, err - } - return result[0], nil + return nil, fmt.Errorf("unknown era ID: %d", currentEra) } }