diff --git a/api/keystore/keystore.go b/api/keystore/keystore.go index ea8c871848b1..b6b96b89119d 100644 --- a/api/keystore/keystore.go +++ b/api/keystore/keystore.go @@ -242,12 +242,12 @@ func (ks *keystore) DeleteUser(username, pw string) error { defer it.Release() for it.Next() { - if err = dataBatch.Delete(it.Key()); err != nil { + if err := dataBatch.Delete(it.Key()); err != nil { return err } } - if err = it.Error(); err != nil { + if err := it.Error(); err != nil { return err } diff --git a/api/keystore/service_test.go b/api/keystore/service_test.go index b208d1e77a57..8ef100f0c268 100644 --- a/api/keystore/service_test.go +++ b/api/keystore/service_test.go @@ -405,7 +405,8 @@ func TestServiceDeleteUser(t *testing.T) { } // deleted user details should be available to create user again. - if err = s.CreateUser(nil, &api.UserPass{Username: testUser, Password: password}, &api.EmptyReply{}); err != nil { + err := s.CreateUser(nil, &api.UserPass{Username: testUser, Password: password}, &api.EmptyReply{}) + if err != nil { t.Fatalf("failed to create user: %v", err) } } diff --git a/config/config.go b/config/config.go index c888cf4610d8..5d48244bd74a 100644 --- a/config/config.go +++ b/config/config.go @@ -223,7 +223,8 @@ func getHTTPConfig(v *viper.Viper) (node.HTTPConfig, error) { } case v.IsSet(HTTPSKeyFileKey): httpsKeyFilepath := GetExpandedArg(v, HTTPSKeyFileKey) - if httpsKey, err = os.ReadFile(filepath.Clean(httpsKeyFilepath)); err != nil { + httpsKey, err = os.ReadFile(filepath.Clean(httpsKeyFilepath)) + if err != nil { return node.HTTPConfig{}, err } } @@ -237,7 +238,8 @@ func getHTTPConfig(v *viper.Viper) (node.HTTPConfig, error) { } case v.IsSet(HTTPSCertFileKey): httpsCertFilepath := GetExpandedArg(v, HTTPSCertFileKey) - if httpsCert, err = os.ReadFile(filepath.Clean(httpsCertFilepath)); err != nil { + httpsCert, err = os.ReadFile(filepath.Clean(httpsCertFilepath)) + if err != nil { return node.HTTPConfig{}, err } } diff --git a/database/test_database.go b/database/test_database.go index b361fbf33553..4ea7a99bbbb0 100644 --- a/database/test_database.go +++ b/database/test_database.go @@ -261,7 +261,7 @@ func TestBatchPut(t *testing.T, db Database) { t.Fatalf("Unexpected error on db.Delete: %s", err) } - if batch = db.NewBatch(); batch == nil { + if batch := db.NewBatch(); batch == nil { t.Fatalf("db.NewBatch returned nil") } else if err := batch.Put(key, value); err != nil { t.Fatalf("Unexpected error on batch.Put: %s", err) diff --git a/indexer/index.go b/indexer/index.go index a1036d47b759..b997886e8cb9 100644 --- a/indexer/index.go +++ b/indexer/index.go @@ -212,7 +212,7 @@ func (i *index) getContainerByIndexBytes(indexBytes []byte) (Container, error) { return Container{}, fmt.Errorf("couldn't read from database: %w", err) } var container Container - if _, err = i.codec.Unmarshal(containerBytes, &container); err != nil { + if _, err := i.codec.Unmarshal(containerBytes, &container); err != nil { return Container{}, fmt.Errorf("couldn't unmarshal container: %w", err) } return container, nil diff --git a/ipcs/socket/socket_test.go b/ipcs/socket/socket_test.go index 4baf0a4ce42a..c71f3cd2fe65 100644 --- a/ipcs/socket/socket_test.go +++ b/ipcs/socket/socket_test.go @@ -47,11 +47,11 @@ func TestSocketSendAndReceive(t *testing.T) { // Test max message size client.SetMaxMessageSize(msgLen) - if _, err = client.Recv(); err != nil { + if _, err := client.Recv(); err != nil { t.Fatal("Failed to receive from socket:", err.Error()) } client.SetMaxMessageSize(msgLen - 1) - if _, err = client.Recv(); err != ErrMessageTooLarge { + if _, err := client.Recv(); err != ErrMessageTooLarge { t.Fatal("Should have received message too large error, got:", err) } } diff --git a/ipcs/socket/socket_unix.go b/ipcs/socket/socket_unix.go index 578a29df2aa0..d4f6307c06f3 100644 --- a/ipcs/socket/socket_unix.go +++ b/ipcs/socket/socket_unix.go @@ -23,18 +23,19 @@ func listen(addr string) (net.Listener, error) { return nil, err } - // Try to listen on the socket. If that fails we check to see if it's a stale - // socket and remove it if it is. Then we try to listen one more time. + // Try to listen on the socket. l, err := net.ListenUnix("unix", uAddr) - if err != nil { - if err = removeIfStaleUnixSocket(addr); err != nil { - return nil, err - } - if l, err = net.ListenUnix("unix", uAddr); err != nil { - return nil, err - } + if err == nil { + return l, nil } - return l, err + + // Check to see if the socket is stale and remove it if it is. + if err := removeIfStaleUnixSocket(addr); err != nil { + return nil, err + } + + // Try listening again now that it shouldn't be stale. + return net.ListenUnix("unix", uAddr) } // Dial creates a new *Client connected to the given address over a Unix socket @@ -59,13 +60,16 @@ func Dial(addr string) (*Client, error) { // that is refusing connections func removeIfStaleUnixSocket(socketPath string) error { // Ensure it's a socket; if not return without an error - if st, err := os.Stat(socketPath); err != nil || st.Mode()&os.ModeType != os.ModeSocket { + st, err := os.Stat(socketPath) + if err != nil { + return nil + } + if st.Mode()&os.ModeType != os.ModeSocket { return nil } // Try to connect conn, err := net.DialTimeout("unix", socketPath, staleSocketTimeout) - switch { // The connection was refused so this socket is stale; remove it case isSyscallError(err, syscall.ECONNREFUSED): @@ -74,6 +78,8 @@ func removeIfStaleUnixSocket(socketPath string) error { // The socket is alive so close this connection and leave the socket alone case err == nil: return conn.Close() + + default: + return nil } - return nil } diff --git a/node/node.go b/node/node.go index 421e130f3f24..dfd48c3d4ea1 100644 --- a/node/node.go +++ b/node/node.go @@ -1237,7 +1237,6 @@ func (n *Node) Initialize( ) error { n.Log = logger n.Config = config - var err error n.ID = ids.NodeIDFromCert(n.Config.StakingTLSCert.Leaf) n.LogFactory = logFactory n.DoneShuttingDown.Add(1) @@ -1251,11 +1250,12 @@ func (n *Node) Initialize( zap.Reflect("config", n.Config), ) - if err = n.initBeacons(); err != nil { // Configure the beacons + if err := n.initBeacons(); err != nil { // Configure the beacons return fmt.Errorf("problem initializing node beacons: %w", err) } // Set up tracer + var err error n.tracer, err = trace.New(n.Config.TraceConfig) if err != nil { return fmt.Errorf("couldn't initialize tracer: %w", err) @@ -1307,7 +1307,7 @@ func (n *Node) Initialize( } n.initCPUTargeter(&config.CPUTargeterConfig, primaryNetVdrs) n.initDiskTargeter(&config.DiskTargeterConfig, primaryNetVdrs) - if err = n.initNetworking(primaryNetVdrs); err != nil { // Set up networking layer. + if err := n.initNetworking(primaryNetVdrs); err != nil { // Set up networking layer. return fmt.Errorf("problem initializing networking: %w", err) } diff --git a/snow/consensus/avalanche/poll/set_test.go b/snow/consensus/avalanche/poll/set_test.go index e4a35eccaec6..f9be20888aa7 100644 --- a/snow/consensus/avalanche/poll/set_test.go +++ b/snow/consensus/avalanche/poll/set_test.go @@ -70,11 +70,11 @@ func TestCreateAndFinishPoll(t *testing.T) { t.Fatalf("Should only have one active poll") } else if results := s.Vote(1, vdr1, votes); len(results) > 0 { t.Fatalf("Shouldn't have been able to finish a non-existent poll") - } else if results = s.Vote(0, vdr1, votes); len(results) > 0 { + } else if results := s.Vote(0, vdr1, votes); len(results) > 0 { t.Fatalf("Shouldn't have been able to finish an ongoing poll") - } else if results = s.Vote(0, vdr1, votes); len(results) > 0 { + } else if results := s.Vote(0, vdr1, votes); len(results) > 0 { t.Fatalf("Should have dropped a duplicated poll") - } else if results = s.Vote(0, vdr2, votes); len(results) == 0 { + } else if results := s.Vote(0, vdr2, votes); len(results) == 0 { t.Fatalf("Should have finished the poll") } else if len(results) != 1 { t.Fatalf("Wrong number of results returned") diff --git a/snow/consensus/snowman/poll/set_test.go b/snow/consensus/snowman/poll/set_test.go index 0dfbc325fe57..82df52a3e31e 100644 --- a/snow/consensus/snowman/poll/set_test.go +++ b/snow/consensus/snowman/poll/set_test.go @@ -245,11 +245,11 @@ func TestCreateAndFinishSuccessfulPoll(t *testing.T) { t.Fatalf("Should only have one active poll") } else if results := s.Vote(1, vdr1, vtxID); len(results) > 0 { t.Fatalf("Shouldn't have been able to finish a non-existent poll") - } else if results = s.Vote(0, vdr1, vtxID); len(results) > 0 { + } else if results := s.Vote(0, vdr1, vtxID); len(results) > 0 { t.Fatalf("Shouldn't have been able to finish an ongoing poll") - } else if results = s.Vote(0, vdr1, vtxID); len(results) > 0 { + } else if results := s.Vote(0, vdr1, vtxID); len(results) > 0 { t.Fatalf("Should have dropped a duplicated poll") - } else if results = s.Vote(0, vdr2, vtxID); len(results) == 0 { + } else if results := s.Vote(0, vdr2, vtxID); len(results) == 0 { t.Fatalf("Should have finished the") } else if len(results) != 1 { t.Fatalf("Wrong number of results returned") @@ -290,11 +290,11 @@ func TestCreateAndFinishFailedPoll(t *testing.T) { t.Fatalf("Should only have one active poll") } else if results := s.Drop(1, vdr1); len(results) > 0 { t.Fatalf("Shouldn't have been able to finish a non-existent poll") - } else if results = s.Drop(0, vdr1); len(results) > 0 { + } else if results := s.Drop(0, vdr1); len(results) > 0 { t.Fatalf("Shouldn't have been able to finish an ongoing poll") - } else if results = s.Drop(0, vdr1); len(results) > 0 { + } else if results := s.Drop(0, vdr1); len(results) > 0 { t.Fatalf("Should have dropped a duplicated poll") - } else if results = s.Drop(0, vdr2); len(results) == 0 { + } else if results := s.Drop(0, vdr2); len(results) == 0 { t.Fatalf("Should have finished the") } else if list := results[0].List(); len(list) != 0 { t.Fatalf("Wrong number of vertices returned") diff --git a/snow/engine/avalanche/state/state.go b/snow/engine/avalanche/state/state.go index 82c0aaeb9fcf..a808b3fea960 100644 --- a/snow/engine/avalanche/state/state.go +++ b/snow/engine/avalanche/state/state.go @@ -28,18 +28,13 @@ type state struct { // Returns nil if it's not found. // TODO this should return an error func (s *state) Vertex(id ids.ID) vertex.StatelessVertex { - var ( - vtx vertex.StatelessVertex - bytes []byte - err error - ) - if vtxIntf, found := s.dbCache.Get(id); found { - vtx, _ = vtxIntf.(vertex.StatelessVertex) + vtx, _ := vtxIntf.(vertex.StatelessVertex) return vtx } - if bytes, err = s.db.Get(id[:]); err != nil { + bytes, err := s.db.Get(id[:]) + if err != nil { s.log.Verbo("failed to get vertex from database", zap.Binary("key", id[:]), zap.Error(err), @@ -48,7 +43,8 @@ func (s *state) Vertex(id ids.ID) vertex.StatelessVertex { return nil } - if vtx, err = s.serializer.parseVertex(bytes); err != nil { + vtx, err := s.serializer.parseVertex(bytes) + if err != nil { s.log.Error("failed parsing saved vertex", zap.Binary("key", id[:]), zap.Binary("vertex", bytes), diff --git a/snow/engine/snowman/block/batched_vm.go b/snow/engine/snowman/block/batched_vm.go index 0fb79c02fb93..32b9ef90ba53 100644 --- a/snow/engine/snowman/block/batched_vm.go +++ b/snow/engine/snowman/block/batched_vm.go @@ -74,7 +74,8 @@ func GetAncestors( ancestorsBytesLen := len(blk.Bytes()) + wrappers.IntLen // length, in bytes, of all elements of ancestors for numFetched := 1; numFetched < maxBlocksNum && time.Since(startTime) < maxBlocksRetrivalTime; numFetched++ { - if blk, err = vm.GetBlock(ctx, blk.Parent()); err != nil { + blk, err = vm.GetBlock(ctx, blk.Parent()) + if err != nil { break } blkBytes := blk.Bytes() diff --git a/snow/engine/snowman/syncer/state_syncer.go b/snow/engine/snowman/syncer/state_syncer.go index d672e523bbdc..d0f32e1e67d2 100644 --- a/snow/engine/snowman/syncer/state_syncer.go +++ b/snow/engine/snowman/syncer/state_syncer.go @@ -416,7 +416,7 @@ func (ss *stateSyncer) startup(ctx context.Context) error { } ss.frontierSeeders = validators.NewSet() - if err = ss.frontierSeeders.Set(beacons); err != nil { + if err := ss.frontierSeeders.Set(beacons); err != nil { return err } diff --git a/snow/engine/snowman/transitive.go b/snow/engine/snowman/transitive.go index 42ae66e2bf0d..fd040a30f251 100644 --- a/snow/engine/snowman/transitive.go +++ b/snow/engine/snowman/transitive.go @@ -586,12 +586,13 @@ func (t *Transitive) issueWithAncestors(ctx context.Context, blk snowman.Block) // issue [blk] and its ancestors into consensus status := blk.Status() for status.Fetched() && !t.wasIssued(blk) { - if err := t.issue(ctx, blk); err != nil { + err := t.issue(ctx, blk) + if err != nil { return false, err } blkID = blk.Parent() - var err error - if blk, err = t.GetBlock(ctx, blkID); err != nil { + blk, err = t.GetBlock(ctx, blkID) + if err != nil { status = choices.Unknown break } diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 1d949a371112..b36ade7fb2c9 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -2437,7 +2437,7 @@ func TestImportExportKey(t *testing.T) { PrivateKey: sk, } importReply := &api.JSONAddress{} - if err = s.ImportKey(nil, importArgs, importReply); err != nil { + if err := s.ImportKey(nil, importArgs, importReply); err != nil { t.Fatal(err) } @@ -2453,7 +2453,7 @@ func TestImportExportKey(t *testing.T) { Address: addrStr, } exportReply := &ExportKeyReply{} - if err = s.ExportKey(nil, exportArgs, exportReply); err != nil { + if err := s.ExportKey(nil, exportArgs, exportReply); err != nil { t.Fatal(err) } @@ -2486,7 +2486,7 @@ func TestImportAVMKeyNoDuplicates(t *testing.T) { PrivateKey: sk, } reply := api.JSONAddress{} - if err = s.ImportKey(nil, &args, &reply); err != nil { + if err := s.ImportKey(nil, &args, &reply); err != nil { t.Fatal(err) } @@ -2500,7 +2500,7 @@ func TestImportAVMKeyNoDuplicates(t *testing.T) { } reply2 := api.JSONAddress{} - if err = s.ImportKey(nil, &args, &reply2); err != nil { + if err := s.ImportKey(nil, &args, &reply2); err != nil { t.Fatal(err) } @@ -2644,7 +2644,7 @@ func TestSendMultiple(t *testing.T) { t.Fatal("Transaction ID returned by SendMultiple does not match the transaction found in vm's pending transactions") } - if _, err = vm.GetTx(context.Background(), reply.TxID); err != nil { + if _, err := vm.GetTx(context.Background(), reply.TxID); err != nil { t.Fatalf("Failed to retrieve created transaction: %s", err) } }) diff --git a/vms/avm/tx_semantic_verify_test.go b/vms/avm/tx_semantic_verify_test.go index 7cb6a862d118..63230b041315 100644 --- a/vms/avm/tx_semantic_verify_test.go +++ b/vms/avm/tx_semantic_verify_test.go @@ -226,7 +226,7 @@ func TestBaseTxSemanticVerifyUnauthorizedFx(t *testing.T) { } vm.batchTimeout = 0 - if err = vm.SetState(context.Background(), snow.Bootstrapping); err != nil { + if err := vm.SetState(context.Background(), snow.Bootstrapping); err != nil { t.Fatal(err) } @@ -645,7 +645,7 @@ func TestBaseTxSemanticVerifyPendingUnauthorizedFx(t *testing.T) { } vm.batchTimeout = 0 - if err = vm.SetState(context.Background(), snow.Bootstrapping); err != nil { + if err := vm.SetState(context.Background(), snow.Bootstrapping); err != nil { t.Fatal(err) } @@ -793,7 +793,7 @@ func TestBaseTxSemanticVerifyPendingInvalidSignature(t *testing.T) { } vm.batchTimeout = 0 - if err = vm.SetState(context.Background(), snow.Bootstrapping); err != nil { + if err := vm.SetState(context.Background(), snow.Bootstrapping); err != nil { t.Fatal(err) } diff --git a/vms/avm/vm_test.go b/vms/avm/vm_test.go index 2653c2f09951..ab2646223dc4 100644 --- a/vms/avm/vm_test.go +++ b/vms/avm/vm_test.go @@ -703,7 +703,7 @@ func TestIssueNFT(t *testing.T) { t.Fatal(err) } - if _, err = vm.IssueTx(createAssetTx.Bytes()); err != nil { + if _, err := vm.IssueTx(createAssetTx.Bytes()); err != nil { t.Fatal(err) } @@ -732,7 +732,7 @@ func TestIssueNFT(t *testing.T) { t.Fatal(err) } - if _, err = vm.IssueTx(mintNFTTx.Bytes()); err != nil { + if _, err := vm.IssueTx(mintNFTTx.Bytes()); err != nil { t.Fatal(err) } @@ -766,7 +766,7 @@ func TestIssueNFT(t *testing.T) { t.Fatal(err) } - if _, err = vm.IssueTx(transferNFTTx.Bytes()); err != nil { + if _, err := vm.IssueTx(transferNFTTx.Bytes()); err != nil { t.Fatal(err) } } @@ -848,7 +848,7 @@ func TestIssueProperty(t *testing.T) { t.Fatal(err) } - if _, err = vm.IssueTx(createAssetTx.Bytes()); err != nil { + if _, err := vm.IssueTx(createAssetTx.Bytes()); err != nil { t.Fatal(err) } @@ -886,7 +886,7 @@ func TestIssueProperty(t *testing.T) { t.Fatal(err) } - if _, err = vm.IssueTx(mintPropertyTx.Bytes()); err != nil { + if _, err := vm.IssueTx(mintPropertyTx.Bytes()); err != nil { t.Fatal(err) } @@ -912,7 +912,7 @@ func TestIssueProperty(t *testing.T) { t.Fatal(err) } - if _, err = vm.IssueTx(burnPropertyTx.Bytes()); err != nil { + if _, err := vm.IssueTx(burnPropertyTx.Bytes()); err != nil { t.Fatal(err) } } @@ -1531,7 +1531,7 @@ func TestIssueImportTx(t *testing.T) { } vm.batchTimeout = 0 - if err = vm.SetState(context.Background(), snow.Bootstrapping); err != nil { + if err := vm.SetState(context.Background(), snow.Bootstrapping); err != nil { t.Fatal(err) } @@ -1700,7 +1700,7 @@ func TestForceAcceptImportTx(t *testing.T) { } vm.batchTimeout = 0 - if err = vm.SetState(context.Background(), snow.Bootstrapping); err != nil { + if err := vm.SetState(context.Background(), snow.Bootstrapping); err != nil { t.Fatal(err) } @@ -1937,7 +1937,7 @@ func TestClearForceAcceptedExportTx(t *testing.T) { } vm.batchTimeout = 0 - if err = vm.SetState(context.Background(), snow.Bootstrapping); err != nil { + if err := vm.SetState(context.Background(), snow.Bootstrapping); err != nil { t.Fatal(err) } diff --git a/vms/avm/wallet_service_test.go b/vms/avm/wallet_service_test.go index 0341d1dd933e..3d29ee916271 100644 --- a/vms/avm/wallet_service_test.go +++ b/vms/avm/wallet_service_test.go @@ -124,7 +124,7 @@ func TestWalletService_SendMultiple(t *testing.T) { t.Fatal("Transaction ID returned by SendMultiple does not match the transaction found in vm's pending transactions") } - if _, err = vm.GetTx(context.Background(), reply.TxID); err != nil { + if _, err := vm.GetTx(context.Background(), reply.TxID); err != nil { t.Fatalf("Failed to retrieve created transaction: %s", err) } }) diff --git a/vms/components/avax/utxo_fetching.go b/vms/components/avax/utxo_fetching.go index efc0afd1ea87..e8a2c88ac94a 100644 --- a/vms/components/avax/utxo_fetching.go +++ b/vms/components/avax/utxo_fetching.go @@ -22,7 +22,8 @@ func GetBalance(db UTXOReader, addrs ids.ShortSet) (uint64, error) { balance := uint64(0) for _, utxo := range utxos { if out, ok := utxo.Out.(Amounter); ok { - if balance, err = safemath.Add64(out.Amount(), balance); err != nil { + balance, err = safemath.Add64(out.Amount(), balance) + if err != nil { return 0, err } } diff --git a/vms/components/chain/state_test.go b/vms/components/chain/state_test.go index 36d6048707c5..4a720a13d7c6 100644 --- a/vms/components/chain/state_test.go +++ b/vms/components/chain/state_test.go @@ -786,7 +786,7 @@ func TestSetLastAcceptedBlock(t *testing.T) { if lastAcceptedID != postSetBlk1.ID() { t.Fatal("Expected last accepted block to be postSetBlk1") } - if lastAcceptedID = chainState.LastAcceptedBlock().ID(); lastAcceptedID != postSetBlk1.ID() { + if lastAcceptedID := chainState.LastAcceptedBlock().ID(); lastAcceptedID != postSetBlk1.ID() { t.Fatal("Expected last accepted block to be postSetBlk1") } @@ -808,7 +808,7 @@ func TestSetLastAcceptedBlock(t *testing.T) { if lastAcceptedID != postSetBlk2.ID() { t.Fatal("Expected last accepted block to be postSetBlk2") } - if lastAcceptedID = chainState.LastAcceptedBlock().ID(); lastAcceptedID != postSetBlk2.ID() { + if lastAcceptedID := chainState.LastAcceptedBlock().ID(); lastAcceptedID != postSetBlk2.ID() { t.Fatal("Expected last accepted block to be postSetBlk2") } diff --git a/vms/components/state/state_test.go b/vms/components/state/state_test.go index 1230d1ae701c..c9988ff10809 100644 --- a/vms/components/state/state_test.go +++ b/vms/components/state/state_test.go @@ -205,7 +205,7 @@ func TestGetWrongTypeID(t *testing.T) { value: 5, } blockID := ids.ID{1, 2, 3} - if err = state.Put(db, blockTypeID, blockID, block); err != nil { + if err := state.Put(db, blockTypeID, blockID, block); err != nil { t.Fatal(err) } @@ -251,7 +251,7 @@ func TestSameKeyDifferentTypeID(t *testing.T) { } // put it using sharedKey - if err = state.Put(db, accountTypeID, sharedKey, acc); err != nil { + if err := state.Put(db, accountTypeID, sharedKey, acc); err != nil { t.Fatal(err) } @@ -262,7 +262,7 @@ func TestSameKeyDifferentTypeID(t *testing.T) { } // put it using sharedKey - if err = state.Put(db, blockTypeID, sharedKey, block1); err != nil { + if err := state.Put(db, blockTypeID, sharedKey, block1); err != nil { t.Fatal(err) } @@ -328,7 +328,7 @@ func TestOverwrite(t *testing.T) { key := ids.ID{1, 2, 3} // put it - if err = state.Put(db, blockTypeID, key, block1); err != nil { + if err := state.Put(db, blockTypeID, key, block1); err != nil { t.Fatal(err) } @@ -339,7 +339,7 @@ func TestOverwrite(t *testing.T) { } // put it with the same key - if err = state.Put(db, blockTypeID, key, block2); err != nil { + if err := state.Put(db, blockTypeID, key, block2); err != nil { t.Fatal(err) } @@ -389,7 +389,7 @@ func TestHappyPath(t *testing.T) { } // put it - if err = state.Put(db, accountTypeID, acc1.id, acc1); err != nil { + if err := state.Put(db, accountTypeID, acc1.id, acc1); err != nil { t.Fatal(err) } @@ -419,7 +419,7 @@ func TestHappyPath(t *testing.T) { } // put it - if err = state.Put(db, accountTypeID, acc2.id, acc2); err != nil { + if err := state.Put(db, accountTypeID, acc2.id, acc2); err != nil { t.Fatal(err) } @@ -455,7 +455,7 @@ func TestHappyPath(t *testing.T) { } // put it - if err = state.Put(db, blockTypeID, block1ID, block1); err != nil { + if err := state.Put(db, blockTypeID, block1ID, block1); err != nil { t.Fatal(err) } @@ -483,7 +483,7 @@ func TestHappyPath(t *testing.T) { } // put it - if err = state.Put(db, blockTypeID, block2ID, block2); err != nil { + if err := state.Put(db, blockTypeID, block2ID, block2); err != nil { t.Fatal(err) } diff --git a/vms/platformvm/blocks/builder/network.go b/vms/platformvm/blocks/builder/network.go index 1d005bd3b9ab..6f29eba83fc0 100644 --- a/vms/platformvm/blocks/builder/network.go +++ b/vms/platformvm/blocks/builder/network.go @@ -138,7 +138,7 @@ func (n *network) AppGossip(_ context.Context, nodeID ids.NodeID, msgBytes []byt } // add to mempool - if err = n.blkBuilder.AddUnverifiedTx(tx); err != nil { + if err := n.blkBuilder.AddUnverifiedTx(tx); err != nil { n.ctx.Log.Debug("tx failed verification", zap.Stringer("nodeID", nodeID), zap.Error(err), diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 98a05128c5ce..b6e56c5a68f8 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -119,7 +119,7 @@ func TestCreateBlockchainArgsParsing(t *testing.T) { if err != nil { t.Fatal(err) } - if _, err = stdjson.Marshal(args.GenesisData); err != nil { + if _, err := stdjson.Marshal(args.GenesisData); err != nil { t.Fatal(err) } } diff --git a/vms/platformvm/state/state.go b/vms/platformvm/state/state.go index ced2f9f5e878..93c92b314355 100644 --- a/vms/platformvm/state/state.go +++ b/vms/platformvm/state/state.go @@ -1455,7 +1455,7 @@ func (s *state) writeBlocks() error { delete(s.addedBlocks, blkID) s.blockCache.Put(blkID, stateBlk) - if err = s.blockDB.Put(blkID[:], blockBytes); err != nil { + if err := s.blockDB.Put(blkID[:], blockBytes); err != nil { return fmt.Errorf("failed to write block %s: %w", blkID, err) } } @@ -1547,7 +1547,7 @@ func (s *state) writeCurrentPrimaryNetworkStakers(height uint64) error { return fmt.Errorf("failed to serialize current validator: %w", err) } - if err = s.currentValidatorList.Put(staker.TxID[:], vdrBytes); err != nil { + if err := s.currentValidatorList.Put(staker.TxID[:], vdrBytes); err != nil { return fmt.Errorf("failed to write current validator to list: %w", err) } diff --git a/vms/proposervm/vm_byzantine_test.go b/vms/proposervm/vm_byzantine_test.go index e93f4c95971c..be414b31df10 100644 --- a/vms/proposervm/vm_byzantine_test.go +++ b/vms/proposervm/vm_byzantine_test.go @@ -507,7 +507,7 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { }, } - if err = bBlock.Verify(context.Background()); err != nil { + if err := bBlock.Verify(context.Background()); err != nil { t.Fatal(err) } diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index 3d6aa49e7d48..8ab6c7d9950a 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -641,7 +641,7 @@ func TestTwoProBlocksWithSameParentCanBothVerify(t *testing.T) { if err != nil { t.Fatal("Could not build block") } - if err = builtBlk.Verify(context.Background()); err != nil { + if err := builtBlk.Verify(context.Background()); err != nil { t.Fatal("Built block does not verify") } @@ -690,7 +690,7 @@ func TestTwoProBlocksWithSameParentCanBothVerify(t *testing.T) { } // prove that also block from network verifies - if err = netProBlk.Verify(context.Background()); err != nil { + if err := netProBlk.Verify(context.Background()); err != nil { t.Fatal("block from network does not verify") } } @@ -852,7 +852,7 @@ func TestPreFork_SetPreference(t *testing.T) { return nil, errUnknownBlock } } - if err = proVM.SetPreference(context.Background(), builtBlk.ID()); err != nil { + if err := proVM.SetPreference(context.Background(), builtBlk.ID()); err != nil { t.Fatal("Could not set preference on proposer Block") } @@ -1688,7 +1688,7 @@ func TestTooFarAdvanced(t *testing.T) { }, } - if err = bBlock.Verify(context.Background()); err != errProposerWindowNotStarted { + if err := bBlock.Verify(context.Background()); err != errProposerWindowNotStarted { t.Fatal("should have errored errProposerWindowNotStarted") } @@ -1712,7 +1712,7 @@ func TestTooFarAdvanced(t *testing.T) { }, } - if err = bBlock.Verify(context.Background()); err != errTimeTooAdvanced { + if err := bBlock.Verify(context.Background()); err != errTimeTooAdvanced { t.Fatal("should have errored errTimeTooAdvanced") } }