Skip to content

Commit 10e407d

Browse files
authored
Merge branch 'main' into feat/cost-model-update
2 parents 7eff7f0 + d6f3ddb commit 10e407d

32 files changed

+824
-342
lines changed

cbor/cbor.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,3 @@ func (d *DecodeStoreCbor) SetCbor(cborData []byte) {
6969
func (d DecodeStoreCbor) Cbor() []byte {
7070
return d.cborData
7171
}
72-
73-
// UnmarshalCbor decodes the specified CBOR into the destination object and saves the original CBOR
74-
func (d *DecodeStoreCbor) UnmarshalCbor(
75-
cborData []byte,
76-
dest DecodeStoreCborInterface,
77-
) error {
78-
if err := DecodeGeneric(cborData, dest); err != nil {
79-
return err
80-
}
81-
// Store a copy of the original CBOR data
82-
// This must be done after we copy from the temp object above, or it gets wiped out
83-
// when using struct embedding and the DecodeStoreCbor struct is embedded at a deeper level
84-
d.SetCbor(cborData)
85-
return nil
86-
}

ledger/allegra/allegra.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ type AllegraBlock struct {
5353
}
5454

5555
func (b *AllegraBlock) UnmarshalCBOR(cborData []byte) error {
56-
return b.UnmarshalCbor(cborData, b)
56+
type tAllegraBlock AllegraBlock
57+
var tmp tAllegraBlock
58+
if _, err := cbor.Decode(cborData, &tmp); err != nil {
59+
return err
60+
}
61+
*b = AllegraBlock(tmp)
62+
b.SetCbor(cborData)
63+
return nil
5764
}
5865

5966
func (AllegraBlock) Type() int {
@@ -152,7 +159,14 @@ type AllegraTransactionBody struct {
152159
}
153160

154161
func (b *AllegraTransactionBody) UnmarshalCBOR(cborData []byte) error {
155-
return b.UnmarshalCbor(cborData, b)
162+
type tAllegraTransactionBody AllegraTransactionBody
163+
var tmp tAllegraTransactionBody
164+
if _, err := cbor.Decode(cborData, &tmp); err != nil {
165+
return err
166+
}
167+
*b = AllegraTransactionBody(tmp)
168+
b.SetCbor(cborData)
169+
return nil
156170
}
157171

158172
func (b *AllegraTransactionBody) Inputs() []common.TransactionInput {
@@ -219,8 +233,15 @@ type AllegraTransaction struct {
219233
TxMetadata *cbor.LazyValue
220234
}
221235

222-
func (t *AllegraTransaction) UnmarshalCBOR(data []byte) error {
223-
return t.UnmarshalCbor(data, t)
236+
func (t *AllegraTransaction) UnmarshalCBOR(cborData []byte) error {
237+
type tAllegraTransaction AllegraTransaction
238+
var tmp tAllegraTransaction
239+
if _, err := cbor.Decode(cborData, &tmp); err != nil {
240+
return err
241+
}
242+
*t = AllegraTransaction(tmp)
243+
t.SetCbor(cborData)
244+
return nil
224245
}
225246

226247
func (AllegraTransaction) Type() int {

ledger/allegra/pparams.go

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,14 @@ package allegra
1616

1717
import (
1818
"github.com/blinklabs-io/gouroboros/ledger/shelley"
19-
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
2019
)
2120

22-
type AllegraProtocolParameters struct {
23-
shelley.ShelleyProtocolParameters
24-
}
25-
26-
func (p *AllegraProtocolParameters) Update(
27-
paramUpdate *AllegraProtocolParameterUpdate,
28-
) {
29-
p.ShelleyProtocolParameters.Update(
30-
&paramUpdate.ShelleyProtocolParameterUpdate,
31-
)
32-
}
33-
34-
type AllegraProtocolParameterUpdate struct {
35-
shelley.ShelleyProtocolParameterUpdate
36-
}
37-
38-
func (u *AllegraProtocolParameterUpdate) UnmarshalCBOR(data []byte) error {
39-
return u.UnmarshalCbor(data, u)
40-
}
21+
type AllegraProtocolParameters = shelley.ShelleyProtocolParameters
4122

42-
func (p *AllegraProtocolParameters) Utxorpc() *cardano.PParams {
43-
return p.ShelleyProtocolParameters.Utxorpc()
44-
}
23+
type AllegraProtocolParameterUpdate = shelley.ShelleyProtocolParameterUpdate
4524

4625
func UpgradePParams(
4726
prevPParams shelley.ShelleyProtocolParameters,
4827
) AllegraProtocolParameters {
49-
return AllegraProtocolParameters{
50-
ShelleyProtocolParameters: prevPParams,
51-
}
28+
return AllegraProtocolParameters(prevPParams)
5229
}

ledger/allegra/pparams_test.go

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/blinklabs-io/gouroboros/cbor"
2424
"github.com/blinklabs-io/gouroboros/ledger/allegra"
25-
"github.com/blinklabs-io/gouroboros/ledger/shelley"
2625
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
2726
)
2827

@@ -34,28 +33,20 @@ func TestAllegraProtocolParamsUpdate(t *testing.T) {
3433
}{
3534
{
3635
startParams: allegra.AllegraProtocolParameters{
37-
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
38-
Decentralization: &cbor.Rat{Rat: new(big.Rat).SetInt64(1)},
39-
},
36+
Decentralization: &cbor.Rat{Rat: new(big.Rat).SetInt64(1)},
4037
},
4138
updateCbor: "a10cd81e82090a",
4239
expectedParams: allegra.AllegraProtocolParameters{
43-
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
44-
Decentralization: &cbor.Rat{Rat: big.NewRat(9, 10)},
45-
},
40+
Decentralization: &cbor.Rat{Rat: big.NewRat(9, 10)},
4641
},
4742
},
4843
{
4944
startParams: allegra.AllegraProtocolParameters{
50-
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
51-
ProtocolMajor: 3,
52-
},
45+
ProtocolMajor: 3,
5346
},
5447
updateCbor: "a10e820400",
5548
expectedParams: allegra.AllegraProtocolParameters{
56-
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
57-
ProtocolMajor: 4,
58-
},
49+
ProtocolMajor: 4,
5950
},
6051
},
6152
}
@@ -82,23 +73,21 @@ func TestAllegraProtocolParamsUpdate(t *testing.T) {
8273

8374
func TestAllegraUtxorpc(t *testing.T) {
8475
inputParams := allegra.AllegraProtocolParameters{
85-
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
86-
MinFeeA: 500,
87-
MinFeeB: 2,
88-
MaxBlockBodySize: 65536,
89-
MaxTxSize: 16384,
90-
MaxBlockHeaderSize: 1024,
91-
KeyDeposit: 2000,
92-
PoolDeposit: 500000,
93-
MaxEpoch: 2160,
94-
NOpt: 100,
95-
A0: &cbor.Rat{Rat: big.NewRat(1, 2)},
96-
Rho: &cbor.Rat{Rat: big.NewRat(3, 4)},
97-
Tau: &cbor.Rat{Rat: big.NewRat(5, 6)},
98-
ProtocolMajor: 8,
99-
ProtocolMinor: 0,
100-
MinUtxoValue: 1000000,
101-
},
76+
MinFeeA: 500,
77+
MinFeeB: 2,
78+
MaxBlockBodySize: 65536,
79+
MaxTxSize: 16384,
80+
MaxBlockHeaderSize: 1024,
81+
KeyDeposit: 2000,
82+
PoolDeposit: 500000,
83+
MaxEpoch: 2160,
84+
NOpt: 100,
85+
A0: &cbor.Rat{Rat: big.NewRat(1, 2)},
86+
Rho: &cbor.Rat{Rat: big.NewRat(3, 4)},
87+
Tau: &cbor.Rat{Rat: big.NewRat(5, 6)},
88+
ProtocolMajor: 8,
89+
ProtocolMinor: 0,
90+
MinUtxoValue: 1000000,
10291
}
10392

10493
expectedUtxorpc := &cardano.PParams{

ledger/allegra/rules.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func UtxoValidateFeeTooSmallUtxo(
7474
tx,
7575
slot,
7676
ls,
77-
&tmpPparams.ShelleyProtocolParameters,
77+
tmpPparams,
7878
)
7979
}
8080

@@ -119,7 +119,7 @@ func UtxoValidateValueNotConservedUtxo(
119119
tx,
120120
slot,
121121
ls,
122-
&tmpPparams.ShelleyProtocolParameters,
122+
tmpPparams,
123123
)
124124
}
125125

@@ -137,7 +137,7 @@ func UtxoValidateOutputTooSmallUtxo(
137137
tx,
138138
slot,
139139
ls,
140-
&tmpPparams.ShelleyProtocolParameters,
140+
tmpPparams,
141141
)
142142
}
143143

@@ -164,6 +164,6 @@ func UtxoValidateMaxTxSizeUtxo(
164164
tx,
165165
slot,
166166
ls,
167-
&tmpPparams.ShelleyProtocolParameters,
167+
tmpPparams,
168168
)
169169
}

ledger/allegra/rules_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,8 @@ func TestUtxoValidateFeeTooSmallUtxo(t *testing.T) {
203203
}
204204
testTx.SetCbor(testTxCbor)
205205
testProtocolParams := &allegra.AllegraProtocolParameters{
206-
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
207-
MinFeeA: 7,
208-
MinFeeB: 53,
209-
},
206+
MinFeeA: 7,
207+
MinFeeB: 53,
210208
}
211209
testLedgerState := test.MockLedgerState{}
212210
testSlot := uint64(0)
@@ -526,9 +524,7 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
526524
}
527525
testSlot := uint64(0)
528526
testProtocolParams := &allegra.AllegraProtocolParameters{
529-
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
530-
KeyDeposit: uint(testStakeDeposit),
531-
},
527+
KeyDeposit: uint(testStakeDeposit),
532528
}
533529
// Exact amount
534530
t.Run(
@@ -675,9 +671,7 @@ func TestUtxoValidateOutputTooSmallUtxo(t *testing.T) {
675671
testLedgerState := test.MockLedgerState{}
676672
testSlot := uint64(0)
677673
testProtocolParams := &allegra.AllegraProtocolParameters{
678-
ShelleyProtocolParameters: shelley.ShelleyProtocolParameters{
679-
MinUtxoValue: 100000,
680-
},
674+
MinUtxoValue: 100000,
681675
}
682676
// Good
683677
t.Run(

ledger/alonzo/alonzo.go

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ type AlonzoBlock struct {
5656
}
5757

5858
func (b *AlonzoBlock) UnmarshalCBOR(cborData []byte) error {
59-
return b.UnmarshalCbor(cborData, b)
59+
type tAlonzoBlock AlonzoBlock
60+
var tmp tAlonzoBlock
61+
if _, err := cbor.Decode(cborData, &tmp); err != nil {
62+
return err
63+
}
64+
*b = AlonzoBlock(tmp)
65+
b.SetCbor(cborData)
66+
return nil
6067
}
6168

6269
func (AlonzoBlock) Type() int {
@@ -166,7 +173,14 @@ type AlonzoTransactionBody struct {
166173
}
167174

168175
func (b *AlonzoTransactionBody) UnmarshalCBOR(cborData []byte) error {
169-
return b.UnmarshalCbor(cborData, b)
176+
type tAlonzoTransactionBody AlonzoTransactionBody
177+
var tmp tAlonzoTransactionBody
178+
if _, err := cbor.Decode(cborData, &tmp); err != nil {
179+
return err
180+
}
181+
*b = AlonzoTransactionBody(tmp)
182+
b.SetCbor(cborData)
183+
return nil
170184
}
171185

172186
func (b *AlonzoTransactionBody) Inputs() []common.TransactionInput {
@@ -255,8 +269,6 @@ type AlonzoTransactionOutput struct {
255269
}
256270

257271
func (o *AlonzoTransactionOutput) UnmarshalCBOR(cborData []byte) error {
258-
// Save original CBOR
259-
o.SetCbor(cborData)
260272
// Try to parse as legacy mary.Mary output first
261273
var tmpOutput mary.MaryTransactionOutput
262274
if _, err := cbor.Decode(cborData, &tmpOutput); err == nil {
@@ -265,8 +277,15 @@ func (o *AlonzoTransactionOutput) UnmarshalCBOR(cborData []byte) error {
265277
o.OutputAmount = tmpOutput.OutputAmount
266278
o.legacyOutput = true
267279
} else {
268-
return cbor.DecodeGeneric(cborData, o)
280+
type tAlonzoTransactionOutput AlonzoTransactionOutput
281+
var tmp tAlonzoTransactionOutput
282+
if _, err := cbor.Decode(cborData, &tmp); err != nil {
283+
return err
284+
}
285+
*o = AlonzoTransactionOutput(tmp)
269286
}
287+
// Save original CBOR
288+
o.SetCbor(cborData)
270289
return nil
271290
}
272291

@@ -391,7 +410,14 @@ type AlonzoTransactionWitnessSet struct {
391410
}
392411

393412
func (w *AlonzoTransactionWitnessSet) UnmarshalCBOR(cborData []byte) error {
394-
return w.UnmarshalCbor(cborData, w)
413+
type tAlonzoTransactionWitnessSet AlonzoTransactionWitnessSet
414+
var tmp tAlonzoTransactionWitnessSet
415+
if _, err := cbor.Decode(cborData, &tmp); err != nil {
416+
return err
417+
}
418+
*w = AlonzoTransactionWitnessSet(tmp)
419+
w.SetCbor(cborData)
420+
return nil
395421
}
396422

397423
func (w AlonzoTransactionWitnessSet) Vkey() []common.VkeyWitness {
@@ -437,8 +463,15 @@ type AlonzoTransaction struct {
437463
TxMetadata *cbor.LazyValue
438464
}
439465

440-
func (t *AlonzoTransaction) UnmarshalCBOR(data []byte) error {
441-
return t.UnmarshalCbor(data, t)
466+
func (t *AlonzoTransaction) UnmarshalCBOR(cborData []byte) error {
467+
type tAlonzoTransaction AlonzoTransaction
468+
var tmp tAlonzoTransaction
469+
if _, err := cbor.Decode(cborData, &tmp); err != nil {
470+
return err
471+
}
472+
*t = AlonzoTransaction(tmp)
473+
t.SetCbor(cborData)
474+
return nil
442475
}
443476

444477
func (AlonzoTransaction) Type() int {

0 commit comments

Comments
 (0)