Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 0 additions & 15 deletions cbor/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,3 @@ func (d *DecodeStoreCbor) SetCbor(cborData []byte) {
func (d DecodeStoreCbor) Cbor() []byte {
return d.cborData
}

// UnmarshalCbor decodes the specified CBOR into the destination object and saves the original CBOR
func (d *DecodeStoreCbor) UnmarshalCbor(
cborData []byte,
dest DecodeStoreCborInterface,
) error {
if err := DecodeGeneric(cborData, dest); err != nil {
return err
}
// Store a copy of the original CBOR data
// This must be done after we copy from the temp object above, or it gets wiped out
// when using struct embedding and the DecodeStoreCbor struct is embedded at a deeper level
d.SetCbor(cborData)
return nil
}
29 changes: 3 additions & 26 deletions ledger/allegra/pparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,14 @@ package allegra

import (
"github.com/blinklabs-io/gouroboros/ledger/shelley"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

type AllegraProtocolParameters struct {
shelley.ShelleyProtocolParameters
}

func (p *AllegraProtocolParameters) Update(
paramUpdate *AllegraProtocolParameterUpdate,
) {
p.ShelleyProtocolParameters.Update(
&paramUpdate.ShelleyProtocolParameterUpdate,
)
}

type AllegraProtocolParameterUpdate struct {
shelley.ShelleyProtocolParameterUpdate
}

func (u *AllegraProtocolParameterUpdate) UnmarshalCBOR(data []byte) error {
return u.UnmarshalCbor(data, u)
}
type AllegraProtocolParameters = shelley.ShelleyProtocolParameters

func (p *AllegraProtocolParameters) Utxorpc() *cardano.PParams {
return p.ShelleyProtocolParameters.Utxorpc()
}
type AllegraProtocolParameterUpdate = shelley.ShelleyProtocolParameterUpdate

func UpgradePParams(
prevPParams shelley.ShelleyProtocolParameters,
) AllegraProtocolParameters {
return AllegraProtocolParameters{
ShelleyProtocolParameters: prevPParams,
}
return AllegraProtocolParameters(prevPParams)
}
49 changes: 19 additions & 30 deletions ledger/allegra/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/allegra"
"github.com/blinklabs-io/gouroboros/ledger/shelley"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

Expand All @@ -34,28 +33,20 @@ func TestAllegraProtocolParamsUpdate(t *testing.T) {
}{
{
startParams: allegra.AllegraProtocolParameters{
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
Decentralization: &cbor.Rat{Rat: new(big.Rat).SetInt64(1)},
},
Decentralization: &cbor.Rat{Rat: new(big.Rat).SetInt64(1)},
},
updateCbor: "a10cd81e82090a",
expectedParams: allegra.AllegraProtocolParameters{
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
Decentralization: &cbor.Rat{Rat: big.NewRat(9, 10)},
},
Decentralization: &cbor.Rat{Rat: big.NewRat(9, 10)},
},
},
{
startParams: allegra.AllegraProtocolParameters{
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
ProtocolMajor: 3,
},
ProtocolMajor: 3,
},
updateCbor: "a10e820400",
expectedParams: allegra.AllegraProtocolParameters{
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
ProtocolMajor: 4,
},
ProtocolMajor: 4,
},
},
}
Expand All @@ -82,23 +73,21 @@ func TestAllegraProtocolParamsUpdate(t *testing.T) {

func TestAllegraUtxorpc(t *testing.T) {
inputParams := allegra.AllegraProtocolParameters{
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
MinFeeA: 500,
MinFeeB: 2,
MaxBlockBodySize: 65536,
MaxTxSize: 16384,
MaxBlockHeaderSize: 1024,
KeyDeposit: 2000,
PoolDeposit: 500000,
MaxEpoch: 2160,
NOpt: 100,
A0: &cbor.Rat{Rat: big.NewRat(1, 2)},
Rho: &cbor.Rat{Rat: big.NewRat(3, 4)},
Tau: &cbor.Rat{Rat: big.NewRat(5, 6)},
ProtocolMajor: 8,
ProtocolMinor: 0,
MinUtxoValue: 1000000,
},
MinFeeA: 500,
MinFeeB: 2,
MaxBlockBodySize: 65536,
MaxTxSize: 16384,
MaxBlockHeaderSize: 1024,
KeyDeposit: 2000,
PoolDeposit: 500000,
MaxEpoch: 2160,
NOpt: 100,
A0: &cbor.Rat{Rat: big.NewRat(1, 2)},
Rho: &cbor.Rat{Rat: big.NewRat(3, 4)},
Tau: &cbor.Rat{Rat: big.NewRat(5, 6)},
ProtocolMajor: 8,
ProtocolMinor: 0,
MinUtxoValue: 1000000,
}

expectedUtxorpc := &cardano.PParams{
Expand Down
8 changes: 4 additions & 4 deletions ledger/allegra/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func UtxoValidateFeeTooSmallUtxo(
tx,
slot,
ls,
&tmpPparams.ShelleyProtocolParameters,
tmpPparams,
)
}

Expand Down Expand Up @@ -119,7 +119,7 @@ func UtxoValidateValueNotConservedUtxo(
tx,
slot,
ls,
&tmpPparams.ShelleyProtocolParameters,
tmpPparams,
)
}

Expand All @@ -137,7 +137,7 @@ func UtxoValidateOutputTooSmallUtxo(
tx,
slot,
ls,
&tmpPparams.ShelleyProtocolParameters,
tmpPparams,
)
}

Expand All @@ -164,6 +164,6 @@ func UtxoValidateMaxTxSizeUtxo(
tx,
slot,
ls,
&tmpPparams.ShelleyProtocolParameters,
tmpPparams,
)
}
14 changes: 4 additions & 10 deletions ledger/allegra/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ func TestUtxoValidateFeeTooSmallUtxo(t *testing.T) {
}
testTx.SetCbor(testTxCbor)
testProtocolParams := &allegra.AllegraProtocolParameters{
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
MinFeeA: 7,
MinFeeB: 53,
},
MinFeeA: 7,
MinFeeB: 53,
}
testLedgerState := test.MockLedgerState{}
testSlot := uint64(0)
Expand Down Expand Up @@ -526,9 +524,7 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
}
testSlot := uint64(0)
testProtocolParams := &allegra.AllegraProtocolParameters{
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
KeyDeposit: uint(testStakeDeposit),
},
KeyDeposit: uint(testStakeDeposit),
}
// Exact amount
t.Run(
Expand Down Expand Up @@ -675,9 +671,7 @@ func TestUtxoValidateOutputTooSmallUtxo(t *testing.T) {
testLedgerState := test.MockLedgerState{}
testSlot := uint64(0)
testProtocolParams := &allegra.AllegraProtocolParameters{
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
MinUtxoValue: 100000,
},
MinUtxoValue: 100000,
}
// Good
t.Run(
Expand Down
138 changes: 121 additions & 17 deletions ledger/alonzo/pparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,24 @@ import (
)

type AlonzoProtocolParameters struct {
mary.MaryProtocolParameters
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
Decentralization *cbor.Rat
ExtraEntropy common.Nonce
ProtocolMajor uint
ProtocolMinor uint
MinUtxoValue uint
MinPoolCost uint64
AdaPerUtxoByte uint64
CostModels map[uint][]int64
Expand All @@ -39,9 +56,55 @@ type AlonzoProtocolParameters struct {
func (p *AlonzoProtocolParameters) Update(
paramUpdate *AlonzoProtocolParameterUpdate,
) {
p.MaryProtocolParameters.Update(
&paramUpdate.MaryProtocolParameterUpdate,
)
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.Decentralization != nil {
p.Decentralization = paramUpdate.Decentralization
}
if paramUpdate.ProtocolVersion != nil {
p.ProtocolMajor = paramUpdate.ProtocolVersion.Major
p.ProtocolMinor = paramUpdate.ProtocolVersion.Minor
}
if paramUpdate.ExtraEntropy != nil {
p.ExtraEntropy = *paramUpdate.ExtraEntropy
}
if paramUpdate.MinUtxoValue != nil {
p.MinUtxoValue = *paramUpdate.MinUtxoValue
}
if paramUpdate.MinPoolCost != nil {
p.MinPoolCost = *paramUpdate.MinPoolCost
}
Expand Down Expand Up @@ -100,20 +163,45 @@ func (p *AlonzoProtocolParameters) UpdateFromGenesis(genesis *AlonzoGenesis) {
}

type AlonzoProtocolParameterUpdate struct {
mary.MaryProtocolParameterUpdate
MinPoolCost *uint64 `cbor:"16,keyasint"`
AdaPerUtxoByte *uint64 `cbor:"17,keyasint"`
CostModels map[uint][]int64 `cbor:"18,keyasint"`
ExecutionCosts *common.ExUnitPrice `cbor:"19,keyasint"`
MaxTxExUnits *common.ExUnits `cbor:"20,keyasint"`
MaxBlockExUnits *common.ExUnits `cbor:"21,keyasint"`
MaxValueSize *uint `cbor:"22,keyasint"`
CollateralPercentage *uint `cbor:"23,keyasint"`
MaxCollateralInputs *uint `cbor:"24,keyasint"`
cbor.DecodeStoreCbor
MinFeeA *uint `cbor:"0,keyasint"`
MinFeeB *uint `cbor:"1,keyasint"`
MaxBlockBodySize *uint `cbor:"2,keyasint"`
MaxTxSize *uint `cbor:"3,keyasint"`
MaxBlockHeaderSize *uint `cbor:"4,keyasint"`
KeyDeposit *uint `cbor:"5,keyasint"`
PoolDeposit *uint `cbor:"6,keyasint"`
MaxEpoch *uint `cbor:"7,keyasint"`
NOpt *uint `cbor:"8,keyasint"`
A0 *cbor.Rat `cbor:"9,keyasint"`
Rho *cbor.Rat `cbor:"10,keyasint"`
Tau *cbor.Rat `cbor:"11,keyasint"`
Decentralization *cbor.Rat `cbor:"12,keyasint"`
ExtraEntropy *common.Nonce `cbor:"13,keyasint"`
ProtocolVersion *common.ProtocolParametersProtocolVersion `cbor:"14,keyasint"`
MinUtxoValue *uint `cbor:"15,keyasint"`
MinPoolCost *uint64 `cbor:"16,keyasint"`
AdaPerUtxoByte *uint64 `cbor:"17,keyasint"`
CostModels map[uint][]int64 `cbor:"18,keyasint"`
ExecutionCosts *common.ExUnitPrice `cbor:"19,keyasint"`
MaxTxExUnits *common.ExUnits `cbor:"20,keyasint"`
MaxBlockExUnits *common.ExUnits `cbor:"21,keyasint"`
MaxValueSize *uint `cbor:"22,keyasint"`
CollateralPercentage *uint `cbor:"23,keyasint"`
MaxCollateralInputs *uint `cbor:"24,keyasint"`
}

func (u *AlonzoProtocolParameterUpdate) UnmarshalCBOR(data []byte) error {
return u.UnmarshalCbor(data, u)
func (AlonzoProtocolParameterUpdate) IsProtocolParameterUpdate() {}

func (u *AlonzoProtocolParameterUpdate) UnmarshalCBOR(cborData []byte) error {
type tAlonzoProtocolParameterUpdate AlonzoProtocolParameterUpdate
var tmp tAlonzoProtocolParameterUpdate
if _, err := cbor.Decode(cborData, &tmp); err != nil {
return err
}
*u = AlonzoProtocolParameterUpdate(tmp)
u.SetCbor(cborData)
return nil
}

func (p *AlonzoProtocolParameters) Utxorpc() *cardano.PParams {
Expand Down Expand Up @@ -203,6 +291,22 @@ func UpgradePParams(
prevPParams mary.MaryProtocolParameters,
) AlonzoProtocolParameters {
return AlonzoProtocolParameters{
MaryProtocolParameters: prevPParams,
MinFeeA: prevPParams.MinFeeA,
MinFeeB: prevPParams.MinFeeB,
MaxBlockBodySize: prevPParams.MaxBlockBodySize,
MaxTxSize: prevPParams.MaxTxSize,
MaxBlockHeaderSize: prevPParams.MaxBlockHeaderSize,
KeyDeposit: prevPParams.KeyDeposit,
PoolDeposit: prevPParams.PoolDeposit,
MaxEpoch: prevPParams.MaxEpoch,
NOpt: prevPParams.NOpt,
A0: prevPParams.A0,
Rho: prevPParams.Rho,
Tau: prevPParams.Tau,
Decentralization: prevPParams.Decentralization,
ExtraEntropy: prevPParams.ExtraEntropy,
ProtocolMajor: prevPParams.ProtocolMajor,
ProtocolMinor: prevPParams.ProtocolMinor,
MinUtxoValue: prevPParams.MinUtxoValue,
}
}
Loading
Loading