Skip to content

Commit

Permalink
feat: return epoch with protocol param updates (#719)
Browse files Browse the repository at this point in the history
This commit also:

* creates an interface type for protocol parameter updates
* stores CBOR for protocol parameter updates
* changes DecodeStoreCbor Cbor() to value receiver for more flexibility
  • Loading branch information
agaffney authored Sep 26, 2024
1 parent f8e7de0 commit edf9f8b
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cbor/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (d *DecodeStoreCbor) SetCbor(cborData []byte) {
}

// Cbor returns the original CBOR for the object
func (d *DecodeStoreCbor) Cbor() []byte {
func (d DecodeStoreCbor) Cbor() []byte {
return d.cborData
}

Expand Down
10 changes: 5 additions & 5 deletions ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ func (b *AllegraTransactionBody) ValidityIntervalStart() uint64 {
return b.TxValidityIntervalStart
}

func (b *AllegraTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
updateMap := make(map[common.Blake2b224]any)
func (b *AllegraTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
return b.Update.Epoch, updateMap
}

type AllegraTransaction struct {
Expand Down Expand Up @@ -278,8 +278,8 @@ func (t AllegraTransaction) Produced() []common.Utxo {
return ret
}

func (t AllegraTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
return t.Body.ProtocolParametersUpdate()
func (t AllegraTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
return t.Body.ProtocolParameterUpdates()
}

func (t *AllegraTransaction) Cbor() []byte {
Expand Down
10 changes: 5 additions & 5 deletions ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ func (b *AlonzoTransactionBody) Outputs() []common.TransactionOutput {
return ret
}

func (b *AlonzoTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
updateMap := make(map[common.Blake2b224]any)
func (b *AlonzoTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
return b.Update.Epoch, updateMap
}

func (b *AlonzoTransactionBody) Collateral() []common.TransactionInput {
Expand Down Expand Up @@ -349,8 +349,8 @@ func (t AlonzoTransaction) ValidityIntervalStart() uint64 {
return t.Body.ValidityIntervalStart()
}

func (t AlonzoTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
return t.Body.ProtocolParametersUpdate()
func (t AlonzoTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
return t.Body.ProtocolParameterUpdates()
}

func (t AlonzoTransaction) ReferenceInputs() []common.TransactionInput {
Expand Down
17 changes: 12 additions & 5 deletions ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ func (b *BabbageTransactionBody) Outputs() []common.TransactionOutput {
return ret
}

func (b *BabbageTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
updateMap := make(map[common.Blake2b224]any)
func (b *BabbageTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
return b.Update.Epoch, updateMap
}

func (b *BabbageTransactionBody) ReferenceInputs() []common.TransactionInput {
Expand Down Expand Up @@ -523,8 +523,8 @@ func (t BabbageTransaction) ValidityIntervalStart() uint64 {
return t.Body.ValidityIntervalStart()
}

func (t BabbageTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
return t.Body.ProtocolParametersUpdate()
func (t BabbageTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
return t.Body.ProtocolParameterUpdates()
}

func (t BabbageTransaction) ReferenceInputs() []common.TransactionInput {
Expand Down Expand Up @@ -685,6 +685,7 @@ type BabbageProtocolParameters struct {
}

type BabbageProtocolParameterUpdate struct {
cbor.DecodeStoreCbor
MinFeeA uint `cbor:"0,keyasint"`
MinFeeB uint `cbor:"1,keyasint"`
MaxBlockBodySize uint `cbor:"2,keyasint"`
Expand Down Expand Up @@ -713,6 +714,12 @@ type BabbageProtocolParameterUpdate struct {
MaxCollateralInputs uint `cbor:"24,keyasint"`
}

func (BabbageProtocolParameterUpdate) IsProtocolParameterUpdate() {}

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

func NewBabbageBlockFromCbor(data []byte) (*BabbageBlock, error) {
var babbageBlock BabbageBlock
if _, err := cbor.Decode(data, &babbageBlock); err != nil {
Expand Down
11 changes: 4 additions & 7 deletions ledger/byron/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,10 @@ func (t *ByronTransaction) Utxorpc() *utxorpc.Tx {
return &utxorpc.Tx{}
}

func (t *ByronTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
// TODO: Implement this add missing Body TransactionBody
updateMap := make(map[common.Blake2b224]any)
// for k, v := range t.Body.Update.ProtocolParamUpdates {
// updateMap[k] = v
// }
return updateMap
func (t *ByronTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
// No protocol parameter updates in Byron
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
return 0, updateMap
}

type ByronTransactionInput struct {
Expand Down
20 changes: 20 additions & 0 deletions ledger/common/pparams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 common

type ProtocolParameterUpdate interface {
IsProtocolParameterUpdate()
Cbor() []byte
}
2 changes: 1 addition & 1 deletion ledger/common/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type TransactionBody interface {
Inputs() []TransactionInput
Outputs() []TransactionOutput
TTL() uint64
ProtocolParametersUpdate() map[Blake2b224]any
ProtocolParameterUpdates() (uint64, map[Blake2b224]ProtocolParameterUpdate)
ValidityIntervalStart() uint64
ReferenceInputs() []TransactionInput
Collateral() []TransactionInput
Expand Down
10 changes: 5 additions & 5 deletions ledger/conway/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ func (b *ConwayTransactionBody) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (b *ConwayTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
updateMap := make(map[common.Blake2b224]any)
func (b *ConwayTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
return b.Update.Epoch, updateMap
}

func (b *ConwayTransactionBody) VotingProcedures() common.VotingProcedures {
Expand Down Expand Up @@ -339,8 +339,8 @@ func (t ConwayTransaction) ValidityIntervalStart() uint64 {
return t.Body.ValidityIntervalStart()
}

func (t ConwayTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
return t.Body.ProtocolParametersUpdate()
func (t ConwayTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
return t.Body.ProtocolParameterUpdates()
}

func (t ConwayTransaction) ReferenceInputs() []common.TransactionInput {
Expand Down
10 changes: 5 additions & 5 deletions ledger/mary/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ func (b *MaryTransactionBody) Outputs() []common.TransactionOutput {
return ret
}

func (b *MaryTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
updateMap := make(map[common.Blake2b224]any)
func (b *MaryTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
return b.Update.Epoch, updateMap
}

func (b *MaryTransactionBody) AssetMint() *common.MultiAsset[common.MultiAssetTypeMint] {
Expand Down Expand Up @@ -210,8 +210,8 @@ func (t MaryTransaction) ValidityIntervalStart() uint64 {
return t.Body.ValidityIntervalStart()
}

func (t MaryTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
return t.Body.ProtocolParametersUpdate()
func (t MaryTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
return t.Body.ProtocolParameterUpdates()
}

func (t MaryTransaction) ReferenceInputs() []common.TransactionInput {
Expand Down
17 changes: 12 additions & 5 deletions ledger/shelley/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ func (b *ShelleyTransactionBody) ValidityIntervalStart() uint64 {
return 0
}

func (b *ShelleyTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
updateMap := make(map[common.Blake2b224]any)
func (b *ShelleyTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
return b.Update.Epoch, updateMap
}

func (b *ShelleyTransactionBody) ReferenceInputs() []common.TransactionInput {
Expand Down Expand Up @@ -554,8 +554,8 @@ func (t ShelleyTransaction) Utxorpc() *utxorpc.Tx {
return t.Body.Utxorpc()
}

func (t *ShelleyTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
return t.Body.ProtocolParametersUpdate()
func (t *ShelleyTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
return t.Body.ProtocolParameterUpdates()
}

func (t *ShelleyTransaction) Cbor() []byte {
Expand Down Expand Up @@ -606,6 +606,7 @@ type ShelleyProtocolParameters struct {
}

type ShelleyProtocolParameterUpdate struct {
cbor.DecodeStoreCbor
MinFeeA uint `cbor:"0,keyasint"`
MinFeeB uint `cbor:"1,keyasint"`
MaxBlockBodySize uint `cbor:"2,keyasint"`
Expand All @@ -628,6 +629,12 @@ type ShelleyProtocolParameterUpdate struct {
MinUtxoValue uint `cbor:"15,keyasint"`
}

func (ShelleyProtocolParameterUpdate) IsProtocolParameterUpdate() {}

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

const (
NonceType0 = 0
NonceType1 = 1
Expand Down

0 comments on commit edf9f8b

Please sign in to comment.