From 94c1fdfd30a7810a3f3f22b8f69341060bfa6446 Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Wed, 17 Jul 2024 17:54:27 -0500 Subject: [PATCH] feat: support for Conway protocol parameter updates 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 cddba314..9a8ad49c 100644 --- a/ledger/conway.go +++ b/ledger/conway.go @@ -155,6 +155,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 @@ -265,7 +314,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) } }