diff --git a/cmd/neofs-adm/internal/modules/config/config_test.go b/cmd/neofs-adm/internal/modules/config/config_test.go index 3ea134fcfa..937e69e540 100644 --- a/cmd/neofs-adm/internal/modules/config/config_test.go +++ b/cmd/neofs-adm/internal/modules/config/config_test.go @@ -34,12 +34,11 @@ func TestGenerateConfigExample(t *testing.T) { require.Equal(t, 1000, v.GetInt("network.fee.container")) require.Equal(t, 100000000, v.GetInt("network.fee.withdraw")) - var i int - for i = 0; i < n; i++ { + for i := range n { key := "credentials." + glagolitsa.LetterByIndex(i) require.Equal(t, "password", v.GetString(key)) } - key := "credentials." + glagolitsa.LetterByIndex(i) + key := "credentials." + glagolitsa.LetterByIndex(n) require.Equal(t, "", v.GetString(key)) } diff --git a/cmd/neofs-adm/internal/modules/morph/generate_test.go b/cmd/neofs-adm/internal/modules/morph/generate_test.go index 504b0ebdf3..357f8b71ba 100644 --- a/cmd/neofs-adm/internal/modules/morph/generate_test.go +++ b/cmd/neofs-adm/internal/modules/morph/generate_test.go @@ -55,13 +55,13 @@ func TestGenerateAlphabet(t *testing.T) { buf.Reset() v.Set(alphabetWalletsFlag, walletDir) require.NoError(t, generateAlphabetCmd.Flags().Set(alphabetSizeFlag, strconv.FormatUint(size, 10))) - for i := uint64(0); i < size; i++ { + for i := range uint64(size) { buf.WriteString(strconv.FormatUint(i, 10) + "\r") } require.NoError(t, generateAlphabetCreds(generateAlphabetCmd, nil)) - for i := uint64(0); i < size; i++ { + for i := range uint64(size) { p := filepath.Join(walletDir, glagolitsa.LetterByIndex(int(i))+".json") w, err := wallet.NewWalletFromFile(p) require.NoError(t, err, "wallet doesn't exist") diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_register.go b/cmd/neofs-adm/internal/modules/morph/initialize_register.go index 5f717f0a59..9b3f451c5b 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_register.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_register.go @@ -130,7 +130,10 @@ func (c *initializeContext) transferNEOToAlphabetContracts() error { func (c *initializeContext) transferNEOFinished() (bool, error) { neoR := neo.NewReader(invoker.New(c.Client, nil)) bal, err := neoR.BalanceOf(c.CommitteeAcc.Contract.ScriptHash()) - return bal.Int64() < native.NEOTotalSupply, err + if err != nil { + return false, err + } + return bal.Int64() < native.NEOTotalSupply, nil } var errGetPriceInvalid = errors.New("`getRegisterPrice`: invalid response") diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go b/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go index 44b7e8bc50..0b5e8462b0 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go @@ -73,7 +73,10 @@ func (c *initializeContext) transferFundsFinished() (bool, error) { gasR := gas.NewReader(invoker.New(c.Client, nil)) res, err := gasR.BalanceOf(acc.Contract.ScriptHash()) - return res.Int64() > initialAlphabetGASAmount/2, err + if err != nil { + return false, err + } + return res.Int64() > initialAlphabetGASAmount/2, nil } func (c *initializeContext) multiSignAndSend(tx *transaction.Transaction, accType string) error { diff --git a/cmd/neofs-adm/internal/modules/morph/local_client.go b/cmd/neofs-adm/internal/modules/morph/local_client.go index 0f558cc452..6fca7dee89 100644 --- a/cmd/neofs-adm/internal/modules/morph/local_client.go +++ b/cmd/neofs-adm/internal/modules/morph/local_client.go @@ -212,13 +212,12 @@ func (l *localClient) CalculateNetworkFee(tx *transaction.Transaction) (int64, e continue } - fee, sizeDelta := fee.Calculate(ef, verificationScript) - netFee += fee + verificationFee, sizeDelta := fee.Calculate(ef, verificationScript) + netFee += verificationFee size += sizeDelta } - fee := l.bc.FeePerByte() - netFee += int64(size) * fee + netFee += int64(size) * l.bc.FeePerByte() return netFee, nil } @@ -319,7 +318,7 @@ func invokeFunction(c Client, h util.Uint160, method string, parameters []any, s script, err := b.Script() if err != nil { - return nil, fmt.Errorf("BUG: invalid parameters for '%s': %v", method, err) + return nil, fmt.Errorf("BUG: invalid parameters for '%s': %w", method, err) } return c.InvokeScript(script, signers) diff --git a/cmd/neofs-adm/internal/modules/morph/notary.go b/cmd/neofs-adm/internal/modules/morph/notary.go index 18dec62a87..181edfaab6 100644 --- a/cmd/neofs-adm/internal/modules/morph/notary.go +++ b/cmd/neofs-adm/internal/modules/morph/notary.go @@ -31,7 +31,7 @@ func depositNotary(cmd *cobra.Command, _ []string) error { w, err := wallet.NewWalletFromFile(p) if err != nil { - return fmt.Errorf("can't open wallet: %v", err) + return fmt.Errorf("can't open wallet: %w", err) } accHash := w.GetChangeAddress() @@ -50,12 +50,12 @@ func depositNotary(cmd *cobra.Command, _ []string) error { prompt := fmt.Sprintf("Enter password for %s >", address.Uint160ToString(accHash)) pass, err := input.ReadPassword(prompt) if err != nil { - return fmt.Errorf("can't get password: %v", err) + return fmt.Errorf("can't get password: %w", err) } err = acc.Decrypt(pass, keys.NEP2ScryptParams()) if err != nil { - return fmt.Errorf("can't unlock account: %v", err) + return fmt.Errorf("can't unlock account: %w", err) } gasStr, err := cmd.Flags().GetString(refillGasAmountFlag) @@ -86,7 +86,7 @@ func depositNotary(cmd *cobra.Command, _ []string) error { height, err := c.GetBlockCount() if err != nil { - return fmt.Errorf("can't get current height: %v", err) + return fmt.Errorf("can't get current height: %w", err) } act, err := actor.New(c, []actor.SignerAccount{{ diff --git a/cmd/neofs-adm/internal/modules/morph/verified_domains.go b/cmd/neofs-adm/internal/modules/morph/verified_domains.go index 12699ef065..caf4e89a0e 100644 --- a/cmd/neofs-adm/internal/modules/morph/verified_domains.go +++ b/cmd/neofs-adm/internal/modules/morph/verified_domains.go @@ -120,7 +120,7 @@ func verifiedNodesDomainSetAccessList(cmd *cobra.Command, _ []string) error { w, err := wallet.NewWalletFromFile(viper.GetString(walletFlag)) if err != nil { - return fmt.Errorf("decode Neo wallet from file: %v", err) + return fmt.Errorf("decode Neo wallet from file: %w", err) } var accAddr util.Uint160 @@ -141,12 +141,12 @@ func verifiedNodesDomainSetAccessList(cmd *cobra.Command, _ []string) error { prompt := fmt.Sprintf("Enter password for %s >", address.Uint160ToString(accAddr)) pass, err := input.ReadPassword(prompt) if err != nil { - return fmt.Errorf("failed to read account password: %v", err) + return fmt.Errorf("failed to read account password: %w", err) } err = acc.Decrypt(pass, keys.NEP2ScryptParams()) if err != nil { - return fmt.Errorf("failed to unlock the account with password: %v", err) + return fmt.Errorf("failed to unlock the account with password: %w", err) } n3Client, err := getN3Client(vpr) diff --git a/cmd/neofs-cli/modules/acl/extended/create_test.go b/cmd/neofs-cli/modules/acl/extended/create_test.go index d09d976a22..0fe7829469 100644 --- a/cmd/neofs-cli/modules/acl/extended/create_test.go +++ b/cmd/neofs-cli/modules/acl/extended/create_test.go @@ -12,7 +12,7 @@ func TestParseTable(t *testing.T) { tests := [...]struct { name string // test name rule string // input extended ACL rule - jsonRecord string // produced record after successfull parsing + jsonRecord string // produced record after successful parsing }{ { name: "valid rule with multiple filters", diff --git a/cmd/neofs-cli/modules/util/acl.go b/cmd/neofs-cli/modules/util/acl.go index ddc00756ca..59658679d8 100644 --- a/cmd/neofs-cli/modules/util/acl.go +++ b/cmd/neofs-cli/modules/util/acl.go @@ -183,7 +183,7 @@ func ParseEACLRules(table *eacl.Table, rules []string) error { for _, ruleStr := range rules { err := ParseEACLRule(table, ruleStr) if err != nil { - return fmt.Errorf("can't create extended acl record from rule '%s': %v", ruleStr, err) + return fmt.Errorf("can't create extended acl record from rule '%s': %w", ruleStr, err) } } return nil @@ -199,7 +199,7 @@ func ParseEACLRules(table *eacl.Table, rules []string) error { func ParseEACLRule(table *eacl.Table, rule string) error { r, err := shlex.Split(rule) if err != nil { - return fmt.Errorf("can't parse rule '%s': %v", rule, err) + return fmt.Errorf("can't parse rule '%s': %w", rule, err) } return parseEACLTable(table, r) } diff --git a/cmd/neofs-node/config/calls.go b/cmd/neofs-node/config/calls.go index d79b68e5ce..d142f00303 100644 --- a/cmd/neofs-node/config/calls.go +++ b/cmd/neofs-node/config/calls.go @@ -32,7 +32,7 @@ func (x *Config) Sub(name string) *Config { // Value returns the configuration value by name. // -// Result can be casted to a particular type +// Result can be cast to a particular type // via corresponding function (e.g. StringSlice). // Note: casting via Go `.()` operator is not // recommended. diff --git a/cmd/neofs-node/config/cast.go b/cmd/neofs-node/config/cast.go index 9036c3ab0a..3b37b171ad 100644 --- a/cmd/neofs-node/config/cast.go +++ b/cmd/neofs-node/config/cast.go @@ -18,7 +18,7 @@ func panicOnErr(err error) { // StringSlice reads a configuration value // from c by name and casts it to a []string. // -// Panics if the value can not be casted. +// Panics if the value can not be cast. func StringSlice(c *Config, name string) []string { x, err := cast.ToStringSliceE(c.Value(name)) panicOnErr(err) @@ -29,7 +29,7 @@ func StringSlice(c *Config, name string) []string { // StringSliceSafe reads a configuration value // from c by name and casts it to a []string. // -// Returns nil if the value can not be casted. +// Returns nil if the value can not be cast. func StringSliceSafe(c *Config, name string) []string { return cast.ToStringSlice(c.Value(name)) } @@ -37,7 +37,7 @@ func StringSliceSafe(c *Config, name string) []string { // String reads a configuration value // from c by name and casts it to a string. // -// Panics if the value can not be casted. +// Panics if the value can not be cast. func String(c *Config, name string) string { x, err := cast.ToStringE(c.Value(name)) panicOnErr(err) @@ -48,7 +48,7 @@ func String(c *Config, name string) string { // StringSafe reads a configuration value // from c by name and casts it to a string. // -// Returns "" if the value can not be casted. +// Returns "" if the value can not be cast. func StringSafe(c *Config, name string) string { return cast.ToString(c.Value(name)) } @@ -56,7 +56,7 @@ func StringSafe(c *Config, name string) string { // Duration reads a configuration value // from c by name and casts it to time.Duration. // -// Panics if the value can not be casted. +// Panics if the value can not be cast. func Duration(c *Config, name string) time.Duration { x, err := cast.ToDurationE(c.Value(name)) panicOnErr(err) @@ -67,7 +67,7 @@ func Duration(c *Config, name string) time.Duration { // DurationSafe reads a configuration value // from c by name and casts it to time.Duration. // -// Returns 0 if the value can not be casted. +// Returns 0 if the value can not be cast. func DurationSafe(c *Config, name string) time.Duration { return cast.ToDuration(c.Value(name)) } @@ -75,7 +75,7 @@ func DurationSafe(c *Config, name string) time.Duration { // Bool reads a configuration value // from c by name and casts it to bool. // -// Panics if the value can not be casted. +// Panics if the value can not be cast. func Bool(c *Config, name string) bool { x, err := cast.ToBoolE(c.Value(name)) panicOnErr(err) @@ -86,7 +86,7 @@ func Bool(c *Config, name string) bool { // BoolSafe reads a configuration value // from c by name and casts it to bool. // -// Returns false if the value can not be casted. +// Returns false if the value can not be cast. func BoolSafe(c *Config, name string) bool { return cast.ToBool(c.Value(name)) } @@ -94,7 +94,7 @@ func BoolSafe(c *Config, name string) bool { // Uint32 reads a configuration value // from c by name and casts it to uint32. // -// Panics if the value can not be casted. +// Panics if the value can not be cast. func Uint32(c *Config, name string) uint32 { x, err := cast.ToUint32E(c.Value(name)) panicOnErr(err) @@ -105,7 +105,7 @@ func Uint32(c *Config, name string) uint32 { // Uint32Safe reads a configuration value // from c by name and casts it to uint32. // -// Returns 0 if the value can not be casted. +// Returns 0 if the value can not be cast. func Uint32Safe(c *Config, name string) uint32 { return cast.ToUint32(c.Value(name)) } @@ -113,7 +113,7 @@ func Uint32Safe(c *Config, name string) uint32 { // Uint reads a configuration value // from c by name and casts it to uint64. // -// Panics if the value can not be casted. +// Panics if the value can not be cast. func Uint(c *Config, name string) uint64 { x, err := cast.ToUint64E(c.Value(name)) panicOnErr(err) @@ -124,7 +124,7 @@ func Uint(c *Config, name string) uint64 { // UintSafe reads a configuration value // from c by name and casts it to uint64. // -// Returns 0 if the value can not be casted. +// Returns 0 if the value can not be cast. func UintSafe(c *Config, name string) uint64 { return cast.ToUint64(c.Value(name)) } @@ -132,7 +132,7 @@ func UintSafe(c *Config, name string) uint64 { // Int reads a configuration value // from c by name and casts it to int64. // -// Panics if the value can not be casted. +// Panics if the value can not be cast. func Int(c *Config, name string) int64 { x, err := cast.ToInt64E(c.Value(name)) panicOnErr(err) @@ -143,7 +143,7 @@ func Int(c *Config, name string) int64 { // IntSafe reads a configuration value // from c by name and casts it to int64. // -// Returns 0 if the value can not be casted. +// Returns 0 if the value can not be cast. func IntSafe(c *Config, name string) int64 { return cast.ToInt64(c.Value(name)) } @@ -155,14 +155,14 @@ func IntSafe(c *Config, name string) int64 { // an additional b at the end. Spaces between the number and the suffix // are allowed. All multipliers are power of 2 (i.e. k is for kibi-byte). // -// Returns 0 if a value can't be casted. +// Returns 0 if a value can't be cast. func SizeInBytesSafe(c *Config, name string) uint64 { s := StringSafe(c, name) return parseSizeInBytes(s) } // The following code is taken from https://github.com/spf13/viper/blob/master/util.go -// with minor corrections (allow to use both `k` and `kb` forms. +// with minor corrections (allow to use both `k` and `kb` forms). // Seems like viper allows to convert sizes but corresponding parser in `cast` package // is missing. diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 5bd29d9973..43ed23346e 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -108,7 +108,7 @@ func (i *delNetInfo) TombstoneLifetime() (uint64, error) { return i.tsLifetime, nil } -// returns node owner ID calculated from configured private key. +// LocalNodeID returns node owner ID calculated from configured private key. // // Implements method needed for Object.Delete service. func (i *delNetInfo) LocalNodeID() user.ID { diff --git a/docs/cli-adm.md b/docs/cli-adm.md index e94e9c1dbe..1ae00c2747 100644 --- a/docs/cli-adm.md +++ b/docs/cli-adm.md @@ -105,4 +105,4 @@ info. These commands **do not migrate actual objects**. ## Private network deployment -Read step-by-step guide of private storage deployment [in docs](./docs/deploy.md). +Read step-by-step guide of private storage deployment [in docs](./deploy.md). diff --git a/pkg/core/netmap/keys.go b/pkg/core/netmap/keys.go index 29cb2dc943..0c64bb7984 100644 --- a/pkg/core/netmap/keys.go +++ b/pkg/core/netmap/keys.go @@ -2,6 +2,6 @@ package netmap // AnnouncedKeys is an interface of utility for working with the announced public keys of the storage nodes. type AnnouncedKeys interface { - // Checks if the key was announced by a local node. + // IsLocalKey checks if the key was announced by a local node. IsLocalKey(key []byte) bool } diff --git a/pkg/core/object/replicate.go b/pkg/core/object/replicate.go index 398d8d5b54..194b99cd0b 100644 --- a/pkg/core/object/replicate.go +++ b/pkg/core/object/replicate.go @@ -54,7 +54,7 @@ func EncodeReplicationMetaInfo(cID cid.ID, oID oid.ID, pSize uint64, // all the errors in the stackitem relate only cases when it is // impossible to use serialized values (too many values, unsupported // types, etc.), unexpected errors at all - panic(fmt.Errorf("unexpected stackitem map serialization failure: %v", err)) + panic(fmt.Errorf("unexpected stackitem map serialization failure: %w", err)) } return result diff --git a/pkg/innerring/config_test.go b/pkg/innerring/config_test.go index a483ff5e41..9dde6e47b0 100644 --- a/pkg/innerring/config_test.go +++ b/pkg/innerring/config_test.go @@ -540,7 +540,7 @@ func TestIsAutoDeploymentMode(t *testing.T) { err = os.Setenv(envKey, "not a boolean") require.NoError(t, err) - b, err = isAutoDeploymentMode(v) + _, err = isAutoDeploymentMode(v) require.Error(t, err) err = os.Setenv(envKey, "false") @@ -571,7 +571,7 @@ fschain_autodeploy: true v.Set("fschain_autodeploy", "not a boolean") - b, err = isAutoDeploymentMode(v) + _, err = isAutoDeploymentMode(v) require.Error(t, err) v.Set("fschain_autodeploy", "false") diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 8f30cf300c..831c463007 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -682,7 +682,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<- return nil, fmt.Errorf("can't read balance contract precision: %w", err) } - repClient, err := repClient.NewFromMorph(server.morphClient, server.contracts.reputation, 0, repClient.AsAlphabet()) + reputationClient, err := repClient.NewFromMorph(server.morphClient, server.contracts.reputation, 0, repClient.AsAlphabet()) if err != nil { return nil, err } @@ -991,7 +991,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<- PoolSize: cfg.GetInt("workers.reputation"), EpochState: server, AlphabetState: server, - ReputationWrapper: repClient, + ReputationWrapper: reputationClient, ManagerBuilder: reputationcommon.NewManagerBuilder( reputationcommon.ManagersPrm{ NetMapSource: server.netmapClient, diff --git a/pkg/innerring/internal/blockchain/blockchain.go b/pkg/innerring/internal/blockchain/blockchain.go index 02cb743a81..082fc46f5a 100644 --- a/pkg/innerring/internal/blockchain/blockchain.go +++ b/pkg/innerring/internal/blockchain/blockchain.go @@ -421,7 +421,7 @@ func New(cfg Config) (res *Blockchain, err error) { if err != nil { closeErr := bcStorage.Close() if closeErr != nil { - err = fmt.Errorf("%w; also failed to close blockchain storage: %v", err, closeErr) + err = fmt.Errorf("%w; also failed to close blockchain storage: %w", err, closeErr) } } }() @@ -518,7 +518,7 @@ func (x *Blockchain) Run(ctx context.Context) (err error) { if err != nil { closeErr := x.storage.Close() if closeErr != nil { - err = fmt.Errorf("%w; also failed to close blockchain storage: %v", err, closeErr) + err = fmt.Errorf("%w; also failed to close blockchain storage: %w", err, closeErr) } } }() diff --git a/pkg/innerring/nns_test.go b/pkg/innerring/nns_test.go index d5fa15533c..856983f002 100644 --- a/pkg/innerring/nns_test.go +++ b/pkg/innerring/nns_test.go @@ -63,7 +63,7 @@ func (x *testInvoker) TraverseIterator(sessionID uuid.UUID, iterator *result.Ite func TestNeoFSNNS_CheckDomainRecord(t *testing.T) { var contractAddr util.Uint160 - rand.Read(contractAddr[:]) + _, _ = rand.Read(contractAddr[:]) const domain = "l2.l1.tld" searchedRecord := "abcdef" diff --git a/pkg/innerring/processors/audit/processor.go b/pkg/innerring/processors/audit/processor.go index f70ba92bf1..17e49f79d5 100644 --- a/pkg/innerring/processors/audit/processor.go +++ b/pkg/innerring/processors/audit/processor.go @@ -26,7 +26,7 @@ type ( TaskManager interface { PushTask(*audit.Task) error - // Must skip all tasks planned for execution and + // Reset must skip all tasks planned for execution and // return their number. Reset() int } diff --git a/pkg/innerring/processors/netmap/nodevalidation/locode/calls_test.go b/pkg/innerring/processors/netmap/nodevalidation/locode/calls_test.go index 9de8d26cb5..1e48ed3487 100644 --- a/pkg/innerring/processors/netmap/nodevalidation/locode/calls_test.go +++ b/pkg/innerring/processors/netmap/nodevalidation/locode/calls_test.go @@ -83,9 +83,7 @@ func TestValidator_Verify(t *testing.T) { // test record with valid but random v require.NoError(t, validator.Verify(n)) }) - t.Run("invalid SN expansion", func(t *testing.T) { - t.Run("invalid Country", func(t *testing.T) { n := nodeInfoWithSomeAttrs() addLocodeAttr(&n, [2]string{"RU", "SPB"}) diff --git a/pkg/innerring/processors/netmap/nodevalidation/privatedomains/validator.go b/pkg/innerring/processors/netmap/nodevalidation/privatedomains/validator.go index 26ed20e97c..dcc8e0d7ec 100644 --- a/pkg/innerring/processors/netmap/nodevalidation/privatedomains/validator.go +++ b/pkg/innerring/processors/netmap/nodevalidation/privatedomains/validator.go @@ -57,11 +57,11 @@ var ( errAccessDenied = errors.New("access denied") ) -// VerifyAndUpdate checks allowance of the storage node represented by the given +// Verify checks allowance of the storage node represented by the given // descriptor to enter the private node group (if any). Returns an error if on // access denial or the check cannot be done at the moment. // -// VerifyAndUpdate does not mutate the argument. +// Verify does not mutate the argument. func (x *Validator) Verify(info netmap.NodeInfo) error { verifiedNodesDomain := info.VerifiedNodesDomain() if verifiedNodesDomain == "" { diff --git a/pkg/innerring/processors/settlement/audit/prm.go b/pkg/innerring/processors/settlement/audit/prm.go index 69d4d1a0ab..d0356190a8 100644 --- a/pkg/innerring/processors/settlement/audit/prm.go +++ b/pkg/innerring/processors/settlement/audit/prm.go @@ -25,20 +25,20 @@ type CalculatorPrm struct { // ResultStorage is an interface of storage of the audit results. type ResultStorage interface { - // Must return all audit results by epoch number. + // AuditResultsForEpoch must return all audit results by epoch number. AuditResultsForEpoch(epoch uint64) ([]*audit.Result, error) } // SGInfo groups the data about NeoFS storage group // necessary for calculating audit fee. type SGInfo interface { - // Must return sum size of the all group members. + // Size must return sum size of the all group members. Size() uint64 } // SGStorage is an interface of storage of the storage groups. type SGStorage interface { - // Must return information about the storage group by address. + // SGInfo must return information about the storage group by address. SGInfo(oid.Address) (SGInfo, error) } diff --git a/pkg/innerring/processors/settlement/common/types.go b/pkg/innerring/processors/settlement/common/types.go index 9cd8a02149..7a7cdcd2ed 100644 --- a/pkg/innerring/processors/settlement/common/types.go +++ b/pkg/innerring/processors/settlement/common/types.go @@ -10,44 +10,44 @@ import ( // NodeInfo groups the data about the storage node // necessary for calculating audit fees. type NodeInfo interface { - // Must return storage price of the node for one epoch in GASe-12. + // Price must return storage price of the node for one epoch in GASe-12. Price() *big.Int - // Must return public key of the node. + // PublicKey must return public key of the node. PublicKey() []byte } // ContainerInfo groups the data about NeoFS container // necessary for calculating audit fee. type ContainerInfo interface { - // Must return identifier of the container owner. + // Owner must return identifier of the container owner. Owner() user.ID } // ContainerStorage is an interface of // storage of the NeoFS containers. type ContainerStorage interface { - // Must return information about the container by ID. + // ContainerInfo must return information about the container by ID. ContainerInfo(cid.ID) (ContainerInfo, error) } // PlacementCalculator is a component interface // that builds placement vectors. type PlacementCalculator interface { - // Must return information about the nodes from container by its ID of the given epoch. + // ContainerNodes must return information about the nodes from container by its ID of the given epoch. ContainerNodes(uint64, cid.ID) ([]NodeInfo, error) } -// AccountStorage is an network member accounts interface. +// AccountStorage is a network member accounts interface. type AccountStorage interface { - // Must resolve information about the storage node + // ResolveKey must resolve information about the storage node // to its ID in system. ResolveKey(NodeInfo) (*user.ID, error) } // Exchanger is an interface of monetary component. type Exchanger interface { - // Must transfer amount of GASe-12 from sender to recipient. + // Transfer must transfer amount of GASe-12 from sender to recipient. // // Amount must be positive. Transfer(sender, recipient user.ID, amount *big.Int, details []byte) diff --git a/pkg/innerring/processors/settlement/deps.go b/pkg/innerring/processors/settlement/deps.go index 76ed2574a0..5baf79d449 100644 --- a/pkg/innerring/processors/settlement/deps.go +++ b/pkg/innerring/processors/settlement/deps.go @@ -6,12 +6,12 @@ import ( // AuditProcessor is an interface of data audit fee processor. type AuditProcessor interface { - // Must process data audit conducted in epoch. + // ProcessAuditSettlements must process data audit conducted in epoch. ProcessAuditSettlements(epoch uint64) } // BasicIncomeInitializer is an interface of basic income context creator. type BasicIncomeInitializer interface { - // Creates context that processes basic income for provided epoch. + // CreateContext creates context that processes basic income for provided epoch. CreateContext(epoch uint64) (*basic.IncomeSettlementContext, error) } diff --git a/pkg/local_object_storage/blobstor/bench_test.go b/pkg/local_object_storage/blobstor/bench_test.go index 32b5ba78ae..941e376244 100644 --- a/pkg/local_object_storage/blobstor/bench_test.go +++ b/pkg/local_object_storage/blobstor/bench_test.go @@ -37,7 +37,7 @@ func newTestFSTree(tb testing.TB) common.Storage { func benchmark(b *testing.B, p common.Storage, objSize uint64, nThreads int) { data := make([]byte, objSize) - rand.Read(data) + _, _ = rand.Read(data) prm := common.PutPrm{ RawData: data, @@ -130,7 +130,7 @@ func BenchmarkGet(b *testing.B) { obj := object.New() data := make([]byte, tc.objSize) - rand.Read(data) + _, _ = rand.Read(data) obj.SetID(oid.ID{1, 2, 3}) obj.SetContainerID(cid.ID{1, 2, 3}) obj.SetPayload(data) @@ -142,7 +142,7 @@ func BenchmarkGet(b *testing.B) { var ach = make(chan oid.Address) for range 100 { go func() { - for j := 0; j < nObjects/100; j++ { + for range nObjects / 100 { prm := prm prm.Address = oidtest.Address() diff --git a/pkg/local_object_storage/blobstor/common/storage_test.go b/pkg/local_object_storage/blobstor/common/storage_test.go index 13b7b7b924..bd374060ec 100644 --- a/pkg/local_object_storage/blobstor/common/storage_test.go +++ b/pkg/local_object_storage/blobstor/common/storage_test.go @@ -28,7 +28,7 @@ func TestCopy(t *testing.T) { for range nObjects { addr := oidtest.Address() data := make([]byte, 32) - rand.Read(data) + _, _ = rand.Read(data) mObjs[addr] = data _, err := src.Put(common.PutPrm{ diff --git a/pkg/local_object_storage/blobstor/compression/bench_test.go b/pkg/local_object_storage/blobstor/compression/bench_test.go index 8178edaacd..83c2b9dec0 100644 --- a/pkg/local_object_storage/blobstor/compression/bench_test.go +++ b/pkg/local_object_storage/blobstor/compression/bench_test.go @@ -24,7 +24,7 @@ func BenchmarkCompression(b *testing.B) { }) b.Run("random slice", func(b *testing.B) { data := make([]byte, size) - rand.Read(data) + _, _ = rand.Read(data) benchWith(b, c, data) }) }) @@ -41,7 +41,7 @@ func benchWith(b *testing.B, c Config, data []byte) { func notSoRandomSlice(size, blockSize int) []byte { data := make([]byte, size) - rand.Read(data[:blockSize]) + _, _ = rand.Read(data[:blockSize]) for i := blockSize; i < size; i += blockSize { copy(data[i:], data[:blockSize]) } diff --git a/pkg/local_object_storage/blobstor/fstree/fstree_write_generic.go b/pkg/local_object_storage/blobstor/fstree/fstree_write_generic.go index d51ec8f8c4..3900892511 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree_write_generic.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree_write_generic.go @@ -60,7 +60,7 @@ func (w *genericWriter) writeData(_ oid.ID, p string, data []byte) error { for i := range retryCount { tmpPath := p + "#" + strconv.FormatUint(uint64(i), 10) err := w.writeAndRename(tmpPath, p, data) - if err != syscall.EEXIST || i == retryCount-1 { + if !errors.Is(err, syscall.EEXIST) || i == retryCount-1 { return err } } @@ -75,11 +75,11 @@ func (w *genericWriter) writeAndRename(tmpPath, p string, data []byte) error { if err != nil { var pe *fs.PathError if errors.As(err, &pe) { - switch pe.Err { - case syscall.ENOSPC: + switch { + case errors.Is(pe.Err, syscall.ENOSPC): err = common.ErrNoSpace _ = os.RemoveAll(tmpPath) - case syscall.EEXIST: + case errors.Is(pe.Err, syscall.EEXIST): return syscall.EEXIST } } diff --git a/pkg/local_object_storage/blobstor/iterate_test.go b/pkg/local_object_storage/blobstor/iterate_test.go index bb8a612efe..7689d91075 100644 --- a/pkg/local_object_storage/blobstor/iterate_test.go +++ b/pkg/local_object_storage/blobstor/iterate_test.go @@ -42,7 +42,7 @@ func TestIterateObjects(t *testing.T) { mObjs := make(map[string]addrData) - for i := uint64(0); i < objNum; i++ { + for i := range uint64(objNum) { sz := smalSz big := i < objNum/2 diff --git a/pkg/local_object_storage/engine/control_test.go b/pkg/local_object_storage/engine/control_test.go index 108ed21a04..7dd8d8647c 100644 --- a/pkg/local_object_storage/engine/control_test.go +++ b/pkg/local_object_storage/engine/control_test.go @@ -150,7 +150,7 @@ func TestExecBlocks(t *testing.T) { }) // put some object - obj := generateObjectWithCID(t, cidtest.ID()) + obj := generateObjectWithCID(cidtest.ID()) addr := object.AddressOf(obj) @@ -206,7 +206,6 @@ func TestPersistentShardID(t *testing.T) { require.Equal(t, id[1], newID[0]) require.Equal(t, id[0], newID[1]) require.NoError(t, e.Close()) - } func TestReload(t *testing.T) { @@ -250,7 +249,7 @@ func TestReload(t *testing.T) { e, currShards := engineWithShards(t, removePath, shardNum) var rcfg ReConfiguration - for i := 0; i < len(currShards)-1; i++ { // without one of the shards + for i := range len(currShards) - 1 { // without one of the shards rcfg.AddShard(currShards[i], nil) } @@ -264,7 +263,7 @@ func TestReload(t *testing.T) { // engineWithShards creates engine with specified number of shards. Returns // slice of paths to their metabase and the engine. -// TODO: #1776 unify engine construction in tests +// TODO: #1776 unify engine construction in tests. func engineWithShards(t *testing.T, path string, num int) (*StorageEngine, []string) { addPath := filepath.Join(path, "add") diff --git a/pkg/local_object_storage/engine/delete_test.go b/pkg/local_object_storage/engine/delete_test.go index 89c8e1246e..09f4ecb4be 100644 --- a/pkg/local_object_storage/engine/delete_test.go +++ b/pkg/local_object_storage/engine/delete_test.go @@ -21,7 +21,7 @@ func TestDeleteBigObject(t *testing.T) { parentID := oidtest.ID() splitID := objectSDK.NewSplitID() - parent := generateObjectWithCID(t, cnr) + parent := generateObjectWithCID(cnr) parent.SetID(parentID) parent.SetPayload(nil) @@ -29,7 +29,7 @@ func TestDeleteBigObject(t *testing.T) { children := make([]*objectSDK.Object, childCount) childIDs := make([]oid.ID, childCount) for i := range children { - children[i] = generateObjectWithCID(t, cnr) + children[i] = generateObjectWithCID(cnr) if i != 0 { children[i].SetPreviousID(childIDs[i-1]) } @@ -41,7 +41,7 @@ func TestDeleteBigObject(t *testing.T) { childIDs[i], _ = children[i].ID() } - link := generateObjectWithCID(t, cnr) + link := generateObjectWithCID(cnr) link.SetParent(parent) link.SetParentID(parentID) link.SetSplitID(splitID) diff --git a/pkg/local_object_storage/engine/engine_test.go b/pkg/local_object_storage/engine/engine_test.go index 26a8519f5e..1e8dbb1667 100644 --- a/pkg/local_object_storage/engine/engine_test.go +++ b/pkg/local_object_storage/engine/engine_test.go @@ -63,7 +63,7 @@ func benchmarkExists(b *testing.B, shardNum int) { addr := oidtest.Address() for range 100 { - obj := generateObjectWithCID(b, cidtest.ID()) + obj := generateObjectWithCID(cidtest.ID()) err := Put(e, obj) if err != nil { b.Fatal(err) @@ -174,7 +174,7 @@ func testEngineFromShardOpts(t *testing.T, num int, extraOpts []shard.Option) *S return engine } -func generateObjectWithCID(t testing.TB, cnr cid.ID) *object.Object { +func generateObjectWithCID(cnr cid.ID) *object.Object { var ver version.Version ver.SetMajor(2) ver.SetMinor(1) diff --git a/pkg/local_object_storage/engine/error_test.go b/pkg/local_object_storage/engine/error_test.go index 3e052d3b57..7c9b549c4e 100644 --- a/pkg/local_object_storage/engine/error_test.go +++ b/pkg/local_object_storage/engine/error_test.go @@ -65,7 +65,7 @@ func TestErrorReporting(t *testing.T) { t.Run("ignore errors by default", func(t *testing.T) { e, dir, id := newEngineWithErrorThreshold(t, "", 0) - obj := generateObjectWithCID(t, cidtest.ID()) + obj := generateObjectWithCID(cidtest.ID()) obj.SetPayload(make([]byte, errSmallSize)) var prm shard.PutPrm @@ -95,7 +95,7 @@ func TestErrorReporting(t *testing.T) { e, dir, id := newEngineWithErrorThreshold(t, "", errThreshold) - obj := generateObjectWithCID(t, cidtest.ID()) + obj := generateObjectWithCID(cidtest.ID()) obj.SetPayload(make([]byte, errSmallSize)) var prm shard.PutPrm @@ -120,7 +120,7 @@ func TestErrorReporting(t *testing.T) { checkShardState(t, e, id[1], 0, mode.ReadWrite) } - for i := uint32(0); i < 2; i++ { + for i := range uint32(2) { _, err = e.Get(GetPrm{addr: object.AddressOf(obj)}) require.Error(t, err) checkShardState(t, e, id[0], errThreshold+i, mode.DegradedReadOnly) @@ -145,7 +145,7 @@ func TestBlobstorFailback(t *testing.T) { objs := make([]*objectSDK.Object, 0, 2) for _, size := range []int{15, errSmallSize + 1} { - obj := generateObjectWithCID(t, cidtest.ID()) + obj := generateObjectWithCID(cidtest.ID()) obj.SetPayload(make([]byte, size)) var prm shard.PutPrm diff --git a/pkg/local_object_storage/engine/evacuate_test.go b/pkg/local_object_storage/engine/evacuate_test.go index d59e4a65a5..f4c3b283a6 100644 --- a/pkg/local_object_storage/engine/evacuate_test.go +++ b/pkg/local_object_storage/engine/evacuate_test.go @@ -53,7 +53,7 @@ func newEngineEvacuate(t *testing.T, shardNum int, objPerShard int) (*StorageEng objects := make([]*objectSDK.Object, 0, objPerShard*len(ids)) for i := 0; ; i++ { - objects = append(objects, generateObjectWithCID(t, cidtest.ID())) + objects = append(objects, generateObjectWithCID(cidtest.ID())) var putPrm PutPrm putPrm.WithObject(objects[i]) @@ -105,7 +105,7 @@ func TestEvacuateShard(t *testing.T) { require.Equal(t, objPerShard, res.count) // We check that all objects are available both before and after shard removal. - // First case is a real-world use-case. It ensures that an object can be put in presense + // First case is a real-world use-case. It ensures that an object can be put in presence // of all metabase checks/marks. // Second case ensures that all objects are indeed moved and available. checkHasObjects(t) diff --git a/pkg/local_object_storage/engine/gc_test.go b/pkg/local_object_storage/engine/gc_test.go index 01515b902a..5ec981e8be 100644 --- a/pkg/local_object_storage/engine/gc_test.go +++ b/pkg/local_object_storage/engine/gc_test.go @@ -67,27 +67,27 @@ func TestChildrenExpiration(t *testing.T) { cnr := cidtest.ID() splitID := objectSDK.NewSplitID() - parent := generateObjectWithCID(t, cnr) + parent := generateObjectWithCID(cnr) parentID, _ := parent.ID() parent.SetAttributes(expAttr) - child1 := generateObjectWithCID(t, cnr) + child1 := generateObjectWithCID(cnr) child1ID, _ := child1.ID() child1.SetSplitID(splitID) - child2 := generateObjectWithCID(t, cnr) + child2 := generateObjectWithCID(cnr) child2ID, _ := child2.ID() child2.SetSplitID(splitID) child2.SetPreviousID(child1ID) - child3 := generateObjectWithCID(t, cnr) + child3 := generateObjectWithCID(cnr) child3ID, _ := child3.ID() child3.SetSplitID(splitID) child3.SetPreviousID(child2ID) child3.SetParent(parent) child3.SetParentID(parentID) - link := generateObjectWithCID(t, cnr) + link := generateObjectWithCID(cnr) link.SetParent(parent) link.SetParentID(parentID) link.SetChildren(child1ID, child2ID, child3ID) @@ -106,20 +106,20 @@ func TestChildrenExpiration(t *testing.T) { t.Run("V2", func(t *testing.T) { cnr := cidtest.ID() - parent := generateObjectWithCID(t, cnr) + parent := generateObjectWithCID(cnr) parentID, _ := parent.ID() parent.SetAttributes(expAttr) - child1 := generateObjectWithCID(t, cnr) + child1 := generateObjectWithCID(cnr) child1ID, _ := child1.ID() child1.SetParent(parent) - child2 := generateObjectWithCID(t, cnr) + child2 := generateObjectWithCID(cnr) child2ID, _ := child2.ID() child2.SetFirstID(child1ID) child2.SetPreviousID(child1ID) - child3 := generateObjectWithCID(t, cnr) + child3 := generateObjectWithCID(cnr) child3ID, _ := child3.ID() child3.SetFirstID(child1ID) child3.SetPreviousID(child2ID) diff --git a/pkg/local_object_storage/engine/get_test.go b/pkg/local_object_storage/engine/get_test.go index f1e2732c61..c5bf6aee2b 100644 --- a/pkg/local_object_storage/engine/get_test.go +++ b/pkg/local_object_storage/engine/get_test.go @@ -10,7 +10,7 @@ import ( func TestStorageEngine_GetBytes(t *testing.T) { e, _, _ := newEngine(t, t.TempDir()) - obj := generateObjectWithCID(t, cidtest.ID()) + obj := generateObjectWithCID(cidtest.ID()) addr := object.AddressOf(obj) objBin := obj.Marshal() diff --git a/pkg/local_object_storage/engine/head_test.go b/pkg/local_object_storage/engine/head_test.go index 2ebf641d16..5cd5a66f4a 100644 --- a/pkg/local_object_storage/engine/head_test.go +++ b/pkg/local_object_storage/engine/head_test.go @@ -17,7 +17,7 @@ func TestHeadRaw(t *testing.T) { cnr := cidtest.ID() splitID := object.NewSplitID() - parent := generateObjectWithCID(t, cnr) + parent := generateObjectWithCID(cnr) addAttribute(parent, "foo", "bar") var parentAddr oid.Address @@ -26,12 +26,12 @@ func TestHeadRaw(t *testing.T) { idParent, _ := parent.ID() parentAddr.SetObject(idParent) - child := generateObjectWithCID(t, cnr) + child := generateObjectWithCID(cnr) child.SetParent(parent) child.SetParentID(idParent) child.SetSplitID(splitID) - link := generateObjectWithCID(t, cnr) + link := generateObjectWithCID(cnr) link.SetParent(parent) link.SetParentID(idParent) diff --git a/pkg/local_object_storage/engine/inhume_test.go b/pkg/local_object_storage/engine/inhume_test.go index b50e2a0d38..651a4a0a32 100644 --- a/pkg/local_object_storage/engine/inhume_test.go +++ b/pkg/local_object_storage/engine/inhume_test.go @@ -22,16 +22,16 @@ func TestStorageEngine_Inhume(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddRootFilter() - tombstoneID := object.AddressOf(generateObjectWithCID(t, cnr)) - parent := generateObjectWithCID(t, cnr) + tombstoneID := object.AddressOf(generateObjectWithCID(cnr)) + parent := generateObjectWithCID(cnr) - child := generateObjectWithCID(t, cnr) + child := generateObjectWithCID(cnr) child.SetParent(parent) idParent, _ := parent.ID() child.SetParentID(idParent) child.SetSplitID(splitID) - link := generateObjectWithCID(t, cnr) + link := generateObjectWithCID(cnr) link.SetParent(parent) link.SetParentID(idParent) idChild, _ := child.ID() @@ -113,7 +113,7 @@ func TestStorageEngine_Inhume(t *testing.T) { }) t.Run("object is on wrong shard", func(t *testing.T) { - obj := generateObjectWithCID(t, cnr) + obj := generateObjectWithCID(cnr) addr := object.AddressOf(obj) e := testNewEngineWithShardNum(t, 2) diff --git a/pkg/local_object_storage/engine/list_test.go b/pkg/local_object_storage/engine/list_test.go index 4c8ee3c411..9cb27dfdfe 100644 --- a/pkg/local_object_storage/engine/list_test.go +++ b/pkg/local_object_storage/engine/list_test.go @@ -29,7 +29,7 @@ func TestListWithCursor(t *testing.T) { for range total { containerID := cidtest.ID() - obj := generateObjectWithCID(t, containerID) + obj := generateObjectWithCID(containerID) var prm PutPrm prm.WithObject(obj) @@ -49,7 +49,7 @@ func TestListWithCursor(t *testing.T) { require.NotEmpty(t, res.AddressList()) got = append(got, res.AddressList()...) - for i := 0; i < total-1; i++ { + for range total - 1 { prm.WithCursor(res.Cursor()) res, err = e.ListWithCursor(prm) diff --git a/pkg/local_object_storage/engine/lock_test.go b/pkg/local_object_storage/engine/lock_test.go index f4b42ec6d7..3f07e4b63f 100644 --- a/pkg/local_object_storage/engine/lock_test.go +++ b/pkg/local_object_storage/engine/lock_test.go @@ -15,7 +15,6 @@ import ( cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/panjf2000/ants/v2" "github.com/stretchr/testify/require" @@ -40,7 +39,7 @@ func TestLockUserScenario(t *testing.T) { const lockerExpiresAfter = 13 cnr := cidtest.ID() - tombObj := generateObjectWithCID(t, cnr) + tombObj := generateObjectWithCID(cnr) tombForLockID := oidtest.ID() tombObj.SetID(tombForLockID) @@ -77,7 +76,7 @@ func TestLockUserScenario(t *testing.T) { a.SetKey(object.AttributeExpirationEpoch) a.SetValue(strconv.Itoa(lockerExpiresAfter)) - lockerObj := generateObjectWithCID(t, cnr) + lockerObj := generateObjectWithCID(cnr) lockerObj.SetID(lockerID) lockerObj.SetAttributes(a) @@ -86,7 +85,7 @@ func TestLockUserScenario(t *testing.T) { tombForLockAddr.SetObject(tombForLockID) // 1. - obj := generateObjectWithCID(t, cnr) + obj := generateObjectWithCID(cnr) id, _ := obj.ID() objAddr.SetObject(id) @@ -164,7 +163,7 @@ func TestLockExpiration(t *testing.T) { var err error // 1. - obj := generateObjectWithCID(t, cnr) + obj := generateObjectWithCID(cnr) err = Put(e, obj) require.NoError(t, err) @@ -174,7 +173,7 @@ func TestLockExpiration(t *testing.T) { a.SetKey(object.AttributeExpirationEpoch) a.SetValue(strconv.Itoa(lockerExpiresAfter)) - lock := generateObjectWithCID(t, cnr) + lock := generateObjectWithCID(cnr) lock.SetType(object.TypeLock) lock.SetAttributes(a) @@ -188,7 +187,7 @@ func TestLockExpiration(t *testing.T) { require.NoError(t, err) var inhumePrm InhumePrm - inhumePrm.WithTombstone(objecttest.Address(), 0, objectcore.AddressOf(obj)) + inhumePrm.WithTombstone(oidtest.Address(), 0, objectcore.AddressOf(obj)) _, err = e.Inhume(inhumePrm) require.ErrorAs(t, err, new(apistatus.ObjectLocked)) @@ -201,7 +200,7 @@ func TestLockExpiration(t *testing.T) { time.Sleep(time.Second) // 4. - inhumePrm.WithTombstone(objecttest.Address(), 0, objectcore.AddressOf(obj)) + inhumePrm.WithTombstone(oidtest.Address(), 0, objectcore.AddressOf(obj)) _, err = e.Inhume(inhumePrm) require.NoError(t, err) @@ -235,13 +234,13 @@ func TestLockForceRemoval(t *testing.T) { var err error // 1. - obj := generateObjectWithCID(t, cnr) + obj := generateObjectWithCID(cnr) err = Put(e, obj) require.NoError(t, err) // 2. - lock := generateObjectWithCID(t, cnr) + lock := generateObjectWithCID(cnr) lock.SetType(object.TypeLock) err = Put(e, lock) @@ -260,7 +259,7 @@ func TestLockForceRemoval(t *testing.T) { _, err = e.Inhume(inhumePrm) require.ErrorAs(t, err, new(apistatus.ObjectLocked)) - inhumePrm.WithTombstone(objecttest.Address(), 0, objectcore.AddressOf(obj)) + inhumePrm.WithTombstone(oidtest.Address(), 0, objectcore.AddressOf(obj)) _, err = e.Inhume(inhumePrm) require.ErrorAs(t, err, new(apistatus.ObjectLocked)) diff --git a/pkg/local_object_storage/engine/tree.go b/pkg/local_object_storage/engine/tree.go index 3abe7c3d76..39cdc1ab7d 100644 --- a/pkg/local_object_storage/engine/tree.go +++ b/pkg/local_object_storage/engine/tree.go @@ -20,7 +20,7 @@ func (e *StorageEngine) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pil lm, err := lst[index].TreeMove(d, treeID, m) if err != nil { - if !errors.Is(err, shard.ErrReadOnlyMode) && err != shard.ErrPiloramaDisabled { + if !errors.Is(err, shard.ErrReadOnlyMode) && !errors.Is(err, shard.ErrPiloramaDisabled) { e.reportShardError(lst[index], "can't perform `TreeMove`", err, zap.Stringer("cid", d.CID), zap.String("tree", treeID)) @@ -40,7 +40,7 @@ func (e *StorageEngine) TreeAddByPath(d pilorama.CIDDescriptor, treeID string, a lm, err := lst[index].TreeAddByPath(d, treeID, attr, path, m) if err != nil { - if !errors.Is(err, shard.ErrReadOnlyMode) && err != shard.ErrPiloramaDisabled { + if !errors.Is(err, shard.ErrReadOnlyMode) && !errors.Is(err, shard.ErrPiloramaDisabled) { e.reportShardError(lst[index], "can't perform `TreeAddByPath`", err, zap.Stringer("cid", d.CID), zap.String("tree", treeID)) @@ -59,7 +59,7 @@ func (e *StorageEngine) TreeApply(d pilorama.CIDDescriptor, treeID string, m *pi err = lst[index].TreeApply(d, treeID, m, backgroundSync) if err != nil { - if !errors.Is(err, shard.ErrReadOnlyMode) && err != shard.ErrPiloramaDisabled { + if !errors.Is(err, shard.ErrReadOnlyMode) && !errors.Is(err, shard.ErrPiloramaDisabled) { e.reportShardError(lst[index], "can't perform `TreeApply`", err, zap.Stringer("cid", d.CID), zap.String("tree", treeID)) @@ -76,7 +76,7 @@ func (e *StorageEngine) TreeGetByPath(cid cidSDK.ID, treeID string, attr string, for _, sh := range e.sortShardsByWeight(cid) { nodes, err = sh.TreeGetByPath(cid, treeID, attr, path, latest) if err != nil { - if err == shard.ErrPiloramaDisabled { + if errors.Is(err, shard.ErrPiloramaDisabled) { break } if !errors.Is(err, pilorama.ErrTreeNotFound) { @@ -99,7 +99,7 @@ func (e *StorageEngine) TreeGetMeta(cid cidSDK.ID, treeID string, nodeID piloram for _, sh := range e.sortShardsByWeight(cid) { m, p, err = sh.TreeGetMeta(cid, treeID, nodeID) if err != nil { - if err == shard.ErrPiloramaDisabled { + if errors.Is(err, shard.ErrPiloramaDisabled) { break } if !errors.Is(err, pilorama.ErrTreeNotFound) { @@ -121,7 +121,7 @@ func (e *StorageEngine) TreeGetChildren(cid cidSDK.ID, treeID string, nodeID pil for _, sh := range e.sortShardsByWeight(cid) { nodes, err = sh.TreeGetChildren(cid, treeID, nodeID) if err != nil { - if err == shard.ErrPiloramaDisabled { + if errors.Is(err, shard.ErrPiloramaDisabled) { break } if !errors.Is(err, pilorama.ErrTreeNotFound) { @@ -143,7 +143,7 @@ func (e *StorageEngine) TreeGetOpLog(cid cidSDK.ID, treeID string, height uint64 for _, sh := range e.sortShardsByWeight(cid) { lm, err = sh.TreeGetOpLog(cid, treeID, height) if err != nil { - if err == shard.ErrPiloramaDisabled { + if errors.Is(err, shard.ErrPiloramaDisabled) { break } if !errors.Is(err, pilorama.ErrTreeNotFound) { @@ -164,7 +164,7 @@ func (e *StorageEngine) TreeDrop(cid cidSDK.ID, treeID string) error { for _, sh := range e.sortShardsByWeight(cid) { err = sh.TreeDrop(cid, treeID) if err != nil { - if err == shard.ErrPiloramaDisabled { + if errors.Is(err, shard.ErrPiloramaDisabled) { break } if !errors.Is(err, pilorama.ErrTreeNotFound) && !errors.Is(err, shard.ErrReadOnlyMode) { diff --git a/pkg/local_object_storage/engine/tree_test.go b/pkg/local_object_storage/engine/tree_test.go index 8d991ba17c..2a340d10ac 100644 --- a/pkg/local_object_storage/engine/tree_test.go +++ b/pkg/local_object_storage/engine/tree_test.go @@ -28,14 +28,14 @@ func benchmarkTreeVsSearch(b *testing.B, objCount int) { treeID := "someTree" for i := range objCount { - obj := generateObjectWithCID(b, cid) + obj := generateObjectWithCID(cid) addAttribute(obj, pilorama.AttributeFilename, strconv.Itoa(i)) err := Put(e, obj) if err != nil { b.Fatal(err) } _, err = e.TreeAddByPath(d, treeID, pilorama.AttributeFilename, nil, - []pilorama.KeyValue{{pilorama.AttributeFilename, []byte(strconv.Itoa(i))}}) + []pilorama.KeyValue{{Key: pilorama.AttributeFilename, Value: []byte(strconv.Itoa(i))}}) if err != nil { b.Fatal(err) } diff --git a/pkg/local_object_storage/metabase/control.go b/pkg/local_object_storage/metabase/control.go index a984a8deb8..b57b3cf824 100644 --- a/pkg/local_object_storage/metabase/control.go +++ b/pkg/local_object_storage/metabase/control.go @@ -63,7 +63,7 @@ func (db *DB) openBolt() error { return nil }) - if err == errBreakBucketForEach { + if errors.Is(err, errBreakBucketForEach) { db.initialized = true err = nil } diff --git a/pkg/local_object_storage/metabase/control_test.go b/pkg/local_object_storage/metabase/control_test.go index df549031a4..da6766693b 100644 --- a/pkg/local_object_storage/metabase/control_test.go +++ b/pkg/local_object_storage/metabase/control_test.go @@ -55,5 +55,8 @@ func metaExists(db *meta.DB, addr oid.Address) (bool, error) { existsPrm.SetAddress(addr) res, err := db.Exists(existsPrm) - return res.Exists(), err + if err != nil { + return false, err + } + return res.Exists(), nil } diff --git a/pkg/local_object_storage/metabase/db.go b/pkg/local_object_storage/metabase/db.go index 9e06131499..3f582fd83c 100644 --- a/pkg/local_object_storage/metabase/db.go +++ b/pkg/local_object_storage/metabase/db.go @@ -165,7 +165,7 @@ func destringifyValue(key, value string, prefix bool) ([]byte, bool, bool) { return v, true, true } - return v, false, err == nil + return v, false, true case object.FilterCreationEpoch, object.FilterPayloadSize: u, err := strconv.ParseUint(value, 10, 64) if err != nil { diff --git a/pkg/local_object_storage/metabase/db_test.go b/pkg/local_object_storage/metabase/db_test.go index f1b4b10120..25f8a978bd 100644 --- a/pkg/local_object_storage/metabase/db_test.go +++ b/pkg/local_object_storage/metabase/db_test.go @@ -11,7 +11,6 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" - objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" usertest "github.com/nspcc-dev/neofs-sdk-go/user/test" @@ -108,7 +107,7 @@ func addAttribute(obj *object.Object, key, val string) { obj.SetAttributes(attrs...) } -func checkExpiredObjects(t *testing.T, db *meta.DB, f func(exp, nonExp *objectSDK.Object)) { +func checkExpiredObjects(t *testing.T, db *meta.DB, f func(exp, nonExp *object.Object)) { expObj := generateObject(t) setExpiration(expObj, currEpoch-1) @@ -122,8 +121,8 @@ func checkExpiredObjects(t *testing.T, db *meta.DB, f func(exp, nonExp *objectSD f(expObj, nonExpObj) } -func setExpiration(o *objectSDK.Object, epoch uint64) { - var attr objectSDK.Attribute +func setExpiration(o *object.Object, epoch uint64) { + var attr object.Attribute attr.SetKey(object.AttributeExpirationEpoch) attr.SetValue(strconv.FormatUint(epoch, 10)) diff --git a/pkg/local_object_storage/metabase/exists_test.go b/pkg/local_object_storage/metabase/exists_test.go index e5c3245d4f..d773ceeede 100644 --- a/pkg/local_object_storage/metabase/exists_test.go +++ b/pkg/local_object_storage/metabase/exists_test.go @@ -180,6 +180,7 @@ func TestDB_Exists(t *testing.T) { require.ErrorIs(t, err, meta.ErrObjectIsExpired) gotObj, err = metaExists(db, object.AddressOf(nonExp)) + require.NoError(t, err) require.True(t, gotObj) }) }) diff --git a/pkg/local_object_storage/metabase/get_test.go b/pkg/local_object_storage/metabase/get_test.go index ffba530f27..b2ff3d78ae 100644 --- a/pkg/local_object_storage/metabase/get_test.go +++ b/pkg/local_object_storage/metabase/get_test.go @@ -288,5 +288,8 @@ func metaGet(db *meta.DB, addr oid.Address, raw bool) (*objectSDK.Object, error) prm.SetRaw(raw) res, err := db.Get(prm) - return res.Header(), err + if err != nil { + return nil, err + } + return res.Header(), nil } diff --git a/pkg/local_object_storage/metabase/graveyard_test.go b/pkg/local_object_storage/metabase/graveyard_test.go index 50ca87849a..714d0a3082 100644 --- a/pkg/local_object_storage/metabase/graveyard_test.go +++ b/pkg/local_object_storage/metabase/graveyard_test.go @@ -9,7 +9,6 @@ import ( meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" - objectsdk "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" @@ -391,7 +390,6 @@ func TestDB_GetGarbage(t *testing.T) { const numOfObjs = 5 cID := cidtest.ID() - var oo []*objectsdk.Object var size uint64 for i := range numOfObjs { @@ -399,7 +397,6 @@ func TestDB_GetGarbage(t *testing.T) { addAttribute(raw, "foo"+strconv.Itoa(i), "bar"+strconv.Itoa(i)) size += raw.PayloadSize() - oo = append(oo, raw) err := putBig(db, raw) require.NoError(t, err) @@ -409,7 +406,6 @@ func TestDB_GetGarbage(t *testing.T) { anotherObj := generateObjectWithCID(t, cidtest.ID()) err := putBig(db, anotherObj) require.NoError(t, err) - oo = append(oo, anotherObj) _, err = db.InhumeContainer(cID) require.NoError(t, err) diff --git a/pkg/local_object_storage/metabase/iterators.go b/pkg/local_object_storage/metabase/iterators.go index c158b00868..14e01ca58b 100644 --- a/pkg/local_object_storage/metabase/iterators.go +++ b/pkg/local_object_storage/metabase/iterators.go @@ -175,11 +175,11 @@ func (db *DB) iterateCoveredByTombstones(tx *bbolt.Tx, tss map[string]oid.Addres } func iteratePhyObjects(tx *bbolt.Tx, f func(cid.ID, oid.ID) error) error { - var cid cid.ID - var oid oid.ID + var cID cid.ID + var oID oid.ID return tx.ForEach(func(name []byte, b *bbolt.Bucket) error { - b58CID, postfix := parseContainerIDWithPrefix(&cid, name) + b58CID, postfix := parseContainerIDWithPrefix(&cID, name) if len(b58CID) == 0 { return nil } @@ -194,8 +194,8 @@ func iteratePhyObjects(tx *bbolt.Tx, f func(cid.ID, oid.ID) error) error { } return b.ForEach(func(k, v []byte) error { - if oid.Decode(k) == nil { - return f(cid, oid) + if oID.Decode(k) == nil { + return f(cID, oID) } return nil diff --git a/pkg/local_object_storage/metabase/list_test.go b/pkg/local_object_storage/metabase/list_test.go index de193f21a0..2fa8617f87 100644 --- a/pkg/local_object_storage/metabase/list_test.go +++ b/pkg/local_object_storage/metabase/list_test.go @@ -33,7 +33,7 @@ func listWithCursorPrepareDB(b *testing.B) *meta.DB { })) // faster single-thread generation obj := generateObject(b) - for i := 0; i < 100_000; i++ { // should be a multiple of all batch sizes + for i := range 100_000 { // should be a multiple of all batch sizes obj.SetID(oidtest.ID()) if i%9 == 0 { // let's have 9 objects per container obj.SetContainerID(cidtest.ID()) @@ -52,7 +52,7 @@ func benchmarkListWithCursor(b *testing.B, db *meta.DB, batchSize int) { for range b.N { res, err := db.ListWithCursor(prm) if err != nil { - if err != meta.ErrEndOfListing { + if !errors.Is(err, meta.ErrEndOfListing) { b.Fatalf("error: %v", err) } prm.SetCursor(nil) @@ -212,7 +212,6 @@ func TestAddObjectDuringListingWithCursor(t *testing.T) { for _, v := range expected { require.Equal(t, 1, v) } - } func sortAddresses(addrWithType []object.AddressWithType) []object.AddressWithType { @@ -228,5 +227,8 @@ func metaListWithCursor(db *meta.DB, count uint32, cursor *meta.Cursor) ([]objec listPrm.SetCursor(cursor) r, err := db.ListWithCursor(listPrm) - return r.AddressList(), r.Cursor(), err + if err != nil { + return nil, nil, err + } + return r.AddressList(), r.Cursor(), nil } diff --git a/pkg/local_object_storage/metabase/put.go b/pkg/local_object_storage/metabase/put.go index 670b6357af..21d3f97a06 100644 --- a/pkg/local_object_storage/metabase/put.go +++ b/pkg/local_object_storage/metabase/put.go @@ -511,7 +511,7 @@ func updateSplitInfo(tx *bbolt.Tx, addr oid.Address, from *objectSDK.SplitInfo) } // splitInfoFromObject returns split info based on last or linkin object. -// Otherwise returns nil, nil. +// Otherwise, returns nil, nil. func splitInfoFromObject(obj *objectSDK.Object) (*objectSDK.SplitInfo, error) { if obj.Parent() == nil { return nil, nil diff --git a/pkg/local_object_storage/metabase/select_test.go b/pkg/local_object_storage/metabase/select_test.go index 5d92d3ac0d..3e0c65d3ea 100644 --- a/pkg/local_object_storage/metabase/select_test.go +++ b/pkg/local_object_storage/metabase/select_test.go @@ -895,7 +895,10 @@ func metaSelect(db *meta.DB, cnr cidSDK.ID, fs objectSDK.SearchFilters) ([]oid.A prm.SetContainerID(cnr) res, err := db.Select(prm) - return res.AddressList(), err + if err != nil { + return nil, err + } + return res.AddressList(), nil } func numQuery(key string, op objectSDK.SearchMatchType, val string) (res objectSDK.SearchFilters) { diff --git a/pkg/local_object_storage/metabase/storage_id_test.go b/pkg/local_object_storage/metabase/storage_id_test.go index 155a8f4180..13b76a6d18 100644 --- a/pkg/local_object_storage/metabase/storage_id_test.go +++ b/pkg/local_object_storage/metabase/storage_id_test.go @@ -63,5 +63,8 @@ func metaStorageID(db *meta.DB, addr oid.Address) ([]byte, error) { sidPrm.SetAddress(addr) r, err := db.StorageID(sidPrm) - return r.StorageID(), err + if err != nil { + return nil, err + } + return r.StorageID(), nil } diff --git a/pkg/local_object_storage/pilorama/forest_test.go b/pkg/local_object_storage/pilorama/forest_test.go index 333398f957..6b67d9c792 100644 --- a/pkg/local_object_storage/pilorama/forest_test.go +++ b/pkg/local_object_storage/pilorama/forest_test.go @@ -1,8 +1,9 @@ package pilorama import ( + crand "crypto/rand" "fmt" - "math/rand" + "math/rand/v2" "os" "path/filepath" "strconv" @@ -225,6 +226,7 @@ func testForestTreeDrop(t *testing.T, s Forest) { } } list, err := s.TreeList(cid) + require.NoError(t, err) require.NotEmpty(t, list) require.NoError(t, s.TreeDrop(cid, "")) @@ -683,8 +685,7 @@ func prepareRandomTree(nodeCount, opCount int) []Move { }, Child: uint64(i) + 1, } - //nolint:staticcheck - rand.Read(ops[i].Meta.Items[1].Value) + _, _ = crand.Read(ops[i].Meta.Items[1].Value) } for i := nodeCount; i < len(ops); i++ { @@ -702,15 +703,14 @@ func prepareRandomTree(nodeCount, opCount int) []Move { if rand.Uint32()%5 == 0 { ops[i].Parent = TrashID } - //nolint:staticcheck - rand.Read(ops[i].Meta.Items[1].Value) + _, _ = crand.Read(ops[i].Meta.Items[1].Value) } return ops } func compareForests(t *testing.T, expected, actual Forest, cid cidSDK.ID, treeID string, nodeCount int) { - for i := uint64(0); i < uint64(nodeCount); i++ { + for i := range uint64(nodeCount) { expectedMeta, expectedParent, err := expected.TreeGetMeta(cid, treeID, i) require.NoError(t, err) actualMeta, actualParent, err := actual.TreeGetMeta(cid, treeID, i) @@ -741,9 +741,6 @@ func compareForests(t *testing.T, expected, actual Forest, cid cidSDK.ID, treeID } func testForestTreeParallelApply(t *testing.T, constructor func(t testing.TB, _ ...Option) Forest, batchSize, opCount, iterCount int) { - //nolint:staticcheck - rand.Seed(42) - const nodeCount = 5 ops := prepareRandomTree(nodeCount, opCount) @@ -763,7 +760,7 @@ func testForestTreeParallelApply(t *testing.T, constructor func(t testing.TB, _ actual := constructor(t, WithMaxBatchSize(batchSize)) wg := new(sync.WaitGroup) - ch := make(chan *Move, 0) + ch := make(chan *Move) for range batchSize { wg.Add(1) go func() { @@ -785,9 +782,6 @@ func testForestTreeParallelApply(t *testing.T, constructor func(t testing.TB, _ } func testForestTreeApplyRandom(t *testing.T, constructor func(t testing.TB, _ ...Option) Forest) { - //nolint:staticcheck - rand.Seed(42) - const ( nodeCount = 5 opCount = 20 @@ -834,12 +828,12 @@ func BenchmarkApplySequential(b *testing.B) { ops := make([]Move, opCount) for i := range ops { ops[i] = Move{ - Parent: uint64(rand.Intn(benchNodeCount)), + Parent: uint64(rand.IntN(benchNodeCount)), Meta: Meta{ Time: Timestamp(i), Items: []KeyValue{{Value: []byte{0, 1, 2, 3, 4}}}, }, - Child: uint64(rand.Intn(benchNodeCount)), + Child: uint64(rand.IntN(benchNodeCount)), } } return ops @@ -867,15 +861,15 @@ func BenchmarkApplyReorderLast(b *testing.B) { ops := make([]Move, opCount) for i := range ops { ops[i] = Move{ - Parent: uint64(rand.Intn(benchNodeCount)), + Parent: uint64(rand.IntN(benchNodeCount)), Meta: Meta{ Time: Timestamp(i), Items: []KeyValue{{Value: []byte{0, 1, 2, 3, 4}}}, }, - Child: uint64(rand.Intn(benchNodeCount)), + Child: uint64(rand.IntN(benchNodeCount)), } if i != 0 && i%blockSize == 0 { - for j := 0; j < blockSize/2; j++ { + for j := range blockSize / 2 { ops[i-j], ops[i+j-blockSize] = ops[i+j-blockSize], ops[i-j] } } @@ -889,9 +883,6 @@ func BenchmarkApplyReorderLast(b *testing.B) { } func benchmarkApply(b *testing.B, s Forest, genFunc func(int) []Move) { - //nolint:staticcheck - rand.Seed(42) - ops := genFunc(b.N) cid := cidtest.ID() d := CIDDescriptor{cid, 0, 1} diff --git a/pkg/local_object_storage/shard/container_test.go b/pkg/local_object_storage/shard/container_test.go index f7a59817c4..ca1d0de44d 100644 --- a/pkg/local_object_storage/shard/container_test.go +++ b/pkg/local_object_storage/shard/container_test.go @@ -15,28 +15,24 @@ func TestShard_DeleteContainer(t *testing.T) { defer releaseShard(sh, t) cID := cidtest.ID() - var objs []*objectSDK.Object var prm shard.PutPrm - o1 := generateObjectWithCID(t, cID) + o1 := generateObjectWithCID(cID) prm.SetObject(o1) _, err := sh.Put(prm) require.NoError(t, err) - objs = append(objs, o1) - o2 := generateObjectWithCID(t, cID) + o2 := generateObjectWithCID(cID) o2.SetType(objectSDK.TypeStorageGroup) prm.SetObject(o2) _, err = sh.Put(prm) require.NoError(t, err) - objs = append(objs, o2) - o3 := generateObjectWithCID(t, cID) + o3 := generateObjectWithCID(cID) prm.SetObject(o3) o3.SetType(objectSDK.TypeLock) _, err = sh.Put(prm) require.NoError(t, err) - objs = append(objs, o3) err = sh.DeleteContainer(context.Background(), cID) require.NoError(t, err) diff --git a/pkg/local_object_storage/shard/control_test.go b/pkg/local_object_storage/shard/control_test.go index ed2979f5c9..64dd3afcbe 100644 --- a/pkg/local_object_storage/shard/control_test.go +++ b/pkg/local_object_storage/shard/control_test.go @@ -175,7 +175,7 @@ func TestRefillMetabase(t *testing.T) { locked := make([]oid.ID, 1, 2) locked[0] = oidtest.ID() cnrLocked := cidtest.ID() - for i := uint64(0); i < objNum; i++ { + for range uint64(objNum) { obj := objecttest.Object() obj.SetType(objectSDK.TypeRegular) diff --git a/pkg/local_object_storage/shard/delete_test.go b/pkg/local_object_storage/shard/delete_test.go index 2acd094b04..02363f6b55 100644 --- a/pkg/local_object_storage/shard/delete_test.go +++ b/pkg/local_object_storage/shard/delete_test.go @@ -26,7 +26,7 @@ func testShardDelete(t *testing.T, hasWriteCache bool) { cnr := cidtest.ID() - obj := generateObjectWithCID(t, cnr) + obj := generateObjectWithCID(cnr) addAttribute(obj, "foo", "bar") var putPrm shard.PutPrm @@ -55,7 +55,7 @@ func testShardDelete(t *testing.T, hasWriteCache bool) { }) t.Run("small object", func(t *testing.T) { - obj := generateObjectWithCID(t, cnr) + obj := generateObjectWithCID(cnr) addAttribute(obj, "foo", "bar") addPayload(obj, 1<<5) diff --git a/pkg/local_object_storage/shard/dump_test.go b/pkg/local_object_storage/shard/dump_test.go index 0e0dea8f15..573b1a8097 100644 --- a/pkg/local_object_storage/shard/dump_test.go +++ b/pkg/local_object_storage/shard/dump_test.go @@ -2,8 +2,8 @@ package shard_test import ( "bytes" + "crypto/rand" "io" - "math/rand" "os" "path/filepath" "testing" @@ -95,9 +95,8 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) { size = bsBigObjectSize - headerSize } data := make([]byte, size) - //nolint:staticcheck - rand.Read(data) - obj := generateObjectWithPayload(t, cnr, data) + _, _ = rand.Read(data) + obj := generateObjectWithPayload(cnr, data) objects[i] = obj var prm shard.PutPrm @@ -227,7 +226,7 @@ func TestStream(t *testing.T) { objects := make([]*objectSDK.Object, objCount) for i := range objCount { cnr := cidtest.ID() - obj := generateObjectWithCID(t, cnr) + obj := generateObjectWithCID(cnr) objects[i] = obj var prm shard.PutPrm @@ -322,7 +321,7 @@ func TestDumpIgnoreErrors(t *testing.T) { objects := make([]*objectSDK.Object, objCount) for i := range objCount { size := (wcSmallObjectSize << (i % 4)) - headerSize - obj := generateObjectWithPayload(t, cidtest.ID(), make([]byte, size)) + obj := generateObjectWithPayload(cidtest.ID(), make([]byte, size)) objects[i] = obj var prm shard.PutPrm diff --git a/pkg/local_object_storage/shard/exists.go b/pkg/local_object_storage/shard/exists.go index fce28bd675..c359092b05 100644 --- a/pkg/local_object_storage/shard/exists.go +++ b/pkg/local_object_storage/shard/exists.go @@ -52,6 +52,9 @@ func (s *Shard) Exists(prm ExistsPrm) (ExistsRes, error) { var res common.ExistsRes res, err = s.blobStor.Exists(p) + if err != nil { + return ExistsRes{}, err + } exists = res.Exists } else { var existsPrm meta.ExistsPrm @@ -62,6 +65,9 @@ func (s *Shard) Exists(prm ExistsPrm) (ExistsRes, error) { var res meta.ExistsRes res, err = s.metaBase.Exists(existsPrm) + if err != nil { + return ExistsRes{}, err + } exists = res.Exists() } diff --git a/pkg/local_object_storage/shard/gc_test.go b/pkg/local_object_storage/shard/gc_test.go index 393991cedc..50875eff80 100644 --- a/pkg/local_object_storage/shard/gc_test.go +++ b/pkg/local_object_storage/shard/gc_test.go @@ -21,7 +21,6 @@ import ( cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" neofscryptotest "github.com/nspcc-dev/neofs-sdk-go/crypto/test" "github.com/nspcc-dev/neofs-sdk-go/object" - objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/panjf2000/ants/v2" "github.com/stretchr/testify/require" @@ -84,17 +83,17 @@ func TestGC_ExpiredObjectWithExpiredLock(t *testing.T) { cnr := cidtest.ID() - var expAttr objectSDK.Attribute + var expAttr object.Attribute expAttr.SetKey(objectV2.SysAttributeExpEpoch) expAttr.SetValue("1") - obj := generateObjectWithCID(t, cnr) + obj := generateObjectWithCID(cnr) obj.SetAttributes(expAttr) objID, _ := obj.ID() expAttr.SetValue("3") - lock := generateObjectWithCID(t, cnr) + lock := generateObjectWithCID(cnr) lock.SetType(object.TypeLock) lock.SetAttributes(expAttr) lockID, _ := lock.ID() @@ -137,7 +136,7 @@ func TestGC_ContainerCleanup(t *testing.T) { for i := range numOfObjs { var putPrm shard.PutPrm - obj := generateObjectWithCID(t, cID) + obj := generateObjectWithCID(cID) addAttribute(obj, fmt.Sprintf("foo%d", i), fmt.Sprintf("bar%d", i)) if i%2 == 0 { addPayload(obj, 1<<5) // small @@ -195,7 +194,7 @@ func TestExpiration(t *testing.T) { { Storage: fstree.New( fstree.WithPath(filepath.Join(rootPath, "blob"))), - Policy: func(_ *objectSDK.Object, _ []byte) bool { return true }, + Policy: func(_ *object.Object, _ []byte) bool { return true }, }, }), ), @@ -228,12 +227,12 @@ func TestExpiration(t *testing.T) { }) ch := sh.NotificationChannel() - var expAttr objectSDK.Attribute + var expAttr object.Attribute expAttr.SetKey(objectV2.SysAttributeExpEpoch) - obj := generateObject(t) + obj := generateObject() - for i, typ := range []object.Type{object.TypeRegular, object.TypeTombstone, object.TypeLink, objectSDK.TypeStorageGroup} { + for i, typ := range []object.Type{object.TypeRegular, object.TypeTombstone, object.TypeLink, object.TypeStorageGroup} { t.Run(fmt.Sprintf("type: %s", typ), func(t *testing.T) { exp := uint64(i * 10) diff --git a/pkg/local_object_storage/shard/get_test.go b/pkg/local_object_storage/shard/get_test.go index 9010254d41..0376f72bff 100644 --- a/pkg/local_object_storage/shard/get_test.go +++ b/pkg/local_object_storage/shard/get_test.go @@ -33,7 +33,7 @@ func testShardGet(t *testing.T, hasWriteCache bool) { var getPrm shard.GetPrm t.Run("small object", func(t *testing.T) { - obj := generateObject(t) + obj := generateObject() addAttribute(obj, "foo", "bar") addPayload(obj, 1<<5) addr := object.AddressOf(obj) @@ -54,7 +54,7 @@ func testShardGet(t *testing.T, hasWriteCache bool) { }) t.Run("big object", func(t *testing.T) { - obj := generateObject(t) + obj := generateObject() addAttribute(obj, "foo", "bar") obj.SetID(oidtest.ID()) addPayload(obj, 1<<20) // big obj @@ -76,15 +76,15 @@ func testShardGet(t *testing.T, hasWriteCache bool) { }) t.Run("parent object", func(t *testing.T) { - obj := generateObject(t) + obj := generateObject() addAttribute(obj, "foo", "bar") cnr := cidtest.ID() splitID := objectSDK.NewSplitID() - parent := generateObjectWithCID(t, cnr) + parent := generateObjectWithCID(cnr) addAttribute(parent, "parent", "attribute") - child := generateObjectWithCID(t, cnr) + child := generateObjectWithCID(cnr) child.SetParent(parent) idParent, _ := parent.ID() child.SetParentID(idParent) diff --git a/pkg/local_object_storage/shard/head.go b/pkg/local_object_storage/shard/head.go index 1de83111ee..69bf5049b1 100644 --- a/pkg/local_object_storage/shard/head.go +++ b/pkg/local_object_storage/shard/head.go @@ -53,6 +53,9 @@ func (s *Shard) Head(prm HeadPrm) (HeadRes, error) { var res GetRes res, err = s.Get(getPrm) + if err != nil { + return HeadRes{}, err + } obj = res.Object() } else { var headParams meta.GetPrm @@ -61,10 +64,13 @@ func (s *Shard) Head(prm HeadPrm) (HeadRes, error) { var res meta.GetRes res, err = s.metaBase.Get(headParams) + if err != nil { + return HeadRes{}, err + } obj = res.Header() } return HeadRes{ obj: obj, - }, err + }, nil } diff --git a/pkg/local_object_storage/shard/head_test.go b/pkg/local_object_storage/shard/head_test.go index 00de09cfd9..c9bf80c064 100644 --- a/pkg/local_object_storage/shard/head_test.go +++ b/pkg/local_object_storage/shard/head_test.go @@ -30,7 +30,7 @@ func testShardHead(t *testing.T, hasWriteCache bool) { var headPrm shard.HeadPrm t.Run("regular object", func(t *testing.T) { - obj := generateObject(t) + obj := generateObject() addAttribute(obj, "foo", "bar") putPrm.SetObject(obj) @@ -49,10 +49,10 @@ func testShardHead(t *testing.T, hasWriteCache bool) { cnr := cidtest.ID() splitID := objectSDK.NewSplitID() - parent := generateObjectWithCID(t, cnr) + parent := generateObjectWithCID(cnr) addAttribute(parent, "foo", "bar") - child := generateObjectWithCID(t, cnr) + child := generateObjectWithCID(cnr) child.SetParent(parent) idParent, _ := parent.ID() child.SetParentID(idParent) diff --git a/pkg/local_object_storage/shard/inhume_test.go b/pkg/local_object_storage/shard/inhume_test.go index ab81c6355c..c72b336508 100644 --- a/pkg/local_object_storage/shard/inhume_test.go +++ b/pkg/local_object_storage/shard/inhume_test.go @@ -26,10 +26,10 @@ func testShardInhume(t *testing.T, hasWriteCache bool) { cnr := cidtest.ID() - obj := generateObjectWithCID(t, cnr) + obj := generateObjectWithCID(cnr) addAttribute(obj, "foo", "bar") - ts := generateObjectWithCID(t, cnr) + ts := generateObjectWithCID(cnr) var putPrm shard.PutPrm putPrm.SetObject(obj) diff --git a/pkg/local_object_storage/shard/list_test.go b/pkg/local_object_storage/shard/list_test.go index 9c7332766c..9ebffe2be1 100644 --- a/pkg/local_object_storage/shard/list_test.go +++ b/pkg/local_object_storage/shard/list_test.go @@ -38,11 +38,11 @@ func testShardList(t *testing.T, sh *shard.Shard) { cnr := cidtest.ID() for range N { - obj := generateObjectWithCID(t, cnr) + obj := generateObjectWithCID(cnr) addPayload(obj, 1<<2) // add parent as virtual object, it must be ignored in List() - parent := generateObjectWithCID(t, cnr) + parent := generateObjectWithCID(cnr) idParent, _ := parent.ID() obj.SetParentID(idParent) obj.SetParent(parent) diff --git a/pkg/local_object_storage/shard/lock_test.go b/pkg/local_object_storage/shard/lock_test.go index abf92d4226..f9e71b6cac 100644 --- a/pkg/local_object_storage/shard/lock_test.go +++ b/pkg/local_object_storage/shard/lock_test.go @@ -58,10 +58,10 @@ func TestShard_Lock(t *testing.T) { }) cnr := cidtest.ID() - obj := generateObjectWithCID(t, cnr) + obj := generateObjectWithCID(cnr) objID, _ := obj.ID() - lock := generateObjectWithCID(t, cnr) + lock := generateObjectWithCID(cnr) lock.SetType(object.TypeLock) lockID, _ := lock.ID() @@ -83,7 +83,7 @@ func TestShard_Lock(t *testing.T) { require.NoError(t, err) t.Run("inhuming locked objects", func(t *testing.T) { - ts := generateObjectWithCID(t, cnr) + ts := generateObjectWithCID(cnr) var inhumePrm shard.InhumePrm inhumePrm.InhumeByTomb(objectcore.AddressOf(ts), 0, objectcore.AddressOf(obj)) @@ -97,7 +97,7 @@ func TestShard_Lock(t *testing.T) { }) t.Run("inhuming lock objects", func(t *testing.T) { - ts := generateObjectWithCID(t, cnr) + ts := generateObjectWithCID(cnr) var inhumePrm shard.InhumePrm inhumePrm.InhumeByTomb(objectcore.AddressOf(ts), 0, objectcore.AddressOf(lock)) @@ -141,7 +141,7 @@ func TestShard_IsLocked(t *testing.T) { sh := newShard(t, false) cnr := cidtest.ID() - obj := generateObjectWithCID(t, cnr) + obj := generateObjectWithCID(cnr) cnrID, _ := obj.ContainerID() objID, _ := obj.ID() diff --git a/pkg/local_object_storage/shard/metrics_test.go b/pkg/local_object_storage/shard/metrics_test.go index 9b4b808046..54e1c0b565 100644 --- a/pkg/local_object_storage/shard/metrics_test.go +++ b/pkg/local_object_storage/shard/metrics_test.go @@ -41,7 +41,7 @@ func (m metricsStore) AddToObjectCounter(objectType string, delta int) { } else { m.objectCounters[objectType] = 0 } - case delta == 0: + default: return } } @@ -68,21 +68,22 @@ func (m *metricsStore) AddToPayloadSize(size int64) { const physical = "phy" const logical = "logic" -const readonly = "readonly" func TestCounters(t *testing.T) { dir := t.TempDir() sh, mm := shardWithMetrics(t, dir) - sh.SetMode(mode.ReadOnly) + err := sh.SetMode(mode.ReadOnly) + require.NoError(t, err) require.True(t, mm.readOnly) - sh.SetMode(mode.ReadWrite) + err = sh.SetMode(mode.ReadWrite) + require.NoError(t, err) require.False(t, mm.readOnly) const objNumber = 10 oo := make([]*object.Object, objNumber) for i := range objNumber { - oo[i] = generateObject(t) + oo[i] = generateObject() } t.Run("defaults", func(t *testing.T) { @@ -139,7 +140,7 @@ func TestCounters(t *testing.T) { t.Run("inhume_TS", func(t *testing.T) { var prm shard.InhumePrm - ts := objectcore.AddressOf(generateObject(t)) + ts := objectcore.AddressOf(generateObject()) phy := mm.objectCounters[physical] logic := mm.objectCounters[logical] @@ -226,7 +227,7 @@ func shardWithMetrics(t *testing.T, path string) (*shard.Shard, *metricsStore) { func addrFromObjs(oo []*object.Object) []oid.Address { aa := make([]oid.Address, len(oo)) - for i := range len(oo) { + for i := range oo { aa[i] = objectcore.AddressOf(oo[i]) } diff --git a/pkg/local_object_storage/shard/range_test.go b/pkg/local_object_storage/shard/range_test.go index b5273765d2..407a997eea 100644 --- a/pkg/local_object_storage/shard/range_test.go +++ b/pkg/local_object_storage/shard/range_test.go @@ -82,7 +82,7 @@ func testShardGetRange(t *testing.T, hasWriteCache bool) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - obj := generateObject(t) + obj := generateObject() addAttribute(obj, "foo", "bar") addPayload(obj, tc.payloadSize) diff --git a/pkg/local_object_storage/shard/shard_test.go b/pkg/local_object_storage/shard/shard_test.go index e2be2f8bf8..df0e5bc896 100644 --- a/pkg/local_object_storage/shard/shard_test.go +++ b/pkg/local_object_storage/shard/shard_test.go @@ -1,8 +1,8 @@ package shard_test import ( + "crypto/rand" "crypto/sha256" - "math/rand" "path/filepath" "testing" "time" @@ -95,18 +95,17 @@ func releaseShard(s *shard.Shard, t testing.TB) { require.NoError(t, s.Close()) } -func generateObject(t *testing.T) *object.Object { - return generateObjectWithCID(t, cidtest.ID()) +func generateObject() *object.Object { + return generateObjectWithCID(cidtest.ID()) } -func generateObjectWithCID(t *testing.T, cnr cid.ID) *object.Object { +func generateObjectWithCID(cnr cid.ID) *object.Object { data := make([]byte, 32) - //nolint:staticcheck - rand.Read(data) - return generateObjectWithPayload(t, cnr, data) + _, _ = rand.Read(data) + return generateObjectWithPayload(cnr, data) } -func generateObjectWithPayload(t testing.TB, cnr cid.ID, data []byte) *object.Object { +func generateObjectWithPayload(cnr cid.ID, data []byte) *object.Object { var ver version.Version ver.SetMajor(2) ver.SetMinor(1) @@ -142,7 +141,6 @@ func addAttribute(obj *object.Object, key, val string) { func addPayload(obj *object.Object, size int) { buf := make([]byte, size) - //nolint:staticcheck _, _ = rand.Read(buf) obj.SetPayload(buf) diff --git a/pkg/local_object_storage/shard/shutdown_test.go b/pkg/local_object_storage/shard/shutdown_test.go index b9750b85ce..de08b84161 100644 --- a/pkg/local_object_storage/shard/shutdown_test.go +++ b/pkg/local_object_storage/shard/shutdown_test.go @@ -1,7 +1,7 @@ package shard_test import ( - "math/rand" + "crypto/rand" "testing" "github.com/nspcc-dev/neofs-node/pkg/core/object" @@ -20,15 +20,11 @@ func TestWriteCacheObjectLoss(t *testing.T) { objects := make([]*objectSDK.Object, objCount) for i := range objects { - size := smallSize - // if i%2 == 0 { - size = smallSize / 2 - // } + size := smallSize / 2 data := make([]byte, size) - //nolint:staticcheck - rand.Read(data) + _, _ = rand.Read(data) - objects[i] = generateObjectWithPayload(t, cidtest.ID(), data) + objects[i] = generateObjectWithPayload(cidtest.ID(), data) } dir := t.TempDir() diff --git a/pkg/local_object_storage/writecache/flush_test.go b/pkg/local_object_storage/writecache/flush_test.go index f45962e67b..475868a5c1 100644 --- a/pkg/local_object_storage/writecache/flush_test.go +++ b/pkg/local_object_storage/writecache/flush_test.go @@ -271,7 +271,6 @@ func putObject(t *testing.T, c Cache, size int) objectPair { require.NoError(t, err) return objectPair{prm.Address, prm.Object} - } func newObject(t *testing.T, size int) (*object.Object, []byte) { diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index e9c4bf8cfe..c38f109b43 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -572,7 +572,7 @@ func (c *Client) MsPerBlock() (res int64, err error) { } // IsValidScript returns true if invocation script executes with HALT state. -func (c *Client) IsValidScript(script []byte, signers []transaction.Signer) (res bool, err error) { +func (c *Client) IsValidScript(script []byte, signers []transaction.Signer) (bool, error) { c.switchLock.RLock() defer c.switchLock.RUnlock() @@ -580,12 +580,12 @@ func (c *Client) IsValidScript(script []byte, signers []transaction.Signer) (res return false, ErrConnectionLost } - result, err := c.client.InvokeScript(script, signers) + res, err := c.client.InvokeScript(script, signers) if err != nil { return false, fmt.Errorf("invokeScript: %w", err) } - return result.State == vmstate.Halt.String(), nil + return res.State == vmstate.Halt.String(), nil } // AccountVote returns a key the provided account has voted with its NEO @@ -601,16 +601,16 @@ func (c *Client) AccountVote(addr util.Uint160) (*keys.PublicKey, error) { neoReader := neo.NewReader(invoker.New(c.client, nil)) - state, err := neoReader.GetAccountState(addr) + accountState, err := neoReader.GetAccountState(addr) if err != nil { return nil, fmt.Errorf("can't get vote info: %w", err) } - if state == nil { + if accountState == nil { return nil, nil } - return state.VoteTo, nil + return accountState.VoteTo, nil } func (c *Client) setActor(act *actor.Actor) { diff --git a/pkg/morph/client/netmap/config.go b/pkg/morph/client/netmap/config.go index f9a8e1159e..7174d603d8 100644 --- a/pkg/morph/client/netmap/config.go +++ b/pkg/morph/client/netmap/config.go @@ -316,7 +316,7 @@ func (c *Client) ReadNetworkConfiguration() (NetworkConfiguration, error) { case EigenTrustAlphaConfig: res.EigenTrustAlpha, err = strconv.ParseFloat(string(value), 64) if err != nil { - return fmt.Errorf("invalid prm %s: %v", EigenTrustAlphaConfig, err) + return fmt.Errorf("invalid prm %s: %w", EigenTrustAlphaConfig, err) } case InnerRingCandidateFeeConfig: res.IRCandidateFee = bytesToUint64(value) diff --git a/pkg/morph/event/container/put_notary.go b/pkg/morph/event/container/put_notary.go index f489537f33..bf5d186464 100644 --- a/pkg/morph/event/container/put_notary.go +++ b/pkg/morph/event/container/put_notary.go @@ -46,7 +46,7 @@ const ( // put container requests. PutNotaryEvent = "put" - // PutNotaryEvent is an ID of notary "put named container" notification. + // PutNamedNotaryEvent is an ID of notary "put named container" notification. PutNamedNotaryEvent = "putNamed" ) diff --git a/pkg/morph/timer/block_test.go b/pkg/morph/timer/block_test.go index a0981ca5a9..ae5310000b 100644 --- a/pkg/morph/timer/block_test.go +++ b/pkg/morph/timer/block_test.go @@ -8,7 +8,7 @@ import ( ) func tickN(t *timer.BlockTimer, n uint32) { - for i := uint32(0); i < n; i++ { + for range n { t.Tick(0) } } @@ -208,7 +208,7 @@ func TestBlockTimer_TickSameHeight(t *testing.T) { require.NoError(t, bt.Reset()) check := func(t *testing.T, h uint32, base, delta int) { - for i := 0; i < 2*int(blockDur); i++ { + for range 2 * blockDur { bt.Tick(h) require.Equal(t, base, baseCounter) require.Equal(t, delta, deltaCounter) diff --git a/pkg/network/group.go b/pkg/network/group.go index 59c82b5440..c5aa53eac6 100644 --- a/pkg/network/group.go +++ b/pkg/network/group.go @@ -68,11 +68,11 @@ func (x AddressGroup) Swap(i, j int) { // MultiAddressIterator is an interface of network address group. type MultiAddressIterator interface { - // Must iterate over network addresses and pass each one + // IterateAddresses must iterate over network addresses and pass each one // to the handler until it returns true. IterateAddresses(func(string) bool) - // Must return number of addresses in group. + // NumberOfAddresses must return number of addresses in group. NumberOfAddresses() int } diff --git a/pkg/services/audit/result_test.go b/pkg/services/audit/result_test.go index 109ffe34d4..d6f7eb6c94 100644 --- a/pkg/services/audit/result_test.go +++ b/pkg/services/audit/result_test.go @@ -1,7 +1,8 @@ package audit_test import ( - "math/rand" + crand "crypto/rand" + "math/rand/v2" "testing" apiaudit "github.com/nspcc-dev/neofs-api-go/v2/audit" @@ -82,7 +83,7 @@ func TestResultMarshaling(t *testing.T) { require.Nil(t, dst.AuditorPublicKey) src.AuditorPublicKey = make([]byte, 33) - rand.Read(src.AuditorPublicKey) + _, _ = crand.Read(src.AuditorPublicKey) require.NoError(t, dst.Unmarshal(src.Marshal())) require.Equal(t, src.AuditorPublicKey, dst.AuditorPublicKey) }) diff --git a/pkg/services/container/announcement/load/controller/calls_test.go b/pkg/services/container/announcement/load/controller/calls_test.go index 4693864cc0..1fd7f727f5 100644 --- a/pkg/services/container/announcement/load/controller/calls_test.go +++ b/pkg/services/container/announcement/load/controller/calls_test.go @@ -126,7 +126,7 @@ func TestSimpleScenario(t *testing.T) { // store one half of "good" announcements to 1st metrics storage, another - to 2nd // and "bad" to both - for i := 0; i < goodNum/2; i++ { + for i := range goodNum / 2 { require.NoError(t, localStorageN1.Put(announces[i])) } diff --git a/pkg/services/container/announcement/load/controller/deps.go b/pkg/services/container/announcement/load/controller/deps.go index 83bd8836d7..f723f12a41 100644 --- a/pkg/services/container/announcement/load/controller/deps.go +++ b/pkg/services/container/announcement/load/controller/deps.go @@ -64,7 +64,7 @@ type Writer interface { // Put must not be called after Close. Put(container.SizeEstimation) error - // Close exits with method-providing Writer. + // Closer close exits with method-providing Writer. // // All cached values must be flushed before // the Close's return. diff --git a/pkg/services/container/announcement/load/route/deps.go b/pkg/services/container/announcement/load/route/deps.go index bef958c413..2f5138db28 100644 --- a/pkg/services/container/announcement/load/route/deps.go +++ b/pkg/services/container/announcement/load/route/deps.go @@ -12,12 +12,12 @@ type ServerInfo interface { // from the route in a binary representation. PublicKey() []byte - // Iterates over network addresses of the node + // IterateAddresses iterates over network addresses of the node // in the route. Breaks iterating on true return // of the handler. IterateAddresses(func(string) bool) - // Returns number of server's network addresses. + // NumberOfAddresses returns number of server's network addresses. NumberOfAddresses() int // ExternalAddresses returns external node's addresses. diff --git a/pkg/services/container/announcement/load/route/placement/calls.go b/pkg/services/container/announcement/load/route/placement/calls.go index 0c4fa702d1..10ecbd112c 100644 --- a/pkg/services/container/announcement/load/route/placement/calls.go +++ b/pkg/services/container/announcement/load/route/placement/calls.go @@ -9,7 +9,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/container" ) -// NextStage composes container nodes for the container and epoch from a, +// NextStage composes container nodes for the container and epoch from a // and returns the list of nodes with maximum weight (one from each vector). // // If passed route has more than one point, then endpoint of the route is reached. diff --git a/pkg/services/container/morph/executor_test.go b/pkg/services/container/morph/executor_test.go index aed03c5ba0..f87667e38a 100644 --- a/pkg/services/container/morph/executor_test.go +++ b/pkg/services/container/morph/executor_test.go @@ -218,8 +218,6 @@ func TestValidateToken(t *testing.T) { _, err = e.Delete(context.TODO(), &tokV2, &reqBody) require.Error(t, err) - - return }) t.Run("wrong verb token", func(t *testing.T) { @@ -235,8 +233,6 @@ func TestValidateToken(t *testing.T) { _, err = e.Delete(context.TODO(), &tokV2, &reqBody) require.Error(t, err) - - return }) t.Run("incorrect cID", func(t *testing.T) { diff --git a/pkg/services/control/ir/server/deps.go b/pkg/services/control/ir/server/deps.go index 2fdc6751f1..9b38101b40 100644 --- a/pkg/services/control/ir/server/deps.go +++ b/pkg/services/control/ir/server/deps.go @@ -5,7 +5,7 @@ import control "github.com/nspcc-dev/neofs-node/pkg/services/control/ir" // HealthChecker is component interface for calculating // the current health status of a node. type HealthChecker interface { - // Must calculate and return current health status of the IR application. + // HealthStatus must calculate and return current health status of the IR application. // // If status can not be calculated for any reason, // control.HealthStatus_HEALTH_STATUS_UNDEFINED should be returned. diff --git a/pkg/services/control/server/server.go b/pkg/services/control/server/server.go index 806570b973..5da9823600 100644 --- a/pkg/services/control/server/server.go +++ b/pkg/services/control/server/server.go @@ -26,13 +26,13 @@ type Server struct { // HealthChecker is component interface for calculating // the current health status of a node. type HealthChecker interface { - // Must calculate and return current status of the node in NeoFS network map. + // NetmapStatus must calculate and return current status of the node in NeoFS network map. // // If status can not be calculated for any reason, // control.netmapStatus_STATUS_UNDEFINED should be returned. NetmapStatus() control.NetmapStatus - // Must calculate and return current health status of the node application. + // HealthStatus must calculate and return current health status of the node application. // // If status can not be calculated for any reason, // control.HealthStatus_HEALTH_STATUS_UNDEFINED should be returned. diff --git a/pkg/services/control/service_test.go b/pkg/services/control/service_test.go index 0dc290cd8f..38bb5cb83d 100644 --- a/pkg/services/control/service_test.go +++ b/pkg/services/control/service_test.go @@ -76,16 +76,16 @@ func equalListShardResponseBodies(b1, b2 *control.ListShardsResponse_Body) bool } for i := range b1.Shards { + info1 := b1.Shards[i].GetBlobstor() + info2 := b2.Shards[i].GetBlobstor() + if b1.Shards[i].GetMetabasePath() != b2.Shards[i].GetMetabasePath() || b1.Shards[i].GetWritecachePath() != b2.Shards[i].GetWritecachePath() || b1.Shards[i].GetPiloramaPath() != b2.Shards[i].GetPiloramaPath() || - !bytes.Equal(b1.Shards[i].GetShard_ID(), b2.Shards[i].GetShard_ID()) { + !bytes.Equal(b1.Shards[i].GetShard_ID(), b2.Shards[i].GetShard_ID()) || + !compareBlobstorInfo(info1, info2) { return false } - - info1 := b1.Shards[i].GetBlobstor() - info2 := b2.Shards[i].GetBlobstor() - return compareBlobstorInfo(info1, info2) } for i := range b1.Shards { @@ -101,6 +101,7 @@ func equalListShardResponseBodies(b1, b2 *control.ListShardsResponse_Body) bool return true } + func compareBlobstorInfo(a, b []*control.BlobstorInfo) bool { if len(a) != len(b) { return false diff --git a/pkg/services/netmap/executor.go b/pkg/services/netmap/executor.go index d186fbdc3c..fd9cbfc54a 100644 --- a/pkg/services/netmap/executor.go +++ b/pkg/services/netmap/executor.go @@ -23,7 +23,7 @@ type executorSvc struct { // NodeState encapsulates information // about current node state. type NodeState interface { - // Must return current node state + // LocalNodeInfo must return current node state // in NeoFS API v2 NodeInfo structure. LocalNodeInfo() (*netmap.NodeInfo, error) @@ -36,7 +36,7 @@ type NodeState interface { // NetworkInfo encapsulates source of the // recent information about the NeoFS network. type NetworkInfo interface { - // Must return recent network information in NeoFS API v2 NetworkInfo structure. + // Dump must return recent network information in NeoFS API v2 NetworkInfo structure. // // If protocol version is <=2.9, MillisecondsPerBlock and network config should be unset. Dump(versionsdk.Version) (*netmapSDK.NetworkInfo, error) diff --git a/pkg/services/object/acl/v2/util_test.go b/pkg/services/object/acl/v2/util_test.go index 5c41276d71..852fe52a48 100644 --- a/pkg/services/object/acl/v2/util_test.go +++ b/pkg/services/object/acl/v2/util_test.go @@ -53,7 +53,7 @@ func testGenerateMetaHeader(depth uint32, b *acl.BearerToken, s *session.Token) metaHeader.SetBearerToken(b) metaHeader.SetSessionToken(s) - for i := uint32(0); i < depth; i++ { + for range depth { link := metaHeader metaHeader = new(session.RequestMetaHeader) metaHeader.SetOrigin(link) diff --git a/pkg/services/object/delete/service.go b/pkg/services/object/delete/service.go index 56e7325fe4..849c5f22bb 100644 --- a/pkg/services/object/delete/service.go +++ b/pkg/services/object/delete/service.go @@ -21,11 +21,11 @@ type Option func(*cfg) type NetworkInfo interface { netmap.State - // Must return the lifespan of the tombstones + // TombstoneLifetime must return the lifespan of the tombstones // in the NeoFS epochs. TombstoneLifetime() (uint64, error) - // Returns user ID of the local storage node. Result must not be nil. + // LocalNodeID returns user ID of the local storage node. Result must not be nil. // New tombstone objects will have the result as an owner ID if removal is executed w/o a session. LocalNodeID() user.ID } diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index ff996b0db7..0e5d80dc1e 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -54,12 +54,6 @@ type testClient struct { } } -type testEpochReceiver uint64 - -func (e testEpochReceiver) currentEpoch() (uint64, error) { - return uint64(e), nil -} - func newTestStorage() *testStorage { return &testStorage{ inhumed: make(map[string]struct{}), @@ -195,11 +189,6 @@ func (s *testStorage) inhume(addr oid.Address) { s.inhumed[addr.EncodeToString()] = struct{}{} } -const ( - splitV1 = iota - splitV2 -) - func generateObject(addr oid.Address, prev *oid.ID, payload []byte, children ...oid.ID) *objectSDK.Object { obj := objectSDK.New() obj.SetContainerID(addr.Container()) @@ -268,7 +257,7 @@ func TestGetLocalOnly(t *testing.T) { payloadSz := uint64(10) payload := make([]byte, payloadSz) - rand.Read(payload) + _, _ = rand.Read(payload) addr := oidtest.Address() obj := generateObject(addr, nil, payload) @@ -422,14 +411,14 @@ func testNodeMatrix(t testing.TB, dim []int) ([][]netmap.NodeInfo, [][]string) { ns := make([]netmap.NodeInfo, dim[i]) as := make([]string, dim[i]) - for j := 0; j < dim[i]; j++ { + for j := range dim[i] { a := fmt.Sprintf("/ip4/192.168.0.%s/tcp/%s", strconv.Itoa(i), strconv.Itoa(60000+j), ) bPubKey := make([]byte, 33) - rand.Read(bPubKey) + _, _ = rand.Read(bPubKey) var ni netmap.NodeInfo ni.SetNetworkEndpoints(a) @@ -468,7 +457,7 @@ func generateChain(ln int, cnr cid.ID) ([]*objectSDK.Object, []oid.ID, []byte) { addr.SetObject(curID) payloadPart := make([]byte, 10) - rand.Read(payloadPart) + _, _ = rand.Read(payloadPart) o := generateObject(addr, prevID, []byte{byte(i)}) o.SetPayload(payloadPart) @@ -558,7 +547,7 @@ func TestGetRemoteSmall(t *testing.T) { payloadSz := uint64(10) payload := make([]byte, payloadSz) - rand.Read(payload) + _, _ = rand.Read(payload) obj := generateObject(addr, nil, payload) diff --git a/pkg/services/object/internal/target.go b/pkg/services/object/internal/target.go index cc9bc82f34..828eaacf8e 100644 --- a/pkg/services/object/internal/target.go +++ b/pkg/services/object/internal/target.go @@ -24,7 +24,7 @@ type HeaderWriter interface { // Target is an interface of the object writer. type Target interface { HeaderWriter - // Write writes object payload chunk. + // Writer writes object payload chunk. // // Can be called multiple times. // diff --git a/pkg/services/object/put/proto_test.go b/pkg/services/object/put/proto_test.go index fe18ea6c7a..34bf325248 100644 --- a/pkg/services/object/put/proto_test.go +++ b/pkg/services/object/put/proto_test.go @@ -1,7 +1,7 @@ package putsvc import ( - "math/rand" + "crypto/rand" "testing" objectv2 "github.com/nspcc-dev/neofs-api-go/v2/object" @@ -19,7 +19,7 @@ import ( func TestUnaryReplicateRequest(t *testing.T) { // prepare replicated object payload := make([]byte, 1024) - rand.Read(payload) + _, _ = rand.Read(payload) obj := objecttest.Object() obj.SetPayload(payload) id := oidtest.ID() diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index 14c42a19c3..1ade31d071 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -106,8 +106,8 @@ func (c *testClientCache) get(info clientcore.NodeInfo) (searchClient, error) { return v, nil } -func (s *testStorage) search(exec *execCtx) ([]oid.ID, error) { - v, ok := s.items[exec.containerID().EncodeToString()] +func (ts *testStorage) search(exec *execCtx) ([]oid.ID, error) { + v, ok := ts.items[exec.containerID().EncodeToString()] if !ok { return nil, nil } @@ -115,8 +115,8 @@ func (s *testStorage) search(exec *execCtx) ([]oid.ID, error) { return v.ids, v.err } -func (c *testStorage) searchObjects(_ context.Context, exec *execCtx, _ clientcore.NodeInfo) ([]oid.ID, error) { - v, ok := c.items[exec.containerID().EncodeToString()] +func (ts *testStorage) searchObjects(_ context.Context, exec *execCtx, _ clientcore.NodeInfo) ([]oid.ID, error) { + v, ok := ts.items[exec.containerID().EncodeToString()] if !ok { return nil, nil } @@ -124,15 +124,15 @@ func (c *testStorage) searchObjects(_ context.Context, exec *execCtx, _ clientco return v.ids, v.err } -func (c *testStorage) addResult(addr cid.ID, ids []oid.ID, err error) { - c.items[addr.EncodeToString()] = idsErr{ +func (ts *testStorage) addResult(addr cid.ID, ids []oid.ID, err error) { + ts.items[addr.EncodeToString()] = idsErr{ ids: ids, err: err, } } func testSHA256() (cs [sha256.Size]byte) { - rand.Read(cs[:]) + _, _ = rand.Read(cs[:]) return cs } @@ -206,14 +206,14 @@ func testNodeMatrix(t testing.TB, dim []int) ([][]netmap.NodeInfo, [][]string) { ns := make([]netmap.NodeInfo, dim[i]) as := make([]string, dim[i]) - for j := 0; j < dim[i]; j++ { + for j := range dim[i] { a := fmt.Sprintf("/ip4/192.168.0.%s/tcp/%s", strconv.Itoa(i), strconv.Itoa(60000+j), ) bPubKey := make([]byte, 33) - rand.Read(bPubKey) + _, _ = rand.Read(bPubKey) var ni netmap.NodeInfo ni.SetNetworkEndpoints(a) diff --git a/pkg/services/object/tombstone/verify_test.go b/pkg/services/object/tombstone/verify_test.go index 0b37657421..53327f4de7 100644 --- a/pkg/services/object/tombstone/verify_test.go +++ b/pkg/services/object/tombstone/verify_test.go @@ -82,9 +82,9 @@ func TestVerifier_VerifyTomb(t *testing.T) { cnr := cidtest.ID() children := []object.Object{ - objectWithCnr(t, cnr, false), - objectWithCnr(t, cnr, false), - objectWithCnr(t, cnr, false), + objectWithCnr(cnr, false), + objectWithCnr(cnr, false), + objectWithCnr(cnr, false), } *os = testObjectSource{ @@ -100,7 +100,7 @@ func TestVerifier_VerifyTomb(t *testing.T) { var tomb object.Tombstone cnr := cidtest.ID() - child := objectWithCnr(t, cnr, true) + child := objectWithCnr(cnr, true) childID, _ := child.ID() splitID := child.SplitID() @@ -124,7 +124,7 @@ func TestVerifier_VerifyTomb(t *testing.T) { }) t.Run("LINKs can be found", func(t *testing.T) { - link := objectWithCnr(t, cnr, false) + link := objectWithCnr(cnr, false) link.SetChildren(childID) linkID, _ := link.ID() @@ -255,7 +255,7 @@ func objectsToOIDs(oo []object.Object) []oid.ID { return res } -func objectWithCnr(t *testing.T, cnr cid.ID, hasParent bool) object.Object { +func objectWithCnr(cnr cid.ID, hasParent bool) object.Object { obj := objecttest.Object() obj.SetContainerID(cnr) diff --git a/pkg/services/object_manager/placement/traverser_test.go b/pkg/services/object_manager/placement/traverser_test.go index ab18dac444..2aeb9f85d0 100644 --- a/pkg/services/object_manager/placement/traverser_test.go +++ b/pkg/services/object_manager/placement/traverser_test.go @@ -40,7 +40,7 @@ func copyVectors(v [][]netmap.NodeInfo) [][]netmap.NodeInfo { return vc } -func testPlacement(t *testing.T, ss, rs []int) ([][]netmap.NodeInfo, container.Container) { +func testPlacement(ss, rs []int) ([][]netmap.NodeInfo, container.Container) { nodes := make([][]netmap.NodeInfo, 0, len(rs)) replicas := make([]netmap.ReplicaDescriptor, 0, len(rs)) num := uint32(0) @@ -48,7 +48,7 @@ func testPlacement(t *testing.T, ss, rs []int) ([][]netmap.NodeInfo, container.C for i := range ss { ns := make([]netmap.NodeInfo, 0, ss[i]) - for j := 0; j < ss[i]; j++ { + for range ss[i] { ns = append(ns, testNode(num)) num++ } @@ -83,7 +83,7 @@ func TestTraverserObjectScenarios(t *testing.T) { selectors := []int{2, 3} replicas := []int{1, 2} - nodes, cnr := testPlacement(t, selectors, replicas) + nodes, cnr := testPlacement(selectors, replicas) nodesCopy := copyVectors(nodes) @@ -112,7 +112,7 @@ func TestTraverserObjectScenarios(t *testing.T) { selectors := []int{5, 3} replicas := []int{2, 2} - nodes, cnr := testPlacement(t, selectors, replicas) + nodes, cnr := testPlacement(selectors, replicas) nodesCopy := copyVectors(nodes) @@ -125,7 +125,7 @@ func TestTraverserObjectScenarios(t *testing.T) { ) require.NoError(t, err) - for i := 0; i < len(nodes[0]); i++ { + for range len(nodes[0]) { require.NotNil(t, tr.Next()) } @@ -141,7 +141,7 @@ func TestTraverserObjectScenarios(t *testing.T) { selectors := []int{5, 3} replicas := []int{2, 2} - nodes, cnr := testPlacement(t, selectors, replicas) + nodes, cnr := testPlacement(selectors, replicas) nodesCopy := copyVectors(nodes) @@ -164,7 +164,7 @@ func TestTraverserObjectScenarios(t *testing.T) { require.Empty(t, tr.Next()) require.False(t, tr.Success()) - for i := 0; i < replicas[curVector]; i++ { + for range replicas[curVector] { tr.SubmitSuccess() } } @@ -184,7 +184,7 @@ func TestTraverserObjectScenarios(t *testing.T) { selectors := []int{2, 3} replicas := []int{1, 2} - nodes, cnr := testPlacement(t, selectors, replicas) + nodes, cnr := testPlacement(selectors, replicas) tr, err := NewTraverser( ForContainer(cnr), @@ -214,7 +214,7 @@ func TestCopiesNumber(t *testing.T) { selectors := []int{1, 2, 3} // 3 vectors with 1, 2, 3 lengths replicas := []int{0, 2, 3} // REP 0 ... REP 2 ... REP 3 - nodes, cnr := testPlacement(t, selectors, replicas) + nodes, cnr := testPlacement(selectors, replicas) nodesCopy := copyVectors(nodes) tr, err := NewTraverser( @@ -241,7 +241,7 @@ func TestCopiesNumber(t *testing.T) { selectors := []int{1, 1, 1} // 3 vectors with 1, 1, 1 lengths replicas := []int{1, 1, 1} // REP 1 ... REP 1 ... REP 1 - nodes, cnr := testPlacement(t, selectors, replicas) + nodes, cnr := testPlacement(selectors, replicas) nodesCopy := copyVectors(nodes) tr, err := NewTraverser( @@ -265,7 +265,7 @@ func TestCopiesNumber(t *testing.T) { selectors := []int{10, 10, 10} // 3 vectors with 10, 10, 10 lengths replicas := []int{1, 2, 3} // REP 1 ... REP 2 ... REP 3 - nodes, cnr := testPlacement(t, selectors, replicas) + nodes, cnr := testPlacement(selectors, replicas) nodesCopy := copyVectors(nodes) tr, err := NewTraverser( diff --git a/pkg/services/reputation/common/deps.go b/pkg/services/reputation/common/deps.go index 69cd28e335..f56819d54b 100644 --- a/pkg/services/reputation/common/deps.go +++ b/pkg/services/reputation/common/deps.go @@ -13,7 +13,7 @@ import ( type Context interface { context.Context - // Must return epoch number to select the values. + // Epoch must return epoch number to select the values. Epoch() uint64 } @@ -32,7 +32,7 @@ type Writer interface { // Write must not be called after Close. Write(reputation.Trust) error - // Close exits with method-providing Writer. + // Closer close exits with method-providing Writer. // // All cached values must be flushed before // the Close's return. @@ -70,12 +70,12 @@ type ServerInfo interface { // from the route in a binary representation. PublicKey() []byte - // Iterates over network addresses of the node + // IterateAddresses iterates over network addresses of the node // in the route. Breaks iterating on true return // of the handler. IterateAddresses(func(string) bool) - // Returns number of server's network addresses. + // NumberOfAddresses returns number of server's network addresses. NumberOfAddresses() int // ExternalAddresses returns external addresses of a node. diff --git a/pkg/services/reputation/eigentrust/calculator/deps.go b/pkg/services/reputation/eigentrust/calculator/deps.go index 36c978a02a..466369b5a4 100644 --- a/pkg/services/reputation/eigentrust/calculator/deps.go +++ b/pkg/services/reputation/eigentrust/calculator/deps.go @@ -11,16 +11,16 @@ import ( type Context interface { context.Context - // Must return epoch number to select the values + // Epoch must return epoch number to select the values // for global trust calculation. Epoch() uint64 - // Must return the sequence number of the iteration. + // I must return the sequence number of the iteration. I() uint32 } // InitialTrustSource must provide initial(non-calculated) -// trusts to current node's daughter. Realization may depends +// trusts to current node's daughter. Realization may depend // on daughter. type InitialTrustSource interface { InitialTrust(apireputation.PeerID) (reputation.TrustValue, error) diff --git a/pkg/services/reputation/eigentrust/controller/deps.go b/pkg/services/reputation/eigentrust/controller/deps.go index 8c4752657e..1a900b03a3 100644 --- a/pkg/services/reputation/eigentrust/controller/deps.go +++ b/pkg/services/reputation/eigentrust/controller/deps.go @@ -9,14 +9,14 @@ import ( type IterationContext interface { context.Context - // Must return epoch number to select the values + // Epoch must return epoch number to select the values // for global trust calculation. Epoch() uint64 - // Must return the sequence number of the iteration. + // I must return the sequence number of the iteration. I() uint32 - // Must return true if I() is the last iteration. + // Last must return true if I() is the last iteration. Last() bool } @@ -24,7 +24,7 @@ type IterationContext interface { // responsible for calculating the global trust of // daughter nodes in terms of EigenTrust algorithm. type DaughtersTrustCalculator interface { - // Must perform the iteration step of the loop + // Calculate must perform the iteration step of the loop // for computing the global trust of all daughter // nodes and sending intermediate values // according to EigenTrust description diff --git a/pkg/util/rand/rand.go b/pkg/util/rand/rand.go index 97508f82af..a06296a07f 100644 --- a/pkg/util/rand/rand.go +++ b/pkg/util/rand/rand.go @@ -13,7 +13,7 @@ func Uint64() uint64 { return source.Uint64() } -// Uint64 returns a random uint32 value. +// Uint32 returns a random uint32 value. func Uint32() uint32 { return source.Uint32() }