-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Conway protocol parameter updates
* update protocol parameter set from protocol param update spec * update protocol parameter set from genesis * move GenesisRat type to common Fixes #746
- Loading branch information
Showing
5 changed files
with
391 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
// Copyright 2024 Blink Labs Software | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package conway | ||
|
||
import ( | ||
"github.com/blinklabs-io/gouroboros/cbor" | ||
"github.com/blinklabs-io/gouroboros/ledger/babbage" | ||
"github.com/blinklabs-io/gouroboros/ledger/common" | ||
) | ||
|
||
type ConwayProtocolParameters struct { | ||
cbor.StructAsArray | ||
MinFeeA uint | ||
MinFeeB uint | ||
MaxBlockBodySize uint | ||
MaxTxSize uint | ||
MaxBlockHeaderSize uint | ||
KeyDeposit uint | ||
PoolDeposit uint | ||
MaxEpoch uint | ||
NOpt uint | ||
A0 *cbor.Rat | ||
Rho *cbor.Rat | ||
Tau *cbor.Rat | ||
ProtocolVersion common.ProtocolParametersProtocolVersion | ||
MinPoolCost uint64 | ||
AdaPerUtxoByte uint64 | ||
CostModels map[uint][]uint64 | ||
ExecutionCosts common.ExUnitPrice | ||
MaxTxExUnits common.ExUnit | ||
MaxBlockExUnits common.ExUnit | ||
MaxValueSize uint | ||
CollateralPercentage uint | ||
MaxCollateralInputs uint | ||
PoolVotingThresholds PoolVotingThresholds | ||
DRepVotingThresholds DRepVotingThresholds | ||
MinCommitteeSize uint | ||
CommitteeTermLimit uint64 | ||
GovActionValidityPeriod uint64 | ||
GovActionDeposit uint64 | ||
DRepDeposit uint64 | ||
DRepInactivityPeriod uint64 | ||
MinFeeRefScriptCostPerByte *cbor.Rat | ||
} | ||
|
||
func (p *ConwayProtocolParameters) Update(paramUpdate *ConwayProtocolParameterUpdate) { | ||
if paramUpdate.MinFeeA != nil { | ||
p.MinFeeA = *paramUpdate.MinFeeA | ||
} | ||
if paramUpdate.MinFeeB != nil { | ||
p.MinFeeB = *paramUpdate.MinFeeB | ||
} | ||
if paramUpdate.MaxBlockBodySize != nil { | ||
p.MaxBlockBodySize = *paramUpdate.MaxBlockBodySize | ||
} | ||
if paramUpdate.MaxTxSize != nil { | ||
p.MaxTxSize = *paramUpdate.MaxTxSize | ||
} | ||
if paramUpdate.MaxBlockHeaderSize != nil { | ||
p.MaxBlockHeaderSize = *paramUpdate.MaxBlockHeaderSize | ||
} | ||
if paramUpdate.KeyDeposit != nil { | ||
p.KeyDeposit = *paramUpdate.KeyDeposit | ||
} | ||
if paramUpdate.PoolDeposit != nil { | ||
p.PoolDeposit = *paramUpdate.PoolDeposit | ||
} | ||
if paramUpdate.MaxEpoch != nil { | ||
p.MaxEpoch = *paramUpdate.MaxEpoch | ||
} | ||
if paramUpdate.NOpt != nil { | ||
p.NOpt = *paramUpdate.NOpt | ||
} | ||
if paramUpdate.A0 != nil { | ||
p.A0 = paramUpdate.A0 | ||
} | ||
if paramUpdate.Rho != nil { | ||
p.Rho = paramUpdate.Rho | ||
} | ||
if paramUpdate.Tau != nil { | ||
p.Tau = paramUpdate.Tau | ||
} | ||
if paramUpdate.ProtocolVersion != nil { | ||
p.ProtocolVersion = *paramUpdate.ProtocolVersion | ||
} | ||
if paramUpdate.MinPoolCost != nil { | ||
p.MinPoolCost = *paramUpdate.MinPoolCost | ||
} | ||
if paramUpdate.AdaPerUtxoByte != nil { | ||
p.AdaPerUtxoByte = *paramUpdate.AdaPerUtxoByte | ||
} | ||
if paramUpdate.CostModels != nil { | ||
p.CostModels = paramUpdate.CostModels | ||
} | ||
if paramUpdate.ExecutionCosts != nil { | ||
p.ExecutionCosts = *paramUpdate.ExecutionCosts | ||
} | ||
if paramUpdate.MaxTxExUnits != nil { | ||
p.MaxTxExUnits = *paramUpdate.MaxTxExUnits | ||
} | ||
if paramUpdate.MaxBlockExUnits != nil { | ||
p.MaxBlockExUnits = *paramUpdate.MaxBlockExUnits | ||
} | ||
if paramUpdate.MaxValueSize != nil { | ||
p.MaxValueSize = *paramUpdate.MaxValueSize | ||
} | ||
if paramUpdate.CollateralPercentage != nil { | ||
p.CollateralPercentage = *paramUpdate.CollateralPercentage | ||
} | ||
if paramUpdate.MaxCollateralInputs != nil { | ||
p.MaxCollateralInputs = *paramUpdate.MaxCollateralInputs | ||
} | ||
if paramUpdate.PoolVotingThresholds != nil { | ||
p.PoolVotingThresholds = *paramUpdate.PoolVotingThresholds | ||
} | ||
if paramUpdate.DRepVotingThresholds != nil { | ||
p.DRepVotingThresholds = *paramUpdate.DRepVotingThresholds | ||
} | ||
if paramUpdate.MinCommitteeSize != nil { | ||
p.MinCommitteeSize = *paramUpdate.MinCommitteeSize | ||
} | ||
if paramUpdate.CommitteeTermLimit != nil { | ||
p.CommitteeTermLimit = *paramUpdate.CommitteeTermLimit | ||
} | ||
if paramUpdate.GovActionValidityPeriod != nil { | ||
p.GovActionValidityPeriod = *paramUpdate.GovActionValidityPeriod | ||
} | ||
if paramUpdate.GovActionDeposit != nil { | ||
p.GovActionDeposit = *paramUpdate.GovActionDeposit | ||
} | ||
if paramUpdate.DRepDeposit != nil { | ||
p.DRepDeposit = *paramUpdate.DRepDeposit | ||
} | ||
if paramUpdate.DRepInactivityPeriod != nil { | ||
p.DRepInactivityPeriod = *paramUpdate.DRepInactivityPeriod | ||
} | ||
if paramUpdate.MinFeeRefScriptCostPerByte != nil { | ||
p.MinFeeRefScriptCostPerByte = paramUpdate.MinFeeRefScriptCostPerByte | ||
} | ||
} | ||
|
||
func (p *ConwayProtocolParameters) UpdateFromGenesis(genesis *ConwayGenesis) { | ||
// TODO | ||
/* | ||
PoolVotingThresholds ConwayGenesisPoolVotingThresholds | ||
DRepVotingThresholds ConwayGenesisDRepVotingThresholds | ||
MinCommitteeSize uint `json:"committeeMinSize"` | ||
CommitteeTermLimit uint64 `json:"committeeMaxTermLength"` | ||
GovActionValidityPeriod uint64 `json:"govActionLifetime"` | ||
GovActionDeposit uint64 | ||
DRepDeposit uint64 `json:"dRepDeposit"` | ||
DRepInactivityPeriod uint64 `json:"dRepActivity"` | ||
MinFeeRefScriptCostPerByte float32 | ||
PlutusV3CostModel []int `json:"plutusV3CostModel"` | ||
*/ | ||
/* | ||
// XXX: do we need to convert this? | ||
p.AdaPerUtxoByte = genesis.LovelacePerUtxoWord | ||
p.MaxValueSize = genesis.MaxValueSize | ||
p.CollateralPercentage = genesis.CollateralPercentage | ||
p.MaxCollateralInputs = genesis.MaxCollateralInputs | ||
p.MaxTxExUnits = common.ExUnit{ | ||
Mem: genesis.MaxTxExUnits.Mem, | ||
Steps: genesis.MaxTxExUnits.Steps, | ||
} | ||
p.MaxBlockExUnits = common.ExUnit{ | ||
Mem: genesis.MaxBlockExUnits.Mem, | ||
Steps: genesis.MaxBlockExUnits.Steps, | ||
} | ||
if genesis.ExecutionPrices.Mem != nil && genesis.ExecutionPrices.Steps != nil { | ||
p.ExecutionCosts = common.ExUnitPrice{ | ||
MemPrice: &cbor.Rat{Rat: genesis.ExecutionPrices.Mem.Rat}, | ||
StepPrice: &cbor.Rat{Rat: genesis.ExecutionPrices.Steps.Rat}, | ||
} | ||
} | ||
// TODO: cost models | ||
// We have 150+ string values to map to array indexes | ||
// CostModels map[string]map[string]int | ||
*/ | ||
} | ||
|
||
type ConwayProtocolParameterUpdate struct { | ||
babbage.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"` | ||
} | ||
|
||
func (u *ConwayProtocolParameterUpdate) UnmarshalCBOR(data []byte) error { | ||
return u.UnmarshalCbor(data, u) | ||
} | ||
|
||
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 | ||
} |
Oops, something went wrong.