From 9ab8a0f3a86c5fefb680ef6f41a573a0debdf0be Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Thu, 6 Mar 2025 17:48:19 -0500 Subject: [PATCH] chore: make format golines Signed-off-by: Chris Gianelloni --- internal/test/ledger/ledger.go | 14 ++- ledger/alonzo/rules.go | 136 +++++++++++++++++++++++---- ledger/alonzo/rules_test.go | 29 ++++-- ledger/babbage/rules.go | 122 ++++++++++++++++++++---- ledger/babbage/rules_test.go | 29 ++++-- ledger/common/address.go | 12 ++- ledger/conway/conway.go | 4 +- ledger/conway/rules.go | 129 +++++++++++++++++++++---- ledger/conway/rules_test.go | 34 ++++--- ledger/shelley/errors.go | 5 +- muxer/muxer.go | 8 +- protocol/blockfetch/server.go | 4 +- protocol/chainsync/client.go | 8 +- protocol/chainsync/server.go | 8 +- protocol/handshake/client.go | 4 +- protocol/handshake/server.go | 12 ++- protocol/handshake/server_test.go | 4 +- protocol/localstatequery/server.go | 16 +++- protocol/localtxmonitor/server.go | 4 +- protocol/localtxsubmission/server.go | 4 +- protocol/peersharing/server.go | 4 +- protocol/txsubmission/client.go | 8 +- protocol/txsubmission/server.go | 4 +- 23 files changed, 490 insertions(+), 112 deletions(-) diff --git a/internal/test/ledger/ledger.go b/internal/test/ledger/ledger.go index bc4a9543..d4f474d3 100644 --- a/internal/test/ledger/ledger.go +++ b/internal/test/ledger/ledger.go @@ -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) { @@ -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) } } diff --git a/ledger/alonzo/rules.go b/ledger/alonzo/rules.go index 0923b50a..5ea82016 100644 --- a/ledger/alonzo/rules.go +++ b/ledger/alonzo/rules.go @@ -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") @@ -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") @@ -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{ @@ -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") @@ -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") @@ -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") @@ -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, + ) } diff --git a/ledger/alonzo/rules_test.go b/ledger/alonzo/rules_test.go index bcbe27d2..e52730b8 100644 --- a/ledger/alonzo/rules_test.go +++ b/ledger/alonzo/rules_test.go @@ -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{ @@ -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{ @@ -535,7 +543,10 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) { TxFee: testFee, TxInputs: shelley.NewShelleyTransactionInputSet( []shelley.ShelleyTransactionInput{ - shelley.NewShelleyTransactionInput(testInputTxId, 0), + shelley.NewShelleyTransactionInput( + testInputTxId, + 0, + ), }, ), }, @@ -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, @@ -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 { diff --git a/ledger/babbage/rules.go b/ledger/babbage/rules.go index f013f9f7..eb2fb9b7 100644 --- a/ledger/babbage/rules.go +++ b/ledger/babbage/rules.go @@ -45,15 +45,30 @@ var UtxoValidationRules = []common.UtxoValidationRuleFunc{ UtxoValidateTooManyCollateralInputs, } -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 { minFee, err := MinFeeTx(tx, pp) if err != nil { return err @@ -67,7 +82,12 @@ func UtxoValidateFeeTooSmallUtxo(tx common.Transaction, slot uint64, ls common.L } } -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.(*BabbageProtocolParameters) if !ok { return errors.New("pparams are not expected type") @@ -98,7 +118,12 @@ func UtxoValidateInsufficientCollateral(tx common.Transaction, slot uint64, ls c } } -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.(*BabbageTransaction) if !ok { return errors.New("transaction is not expected type") @@ -129,7 +154,12 @@ func UtxoValidateCollateralContainsNonAda(tx common.Transaction, slot uint64, ls } // UtxoValidateCollateralEqBalance ensures that the collateral return amount is equal to the collateral input amount minus the total collateral -func UtxoValidateCollateralEqBalance(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateCollateralEqBalance( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { totalCollateral := tx.TotalCollateral() if totalCollateral == 0 { return nil @@ -157,7 +187,12 @@ func UtxoValidateCollateralEqBalance(tx common.Transaction, slot uint64, ls comm } } -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.(*BabbageTransaction) if !ok { return errors.New("transaction is not expected type") @@ -172,11 +207,21 @@ func UtxoValidateNoCollateralInputs(tx common.Transaction, slot uint64, ls commo return alonzo.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.(*BabbageProtocolParameters) if !ok { return errors.New("pparams are not expected type") @@ -231,7 +276,12 @@ func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls co } } -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 { var badOutputs []common.TransactionOutput for _, tmpOutput := range tx.Outputs() { minCoin, err := MinCoinTxOut(tmpOutput, pp) @@ -250,7 +300,12 @@ func UtxoValidateOutputTooSmallUtxo(tx common.Transaction, slot uint64, ls commo } } -func UtxoValidateOutputTooBigUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateOutputTooBigUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*BabbageProtocolParameters) if !ok { return errors.New("pparams are not expected type") @@ -278,19 +333,39 @@ func UtxoValidateOutputTooBigUtxo(tx common.Transaction, slot uint64, ls common. } } -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.(*BabbageProtocolParameters) if !ok { return errors.New("pparams are not expected type") @@ -308,7 +383,12 @@ func UtxoValidateMaxTxSizeUtxo(tx common.Transaction, slot uint64, ls common.Led } } -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.(*BabbageProtocolParameters) if !ok { return errors.New("pparams are not expected type") @@ -322,7 +402,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 alonzo.ExUnitsTooBigUtxoError{ @@ -334,7 +415,12 @@ func UtxoValidateExUnitsTooBigUtxo(tx common.Transaction, slot uint64, ls common } } -func UtxoValidateTooManyCollateralInputs(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateTooManyCollateralInputs( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*BabbageProtocolParameters) if !ok { return errors.New("pparams are not expected type") diff --git a/ledger/babbage/rules_test.go b/ledger/babbage/rules_test.go index b864fc08..141e601b 100644 --- a/ledger/babbage/rules_test.go +++ b/ledger/babbage/rules_test.go @@ -381,8 +381,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 := &babbage.BabbageTransaction{ Body: babbage.BabbageTransactionBody{ TxOutputs: []babbage.BabbageTransactionOutput{ @@ -449,8 +453,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 := &babbage.BabbageTransaction{ Body: babbage.BabbageTransactionBody{ AlonzoTransactionBody: alonzo.AlonzoTransactionBody{ @@ -539,7 +547,10 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) { TxFee: testFee, TxInputs: shelley.NewShelleyTransactionInputSet( []shelley.ShelleyTransactionInput{ - shelley.NewShelleyTransactionInput(testInputTxId, 0), + shelley.NewShelleyTransactionInput( + testInputTxId, + 0, + ), }, ), }, @@ -778,7 +789,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, @@ -846,7 +859,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 { diff --git a/ledger/common/address.go b/ledger/common/address.go index 21f813a2..bfbd0309 100644 --- a/ledger/common/address.go +++ b/ledger/common/address.go @@ -183,18 +183,24 @@ func (a *Address) populateFromBytes(data []byte) error { } payloadBytes, ok := rawAddr.Payload.Content.([]byte) if !ok || rawAddr.Payload.Number != 24 { - return errors.New("invalid Byron address data: unexpected payload content") + return errors.New( + "invalid Byron address data: unexpected payload content", + ) } payloadChecksum := crc32.ChecksumIEEE(payloadBytes) if rawAddr.Checksum != payloadChecksum { - return errors.New("invalid Byron address data: checksum does not match") + return errors.New( + "invalid Byron address data: checksum does not match", + ) } var byronAddr byronAddressPayload if _, err := cbor.Decode(payloadBytes, &byronAddr); err != nil { return err } if len(byronAddr.Hash) != AddressHashSize { - return errors.New("invalid Byron address data: hash is not expected length") + return errors.New( + "invalid Byron address data: hash is not expected length", + ) } a.byronAddressType = byronAddr.AddrType a.byronAddressAttr = byronAddr.Attr diff --git a/ledger/conway/conway.go b/ledger/conway/conway.go index 5486f087..26d3075a 100644 --- a/ledger/conway/conway.go +++ b/ledger/conway/conway.go @@ -259,7 +259,9 @@ func (s *ConwayTransactionInputSet) Items() []shelley.ShelleyTransactionInput { return s.items } -func (s *ConwayTransactionInputSet) SetItems(items []shelley.ShelleyTransactionInput) { +func (s *ConwayTransactionInputSet) SetItems( + items []shelley.ShelleyTransactionInput, +) { s.items = make([]shelley.ShelleyTransactionInput, len(items)) copy(s.items, items) } diff --git a/ledger/conway/rules.go b/ledger/conway/rules.go index 5fd70413..5b36ae62 100644 --- a/ledger/conway/rules.go +++ b/ledger/conway/rules.go @@ -47,7 +47,12 @@ var UtxoValidationRules = []common.UtxoValidationRuleFunc{ UtxoValidateTooManyCollateralInputs, } -func UtxoValidateDisjointRefInputs(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateDisjointRefInputs( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { commonInputs := []common.TransactionInput{} for _, refInput := range tx.ReferenceInputs() { for _, input := range tx.Inputs() { @@ -65,15 +70,30 @@ func UtxoValidateDisjointRefInputs(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 { minFee, err := MinFeeTx(tx, pp) if err != nil { return err @@ -87,7 +107,12 @@ func UtxoValidateFeeTooSmallUtxo(tx common.Transaction, slot uint64, ls common.L } } -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.(*ConwayProtocolParameters) if !ok { return errors.New("pparams are not expected type") @@ -118,7 +143,12 @@ func UtxoValidateInsufficientCollateral(tx common.Transaction, slot uint64, ls c } } -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.(*ConwayTransaction) if !ok { return errors.New("transaction is not expected type") @@ -149,11 +179,21 @@ func UtxoValidateCollateralContainsNonAda(tx common.Transaction, slot uint64, ls } // UtxoValidateCollateralEqBalance ensures that the collateral return amount is equal to the collateral input amount minus the total collateral -func UtxoValidateCollateralEqBalance(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateCollateralEqBalance( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { return babbage.UtxoValidateCollateralEqBalance(tx, slot, ls, pp) } -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.(*ConwayTransaction) if !ok { return errors.New("transaction is not expected type") @@ -168,11 +208,21 @@ func UtxoValidateNoCollateralInputs(tx common.Transaction, slot uint64, ls commo return alonzo.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.(*ConwayProtocolParameters) if !ok { return errors.New("pparams are not expected type") @@ -227,7 +277,12 @@ func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls co } } -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 { var badOutputs []common.TransactionOutput for _, tmpOutput := range tx.Outputs() { minCoin, err := MinCoinTxOut(tmpOutput, pp) @@ -246,7 +301,12 @@ func UtxoValidateOutputTooSmallUtxo(tx common.Transaction, slot uint64, ls commo } } -func UtxoValidateOutputTooBigUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateOutputTooBigUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*ConwayProtocolParameters) if !ok { return errors.New("pparams are not expected type") @@ -274,19 +334,39 @@ func UtxoValidateOutputTooBigUtxo(tx common.Transaction, slot uint64, ls common. } } -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.(*ConwayProtocolParameters) if !ok { return errors.New("pparams are not expected type") @@ -304,7 +384,12 @@ func UtxoValidateMaxTxSizeUtxo(tx common.Transaction, slot uint64, ls common.Led } } -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.(*ConwayProtocolParameters) if !ok { return errors.New("pparams are not expected type") @@ -318,7 +403,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 alonzo.ExUnitsTooBigUtxoError{ @@ -330,7 +416,12 @@ func UtxoValidateExUnitsTooBigUtxo(tx common.Transaction, slot uint64, ls common } } -func UtxoValidateTooManyCollateralInputs(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateTooManyCollateralInputs( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*ConwayProtocolParameters) if !ok { return errors.New("pparams are not expected type") diff --git a/ledger/conway/rules_test.go b/ledger/conway/rules_test.go index 5281f097..c14dead6 100644 --- a/ledger/conway/rules_test.go +++ b/ledger/conway/rules_test.go @@ -378,8 +378,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 := &conway.ConwayTransaction{ Body: conway.ConwayTransactionBody{ BabbageTransactionBody: babbage.BabbageTransactionBody{ @@ -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 := &conway.ConwayTransaction{ Body: conway.ConwayTransactionBody{ BabbageTransactionBody: babbage.BabbageTransactionBody{ @@ -783,7 +791,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, @@ -853,7 +863,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 { @@ -1012,7 +1024,7 @@ func TestUtxoValidateInsufficientCollateral(t *testing.T) { WsRedeemers: conway.ConwayRedeemers{ Redeemers: map[conway.ConwayRedeemerKey]conway.ConwayRedeemerValue{ // Placeholder entry - conway.ConwayRedeemerKey{}: conway.ConwayRedeemerValue{}, + {}: {}, }, }, }, @@ -1100,7 +1112,7 @@ func TestUtxoValidateCollateralContainsNonAda(t *testing.T) { WsRedeemers: conway.ConwayRedeemers{ Redeemers: map[conway.ConwayRedeemerKey]conway.ConwayRedeemerValue{ // Placeholder entry - conway.ConwayRedeemerKey{}: conway.ConwayRedeemerValue{}, + {}: {}, }, }, }, @@ -1192,7 +1204,7 @@ func TestUtxoValidateNoCollateralInputs(t *testing.T) { WsRedeemers: conway.ConwayRedeemers{ Redeemers: map[conway.ConwayRedeemerKey]conway.ConwayRedeemerValue{ // Placeholder entry - conway.ConwayRedeemerKey{}: conway.ConwayRedeemerValue{}, + {}: {}, }, }, }, @@ -1289,7 +1301,7 @@ func TestUtxoValidateExUnitsTooBigUtxo(t *testing.T) { func(t *testing.T) { testTx.WitnessSet.WsRedeemers = conway.ConwayRedeemers{ Redeemers: map[conway.ConwayRedeemerKey]conway.ConwayRedeemerValue{ - conway.ConwayRedeemerKey{}: testRedeemerLarge, + {}: testRedeemerLarge, }, } err := conway.UtxoValidateExUnitsTooBigUtxo( @@ -1321,7 +1333,7 @@ func TestUtxoValidateExUnitsTooBigUtxo(t *testing.T) { func(t *testing.T) { testTx.WitnessSet.WsRedeemers = conway.ConwayRedeemers{ Redeemers: map[conway.ConwayRedeemerKey]conway.ConwayRedeemerValue{ - conway.ConwayRedeemerKey{}: testRedeemerSmall, + {}: testRedeemerSmall, }, } err := conway.UtxoValidateExUnitsTooBigUtxo( diff --git a/ledger/shelley/errors.go b/ledger/shelley/errors.go index 52a0a1bf..f1343cb6 100644 --- a/ledger/shelley/errors.go +++ b/ledger/shelley/errors.go @@ -125,7 +125,10 @@ func (e OutputBootAddrAttrsTooBigError) Error() string { for idx, tmpOutput := range e.Outputs { tmpOutputs[idx] = fmt.Sprintf("%#v", tmpOutput) } - return "output bootstrap address attributes too big: " + strings.Join(tmpOutputs, ", ") + return "output bootstrap address attributes too big: " + strings.Join( + tmpOutputs, + ", ", + ) } type MaxTxSizeUtxoError struct { diff --git a/muxer/muxer.go b/muxer/muxer.go index e3d03055..4097f79a 100644 --- a/muxer/muxer.go +++ b/muxer/muxer.go @@ -286,14 +286,18 @@ func (m *Muxer) readLoop() { // Check for message from initiator when we're not configured as a responder if m.diffusionMode == DiffusionModeInitiator && !msg.IsResponse() { m.sendError( - errors.New("received message from initiator when not configured as a responder"), + errors.New( + "received message from initiator when not configured as a responder", + ), ) return } // Check for message from responder when we're not configured as an initiator if m.diffusionMode == DiffusionModeResponder && msg.IsResponse() { m.sendError( - errors.New("received message from responder when not configured as an initiator"), + errors.New( + "received message from responder when not configured as an initiator", + ), ) return } diff --git a/protocol/blockfetch/server.go b/protocol/blockfetch/server.go index 9f63023b..979dae81 100644 --- a/protocol/blockfetch/server.go +++ b/protocol/blockfetch/server.go @@ -143,7 +143,9 @@ func (s *Server) handleRequestRange(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config == nil || s.config.RequestRangeFunc == nil { - return errors.New("received block-fetch RequestRange message but no callback function is defined") + return errors.New( + "received block-fetch RequestRange message but no callback function is defined", + ) } msgRequestRange := msg.(*MsgRequestRange) return s.config.RequestRangeFunc( diff --git a/protocol/chainsync/client.go b/protocol/chainsync/client.go index a3c9df70..3e7236cc 100644 --- a/protocol/chainsync/client.go +++ b/protocol/chainsync/client.go @@ -607,7 +607,9 @@ func (c *Client) handleRollForward(msgGeneric protocol.Message) error { }() if firstBlockChan == nil && (c.config == nil || (c.config.RollForwardFunc == nil && c.config.RollForwardRawFunc == nil)) { - return errors.New("received chain-sync RollForward message but no callback function is defined") + return errors.New( + "received chain-sync RollForward message but no callback function is defined", + ) } var callbackErr error if c.Mode() == protocol.ProtocolModeNodeToNode { @@ -747,7 +749,9 @@ func (c *Client) handleRollBackward(msg protocol.Message) error { c.sendCurrentTip(msgRollBackward.Tip) if len(c.wantFirstBlockChan) == 0 { if c.config.RollBackwardFunc == nil { - return errors.New("received chain-sync RollBackward message but no callback function is defined") + return errors.New( + "received chain-sync RollBackward message but no callback function is defined", + ) } // Call the user callback function if callbackErr := c.config.RollBackwardFunc(c.callbackContext, msgRollBackward.Point, msgRollBackward.Tip); callbackErr != nil { diff --git a/protocol/chainsync/server.go b/protocol/chainsync/server.go index a65a534e..f70923dc 100644 --- a/protocol/chainsync/server.go +++ b/protocol/chainsync/server.go @@ -181,7 +181,9 @@ func (s *Server) handleRequestNext() error { // "connection_id", s.callbackContext.ConnectionId.String(), // ) if s.config == nil || s.config.RequestNextFunc == nil { - return errors.New("received chain-sync RequestNext message but no callback function is defined") + return errors.New( + "received chain-sync RequestNext message but no callback function is defined", + ) } return s.config.RequestNextFunc(s.callbackContext) } @@ -195,7 +197,9 @@ func (s *Server) handleFindIntersect(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config == nil || s.config.FindIntersectFunc == nil { - return errors.New("received chain-sync FindIntersect message but no callback function is defined") + return errors.New( + "received chain-sync FindIntersect message but no callback function is defined", + ) } msgFindIntersect := msg.(*MsgFindIntersect) point, tip, err := s.config.FindIntersectFunc( diff --git a/protocol/handshake/client.go b/protocol/handshake/client.go index 61f8c75d..807c3d75 100644 --- a/protocol/handshake/client.go +++ b/protocol/handshake/client.go @@ -109,7 +109,9 @@ func (c *Client) handleAcceptVersion(msg protocol.Message) error { "connection_id", c.callbackContext.ConnectionId.String(), ) if c.config.FinishedFunc == nil { - return errors.New("received handshake AcceptVersion message but no callback function is defined") + return errors.New( + "received handshake AcceptVersion message but no callback function is defined", + ) } msgAcceptVersion := msg.(*MsgAcceptVersion) protoVersion := protocol.GetProtocolVersion(msgAcceptVersion.Version) diff --git a/protocol/handshake/server.go b/protocol/handshake/server.go index 0c02373f..092403fd 100644 --- a/protocol/handshake/server.go +++ b/protocol/handshake/server.go @@ -85,7 +85,9 @@ func (s *Server) handleProposeVersions(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.FinishedFunc == nil { - return errors.New("received handshake ProposeVersions message but no callback function is defined") + return errors.New( + "received handshake ProposeVersions message but no callback function is defined", + ) } msgProposeVersions := msg.(*MsgProposeVersions) // Compute intersection of supported and proposed protocol versions @@ -133,7 +135,9 @@ func (s *Server) handleProposeVersions(msg protocol.Message) error { []any{ RefuseReasonDecodeError, proposedVersion, - errors.New("handshake failed: refused due to empty version data"), + errors.New( + "handshake failed: refused due to empty version data", + ), }, ) if err := s.SendMessage(msgRefuse); err != nil { @@ -165,7 +169,9 @@ func (s *Server) handleProposeVersions(msg protocol.Message) error { []any{ RefuseReasonDecodeError, proposedVersion, - errors.New("handshake failed: refused due to empty version map"), + errors.New( + "handshake failed: refused due to empty version map", + ), }, ) if err := s.SendMessage(msgRefuse); err != nil { diff --git a/protocol/handshake/server_test.go b/protocol/handshake/server_test.go index 998e103a..cdd05181 100644 --- a/protocol/handshake/server_test.go +++ b/protocol/handshake/server_test.go @@ -98,7 +98,9 @@ func TestServerHandshakeRefuseVersionMismatch(t *testing.T) { defer func() { goleak.VerifyNone(t) }() - expectedErr := errors.New("handshake failed: refused due to version mismatch") + expectedErr := errors.New( + "handshake failed: refused due to version mismatch", + ) mockConn := ouroboros_mock.NewConnection( ouroboros_mock.ProtocolRoleServer, []ouroboros_mock.ConversationEntry{ diff --git a/protocol/localstatequery/server.go b/protocol/localstatequery/server.go index 17b23da4..89cfcf65 100644 --- a/protocol/localstatequery/server.go +++ b/protocol/localstatequery/server.go @@ -102,7 +102,9 @@ func (s *Server) handleAcquire(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.AcquireFunc == nil { - return errors.New("received local-state-query Acquire message but no callback function is defined") + return errors.New( + "received local-state-query Acquire message but no callback function is defined", + ) } var acquireTarget AcquireTarget switch msgAcquire := msg.(type) { @@ -148,7 +150,9 @@ func (s *Server) handleQuery(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.QueryFunc == nil { - return errors.New("received local-state-query Query message but no callback function is defined") + return errors.New( + "received local-state-query Query message but no callback function is defined", + ) } msgQuery := msg.(*MsgQuery) // Call the user callback function @@ -177,7 +181,9 @@ func (s *Server) handleRelease() error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.ReleaseFunc == nil { - return errors.New("received local-state-query Release message but no callback function is defined") + return errors.New( + "received local-state-query Release message but no callback function is defined", + ) } // Call the user callback function return s.config.ReleaseFunc(s.callbackContext) @@ -192,7 +198,9 @@ func (s *Server) handleReAcquire(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.AcquireFunc == nil { - return errors.New("received local-state-query ReAcquire message but no callback function is defined") + return errors.New( + "received local-state-query ReAcquire message but no callback function is defined", + ) } var acquireTarget AcquireTarget switch msgReAcquire := msg.(type) { diff --git a/protocol/localtxmonitor/server.go b/protocol/localtxmonitor/server.go index 3511e5f7..92dc562c 100644 --- a/protocol/localtxmonitor/server.go +++ b/protocol/localtxmonitor/server.go @@ -94,7 +94,9 @@ func (s *Server) handleAcquire() error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.GetMempoolFunc == nil { - return errors.New("received local-tx-monitor Acquire message but no GetMempool callback function is defined") + return errors.New( + "received local-tx-monitor Acquire message but no GetMempool callback function is defined", + ) } // Call the user callback function to get mempool information mempoolSlotNumber, mempoolCapacity, mempoolTxs, err := s.config.GetMempoolFunc( diff --git a/protocol/localtxsubmission/server.go b/protocol/localtxsubmission/server.go index d68490e1..89f0958d 100644 --- a/protocol/localtxsubmission/server.go +++ b/protocol/localtxsubmission/server.go @@ -81,7 +81,9 @@ func (s *Server) handleSubmitTx(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.SubmitTxFunc == nil { - return errors.New("received local-tx-submission SubmitTx message but no callback function is defined") + return errors.New( + "received local-tx-submission SubmitTx message but no callback function is defined", + ) } msgSubmitTx := msg.(*MsgSubmitTx) // Call the user callback function and send Accept/RejectTx based on result diff --git a/protocol/peersharing/server.go b/protocol/peersharing/server.go index e05dcb72..75ba4d65 100644 --- a/protocol/peersharing/server.go +++ b/protocol/peersharing/server.go @@ -87,7 +87,9 @@ func (s *Server) handleShareRequest(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config == nil || s.config.ShareRequestFunc == nil { - return errors.New("received peer-sharing ShareRequest message but no callback function is defined") + return errors.New( + "received peer-sharing ShareRequest message but no callback function is defined", + ) } msgShareRequest := msg.(*MsgShareRequest) peers, err := s.config.ShareRequestFunc( diff --git a/protocol/txsubmission/client.go b/protocol/txsubmission/client.go index 80587c51..43a21649 100644 --- a/protocol/txsubmission/client.go +++ b/protocol/txsubmission/client.go @@ -111,7 +111,9 @@ func (c *Client) handleRequestTxIds(msg protocol.Message) error { "connection_id", c.callbackContext.ConnectionId.String(), ) if c.config.RequestTxIdsFunc == nil { - return errors.New("received tx-submission RequestTxIds message but no callback function is defined") + return errors.New( + "received tx-submission RequestTxIds message but no callback function is defined", + ) } msgRequestTxIds := msg.(*MsgRequestTxIds) // Call the user callback function @@ -140,7 +142,9 @@ func (c *Client) handleRequestTxs(msg protocol.Message) error { "connection_id", c.callbackContext.ConnectionId.String(), ) if c.config.RequestTxsFunc == nil { - return errors.New("received tx-submission RequestTxs message but no callback function is defined") + return errors.New( + "received tx-submission RequestTxs message but no callback function is defined", + ) } msgRequestTxs := msg.(*MsgRequestTxs) // Call the user callback function diff --git a/protocol/txsubmission/server.go b/protocol/txsubmission/server.go index 197a483a..7f319ca9 100644 --- a/protocol/txsubmission/server.go +++ b/protocol/txsubmission/server.go @@ -225,7 +225,9 @@ func (s *Server) handleInit() error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config == nil || s.config.InitFunc == nil { - return errors.New("received tx-submission Init message but no callback function is defined") + return errors.New( + "received tx-submission Init message but no callback function is defined", + ) } // Call the user callback function return s.config.InitFunc(s.callbackContext)