From d6c4682479cecda73a67bebca7e97fc0ebf5137d Mon Sep 17 00:00:00 2001 From: Siddarth Kumar Date: Thu, 18 Apr 2024 18:48:02 +0200 Subject: [PATCH] chore_: bump go to 1.20 (#5027) This commit attempts to upgrade go version to 1.20.12 This commit also removes the following items from lint checks : * `goconst` * `structcheck` * `deadcode` * `golint` * `varcheck` Mobile PR for QA purposes -> https://github.com/status-im/status-mobile/pull/19564 --- .golangci.yml | 5 ----- go.mod | 2 +- mailserver/mailserver_test.go | 8 ++++++-- multiaccounts/accounts/keycard_database.go | 3 ++- nix/overlay.nix | 8 ++++---- protocol/activity_center_persistence.go | 2 +- protocol/communities/persistence.go | 2 +- protocol/message_persistence.go | 2 +- protocol/messenger_mailserver_cycle.go | 19 +++++++++++++++++++ protocol/transport/filters_manager.go | 4 +++- services/wallet/collectibles/service.go | 4 +++- services/wallet/collectibles/types.go | 4 +++- .../transfer/block_ranges_sequential_dao.go | 2 +- services/wallet/transfer/database.go | 4 +++- transactions/testhelpers.go | 8 ++++++-- transactions/transactor_test.go | 4 +++- 16 files changed, 57 insertions(+), 24 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6724be2e6..13cd6cc1d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -42,22 +42,17 @@ linters-settings: linters: disable-all: true enable: - - deadcode - errcheck - gosec - - goconst - goimports - - golint - govet - ineffassign - megacheck - misspell - - structcheck # You can't disable typecheck, see: # https://github.com/golangci/golangci-lint/blob/master/docs/src/docs/welcome/faq.mdx#why-do-you-have-typecheck-errors - typecheck - unconvert - - varcheck fast: false issues: diff --git a/go.mod b/go.mod index 4ccdfecdf..c3ea253e4 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/status-im/status-go -go 1.19 +go 1.20 replace github.com/ethereum/go-ethereum v1.10.26 => github.com/status-im/go-ethereum v1.10.25-status.13 diff --git a/mailserver/mailserver_test.go b/mailserver/mailserver_test.go index 6e707e797..9ed2e2337 100644 --- a/mailserver/mailserver_test.go +++ b/mailserver/mailserver_test.go @@ -107,7 +107,9 @@ func (s *MailserverSuite) TestInit() { }, } - for _, tc := range testCases { + for _, testCase := range testCases { + // to satisfy gosec: C601 checks + tc := testCase s.T().Run(tc.info, func(*testing.T) { mailServer := &WakuMailServer{} shh := waku.New(&waku.DefaultConfig, nil) @@ -299,7 +301,9 @@ func (s *MailserverSuite) TestMailServer() { info: "Processing a request where difference between from and to is > 24 should fail", }, } - for _, tc := range testCases { + for _, testCase := range testCases { + // to satisfy gosec: C601 checks + tc := testCase s.T().Run(tc.info, func(*testing.T) { request := s.createRequest(tc.params) src := crypto.FromECDSAPub(&tc.params.key.PublicKey) diff --git a/multiaccounts/accounts/keycard_database.go b/multiaccounts/accounts/keycard_database.go index 4a0ab98c0..c83754f10 100644 --- a/multiaccounts/accounts/keycard_database.go +++ b/multiaccounts/accounts/keycard_database.go @@ -263,7 +263,8 @@ func (db *Database) deleteKeycardAccounts(tx *sql.Tx, kcUID string, accountAddre } inVector := strings.Repeat(",?", len(accountAddresses)-1) - query := ` + //nolint: gosec + query := ` DELETE FROM keycards_accounts diff --git a/nix/overlay.nix b/nix/overlay.nix index 2ca5f9e99..4b528356d 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -22,12 +22,12 @@ in rec { ]; }; - go = prev.go_1_19; - buildGoModule = prev.buildGo119Module; - buildGoPackage = prev.buildGo119Package; + go = prev.go_1_20; + buildGoModule = prev.buildGo120Module; + buildGoPackage = prev.buildGo120Package; golangci-lint = prev.golangci-lint.override { - buildGoModule = args: prev.buildGo119Module ( args // rec { + buildGoModule = args: prev.buildGo120Module ( args // rec { version = "1.52.2"; src = prev.fetchFromGitHub { owner = "golangci"; diff --git a/protocol/activity_center_persistence.go b/protocol/activity_center_persistence.go index ed1c0ad1a..02b1efafe 100644 --- a/protocol/activity_center_persistence.go +++ b/protocol/activity_center_persistence.go @@ -853,7 +853,7 @@ func (db sqlitePersistence) MarkActivityCenterNotificationsDeleted(ids []types.H return nil, err } - update := "UPDATE activity_center_notifications SET deleted = 1, updated_at = ? WHERE id IN (" + inVector + ") AND NOT deleted" + update := "UPDATE activity_center_notifications SET deleted = 1, updated_at = ? WHERE id IN (" + inVector + ") AND NOT deleted" //nolint: gosec _, err = tx.Exec(update, args...) if err != nil { return nil, err diff --git a/protocol/communities/persistence.go b/protocol/communities/persistence.go index 6b32d5118..2ea3aa940 100644 --- a/protocol/communities/persistence.go +++ b/protocol/communities/persistence.go @@ -960,7 +960,7 @@ func (p *Persistence) GetLatestWakuMessageTimestamp(topics []types.TopicType) (u func (p *Persistence) GetWakuMessagesByFilterTopic(topics []types.TopicType, from uint64, to uint64) ([]types.Message, error) { - query := "SELECT sig, timestamp, topic, payload, padding, hash, third_party_id FROM waku_messages WHERE timestamp >= " + fmt.Sprint(from) + " AND timestamp < " + fmt.Sprint(to) + " AND (" + query := "SELECT sig, timestamp, topic, payload, padding, hash, third_party_id FROM waku_messages WHERE timestamp >= " + fmt.Sprint(from) + " AND timestamp < " + fmt.Sprint(to) + " AND (" //nolint: gosec for i, topic := range topics { query += `topic = "` + topic.String() + `"` diff --git a/protocol/message_persistence.go b/protocol/message_persistence.go index b4e883cf1..3ee1fa332 100644 --- a/protocol/message_persistence.go +++ b/protocol/message_persistence.go @@ -3016,7 +3016,7 @@ func (db sqlitePersistence) findStatusMessageIDForBridgeMessageID(tx *sql.Tx, me } func (db sqlitePersistence) updateStatusMessagesWithResponse(tx *sql.Tx, statusMessagesToUpdate []string, responseValue string) error { - sql := "UPDATE user_messages SET response_to = ? WHERE id IN (?" + strings.Repeat(",?", len(statusMessagesToUpdate)-1) + ")" + sql := "UPDATE user_messages SET response_to = ? WHERE id IN (?" + strings.Repeat(",?", len(statusMessagesToUpdate)-1) + ")" //nolint: gosec stmt, err := tx.Prepare(sql) if err != nil { return err diff --git a/protocol/messenger_mailserver_cycle.go b/protocol/messenger_mailserver_cycle.go index 85e100c0b..77c23bebb 100644 --- a/protocol/messenger_mailserver_cycle.go +++ b/protocol/messenger_mailserver_cycle.go @@ -6,6 +6,7 @@ import ( "fmt" "math" "math/big" + "net" "runtime" "sort" "strings" @@ -27,6 +28,8 @@ const defaultBackoff = 10 * time.Second const graylistBackoff = 3 * time.Minute const isAndroidEmulator = runtime.GOOS == "android" && runtime.GOARCH == "amd64" const findNearestMailServer = !isAndroidEmulator +const overrideDNS = runtime.GOOS == "android" +const bootstrapDNS = "8.8.8.8:53" func (m *Messenger) mailserversByFleet(fleet string) []mailservers.Mailserver { return mailservers.DefaultMailserversByFleet(fleet) @@ -219,6 +222,22 @@ type SortedMailserver struct { } func (m *Messenger) findNewMailserver() error { + + // we have to override DNS manually because of https://github.com/status-im/status-mobile/issues/19581 + if overrideDNS { + var dialer net.Dialer + net.DefaultResolver = &net.Resolver{ + PreferGo: false, + Dial: func(context context.Context, _, _ string) (net.Conn, error) { + conn, err := dialer.DialContext(context, "udp", bootstrapDNS) + if err != nil { + return nil, err + } + return conn, nil + }, + } + } + pinnedMailserver, err := m.getPinnedMailserver() if err != nil { m.logger.Error("Could not obtain the pinned mailserver", zap.Error(err)) diff --git a/protocol/transport/filters_manager.go b/protocol/transport/filters_manager.go index 8016ca5f9..ad57f6a47 100644 --- a/protocol/transport/filters_manager.go +++ b/protocol/transport/filters_manager.go @@ -150,7 +150,9 @@ func (f *FiltersManager) InitCommunityFilters(communityFiltersToInitialize []Com f.mutex.Lock() defer f.mutex.Unlock() - for _, cf := range communityFiltersToInitialize { + for _, communityFilter := range communityFiltersToInitialize { + // to satisfy gosec: C601 checks + cf := communityFilter if cf.PrivKey == nil { continue } diff --git a/services/wallet/collectibles/service.go b/services/wallet/collectibles/service.go index 1c891136b..7eefd1980 100644 --- a/services/wallet/collectibles/service.go +++ b/services/wallet/collectibles/service.go @@ -499,7 +499,9 @@ func (s *Service) notifyCommunityCollectiblesReceived(ownedCollectibles OwnedCol } groups := make(map[CollectibleGroup]Collectible) - for _, collectible := range communityCollectibles { + for _, localCollectible := range communityCollectibles { + // to satisfy gosec: C601 checks + collectible := localCollectible txHash := "" for key, value := range hashMap { if key.Same(&collectible.ID) { diff --git a/services/wallet/collectibles/types.go b/services/wallet/collectibles/types.go index 0c4588b3a..6396ed394 100644 --- a/services/wallet/collectibles/types.go +++ b/services/wallet/collectibles/types.go @@ -159,7 +159,9 @@ func fullCollectiblesDataToDetails(data []thirdparty.FullCollectibleData) []Coll func fullCollectiblesDataToCommunityHeader(data []thirdparty.FullCollectibleData) []Collectible { res := make([]Collectible, 0, len(data)) - for _, c := range data { + for _, localCollectibleData := range data { + // to satisfy gosec: C601 checks + c := localCollectibleData collectibleID := c.CollectibleData.ID communityID := c.CollectibleData.CommunityID diff --git a/services/wallet/transfer/block_ranges_sequential_dao.go b/services/wallet/transfer/block_ranges_sequential_dao.go index 5036ca59a..615051b34 100644 --- a/services/wallet/transfer/block_ranges_sequential_dao.go +++ b/services/wallet/transfer/block_ranges_sequential_dao.go @@ -115,7 +115,7 @@ func (b *BlockRangeSequentialDAO) getBlockRanges(chainID uint64, addresses []com } } - query := "SELECT address, blk_start, blk_first, blk_last, token_blk_start, token_blk_first, token_blk_last, balance_check_hash FROM blocks_ranges_sequential WHERE address IN (" + + query := "SELECT address, blk_start, blk_first, blk_last, token_blk_start, token_blk_first, token_blk_last, balance_check_hash FROM blocks_ranges_sequential WHERE address IN (" + //nolint: gosec addressesPlaceholder + ") AND network_id = ?" params := []interface{}{} diff --git a/services/wallet/transfer/database.go b/services/wallet/transfer/database.go index 6ee58efa6..7589fecd3 100644 --- a/services/wallet/transfer/database.go +++ b/services/wallet/transfer/database.go @@ -326,7 +326,9 @@ func insertBlocksWithTransactions(chainID uint64, creator statementCreator, head func updateOrInsertTransfers(chainID uint64, creator statementCreator, transfers []Transfer) error { txsDBFields := make([]transferDBFields, 0, len(transfers)) - for _, t := range transfers { + for _, localTransfer := range transfers { + // to satisfy gosec: C601 checks + t := localTransfer var receiptType *uint8 var txHash, blockHash *common.Hash var receiptStatus, cumulativeGasUsed, gasUsed *uint64 diff --git a/transactions/testhelpers.go b/transactions/testhelpers.go index 14e2ff921..d06e6c77f 100644 --- a/transactions/testhelpers.go +++ b/transactions/testhelpers.go @@ -143,7 +143,9 @@ func MockTestTransactions(t *testing.T, chainClient *MockChainClient, testTxs [] return false } for i := range b { - for _, sum := range chainSummaries { + for _, localSummary := range chainSummaries { + // to satisfy gosec: C601 checks + sum := localSummary tx := &sum.tx if sum.answered { continue @@ -165,7 +167,9 @@ func MockTestTransactions(t *testing.T, chainClient *MockChainClient, testTxs [] require.True(t, ok) require.NotNil(t, receiptWrapper) // Simulate parsing of eth_getTransactionReceipt response - for _, sum := range chainSummaries { + for _, localSum := range chainSummaries { + // to satisfy gosec: C601 checks + sum := localSum tx := &sum.tx if tx.Hash == elems[i].Args[0].(eth.Hash) { if !sum.summary.DontConfirm { diff --git a/transactions/transactor_test.go b/transactions/transactor_test.go index e3f432c7d..1ba14a2f3 100644 --- a/transactions/transactor_test.go +++ b/transactions/transactor_test.go @@ -266,7 +266,9 @@ func (s *TransactorSuite) TestSendTransactionWithSignature() { }, } - for _, scenario := range scenarios { + for _, localScenario := range scenarios { + // to satisfy gosec: C601 checks + scenario := localScenario desc := fmt.Sprintf("nonceFromNetwork: %d, tx nonce: %d, expect error: %v", scenario.nonceFromNetwork, scenario.txNonce, scenario.expectError) s.T().Run(desc, func(t *testing.T) { nonce := scenario.txNonce