Skip to content

Commit edf9f8b

Browse files
authored
feat: return epoch with protocol param updates (#719)
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
1 parent f8e7de0 commit edf9f8b

File tree

10 files changed

+70
-39
lines changed

10 files changed

+70
-39
lines changed

cbor/cbor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (d *DecodeStoreCbor) SetCbor(cborData []byte) {
6464
}
6565

6666
// Cbor returns the original CBOR for the object
67-
func (d *DecodeStoreCbor) Cbor() []byte {
67+
func (d DecodeStoreCbor) Cbor() []byte {
6868
return d.cborData
6969
}
7070

ledger/allegra/allegra.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ func (b *AllegraTransactionBody) ValidityIntervalStart() uint64 {
148148
return b.TxValidityIntervalStart
149149
}
150150

151-
func (b *AllegraTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
152-
updateMap := make(map[common.Blake2b224]any)
151+
func (b *AllegraTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
152+
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
153153
for k, v := range b.Update.ProtocolParamUpdates {
154154
updateMap[k] = v
155155
}
156-
return updateMap
156+
return b.Update.Epoch, updateMap
157157
}
158158

159159
type AllegraTransaction struct {
@@ -278,8 +278,8 @@ func (t AllegraTransaction) Produced() []common.Utxo {
278278
return ret
279279
}
280280

281-
func (t AllegraTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
282-
return t.Body.ProtocolParametersUpdate()
281+
func (t AllegraTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
282+
return t.Body.ProtocolParameterUpdates()
283283
}
284284

285285
func (t *AllegraTransaction) Cbor() []byte {

ledger/alonzo/alonzo.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ func (b *AlonzoTransactionBody) Outputs() []common.TransactionOutput {
166166
return ret
167167
}
168168

169-
func (b *AlonzoTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
170-
updateMap := make(map[common.Blake2b224]any)
169+
func (b *AlonzoTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
170+
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
171171
for k, v := range b.Update.ProtocolParamUpdates {
172172
updateMap[k] = v
173173
}
174-
return updateMap
174+
return b.Update.Epoch, updateMap
175175
}
176176

177177
func (b *AlonzoTransactionBody) Collateral() []common.TransactionInput {
@@ -349,8 +349,8 @@ func (t AlonzoTransaction) ValidityIntervalStart() uint64 {
349349
return t.Body.ValidityIntervalStart()
350350
}
351351

352-
func (t AlonzoTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
353-
return t.Body.ProtocolParametersUpdate()
352+
func (t AlonzoTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
353+
return t.Body.ProtocolParameterUpdates()
354354
}
355355

356356
func (t AlonzoTransaction) ReferenceInputs() []common.TransactionInput {

ledger/babbage/babbage.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ func (b *BabbageTransactionBody) Outputs() []common.TransactionOutput {
220220
return ret
221221
}
222222

223-
func (b *BabbageTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
224-
updateMap := make(map[common.Blake2b224]any)
223+
func (b *BabbageTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
224+
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
225225
for k, v := range b.Update.ProtocolParamUpdates {
226226
updateMap[k] = v
227227
}
228-
return updateMap
228+
return b.Update.Epoch, updateMap
229229
}
230230

231231
func (b *BabbageTransactionBody) ReferenceInputs() []common.TransactionInput {
@@ -523,8 +523,8 @@ func (t BabbageTransaction) ValidityIntervalStart() uint64 {
523523
return t.Body.ValidityIntervalStart()
524524
}
525525

526-
func (t BabbageTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
527-
return t.Body.ProtocolParametersUpdate()
526+
func (t BabbageTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
527+
return t.Body.ProtocolParameterUpdates()
528528
}
529529

530530
func (t BabbageTransaction) ReferenceInputs() []common.TransactionInput {
@@ -685,6 +685,7 @@ type BabbageProtocolParameters struct {
685685
}
686686

687687
type BabbageProtocolParameterUpdate struct {
688+
cbor.DecodeStoreCbor
688689
MinFeeA uint `cbor:"0,keyasint"`
689690
MinFeeB uint `cbor:"1,keyasint"`
690691
MaxBlockBodySize uint `cbor:"2,keyasint"`
@@ -713,6 +714,12 @@ type BabbageProtocolParameterUpdate struct {
713714
MaxCollateralInputs uint `cbor:"24,keyasint"`
714715
}
715716

717+
func (BabbageProtocolParameterUpdate) IsProtocolParameterUpdate() {}
718+
719+
func (u *BabbageProtocolParameterUpdate) UnmarshalCBOR(data []byte) error {
720+
return u.UnmarshalCbor(data, u)
721+
}
722+
716723
func NewBabbageBlockFromCbor(data []byte) (*BabbageBlock, error) {
717724
var babbageBlock BabbageBlock
718725
if _, err := cbor.Decode(data, &babbageBlock); err != nil {

ledger/byron/byron.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,10 @@ func (t *ByronTransaction) Utxorpc() *utxorpc.Tx {
297297
return &utxorpc.Tx{}
298298
}
299299

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

309306
type ByronTransactionInput struct {

ledger/common/pparams.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2024 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package common
16+
17+
type ProtocolParameterUpdate interface {
18+
IsProtocolParameterUpdate()
19+
Cbor() []byte
20+
}

ledger/common/tx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type TransactionBody interface {
3636
Inputs() []TransactionInput
3737
Outputs() []TransactionOutput
3838
TTL() uint64
39-
ProtocolParametersUpdate() map[Blake2b224]any
39+
ProtocolParameterUpdates() (uint64, map[Blake2b224]ProtocolParameterUpdate)
4040
ValidityIntervalStart() uint64
4141
ReferenceInputs() []TransactionInput
4242
Collateral() []TransactionInput

ledger/conway/conway.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ func (b *ConwayTransactionBody) UnmarshalCBOR(cborData []byte) error {
203203
return b.UnmarshalCbor(cborData, b)
204204
}
205205

206-
func (b *ConwayTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
207-
updateMap := make(map[common.Blake2b224]any)
206+
func (b *ConwayTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
207+
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
208208
for k, v := range b.Update.ProtocolParamUpdates {
209209
updateMap[k] = v
210210
}
211-
return updateMap
211+
return b.Update.Epoch, updateMap
212212
}
213213

214214
func (b *ConwayTransactionBody) VotingProcedures() common.VotingProcedures {
@@ -339,8 +339,8 @@ func (t ConwayTransaction) ValidityIntervalStart() uint64 {
339339
return t.Body.ValidityIntervalStart()
340340
}
341341

342-
func (t ConwayTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
343-
return t.Body.ProtocolParametersUpdate()
342+
func (t ConwayTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
343+
return t.Body.ProtocolParameterUpdates()
344344
}
345345

346346
func (t ConwayTransaction) ReferenceInputs() []common.TransactionInput {

ledger/mary/mary.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ func (b *MaryTransactionBody) Outputs() []common.TransactionOutput {
156156
return ret
157157
}
158158

159-
func (b *MaryTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
160-
updateMap := make(map[common.Blake2b224]any)
159+
func (b *MaryTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
160+
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
161161
for k, v := range b.Update.ProtocolParamUpdates {
162162
updateMap[k] = v
163163
}
164-
return updateMap
164+
return b.Update.Epoch, updateMap
165165
}
166166

167167
func (b *MaryTransactionBody) AssetMint() *common.MultiAsset[common.MultiAssetTypeMint] {
@@ -210,8 +210,8 @@ func (t MaryTransaction) ValidityIntervalStart() uint64 {
210210
return t.Body.ValidityIntervalStart()
211211
}
212212

213-
func (t MaryTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
214-
return t.Body.ProtocolParametersUpdate()
213+
func (t MaryTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
214+
return t.Body.ProtocolParameterUpdates()
215215
}
216216

217217
func (t MaryTransaction) ReferenceInputs() []common.TransactionInput {

ledger/shelley/shelley.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ func (b *ShelleyTransactionBody) ValidityIntervalStart() uint64 {
237237
return 0
238238
}
239239

240-
func (b *ShelleyTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
241-
updateMap := make(map[common.Blake2b224]any)
240+
func (b *ShelleyTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
241+
updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate)
242242
for k, v := range b.Update.ProtocolParamUpdates {
243243
updateMap[k] = v
244244
}
245-
return updateMap
245+
return b.Update.Epoch, updateMap
246246
}
247247

248248
func (b *ShelleyTransactionBody) ReferenceInputs() []common.TransactionInput {
@@ -554,8 +554,8 @@ func (t ShelleyTransaction) Utxorpc() *utxorpc.Tx {
554554
return t.Body.Utxorpc()
555555
}
556556

557-
func (t *ShelleyTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
558-
return t.Body.ProtocolParametersUpdate()
557+
func (t *ShelleyTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) {
558+
return t.Body.ProtocolParameterUpdates()
559559
}
560560

561561
func (t *ShelleyTransaction) Cbor() []byte {
@@ -606,6 +606,7 @@ type ShelleyProtocolParameters struct {
606606
}
607607

608608
type ShelleyProtocolParameterUpdate struct {
609+
cbor.DecodeStoreCbor
609610
MinFeeA uint `cbor:"0,keyasint"`
610611
MinFeeB uint `cbor:"1,keyasint"`
611612
MaxBlockBodySize uint `cbor:"2,keyasint"`
@@ -628,6 +629,12 @@ type ShelleyProtocolParameterUpdate struct {
628629
MinUtxoValue uint `cbor:"15,keyasint"`
629630
}
630631

632+
func (ShelleyProtocolParameterUpdate) IsProtocolParameterUpdate() {}
633+
634+
func (u *ShelleyProtocolParameterUpdate) UnmarshalCBOR(data []byte) error {
635+
return u.UnmarshalCbor(data, u)
636+
}
637+
631638
const (
632639
NonceType0 = 0
633640
NonceType1 = 1

0 commit comments

Comments
 (0)