Skip to content

Commit aba2b7e

Browse files
authored
fix: use stored CBOR in TX validation rules (#965)
We fall back to encoding to CBOR ourselves if there is no stored CBOR Signed-off-by: Aurora Gaffney <[email protected]>
1 parent 63be43c commit aba2b7e

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

ledger/babbage/rules.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,13 @@ func MinFeeTx(
456456
return 0, errors.New("pparams are not expected type")
457457
}
458458
txBytes := tx.Cbor()
459+
if len(txBytes) == 0 {
460+
var err error
461+
txBytes, err = cbor.Encode(tx)
462+
if err != nil {
463+
return 0, err
464+
}
465+
}
459466
minFee := uint64(
460467
(tmpPparams.MinFeeA * uint(len(txBytes))) + tmpPparams.MinFeeB,
461468
)

ledger/conway/rules.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,13 @@ func MinFeeTx(
457457
return 0, errors.New("pparams are not expected type")
458458
}
459459
txBytes := tx.Cbor()
460+
if len(txBytes) == 0 {
461+
var err error
462+
txBytes, err = cbor.Encode(tx)
463+
if err != nil {
464+
return 0, err
465+
}
466+
}
460467
minFee := uint64(
461468
(tmpPparams.MinFeeA * uint(len(txBytes))) + tmpPparams.MinFeeB,
462469
)

ledger/shelley/rules.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,13 @@ func UtxoValidateMaxTxSizeUtxo(
283283
if !ok {
284284
return errors.New("pparams are not expected type")
285285
}
286-
txBytes, err := cbor.Encode(tx)
287-
if err != nil {
288-
return err
286+
txBytes := tx.Cbor()
287+
if len(txBytes) == 0 {
288+
var err error
289+
txBytes, err = cbor.Encode(tx)
290+
if err != nil {
291+
return err
292+
}
289293
}
290294
if uint(len(txBytes)) <= tmpPparams.MaxTxSize {
291295
return nil
@@ -306,6 +310,13 @@ func MinFeeTx(
306310
return 0, errors.New("pparams are not expected type")
307311
}
308312
txBytes := tx.Cbor()
313+
if len(txBytes) == 0 {
314+
var err error
315+
txBytes, err = cbor.Encode(tx)
316+
if err != nil {
317+
return 0, err
318+
}
319+
}
309320
minFee := uint64(
310321
(tmpPparams.MinFeeA * uint(len(txBytes))) + tmpPparams.MinFeeB,
311322
)

0 commit comments

Comments
 (0)