Skip to content

Commit f7c40d8

Browse files
authored
refactor: merge duplicate ExUnits types (#905)
Signed-off-by: Aurora Gaffney <[email protected]>
1 parent 8c92a01 commit f7c40d8

File tree

11 files changed

+67
-73
lines changed

11 files changed

+67
-73
lines changed

ledger/alonzo/alonzo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ type AlonzoRedeemer struct {
307307
Tag common.RedeemerTag
308308
Index uint32
309309
Data cbor.LazyValue
310-
ExUnits common.RedeemerExUnits
310+
ExUnits common.ExUnits
311311
}
312312

313313
type AlonzoRedeemers []AlonzoRedeemer
@@ -325,13 +325,13 @@ func (r AlonzoRedeemers) Indexes(tag common.RedeemerTag) []uint {
325325
func (r AlonzoRedeemers) Value(
326326
index uint,
327327
tag common.RedeemerTag,
328-
) (cbor.LazyValue, common.RedeemerExUnits) {
328+
) (cbor.LazyValue, common.ExUnits) {
329329
for _, redeemer := range r {
330330
if redeemer.Tag == tag && uint(redeemer.Index) == index {
331331
return redeemer.Data, redeemer.ExUnits
332332
}
333333
}
334-
return cbor.LazyValue{}, common.RedeemerExUnits{}
334+
return cbor.LazyValue{}, common.ExUnits{}
335335
}
336336

337337
type AlonzoTransactionWitnessSet struct {

ledger/alonzo/pparams.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ type AlonzoProtocolParameters struct {
3030
AdaPerUtxoByte uint64
3131
CostModels map[uint][]int64
3232
ExecutionCosts common.ExUnitPrice
33-
MaxTxExUnits common.ExUnit
34-
MaxBlockExUnits common.ExUnit
33+
MaxTxExUnits common.ExUnits
34+
MaxBlockExUnits common.ExUnits
3535
MaxValueSize uint
3636
CollateralPercentage uint
3737
MaxCollateralInputs uint
@@ -80,13 +80,13 @@ func (p *AlonzoProtocolParameters) UpdateFromGenesis(genesis *AlonzoGenesis) {
8080
p.MaxValueSize = genesis.MaxValueSize
8181
p.CollateralPercentage = genesis.CollateralPercentage
8282
p.MaxCollateralInputs = genesis.MaxCollateralInputs
83-
p.MaxTxExUnits = common.ExUnit{
84-
Mem: genesis.MaxTxExUnits.Mem,
85-
Steps: genesis.MaxTxExUnits.Steps,
83+
p.MaxTxExUnits = common.ExUnits{
84+
Memory: uint64(genesis.MaxTxExUnits.Mem),
85+
Steps: uint64(genesis.MaxTxExUnits.Steps),
8686
}
87-
p.MaxBlockExUnits = common.ExUnit{
88-
Mem: genesis.MaxBlockExUnits.Mem,
89-
Steps: genesis.MaxBlockExUnits.Steps,
87+
p.MaxBlockExUnits = common.ExUnits{
88+
Memory: uint64(genesis.MaxBlockExUnits.Mem),
89+
Steps: uint64(genesis.MaxBlockExUnits.Steps),
9090
}
9191
if genesis.ExecutionPrices.Mem != nil &&
9292
genesis.ExecutionPrices.Steps != nil {
@@ -106,8 +106,8 @@ type AlonzoProtocolParameterUpdate struct {
106106
AdaPerUtxoByte *uint64 `cbor:"17,keyasint"`
107107
CostModels map[uint][]int64 `cbor:"18,keyasint"`
108108
ExecutionCosts *common.ExUnitPrice `cbor:"19,keyasint"`
109-
MaxTxExUnits *common.ExUnit `cbor:"20,keyasint"`
110-
MaxBlockExUnits *common.ExUnit `cbor:"21,keyasint"`
109+
MaxTxExUnits *common.ExUnits `cbor:"20,keyasint"`
110+
MaxBlockExUnits *common.ExUnits `cbor:"21,keyasint"`
111111
MaxValueSize *uint `cbor:"22,keyasint"`
112112
CollateralPercentage *uint `cbor:"23,keyasint"`
113113
MaxCollateralInputs *uint `cbor:"24,keyasint"`
@@ -190,11 +190,11 @@ func (p *AlonzoProtocolParameters) Utxorpc() *cardano.PParams {
190190
},
191191
},
192192
MaxExecutionUnitsPerTransaction: &cardano.ExUnits{
193-
Memory: uint64(p.MaxTxExUnits.Mem),
193+
Memory: uint64(p.MaxTxExUnits.Memory),
194194
Steps: uint64(p.MaxTxExUnits.Steps),
195195
},
196196
MaxExecutionUnitsPerBlock: &cardano.ExUnits{
197-
Memory: uint64(p.MaxBlockExUnits.Mem),
197+
Memory: uint64(p.MaxBlockExUnits.Memory),
198198
Steps: uint64(p.MaxBlockExUnits.Steps),
199199
},
200200
}

ledger/alonzo/pparams_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ func TestAlonzoProtocolParamsUpdate(t *testing.T) {
8989
},
9090
},
9191
},
92-
MaxTxExUnits: common.ExUnit{
93-
Mem: 1,
94-
Steps: 1,
92+
MaxTxExUnits: common.ExUnits{
93+
Memory: 1,
94+
Steps: 1,
9595
},
9696
},
9797
updateCbor: "a2021a0001200014821a00aba9501b00000002540be400",
@@ -103,9 +103,9 @@ func TestAlonzoProtocolParamsUpdate(t *testing.T) {
103103
},
104104
},
105105
},
106-
MaxTxExUnits: common.ExUnit{
107-
Mem: 11250000,
108-
Steps: 10000000000,
106+
MaxTxExUnits: common.ExUnits{
107+
Memory: 11250000,
108+
Steps: 10000000000,
109109
},
110110
},
111111
},
@@ -214,13 +214,13 @@ func TestAlonzoUtxorpc(t *testing.T) {
214214
MemPrice: &cbor.Rat{Rat: big.NewRat(1, 2)},
215215
StepPrice: &cbor.Rat{Rat: big.NewRat(2, 3)},
216216
},
217-
MaxTxExUnits: common.ExUnit{
218-
Mem: 1000000,
219-
Steps: 200000,
217+
MaxTxExUnits: common.ExUnits{
218+
Memory: 1000000,
219+
Steps: 200000,
220220
},
221-
MaxBlockExUnits: common.ExUnit{
222-
Mem: 5000000,
223-
Steps: 1000000,
221+
MaxBlockExUnits: common.ExUnits{
222+
Memory: 5000000,
223+
Steps: 1000000,
224224
},
225225
CostModels: map[uint][]int64{
226226
1: {100, 200, 300},

ledger/babbage/pparams.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ type BabbageProtocolParameters struct {
4545
AdaPerUtxoByte uint64
4646
CostModels map[uint][]int64
4747
ExecutionCosts common.ExUnitPrice
48-
MaxTxExUnits common.ExUnit
49-
MaxBlockExUnits common.ExUnit
48+
MaxTxExUnits common.ExUnits
49+
MaxBlockExUnits common.ExUnits
5050
MaxValueSize uint
5151
CollateralPercentage uint
5252
MaxCollateralInputs uint
@@ -143,8 +143,8 @@ type BabbageProtocolParameterUpdate struct {
143143
AdaPerUtxoByte *uint64 `cbor:"17,keyasint"`
144144
CostModels map[uint][]int64 `cbor:"18,keyasint"`
145145
ExecutionCosts *common.ExUnitPrice `cbor:"19,keyasint"`
146-
MaxTxExUnits *common.ExUnit `cbor:"20,keyasint"`
147-
MaxBlockExUnits *common.ExUnit `cbor:"21,keyasint"`
146+
MaxTxExUnits *common.ExUnits `cbor:"20,keyasint"`
147+
MaxBlockExUnits *common.ExUnits `cbor:"21,keyasint"`
148148
MaxValueSize *uint `cbor:"22,keyasint"`
149149
CollateralPercentage *uint `cbor:"23,keyasint"`
150150
MaxCollateralInputs *uint `cbor:"24,keyasint"`
@@ -229,11 +229,11 @@ func (p *BabbageProtocolParameters) Utxorpc() *cardano.PParams {
229229
},
230230
},
231231
MaxExecutionUnitsPerTransaction: &cardano.ExUnits{
232-
Memory: uint64(p.MaxTxExUnits.Mem),
232+
Memory: uint64(p.MaxTxExUnits.Memory),
233233
Steps: uint64(p.MaxTxExUnits.Steps),
234234
},
235235
MaxExecutionUnitsPerBlock: &cardano.ExUnits{
236-
Memory: uint64(p.MaxBlockExUnits.Mem),
236+
Memory: uint64(p.MaxBlockExUnits.Memory),
237237
Steps: uint64(p.MaxBlockExUnits.Steps),
238238
},
239239
}

ledger/babbage/pparams_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ func TestBabbageProtocolParamsUpdate(t *testing.T) {
4444
{
4545
startParams: babbage.BabbageProtocolParameters{
4646
MaxBlockBodySize: 1,
47-
MaxTxExUnits: common.ExUnit{
48-
Mem: 1,
49-
Steps: 1,
47+
MaxTxExUnits: common.ExUnits{
48+
Memory: 1,
49+
Steps: 1,
5050
},
5151
},
5252
updateCbor: "a2021a0001200014821a00aba9501b00000002540be400",
5353
expectedParams: babbage.BabbageProtocolParameters{
5454
MaxBlockBodySize: 73728,
55-
MaxTxExUnits: common.ExUnit{
56-
Mem: 11250000,
57-
Steps: 10000000000,
55+
MaxTxExUnits: common.ExUnits{
56+
Memory: 11250000,
57+
Steps: 10000000000,
5858
},
5959
},
6060
},
@@ -463,13 +463,13 @@ func TestBabbageUtxorpc(t *testing.T) {
463463
MemPrice: &cbor.Rat{Rat: big.NewRat(1, 2)},
464464
StepPrice: &cbor.Rat{Rat: big.NewRat(2, 3)},
465465
},
466-
MaxTxExUnits: common.ExUnit{
467-
Mem: 1000000,
468-
Steps: 200000,
466+
MaxTxExUnits: common.ExUnits{
467+
Memory: 1000000,
468+
Steps: 200000,
469469
},
470-
MaxBlockExUnits: common.ExUnit{
471-
Mem: 5000000,
472-
Steps: 1000000,
470+
MaxBlockExUnits: common.ExUnits{
471+
Memory: 5000000,
472+
Steps: 1000000,
473473
},
474474
CostModels: map[uint][]int64{
475475
1: {100, 200, 300},

ledger/common/common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ func (i IssuerVkey) PoolId() string {
318318
return encoded
319319
}
320320

321-
// RedeemerExUnits represents the steps and memory usage for script execution
322-
type RedeemerExUnits struct {
321+
// ExUnits represents the steps and memory usage for script execution
322+
type ExUnits struct {
323323
cbor.StructAsArray
324324
Memory uint64
325325
Steps uint64

ledger/common/pparams.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ type ProtocolParameters interface {
3636
Utxorpc() *cardano.PParams
3737
}
3838

39-
type ExUnit struct {
40-
cbor.StructAsArray
41-
Mem uint
42-
Steps uint
43-
}
44-
4539
type ExUnitPrice struct {
4640
cbor.StructAsArray
4741
MemPrice *cbor.Rat

ledger/common/tx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type TransactionWitnessSet interface {
8787

8888
type TransactionWitnessRedeemers interface {
8989
Indexes(RedeemerTag) []uint
90-
Value(uint, RedeemerTag) (cbor.LazyValue, RedeemerExUnits)
90+
Value(uint, RedeemerTag) (cbor.LazyValue, ExUnits)
9191
}
9292

9393
type Utxo struct {

ledger/conway/conway.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ type ConwayRedeemerKey struct {
157157
type ConwayRedeemerValue struct {
158158
cbor.StructAsArray
159159
Data cbor.LazyValue
160-
ExUnits common.RedeemerExUnits
160+
ExUnits common.ExUnits
161161
}
162162

163163
type ConwayRedeemers struct {
@@ -203,15 +203,15 @@ func (r ConwayRedeemers) Indexes(tag common.RedeemerTag) []uint {
203203
func (r ConwayRedeemers) Value(
204204
index uint,
205205
tag common.RedeemerTag,
206-
) (cbor.LazyValue, common.RedeemerExUnits) {
206+
) (cbor.LazyValue, common.ExUnits) {
207207
redeemer, ok := r.Redeemers[ConwayRedeemerKey{
208208
Tag: tag,
209209
Index: uint32(index), // #nosec G115
210210
}]
211211
if ok {
212212
return redeemer.Data, redeemer.ExUnits
213213
}
214-
return cbor.LazyValue{}, common.RedeemerExUnits{}
214+
return cbor.LazyValue{}, common.ExUnits{}
215215
}
216216

217217
type ConwayTransactionWitnessSet struct {

ledger/conway/pparams.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ type ConwayProtocolParameters struct {
4343
AdaPerUtxoByte uint64
4444
CostModels map[uint][]int64
4545
ExecutionCosts common.ExUnitPrice
46-
MaxTxExUnits common.ExUnit
47-
MaxBlockExUnits common.ExUnit
46+
MaxTxExUnits common.ExUnits
47+
MaxBlockExUnits common.ExUnits
4848
MaxValueSize uint
4949
CollateralPercentage uint
5050
MaxCollateralInputs uint
@@ -132,11 +132,11 @@ func (p *ConwayProtocolParameters) Utxorpc() *cardano.PParams {
132132
},
133133
},
134134
MaxExecutionUnitsPerTransaction: &cardano.ExUnits{
135-
Memory: uint64(p.MaxTxExUnits.Mem),
135+
Memory: uint64(p.MaxTxExUnits.Memory),
136136
Steps: uint64(p.MaxTxExUnits.Steps),
137137
},
138138
MaxExecutionUnitsPerBlock: &cardano.ExUnits{
139-
Memory: uint64(p.MaxBlockExUnits.Mem),
139+
Memory: uint64(p.MaxBlockExUnits.Memory),
140140
Steps: uint64(p.MaxBlockExUnits.Steps),
141141
},
142142
}

0 commit comments

Comments
 (0)