Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make format golines #942

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions internal/test/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func (ls MockLedgerState) UtxoById(
return common.Utxo{}, errors.New("not found")
}

func (ls MockLedgerState) StakeRegistration(stakingKey []byte) ([]common.StakeRegistrationCertificate, error) {
func (ls MockLedgerState) StakeRegistration(
stakingKey []byte,
) ([]common.StakeRegistrationCertificate, error) {
ret := []common.StakeRegistrationCertificate{}
for _, cert := range ls.MockStakeRegistration {
if string(cert.StakeRegistration.Credential) == string(stakingKey) {
Expand All @@ -56,10 +58,16 @@ func (ls MockLedgerState) StakeRegistration(stakingKey []byte) ([]common.StakeRe
return ret, nil
}

func (ls MockLedgerState) PoolRegistration(poolKeyHash []byte) ([]common.PoolRegistrationCertificate, error) {
func (ls MockLedgerState) PoolRegistration(
poolKeyHash []byte,
) ([]common.PoolRegistrationCertificate, error) {
ret := []common.PoolRegistrationCertificate{}
for _, cert := range ls.MockPoolRegistration {
if string(common.Blake2b224(cert.Operator).Bytes()) == string(poolKeyHash) {
if string(
common.Blake2b224(cert.Operator).Bytes(),
) == string(
poolKeyHash,
) {
ret = append(ret, cert)
}
}
Expand Down
136 changes: 116 additions & 20 deletions ledger/alonzo/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ var UtxoValidationRules = []common.UtxoValidationRuleFunc{
}

// UtxoValidateOutputTooBigUtxo ensures that transaction output values are not too large
func UtxoValidateOutputTooBigUtxo(tx common.Transaction, slot uint64, _ common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateOutputTooBigUtxo(
tx common.Transaction,
slot uint64,
_ common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpPparams, ok := pp.(*AlonzoProtocolParameters)
if !ok {
return errors.New("pparams are not expected type")
Expand Down Expand Up @@ -72,7 +77,12 @@ func UtxoValidateOutputTooBigUtxo(tx common.Transaction, slot uint64, _ common.L
}

// UtxoValidateExUnitsTooBigUtxo ensures that ExUnits for a transaction do not exceed the maximum specified via protocol parameters
func UtxoValidateExUnitsTooBigUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateExUnitsTooBigUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpPparams, ok := pp.(*AlonzoProtocolParameters)
if !ok {
return errors.New("pparams are not expected type")
Expand All @@ -86,7 +96,8 @@ func UtxoValidateExUnitsTooBigUtxo(tx common.Transaction, slot uint64, ls common
totalSteps += redeemer.ExUnits.Steps
totalMemory += redeemer.ExUnits.Memory
}
if totalSteps <= tmpPparams.MaxTxExUnits.Steps && totalMemory <= tmpPparams.MaxTxExUnits.Memory {
if totalSteps <= tmpPparams.MaxTxExUnits.Steps &&
totalMemory <= tmpPparams.MaxTxExUnits.Memory {
return nil
}
return ExUnitsTooBigUtxoError{
Expand All @@ -98,24 +109,49 @@ func UtxoValidateExUnitsTooBigUtxo(tx common.Transaction, slot uint64, ls common
}
}

func UtxoValidateOutsideValidityIntervalUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateOutsideValidityIntervalUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
return allegra.UtxoValidateOutsideValidityIntervalUtxo(tx, slot, ls, pp)
}

func UtxoValidateInputSetEmptyUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateInputSetEmptyUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
return shelley.UtxoValidateInputSetEmptyUtxo(tx, slot, ls, pp)
}

func UtxoValidateFeeTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateFeeTooSmallUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpPparams, ok := pp.(*AlonzoProtocolParameters)
if !ok {
return errors.New("pparams are not expected type")
}
return shelley.UtxoValidateFeeTooSmallUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
return shelley.UtxoValidateFeeTooSmallUtxo(
tx,
slot,
ls,
&tmpPparams.ShelleyProtocolParameters,
)
}

// UtxoValidateInsufficientCollateral ensures that there is sufficient collateral provided
func UtxoValidateInsufficientCollateral(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateInsufficientCollateral(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpPparams, ok := pp.(*AlonzoProtocolParameters)
if !ok {
return errors.New("pparams are not expected type")
Expand Down Expand Up @@ -147,7 +183,12 @@ func UtxoValidateInsufficientCollateral(tx common.Transaction, slot uint64, ls c
}

// UtxoValidateCollateralContainsNonAda ensures that collateral inputs don't contain non-ADA
func UtxoValidateCollateralContainsNonAda(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateCollateralContainsNonAda(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpTx, ok := tx.(*AlonzoTransaction)
if !ok {
return errors.New("transaction is not expected type")
Expand Down Expand Up @@ -178,7 +219,12 @@ func UtxoValidateCollateralContainsNonAda(tx common.Transaction, slot uint64, ls
}

// UtxoValidateNoCollateralInputs ensures that collateral inputs are provided when redeemers are present
func UtxoValidateNoCollateralInputs(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateNoCollateralInputs(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpTx, ok := tx.(*AlonzoTransaction)
if !ok {
return errors.New("transaction is not expected type")
Expand All @@ -193,42 +239,92 @@ func UtxoValidateNoCollateralInputs(tx common.Transaction, slot uint64, ls commo
return NoCollateralInputsError{}
}

func UtxoValidateBadInputsUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateBadInputsUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
return shelley.UtxoValidateBadInputsUtxo(tx, slot, ls, pp)
}

func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateValueNotConservedUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpPparams, ok := pp.(*AlonzoProtocolParameters)
if !ok {
return errors.New("pparams are not expected type")
}
return shelley.UtxoValidateValueNotConservedUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
return shelley.UtxoValidateValueNotConservedUtxo(
tx,
slot,
ls,
&tmpPparams.ShelleyProtocolParameters,
)
}

func UtxoValidateOutputTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateOutputTooSmallUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpPparams, ok := pp.(*AlonzoProtocolParameters)
if !ok {
return errors.New("pparams are not expected type")
}
return shelley.UtxoValidateOutputTooSmallUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
return shelley.UtxoValidateOutputTooSmallUtxo(
tx,
slot,
ls,
&tmpPparams.ShelleyProtocolParameters,
)
}

func UtxoValidateOutputBootAddrAttrsTooBig(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateOutputBootAddrAttrsTooBig(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
return shelley.UtxoValidateOutputBootAddrAttrsTooBig(tx, slot, ls, pp)
}

func UtxoValidateWrongNetwork(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateWrongNetwork(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
return shelley.UtxoValidateWrongNetwork(tx, slot, ls, pp)
}

func UtxoValidateWrongNetworkWithdrawal(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateWrongNetworkWithdrawal(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
return shelley.UtxoValidateWrongNetworkWithdrawal(tx, slot, ls, pp)
}

func UtxoValidateMaxTxSizeUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
func UtxoValidateMaxTxSizeUtxo(
tx common.Transaction,
slot uint64,
ls common.LedgerState,
pp common.ProtocolParameters,
) error {
tmpPparams, ok := pp.(*AlonzoProtocolParameters)
if !ok {
return errors.New("pparams are not expected type")
}
return shelley.UtxoValidateMaxTxSizeUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
return shelley.UtxoValidateMaxTxSizeUtxo(
tx,
slot,
ls,
&tmpPparams.ShelleyProtocolParameters,
)
}
29 changes: 22 additions & 7 deletions ledger/alonzo/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,12 @@ func TestUtxoValidateBadInputsUtxo(t *testing.T) {
}

func TestUtxoValidateWrongNetwork(t *testing.T) {
testCorrectNetworkAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd")
testWrongNetworkAddr, _ := common.NewAddress("addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07")
testCorrectNetworkAddr, _ := common.NewAddress(
"addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd",
)
testWrongNetworkAddr, _ := common.NewAddress(
"addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07",
)
testTx := &alonzo.AlonzoTransaction{
Body: alonzo.AlonzoTransactionBody{
TxOutputs: []alonzo.AlonzoTransactionOutput{
Expand Down Expand Up @@ -448,8 +452,12 @@ func TestUtxoValidateWrongNetwork(t *testing.T) {
}

func TestUtxoValidateWrongNetworkWithdrawal(t *testing.T) {
testCorrectNetworkAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd")
testWrongNetworkAddr, _ := common.NewAddress("addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07")
testCorrectNetworkAddr, _ := common.NewAddress(
"addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd",
)
testWrongNetworkAddr, _ := common.NewAddress(
"addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07",
)
testTx := &alonzo.AlonzoTransaction{
Body: alonzo.AlonzoTransactionBody{
MaryTransactionBody: mary.MaryTransactionBody{
Expand Down Expand Up @@ -535,7 +543,10 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
TxFee: testFee,
TxInputs: shelley.NewShelleyTransactionInputSet(
[]shelley.ShelleyTransactionInput{
shelley.NewShelleyTransactionInput(testInputTxId, 0),
shelley.NewShelleyTransactionInput(
testInputTxId,
0,
),
},
),
},
Expand Down Expand Up @@ -785,7 +796,9 @@ func TestUtxoValidateOutputTooBigUtxo(t *testing.T) {
cbor.NewByteString(tmpAssetName): 1,
}
}
tmpBadMultiAsset := common.NewMultiAsset[common.MultiAssetTypeOutput](tmpBadAssets)
tmpBadMultiAsset := common.NewMultiAsset[common.MultiAssetTypeOutput](
tmpBadAssets,
)
var testOutputValueBad = mary.MaryTransactionOutputValue{
Amount: 1234567,
Assets: &tmpBadMultiAsset,
Expand Down Expand Up @@ -853,7 +866,9 @@ func TestUtxoValidateOutputTooBigUtxo(t *testing.T) {
}

func TestUtxoValidateOutputBootAddrAttrsTooBig(t *testing.T) {
testGoodAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd")
testGoodAddr, _ := common.NewAddress(
"addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd",
)
// Generate random pubkey
testBadAddrPubkey := make([]byte, 28)
if _, err := rand.Read(testBadAddrPubkey); err != nil {
Expand Down
Loading