From 98e447235895021e94b9e0b8e33d5c6eea5b874e Mon Sep 17 00:00:00 2001 From: frank Date: Fri, 7 Feb 2025 17:34:50 +0800 Subject: [PATCH] chore_: remove private information for error log --- abi-spec/utils.go | 2 +- api/geth_backend.go | 9 +- appdatabase/database.go | 4 +- common/utils.go | 38 ++++++++ common/utils_test.go | 97 +++++++++++++++++++ eth-node/bridge/geth/ens/ens.go | 4 +- mobile/status.go | 24 +++-- node/geth_node.go | 5 +- protocol/communities/manager.go | 2 +- protocol/messenger.go | 2 +- protocol/messenger_backup_handler.go | 4 +- protocol/messenger_communities.go | 18 ++-- protocol/messenger_community_shard.go | 3 +- protocol/messenger_contacts.go | 5 +- protocol/messenger_mention.go | 3 +- protocol/messenger_messages.go | 7 +- protocol/messenger_raw_message_resend.go | 6 +- protocol/messenger_sync_settings.go | 4 +- server/handlers.go | 41 ++++---- server/pairing/challenge_management.go | 6 +- server/pairing/client.go | 2 +- server/pairing/handlers.go | 6 +- .../transaction_sent_to_upstream_event.go | 2 +- services/wallet/api.go | 5 +- services/wallet/collectibles/controller.go | 14 ++- services/wallet/collectibles/manager.go | 12 +-- services/wallet/community/manager.go | 4 +- .../wallet/router/pathprocessor/errors.go | 2 +- .../token/balancefetcher/balance_fetcher.go | 5 +- services/web3provider/api.go | 3 +- 30 files changed, 248 insertions(+), 91 deletions(-) create mode 100644 common/utils_test.go diff --git a/abi-spec/utils.go b/abi-spec/utils.go index 8353a606a6f..5584770abba 100644 --- a/abi-spec/utils.go +++ b/abi-spec/utils.go @@ -48,7 +48,7 @@ func Sha3(str string) string { if hexStrictPattern.MatchString(str) { bytes, err = hex.DecodeString(str[2:]) if err != nil { - logutils.ZapLogger().Error("failed to decode hex string when sha3", zap.String("hex", str), zap.Error(err)) + logutils.ZapLogger().Error("failed to decode hex string when sha3", zap.Error(err)) return "" } } else { diff --git a/api/geth_backend.go b/api/geth_backend.go index 32f987fafaa..17bf0196504 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -30,6 +30,7 @@ import ( "github.com/status-im/status-go/appdatabase" "github.com/status-im/status-go/centralizedmetrics" centralizedmetricscommon "github.com/status-im/status-go/centralizedmetrics/common" + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/common/dbsetup" "github.com/status-im/status-go/connection" "github.com/status-im/status-go/eth-node/crypto" @@ -358,7 +359,7 @@ func (b *GethStatusBackend) DeleteImportedKey(address, password, keyStoreDir str if strings.Contains(fileInfo.Name(), address) { _, err := b.accountManager.VerifyAccountPassword(keyStoreDir, "0x"+address, password) if err != nil { - b.logger.Error("failed to verify account", zap.String("account", address), zap.Error(err)) + b.logger.Error("failed to verify account", zap.String("account", gocommon.TruncateWithDot(address)), zap.Error(err)) return err } @@ -2367,7 +2368,7 @@ func (b *GethStatusBackend) getVerifiedWalletAccount(address, password string) ( } exists, err := db.AddressExists(types.HexToAddress(address)) if err != nil { - b.logger.Error("failed to query db for a given address", zap.String("address", address), zap.Error(err)) + b.logger.Error("failed to query db for a given address", zap.String("address", gocommon.TruncateWithDot(address)), zap.Error(err)) return nil, err } @@ -2385,7 +2386,7 @@ func (b *GethStatusBackend) getVerifiedWalletAccount(address, password string) ( } if err != nil { - b.logger.Error("failed to verify account", zap.String("account", address), zap.Error(err)) + b.logger.Error("failed to verify account", zap.String("account", gocommon.TruncateWithDot(address)), zap.Error(err)) return nil, err } @@ -2399,7 +2400,7 @@ func (b *GethStatusBackend) generatePartialAccountKey(db *accounts.Database, add dbPath, err := db.GetPath(types.HexToAddress(address)) path := "m/" + dbPath[strings.LastIndex(dbPath, "/")+1:] if err != nil { - b.logger.Error("failed to get path for given account address", zap.String("account", address), zap.Error(err)) + b.logger.Error("failed to get path for given account address", zap.String("account", gocommon.TruncateWithDot(address)), zap.Error(err)) return nil, err } diff --git a/appdatabase/database.go b/appdatabase/database.go index b84cbde5ded..119d83396c2 100644 --- a/appdatabase/database.go +++ b/appdatabase/database.go @@ -120,7 +120,7 @@ func FixMissingKeyUIDForAccounts(sqlTx *sql.Tx) error { } pk, err := crypto.UnmarshalPubkey(pubkey) if err != nil { - logutils.ZapLogger().Error("Migrating accounts: failed to unmarshal pubkey", zap.String("pubkey", string(pubkey)), zap.Error(err)) + logutils.ZapLogger().Error("Migrating accounts: failed to unmarshal pubkey", zap.String("pubkey", d_common.TruncateWithDot(string(pubkey))), zap.Error(err)) return err } pkBytes := sha256.Sum256(crypto.FromECDSAPub(pk)) @@ -242,7 +242,7 @@ func migrateEnsUsernames(sqlTx *sql.Tx) error { _, err = sqlTx.Exec(`INSERT INTO ens_usernames (username, chain_id) VALUES (?, ?)`, username, defaultChainID) if err != nil { - logutils.ZapLogger().Error("Migrating ens usernames: failed to insert username into new database", zap.String("ensUsername", username), zap.Error(err)) + logutils.ZapLogger().Error("Migrating ens usernames: failed to insert username into new database", zap.Error(err)) } } diff --git a/common/utils.go b/common/utils.go index d1d3939dcd2..2a7b2f7789c 100644 --- a/common/utils.go +++ b/common/utils.go @@ -22,6 +22,8 @@ var ErrInvalidDisplayNameNotAllowed = errors.New("name is not allowed") var DISPLAY_NAME_EXT = []string{"_eth", ".eth", "-eth"} +const DefaultTruncateLength = 8 + func RecoverKey(m *protobuf.ApplicationMetadataMessage) (*ecdsa.PublicKey, error) { if m.Signature == nil { return nil, nil @@ -103,3 +105,39 @@ func LogOnPanic() { panic(err) } + +// TruncateWithDotN truncates a string by keeping n characters (excluding "..") from start and end, +// replacing middle part with "..". +// The total length of returned string will be n + 2 (where 2 is the length of ".."). +// For n characters total (excluding dots), characters are distributed evenly between start and end. +// If n is odd, start gets one extra character. +// Examples: +// +// TruncateWithDotN("0x123456789", 4) // returns "0x1..89" (total length 6) +// TruncateWithDotN("0x123456789", 3) // returns "0x..9" (total length 5) +// TruncateWithDotN("0x123456789", 5) // returns "0x1..89" (total length 7) +// TruncateWithDotN("acdkef099", 3) // returns "ac..9" (total length 5) +// TruncateWithDotN("ab", 4) // returns "ab" (no truncation needed as len <= n) +// TruncateWithDotN("test", 0) // returns "test" (no truncation for n <= 0) +func TruncateWithDotN(s string, n int) string { + if n <= 0 || len(s) <= n { + return s + } + + if n < 2 { // need at least 2 chars (1 at start + 1 at end) + n = 2 + } + + dots := ".." + // For n characters total (excluding dots), we want to keep: + // - ceil(n/2) characters from the start + // - floor(n/2) characters from the end + startChars := (n + 1) / 2 // ceil(n/2) + endChars := n / 2 // floor(n/2) + + return s[:startChars] + dots + s[len(s)-endChars:] +} + +func TruncateWithDot(s string) string { + return TruncateWithDotN(s, DefaultTruncateLength) +} diff --git a/common/utils_test.go b/common/utils_test.go new file mode 100644 index 00000000000..ddcdbce7611 --- /dev/null +++ b/common/utils_test.go @@ -0,0 +1,97 @@ +package common + +import ( + "testing" +) + +func TestTruncateWithDotN(t *testing.T) { + tests := []struct { + name string + input string + n int + expected string + }{ + { + name: "empty string", + input: "", + n: 4, + expected: "", + }, + { + name: "string shorter than n", + input: "123", + n: 4, + expected: "123", + }, + { + name: "string equal to n", + input: "1234", + n: 4, + expected: "1234", + }, + { + name: "hex string with n=4 (even split: 2+2)", + input: "0x123456789", + n: 4, + expected: "0x..89", + }, + { + name: "hex string with n=3 (odd split: 2+1)", + input: "0x123456789", + n: 3, + expected: "0x..9", + }, + { + name: "hex string with n=5 (odd split: 3+2)", + input: "0x123456789", + n: 5, + expected: "0x1..89", + }, + { + name: "normal string with n=3 (odd split: 2+1)", + input: "acdkef099", + n: 3, + expected: "ac..9", + }, + { + name: "hex address with n=6 (even split: 3+3)", + input: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", + n: 6, + expected: "0xd..045", + }, + { + name: "very short n=2 (even split: 1+1)", + input: "abcdef", + n: 2, + expected: "a..f", + }, + { + name: "n=1 adjusted to minimum 2 (even split: 1+1)", + input: "abcdef", + n: 1, + expected: "a..f", + }, + { + name: "negative n", + input: "test", + n: -1, + expected: "test", + }, + { + name: "zero n", + input: "test", + n: 0, + expected: "test", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := TruncateWithDotN(tt.input, tt.n) + if result != tt.expected { + t.Errorf("TruncateWithDotN(%q, %d) = %q, want %q", + tt.input, tt.n, result, tt.expected) + } + }) + } +} diff --git a/eth-node/bridge/geth/ens/ens.go b/eth-node/bridge/geth/ens/ens.go index 1321d0d07c2..807328e99f7 100644 --- a/eth-node/bridge/geth/ens/ens.go +++ b/eth-node/bridge/geth/ens/ens.go @@ -68,13 +68,13 @@ func (m *Verifier) verifyENSName(ensInfo enstypes.ENSDetails, ethclient *ethclie // Resolve ensName resolver, err := ens.NewResolver(ethclient, ensName) if err != nil { - m.logger.Error("error while creating ENS name resolver", zap.String("ensName", ensName), zap.Error(err)) + m.logger.Error("error while creating ENS name resolver", zap.Error(err)) response.Error = err return response } x, y, err := resolver.PubKey() if err != nil { - m.logger.Error("error while resolving public key from ENS name", zap.String("ensName", ensName), zap.Error(err)) + m.logger.Error("error while resolving public key from ENS name", zap.Error(err)) response.Error = err return response } diff --git a/mobile/status.go b/mobile/status.go index 9c174febbd6..664d771775e 100644 --- a/mobile/status.go +++ b/mobile/status.go @@ -25,6 +25,7 @@ import ( "github.com/status-im/status-go/api/multiformat" "github.com/status-im/status-go/centralizedmetrics" "github.com/status-im/status-go/centralizedmetrics/providers" + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/exportlogs" @@ -478,13 +479,13 @@ func login(accountData, password, configJSON string) error { logutils.ZapLogger().Debug("start a node with account", zap.String("key-uid", account.KeyUID)) err := statusBackend.UpdateNodeConfigFleet(account, password, &conf) if err != nil { - logutils.ZapLogger().Error("failed to update node config fleet", zap.String("key-uid", account.KeyUID), zap.Error(err)) + logutils.ZapLogger().Error("failed to update node config fleet", zap.String("key-uid", gocommon.TruncateWithDot(account.KeyUID)), zap.Error(err)) return statusBackend.LoggedIn(account.KeyUID, err) } err = statusBackend.StartNodeWithAccount(account, password, &conf, nil) if err != nil { - logutils.ZapLogger().Error("failed to start a node", zap.String("key-uid", account.KeyUID), zap.Error(err)) + logutils.ZapLogger().Error("failed to start a node", zap.String("key-uid", gocommon.TruncateWithDot(account.KeyUID)), zap.Error(err)) return err } logutils.ZapLogger().Debug("started a node with", zap.String("key-uid", account.KeyUID)) @@ -658,7 +659,7 @@ func SaveAccountAndLogin(accountData, password, settingsJSON, configJSON, subacc logutils.ZapLogger().Debug("starting a node, and saving account with configuration", zap.String("key-uid", account.KeyUID)) err := statusBackend.StartNodeWithAccountAndInitialConfig(account, password, settings, &conf, subaccs, nil) if err != nil { - logutils.ZapLogger().Error("failed to start node and save account", zap.String("key-uid", account.KeyUID), zap.Error(err)) + logutils.ZapLogger().Error("failed to start node and save account", zap.String("key-uid", gocommon.TruncateWithDot(account.KeyUID)), zap.Error(err)) return err } logutils.ZapLogger().Debug("started a node, and saved account", zap.String("key-uid", account.KeyUID)) @@ -767,7 +768,7 @@ func SaveAccountAndLoginWithKeycard(accountData, password, settingsJSON, configJ logutils.ZapLogger().Debug("starting a node, and saving account with configuration", zap.String("key-uid", account.KeyUID)) err := statusBackend.SaveAccountAndStartNodeWithKey(account, password, settings, &conf, subaccs, keyHex) if err != nil { - logutils.ZapLogger().Error("failed to start node and save account", zap.String("key-uid", account.KeyUID), zap.Error(err)) + logutils.ZapLogger().Error("failed to start node and save account", zap.String("key-uid", gocommon.TruncateWithDot(account.KeyUID)), zap.Error(err)) return err } logutils.ZapLogger().Debug("started a node, and saved account", zap.String("key-uid", account.KeyUID)) @@ -794,7 +795,7 @@ func LoginWithKeycard(accountData, password, keyHex string, configJSON string) s logutils.ZapLogger().Debug("start a node with account", zap.String("key-uid", account.KeyUID)) err := statusBackend.StartNodeWithKey(account, password, keyHex, &conf) if err != nil { - logutils.ZapLogger().Error("failed to start a node", zap.String("key-uid", account.KeyUID), zap.Error(err)) + logutils.ZapLogger().Error("failed to start a node", zap.String("key-uid", gocommon.TruncateWithDot(account.KeyUID)), zap.Error(err)) return err } logutils.ZapLogger().Debug("started a node with", zap.String("key-uid", account.KeyUID)) @@ -2066,7 +2067,7 @@ func EncodeTransfer(to string, value string) string { func encodeTransfer(to string, value string) string { result, err := abi_spec.EncodeTransfer(to, value) if err != nil { - logutils.ZapLogger().Error("failed to encode transfer", zap.String("to", to), zap.String("value", value), zap.Error(err)) + logutils.ZapLogger().Error("failed to encode transfer", zap.String("to", gocommon.TruncateWithDot(to)), zap.String("value", gocommon.TruncateWithDot(value)), zap.Error(err)) return "" } return result @@ -2099,6 +2100,7 @@ func encodeFunctionCall(method string, paramsJSON string) string { return result } +// Deprecated: no usage in mobile, we might implemented it within other functions func EncodeFunctionCallV2(requestJSON string) string { return callWithResponse(encodeFunctionCallV2, requestJSON) } @@ -2112,6 +2114,7 @@ func encodeFunctionCallV2(requestJSON string) string { return encodeFunctionCall(request.Method, request.ParamsJSON) } +// Deprecated: no usage in mobile func DecodeParameters(decodeParamJSON string) string { return decodeParameters(decodeParamJSON) } @@ -2159,6 +2162,7 @@ func Sha3(str string) string { return "0x" + abi_spec.Sha3(str) } +// Deprecated: no usage in mobile func Utf8ToHex(str string) string { return callWithResponse(utf8ToHex, str) } @@ -2178,7 +2182,7 @@ func HexToUtf8(hexString string) string { func hexToUtf8(hexString string) string { str, err := abi_spec.HexToUtf8(hexString) if err != nil { - logutils.ZapLogger().Error("failed to convert hex to utf8", zap.String("hexString", hexString), zap.Error(err)) + logutils.ZapLogger().Error("failed to convert hex to utf8", zap.String("hexString", gocommon.TruncateWithDot(hexString)), zap.Error(err)) } return str } @@ -2190,7 +2194,7 @@ func CheckAddressChecksum(address string) string { func checkAddressChecksum(address string) string { valid, err := abi_spec.CheckAddressChecksum(address) if err != nil { - logutils.ZapLogger().Error("failed to invoke check address checksum", zap.String("address", address), zap.Error(err)) + logutils.ZapLogger().Error("failed to invoke check address checksum", zap.String("address", gocommon.TruncateWithDot(address)), zap.Error(err)) } result, _ := json.Marshal(valid) return string(result) @@ -2203,7 +2207,7 @@ func IsAddress(address string) string { func isAddress(address string) string { valid, err := abi_spec.IsAddress(address) if err != nil { - logutils.ZapLogger().Error("failed to invoke IsAddress", zap.String("address", address), zap.Error(err)) + logutils.ZapLogger().Error("failed to invoke IsAddress", zap.String("address", gocommon.TruncateWithDot(address)), zap.Error(err)) } result, _ := json.Marshal(valid) return string(result) @@ -2216,7 +2220,7 @@ func ToChecksumAddress(address string) string { func toChecksumAddress(address string) string { address, err := abi_spec.ToChecksumAddress(address) if err != nil { - logutils.ZapLogger().Error("failed to convert to checksum address", zap.String("address", address), zap.Error(err)) + logutils.ZapLogger().Error("failed to convert to checksum address", zap.String("address", gocommon.TruncateWithDot(address)), zap.Error(err)) } return address } diff --git a/node/geth_node.go b/node/geth_node.go index 7c56db5dde2..9c75489e03c 100644 --- a/node/geth_node.go +++ b/node/geth_node.go @@ -16,6 +16,7 @@ import ( "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/nat" + "github.com/status-im/status-go/common" "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/logutils" "github.com/status-im/status-go/params" @@ -147,7 +148,7 @@ func parseNodes(enodes []string) []*enode.Node { if err == nil { nodes = append(nodes, parsedPeer) } else { - logger.Error("Failed to parse enode", zap.String("enode", item), zap.Error(err)) + logger.Error("Failed to parse enode", zap.String("enode", common.TruncateWithDot(item)), zap.Error(err)) } } @@ -163,7 +164,7 @@ func parseNodesV5(enodes []string) []*discv5.Node { if err == nil { nodes = append(nodes, parsedPeer) } else { - logger.Error("Failed to parse enode", zap.String("enode", enode), zap.Error(err)) + logger.Error("Failed to parse enode", zap.String("enode", common.TruncateWithDot(enode)), zap.Error(err)) } } return nodes diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index 7075b32ff1f..1c306df45d2 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -676,7 +676,7 @@ func (m *Manager) runOwnerVerificationLoop() { func (m *Manager) ValidateCommunityByID(communityID types.HexBytes) (*CommunityResponse, error) { communitiesToValidate, err := m.persistence.getCommunityToValidateByID(communityID) if err != nil { - m.logger.Error("failed to validate community by ID", zap.String("id", communityID.String()), zap.Error(err)) + m.logger.Error("failed to validate community by ID", zap.String("id", utils.TruncateWithDot(communityID.String())), zap.Error(err)) return nil, err } return m.validateCommunity(communitiesToValidate) diff --git a/protocol/messenger.go b/protocol/messenger.go index 2402b0c6ead..cb0dbfb7edf 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -2170,7 +2170,7 @@ func (m *Messenger) sendChatMessage(ctx context.Context, message *common.Message if err == nil { message.Text = replacedText } else { - m.logger.Error("failed to replace text with public key", zap.String("chatID", message.ChatId), zap.String("text", message.Text)) + m.logger.Error("failed to replace text with public key", zap.String("chatID", gocommon.TruncateWithDot(message.ChatId)), zap.Error(err)) } if len(message.ImagePath) != 0 { diff --git a/protocol/messenger_backup_handler.go b/protocol/messenger_backup_handler.go index 009e6d83d0c..46d73a393fe 100644 --- a/protocol/messenger_backup_handler.go +++ b/protocol/messenger_backup_handler.go @@ -374,7 +374,7 @@ func (m *Messenger) requestCommunityKeysAndSharedAddresses(state *ReceivedMessag _, err = m.SendMessageToControlNode(community, rawMessage) if err != nil { - m.logger.Error("failed to request shared addresses", zap.String("communityId", community.IDString()), zap.Error(err)) + m.logger.Error("failed to request shared addresses", zap.String("communityId", utils.TruncateWithDot(community.IDString())), zap.Error(err)) return err } @@ -395,7 +395,7 @@ func (m *Messenger) requestCommunityKeysAndSharedAddresses(state *ReceivedMessag if isEncrypted { err = m.requestCommunityEncryptionKeys(community, nil) if err != nil { - m.logger.Error("failed to request community encryption keys", zap.String("communityId", community.IDString()), zap.Error(err)) + m.logger.Error("failed to request community encryption keys", zap.String("communityId", utils.TruncateWithDot(community.IDString())), zap.Error(err)) return err } } diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index 5796caf0d32..8aab0858fb3 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -335,7 +335,7 @@ func (m *Messenger) handleCommunitiesSubscription(c chan *communities.Subscripti for pkString := range encryptionKeyActions.CommunityKeyAction.RemovedMembers { pk, err := common.HexToPubkey(pkString) if err != nil { - m.logger.Error("failed to decode public key", zap.Error(err), zap.String("pk", pkString)) + m.logger.Error("failed to decode public key", zap.Error(err), zap.String("pk", gocommon.TruncateWithDot(pkString))) } payload, err := proto.Marshal(userKicked) if err != nil { @@ -649,7 +649,7 @@ func (m *Messenger) handleCommunityEncryptionKeysRequest(community *communities. err := m.communitiesKeyDistributor.Distribute(community, keyActions) if err != nil { - m.logger.Error("failed to send community keys", zap.Error(err), zap.String("community ID", community.IDString())) + m.logger.Error("failed to send community keys", zap.String("community ID", gocommon.TruncateWithDot(community.IDString())), zap.Error(err)) } return nil @@ -2337,7 +2337,7 @@ func (m *Messenger) CheckAndDeletePendingRequestToJoinCommunity(ctx context.Cont if timeNow >= requestTimeOutClock { err := m.communitiesManager.DeletePendingRequestToJoin(requestToJoin) if err != nil { - m.logger.Error("failed to delete pending request to join", zap.String("req-id", requestToJoin.ID.String()), zap.Error(err)) + m.logger.Error("failed to delete pending request to join", zap.String("req-id", gocommon.TruncateWithDot(requestToJoin.ID.String())), zap.Error(err)) return nil, err } @@ -4749,7 +4749,7 @@ func (m *Messenger) rekeyCommunities(logger *zap.Logger) { err = m.communitiesKeyDistributor.Distribute(c, keyActions) if err != nil { - logger.Error("failed to rekey community", zap.Error(err), zap.String("community ID", c.IDString())) + logger.Error("failed to rekey community", zap.String("community ID", gocommon.TruncateWithDot(c.IDString())), zap.Error(err)) continue } } @@ -5079,18 +5079,18 @@ func (m *Messenger) HandleDeleteCommunityMemberMessages(state *ReceivedMessageSt func (m *Messenger) leaveCommunityOnSoftKick(community *communities.Community, messengerResponse *MessengerResponse) { response, err := m.kickedOutOfCommunity(community.ID(), true) if err != nil { - m.logger.Error("member soft kick error", zap.String("communityID", types.EncodeHex(community.ID())), zap.Error(err)) + m.logger.Error("member soft kick error", zap.String("communityID", gocommon.TruncateWithDot(types.EncodeHex(community.ID()))), zap.Error(err)) } if err := messengerResponse.Merge(response); err != nil { - m.logger.Error("cannot merge leaveCommunityOnSoftKick response", zap.String("communityID", types.EncodeHex(community.ID())), zap.Error(err)) + m.logger.Error("cannot merge leaveCommunityOnSoftKick response", zap.String("communityID", gocommon.TruncateWithDot(types.EncodeHex(community.ID()))), zap.Error(err)) } } func (m *Messenger) shareRevealedAccountsOnSoftKick(community *communities.Community, messengerResponse *MessengerResponse) { requestToJoin, err := m.sendSharedAddressToControlNode(community.ControlNode(), community) if err != nil { - m.logger.Error("share address to control node failed", zap.String("id", types.EncodeHex(community.ID())), zap.Error(err)) + m.logger.Error("share address to control node failed", zap.String("id", gocommon.TruncateWithDot(types.EncodeHex(community.ID()))), zap.Error(err)) if err == communities.ErrRevealedAccountsAbsent || err == communities.ErrNoRevealedAccountsSignature { m.AddActivityCenterNotificationToResponse(community.IDString(), ActivityCenterNotificationTypeShareAccounts, messengerResponse) @@ -5181,7 +5181,7 @@ func (m *Messenger) getCommunityStorenode(communityID ...string) peer.ID { ms, err := m.communityStorenodes.GetStorenodeByCommunityID(communityID[0]) if err != nil { if !errors.Is(err, storenodes.ErrNotFound) { - m.logger.Error("getting storenode for community, using global", zap.String("communityID", communityID[0]), zap.Error(err)) + m.logger.Error("getting storenode for community, using global", zap.String("communityID", gocommon.TruncateWithDot(communityID[0])), zap.Error(err)) } // if we don't find a specific mailserver for the community, we just use the regular mailserverCycle's one return m.transport.GetActiveStorenode() @@ -5189,7 +5189,7 @@ func (m *Messenger) getCommunityStorenode(communityID ...string) peer.ID { peerID, err := ms.PeerID() if err != nil { - m.logger.Error("getting storenode for community, using global", zap.String("communityID", communityID[0]), zap.Error(err)) + m.logger.Error("getting storenode for community, using global", zap.String("communityID", gocommon.TruncateWithDot(communityID[0])), zap.Error(err)) return m.transport.GetActiveStorenode() } diff --git a/protocol/messenger_community_shard.go b/protocol/messenger_community_shard.go index 8fdda061d70..aa77c4d0ef0 100644 --- a/protocol/messenger_community_shard.go +++ b/protocol/messenger_community_shard.go @@ -9,6 +9,7 @@ import ( "github.com/golang/protobuf/proto" "go.uber.org/zap" + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/protocol/common" @@ -80,7 +81,7 @@ func (m *Messenger) HandleCommunityPublicShardInfo(state *ReceivedMessageState, } logError := func(err error) { - m.logger.Error("HandleCommunityPublicShardInfo failed: ", zap.Error(err), zap.String("communityID", types.EncodeHex(publicShardInfo.CommunityId))) + m.logger.Error("HandleCommunityPublicShardInfo failed: ", zap.Error(err), zap.String("communityID", gocommon.TruncateWithDot(types.EncodeHex(publicShardInfo.CommunityId)))) } err = m.verifyCommunitySignature(a.Payload, a.Signature, publicShardInfo.CommunityId, publicShardInfo.ChainId) diff --git a/protocol/messenger_contacts.go b/protocol/messenger_contacts.go index c2536a0d8d4..84e3106d709 100644 --- a/protocol/messenger_contacts.go +++ b/protocol/messenger_contacts.go @@ -9,6 +9,7 @@ import ( "github.com/golang/protobuf/proto" "go.uber.org/zap" + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/deprecation" "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/types" @@ -289,7 +290,7 @@ func (m *Messenger) updateAcceptedContactRequest(response *MessengerResponse, co contactRequest, err = m.persistence.MessageByID(contactRequestID) } if err != nil { - m.logger.Error("contact request not found", zap.String("contactRequestID", contactRequestID), zap.Error(err)) + m.logger.Error("contact request not found", zap.String("contactRequestID", gocommon.TruncateWithDot(contactRequestID)), zap.Error(err)) return nil, err } @@ -1203,7 +1204,7 @@ func (m *Messenger) GetLatestContactRequestForContact(contactID string) (*Messen contactRequest, err := m.persistence.MessageByID(contactRequestID) if err != nil { - m.logger.Error("contact request not found", zap.String("contactRequestID", contactRequestID), zap.Error(err)) + m.logger.Error("contact request not found", zap.String("contactRequestID", gocommon.TruncateWithDot(contactRequestID)), zap.Error(err)) return nil, err } diff --git a/protocol/messenger_mention.go b/protocol/messenger_mention.go index d624d044876..99369e12330 100644 --- a/protocol/messenger_mention.go +++ b/protocol/messenger_mention.go @@ -13,6 +13,7 @@ import ( "go.uber.org/zap" + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/logutils" "github.com/status-im/status-go/api/multiformat" @@ -386,7 +387,7 @@ func (m *MentionManager) calculateSuggestionsWithMentionableUsers(chatID string, case textOperationReplace: end = state.Start + len([]rune(state.NewText)) default: - m.logger.Error("calculateSuggestionsWithMentionableUsers: unknown textOperation", zap.String("chatID", chatID), zap.String("fullText", fullText), zap.Any("state", state)) + m.logger.Error("calculateSuggestionsWithMentionableUsers: unknown textOperation", zap.String("chatID", gocommon.TruncateWithDot(chatID)), zap.Any("state", state)) } atSignIdx := lastIndexOfAtSign(fullText, end) diff --git a/protocol/messenger_messages.go b/protocol/messenger_messages.go index b723218a770..424632658d0 100644 --- a/protocol/messenger_messages.go +++ b/protocol/messenger_messages.go @@ -7,6 +7,7 @@ import ( "github.com/golang/protobuf/proto" + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/protocol/common" "github.com/status-im/status-go/protocol/protobuf" "github.com/status-im/status-go/protocol/requests" @@ -65,7 +66,7 @@ func (m *Messenger) EditMessage(ctx context.Context, request *requests.EditMessa replacedText, err := m.mentionsManager.ReplaceWithPublicKey(message.ChatId, request.Text) if err != nil { - m.logger.Error("failed to replace text with public key", zap.String("chatID", message.ChatId), zap.String("text", request.Text)) + m.logger.Error("failed to replace text with public key", zap.String("chatID", gocommon.TruncateWithDot(message.ChatId)), zap.Error(err)) // use original text as fallback replacedText = request.Text } @@ -144,7 +145,7 @@ func (m *Messenger) CanDeleteMessageForEveryoneInCommunity(communityID string, p if communityID != "" { community, err := m.communitiesManager.GetByIDString(communityID) if err != nil { - m.logger.Error("failed to find community", zap.String("communityID", communityID), zap.Error(err)) + m.logger.Error("failed to find community", zap.String("communityID", gocommon.TruncateWithDot(communityID)), zap.Error(err)) return false } return community.CanDeleteMessageForEveryone(publicKey) @@ -155,7 +156,7 @@ func (m *Messenger) CanDeleteMessageForEveryoneInCommunity(communityID string, p func (m *Messenger) CanDeleteMessageForEveryoneInPrivateGroupChat(chat *Chat, publicKey *ecdsa.PublicKey) bool { group, err := newProtocolGroupFromChat(chat) if err != nil { - m.logger.Error("failed to find group", zap.String("chatID", chat.ID), zap.Error(err)) + m.logger.Error("failed to find group", zap.String("chatID", gocommon.TruncateWithDot(chat.ID)), zap.Error(err)) return false } admins := group.Admins() diff --git a/protocol/messenger_raw_message_resend.go b/protocol/messenger_raw_message_resend.go index 81018276833..24d5afa7957 100644 --- a/protocol/messenger_raw_message_resend.go +++ b/protocol/messenger_raw_message_resend.go @@ -49,7 +49,7 @@ func (m *Messenger) resendExpiredMessages() error { for _, id := range ids { message, shouldResend, err := m.processMessageID(id) if err != nil { - m.logger.Error("Error processing message ID when trying resend raw message", zap.String("id", id), zap.Error(err)) + m.logger.Error("Error processing message ID when trying resend raw message", zap.String("id", gocommon.TruncateWithDot(id)), zap.Error(err)) } else if shouldResend { m.logger.Debug("Resent raw message", zap.String("id", id), @@ -186,7 +186,7 @@ func (m *Messenger) UpsertRawMessageToWatch(rawMessage *common.RawMessage) (*com // relate watch method: Messenger#watchExpiredMessages func (m *Messenger) AddRawMessageToWatch(rawMessage *common.RawMessage) (*common.RawMessage, error) { if err := m.sender.ValidateRawMessage(rawMessage); err != nil { - m.logger.Error("Can't add raw message to watch", zap.String("messageID", rawMessage.ID), zap.Error(err)) + m.logger.Error("Can't add raw message to watch", zap.String("messageID", gocommon.TruncateWithDot(rawMessage.ID)), zap.Error(err)) return nil, err } @@ -197,7 +197,7 @@ func (m *Messenger) upsertRawMessageToWatch(rawMessage *common.RawMessage) { _, err := m.UpsertRawMessageToWatch(rawMessage) if err != nil { // this is unlikely to happen, but we should log it - m.logger.Error("Can't upsert raw message after SendCommunityMessage", zap.Error(err), zap.String("id", rawMessage.ID)) + m.logger.Error("Can't upsert raw message after SendCommunityMessage", zap.Error(err), zap.String("id", gocommon.TruncateWithDot(rawMessage.ID))) } } diff --git a/protocol/messenger_sync_settings.go b/protocol/messenger_sync_settings.go index 9a10cddd504..727d1199e09 100644 --- a/protocol/messenger_sync_settings.go +++ b/protocol/messenger_sync_settings.go @@ -35,7 +35,7 @@ func (m *Messenger) prepareSyncSettingsMessages(currentClock uint64, prepareForB // Pull clock from the db clock, err := m.settings.GetSettingLastSynced(sf) if err != nil { - logger.Error("m.settings.GetSettingLastSynced", zap.Error(err), zap.Any("SettingField", sf)) + logger.Error("m.settings.GetSettingLastSynced", zap.Error(err), zap.String("SettingField", sf.GetDBName())) errors = append(errors, err) return } @@ -143,7 +143,7 @@ func (m *Messenger) startSyncSettingsLoop() { } rm, _, err := s.SyncProtobufFactory().FromInterface()(s.Value, clock, chat.ID) if err != nil { - logger.Error("SyncProtobufFactory().FromInterface", zap.Error(err), zap.Any("SyncSettingField", s)) + logger.Error("SyncProtobufFactory().FromInterface", zap.Error(err), zap.String("SyncSettingField", s.GetDBName())) break } diff --git a/server/handlers.go b/server/handlers.go index e0f48fd3d2f..02130e80a4e 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -20,6 +20,7 @@ import ( eth_common "github.com/ethereum/go-ethereum/common" + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/images" "github.com/status-im/status-go/ipfs" "github.com/status-im/status-go/multiaccounts" @@ -317,7 +318,7 @@ func handleAccountImagesImpl(multiaccountsDB *multiaccounts.Database, logger *za identityImage, err := multiaccountsDB.GetIdentityImage(parsed.KeyUID, parsed.ImageName) if err != nil { - logger.Error("handleAccountImagesImpl: failed to load image.", zap.String("keyUid", parsed.KeyUID), zap.String("imageName", parsed.ImageName), zap.Error(err)) + logger.Error("handleAccountImagesImpl: failed to load image.", zap.String("keyUid", gocommon.TruncateWithDot(parsed.KeyUID)), zap.String("imageName", parsed.ImageName), zap.Error(err)) return } @@ -332,7 +333,7 @@ func handleAccountImagesImpl(multiaccountsDB *multiaccounts.Database, logger *za payload, err := images.RoundCrop(identityImage.Payload) if err != nil { - logger.Error("handleAccountImagesImpl: failed to crop image.", zap.String("keyUid", parsed.KeyUID), zap.String("imageName", parsed.ImageName), zap.Error(err)) + logger.Error("handleAccountImagesImpl: failed to crop image.", zap.String("keyUid", gocommon.TruncateWithDot(parsed.KeyUID)), zap.String("imageName", parsed.ImageName), zap.Error(err)) return } @@ -341,7 +342,7 @@ func handleAccountImagesImpl(multiaccountsDB *multiaccounts.Database, logger *za if parsed.Ring { account, err := multiaccountsDB.GetAccount(parsed.KeyUID) if err != nil { - logger.Error("handleAccountImagesImpl: failed to GetAccount .", zap.String("keyUid", parsed.KeyUID), zap.Error(err)) + logger.Error("handleAccountImagesImpl: failed to GetAccount .", zap.String("keyUid", gocommon.TruncateWithDot(parsed.KeyUID)), zap.Error(err)) return } @@ -349,12 +350,12 @@ func handleAccountImagesImpl(multiaccountsDB *multiaccounts.Database, logger *za if accColorHash == nil { if parsed.PublicKey == "" { - logger.Error("handleAccountImagesImpl: no public key for color hash", zap.String("keyUid", parsed.KeyUID)) + logger.Error("handleAccountImagesImpl: no public key for color hash", zap.String("keyUid", gocommon.TruncateWithDot(parsed.KeyUID))) } accColorHash, err = colorhash.GenerateFor(parsed.PublicKey) if err != nil { - logger.Error("handleAccountImagesImpl: could not generate color hash", zap.String("keyUid", parsed.KeyUID), zap.Error(err)) + logger.Error("handleAccountImagesImpl: could not generate color hash", zap.String("keyUid", gocommon.TruncateWithDot(parsed.KeyUID)), zap.Error(err)) } } @@ -476,7 +477,7 @@ func handleAccountInitialsImpl(multiaccountsDB *multiaccounts.Database, logger * account, err := multiaccountsDB.GetAccount(parsed.KeyUID) if err != nil { - logger.Error("handleAccountInitialsImpl: failed to get account.", zap.String("keyUid", parsed.KeyUID), zap.Error(err)) + logger.Error("handleAccountInitialsImpl: failed to get account.", zap.String("keyUid", gocommon.TruncateWithDot(parsed.KeyUID)), zap.Error(err)) return } name = account.Name @@ -488,19 +489,19 @@ func handleAccountInitialsImpl(multiaccountsDB *multiaccounts.Database, logger * payload, err := images.GenerateInitialsImage(initials, parsed.BgColor, parsed.Color, parsed.FontFile, parsed.BgSize, parsed.FontSize, parsed.UppercaseRatio) if err != nil { - logger.Error("handleAccountInitialsImpl: failed to generate initials image.", zap.String("keyUid", parsed.KeyUID), zap.String("name", account.Name), zap.Error(err)) + logger.Error("handleAccountInitialsImpl: failed to generate initials image.", zap.String("keyUid", gocommon.TruncateWithDot(parsed.KeyUID)), zap.String("name", account.Name), zap.Error(err)) return } if parsed.Ring { if accColorHash == nil { if parsed.PublicKey == "" { - logger.Error("handleAccountInitialsImpl: no public key, can't draw ring", zap.String("keyUid", parsed.KeyUID), zap.Error(err)) + logger.Error("handleAccountInitialsImpl: no public key, can't draw ring", zap.String("keyUid", gocommon.TruncateWithDot(parsed.KeyUID)), zap.Error(err)) } accColorHash, err = colorhash.GenerateFor(parsed.PublicKey) if err != nil { - logger.Error("handleAccountInitialsImpl: failed to generate color hash from pubkey", zap.String("keyUid", parsed.KeyUID), zap.Error(err)) + logger.Error("handleAccountInitialsImpl: failed to generate color hash from pubkey", zap.String("keyUid", gocommon.TruncateWithDot(parsed.KeyUID)), zap.Error(err)) } } @@ -525,7 +526,7 @@ func handleAccountInitialsImpl(multiaccountsDB *multiaccounts.Database, logger * } if len(payload) == 0 { - logger.Error("handleAccountInitialsImpl: empty image", zap.String("keyUid", parsed.KeyUID), zap.Error(err)) + logger.Error("handleAccountInitialsImpl: empty image", zap.String("keyUid", gocommon.TruncateWithDot(parsed.KeyUID)), zap.Error(err)) return } mime, err := images.GetProtobufImageMime(payload) @@ -553,7 +554,7 @@ func handleAccountInitialsPlaceholder(logger *zap.Logger, w http.ResponseWriter, payload, err := images.GenerateInitialsImage(initials, parsed.BgColor, parsed.Color, parsed.FontFile, parsed.BgSize, parsed.FontSize, parsed.UppercaseRatio) if err != nil { - logger.Error("handleAccountInitialsPlaceholder: failed to generate initials image.", zap.String("keyUid", parsed.KeyUID), zap.String("name", parsed.FullName), zap.Error(err)) + logger.Error("handleAccountInitialsPlaceholder: failed to generate initials image.", zap.String("keyUid", gocommon.TruncateWithDot(parsed.KeyUID)), zap.String("name", parsed.FullName), zap.Error(err)) return } @@ -566,7 +567,7 @@ func handleAccountInitialsPlaceholder(logger *zap.Logger, w http.ResponseWriter, } if len(payload) == 0 { - logger.Error("handleAccountInitialsPlaceholder: empty image", zap.String("keyUid", parsed.KeyUID), zap.Error(err)) + logger.Error("handleAccountInitialsPlaceholder: empty image", zap.String("keyUid", gocommon.TruncateWithDot(parsed.KeyUID)), zap.Error(err)) return } mime, err := images.GetProtobufImageMime(payload) @@ -646,13 +647,13 @@ func handleContactImages(db *sql.DB, logger *zap.Logger) http.HandlerFunc { var payload []byte err := db.QueryRow(`SELECT payload FROM chat_identity_contacts WHERE contact_id = ? and image_type = ?`, parsed.PublicKey, parsed.ImageName).Scan(&payload) if err != nil { - logger.Error("failed to load image.", zap.String("contact id", parsed.PublicKey), zap.String("image type", parsed.ImageName), zap.Error(err)) + logger.Error("failed to load image.", zap.String("contact id", gocommon.TruncateWithDot(parsed.PublicKey)), zap.String("image type", parsed.ImageName), zap.Error(err)) return } img, _, err := image.Decode(bytes.NewReader(payload)) if err != nil { - logger.Error("failed to decode config.", zap.String("contact id", parsed.PublicKey), zap.String("image type", parsed.ImageName), zap.Error(err)) + logger.Error("failed to decode config.", zap.String("contact id", gocommon.TruncateWithDot(parsed.PublicKey)), zap.String("image type", parsed.ImageName), zap.Error(err)) return } width := img.Bounds().Dx() @@ -1028,20 +1029,20 @@ func handleCommunityDescriptionImagesPath(db *sql.DB, getCommunityImages func(co } } if imagePayload == nil { - logger.Error("can't find community description image", zap.String("community id", communityID), zap.String("name", name)) + logger.Error("can't find community description image", zap.String("community id", gocommon.TruncateWithDot(communityID)), zap.String("name", name)) return } mime, err := images.GetProtobufImageMime(imagePayload) if err != nil { - logger.Error("failed to get community image mime", zap.String("community id", communityID), zap.Error(err)) + logger.Error("failed to get community image mime", zap.String("community id", gocommon.TruncateWithDot(communityID)), zap.Error(err)) } w.Header().Set("Content-Type", mime) w.Header().Set("Cache-Control", "no-store") _, err = w.Write(imagePayload) if err != nil { - logger.Error("failed to write community image", zap.String("community id", communityID), zap.Error(err)) + logger.Error("failed to write community image", zap.String("community id", gocommon.TruncateWithDot(communityID)), zap.Error(err)) } } } @@ -1078,7 +1079,7 @@ func handleCommunityDescriptionTokenImagesPath(db *sql.DB, getCommunityTokens fu } } if foundToken == nil { - logger.Error("can't find community description token image", zap.String("community id", communityID), zap.String("symbol", symbol)) + logger.Error("can't find community description token image", zap.String("community id", gocommon.TruncateWithDot(communityID)), zap.String("symbol", symbol)) return } @@ -1089,14 +1090,14 @@ func handleCommunityDescriptionTokenImagesPath(db *sql.DB, getCommunityTokens fu } mime, err := images.GetProtobufImageMime(imagePayload) if err != nil { - logger.Error("failed to get community description token image mime", zap.String("community id", communityID), zap.String("symbol", symbol), zap.Error(err)) + logger.Error("failed to get community description token image mime", zap.String("community id", gocommon.TruncateWithDot(communityID)), zap.String("symbol", symbol), zap.Error(err)) } w.Header().Set("Content-Type", mime) w.Header().Set("Cache-Control", "no-store") _, err = w.Write(imagePayload) if err != nil { - logger.Error("failed to write community description token image", zap.String("community id", communityID), zap.String("symbol", symbol), zap.Error(err)) + logger.Error("failed to write community description token image", zap.String("community id", gocommon.TruncateWithDot(communityID)), zap.String("symbol", symbol), zap.Error(err)) } } } diff --git a/server/pairing/challenge_management.go b/server/pairing/challenge_management.go index 25281c29606..8fbd7518fc6 100644 --- a/server/pairing/challenge_management.go +++ b/server/pairing/challenge_management.go @@ -68,7 +68,7 @@ func NewChallengeGiver(e *PayloadEncryptor, logger *zap.Logger) (*ChallengeGiver func (cg *ChallengeGiver) getIP(r *http.Request) (net.IP, error) { h, _, err := net.SplitHostPort(r.RemoteAddr) if err != nil { - cg.logger.Error("getIP: h, _, err := net.SplitHostPort(r.RemoteAddr)", zap.Error(err), zap.String("r.RemoteAddr", r.RemoteAddr)) + cg.logger.Error("getIP: h, _, err := net.SplitHostPort(r.RemoteAddr)", zap.Error(err)) return nil, &ChallengeError{"error", http.StatusInternalServerError} } return net.ParseIP(h), nil @@ -112,7 +112,7 @@ func (cg *ChallengeGiver) validateClientIP(r *http.Request) error { func (cg *ChallengeGiver) getSession(r *http.Request) (*sessions.Session, error) { s, err := cg.cookieStore.Get(r, sessionChallenge) if err != nil { - cg.logger.Error("checkChallengeResponse: cg.cookieStore.Get(r, sessionChallenge)", zap.Error(err), zap.String("sessionChallenge", sessionChallenge)) + cg.logger.Error("checkChallengeResponse: cg.cookieStore.Get(r, sessionChallenge)", zap.Error(err)) return nil, &ChallengeError{"error", http.StatusInternalServerError} } return s, nil @@ -171,7 +171,7 @@ func (cg *ChallengeGiver) checkChallengeResponse(w http.ResponseWriter, r *http. dcr, err := cg.encryptor.decryptPlain(base58.Decode(clientChallengeResp)) if err != nil { - cg.logger.Error("checkChallengeResponse: cg.encryptor.decryptPlain(base58.Decode(clientChallengeResp))", zap.Error(err), zap.String("clientChallengeResp", clientChallengeResp)) + cg.logger.Error("checkChallengeResponse: cg.encryptor.decryptPlain(base58.Decode(clientChallengeResp))", zap.Error(err)) return &ChallengeError{"error", http.StatusInternalServerError} } diff --git a/server/pairing/client.go b/server/pairing/client.go index f8fc7a39236..ebadbd15e43 100644 --- a/server/pairing/client.go +++ b/server/pairing/client.go @@ -97,7 +97,7 @@ func NewBaseClient(c *ConnectionParams, logger *zap.Logger) (*BaseClient, error) netIPs, err := server.FindReachableAddressesForPairingClient(c.netIPs) if err != nil { - logger.Error("[local pair client] failed to find reachable addresses", zap.Error(err), zap.Any("netIPs", netIPs)) + logger.Error("[local pair client] failed to find reachable addresses", zap.Error(err)) signal.SendLocalPairingEvent(Event{Type: EventConnectionError, Error: err.Error(), Action: ActionConnect}) return nil, err } diff --git a/server/pairing/handlers.go b/server/pairing/handlers.go index a65e85a40cf..6772e0225cc 100644 --- a/server/pairing/handlers.go +++ b/server/pairing/handlers.go @@ -38,7 +38,7 @@ func handleReceiveAccount(logger *zap.Logger, pr PayloadReceiver) http.HandlerFu err = pr.Receive(payload) if err != nil { signal.SendLocalPairingEvent(Event{Type: EventProcessError, Error: err.Error(), Action: ActionPairingAccount}) - logger.Error("handleReceiveAccount pr.Receive(payload)", zap.Error(err), zap.Binary("payload", payload)) + logger.Error("handleReceiveAccount pr.Receive(payload)", zap.Error(err)) http.Error(w, "error", http.StatusInternalServerError) return } @@ -89,7 +89,7 @@ func handleParingSyncDeviceReceive(logger *zap.Logger, pr PayloadReceiver) http. err = pr.Receive(payload) if err != nil { signal.SendLocalPairingEvent(Event{Type: EventProcessError, Error: err.Error(), Action: ActionSyncDevice}) - logger.Error("handleParingSyncDeviceReceive pr.Receive(payload)", zap.Error(err), zap.Binary("payload", payload)) + logger.Error("handleParingSyncDeviceReceive pr.Receive(payload)", zap.Error(err)) http.Error(w, "error", http.StatusInternalServerError) return } @@ -142,7 +142,7 @@ func handleReceiveInstallation(logger *zap.Logger, pmr PayloadMounterReceiver) h err = pmr.Receive(payload) if err != nil { signal.SendLocalPairingEvent(Event{Type: EventProcessError, Error: err.Error(), Action: ActionPairingInstallation}) - logger.Error("handleReceiveInstallation pmr.Receive(payload)", zap.Error(err), zap.Binary("payload", payload)) + logger.Error("handleReceiveInstallation pmr.Receive(payload)", zap.Error(err)) http.Error(w, "error", http.StatusInternalServerError) return } diff --git a/services/rpcfilters/transaction_sent_to_upstream_event.go b/services/rpcfilters/transaction_sent_to_upstream_event.go index 15d8a72587d..c7968f4a0c4 100644 --- a/services/rpcfilters/transaction_sent_to_upstream_event.go +++ b/services/rpcfilters/transaction_sent_to_upstream_event.go @@ -73,7 +73,7 @@ func (e *transactionSentToUpstreamEvent) processTransactionSentToUpstream(transa select { case channel <- transactionInfo: default: - logutils.ZapLogger().Error("dropping messages because the channel is full", zap.Any("transactionInfo", transactionInfo), zap.Int("id", id)) + logutils.ZapLogger().Error("dropping messages because the channel is full", zap.Int("id", id)) } } } diff --git a/services/wallet/api.go b/services/wallet/api.go index da603e5bf7b..f17727776aa 100644 --- a/services/wallet/api.go +++ b/services/wallet/api.go @@ -19,6 +19,7 @@ import ( signercore "github.com/ethereum/go-ethereum/signer/core/apitypes" abi_spec "github.com/status-im/status-go/abi-spec" "github.com/status-im/status-go/account" + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/logutils" @@ -928,7 +929,7 @@ func (api *API) FetchChainIDForURL(ctx context.Context, rpcURL string) (*big.Int func (api *API) getVerifiedWalletAccount(address, password string) (*account.SelectedExtKey, error) { exists, err := api.s.accountsDB.AddressExists(types.HexToAddress(address)) if err != nil { - logutils.ZapLogger().Error("failed to query db for a given address", zap.String("address", address), zap.Error(err)) + logutils.ZapLogger().Error("failed to query db for a given address", zap.String("address", gocommon.TruncateWithDot(address)), zap.Error(err)) return nil, err } @@ -940,7 +941,7 @@ func (api *API) getVerifiedWalletAccount(address, password string) (*account.Sel keyStoreDir := api.s.Config().KeyStoreDir key, err := api.s.gethManager.VerifyAccountPassword(keyStoreDir, address, password) if err != nil { - logutils.ZapLogger().Error("failed to verify account", zap.String("account", address), zap.Error(err)) + logutils.ZapLogger().Error("failed to verify account", zap.String("account", gocommon.TruncateWithDot(address)), zap.Error(err)) return nil, err } diff --git a/services/wallet/collectibles/controller.go b/services/wallet/collectibles/controller.go index dcbeb5ccdc4..ed6ff9a1fdc 100644 --- a/services/wallet/collectibles/controller.go +++ b/services/wallet/collectibles/controller.go @@ -11,6 +11,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/event" + + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/logutils" "github.com/status-im/status-go/multiaccounts/accounts" "github.com/status-im/status-go/multiaccounts/settings" @@ -154,7 +156,8 @@ func (c *Controller) startPeriodicalOwnershipFetch() error { for _, addr := range addresses { err := c.startPeriodicalOwnershipFetchForAccount(common.Address(addr)) if err != nil { - logutils.ZapLogger().Error("Error starting periodical collectibles fetch for accpunt", zap.Stringer("address", addr), zap.Error(err)) + as := addr.String() + logutils.ZapLogger().Error("Error starting periodical collectibles fetch for accpunt", zap.String("address", gocommon.TruncateWithDot(as)), zap.Error(err)) return err } } @@ -309,14 +312,16 @@ func (c *Controller) startAccountsWatcher() { for _, address := range changedAddresses { err := c.startPeriodicalOwnershipFetchForAccount(address) if err != nil { - logutils.ZapLogger().Error("Error starting periodical collectibles fetch", zap.Stringer("address", address), zap.Error(err)) + as := address.String() + logutils.ZapLogger().Error("Error starting periodical collectibles fetch", zap.String("address", gocommon.TruncateWithDot(as)), zap.Error(err)) } } } else if eventType == accountsevent.EventTypeRemoved { for _, address := range changedAddresses { err := c.stopPeriodicalOwnershipFetchForAccount(address) if err != nil { - logutils.ZapLogger().Error("Error starting periodical collectibles fetch", zap.Stringer("address", address), zap.Error(err)) + as := address.String() + logutils.ZapLogger().Error("Error stopping periodical collectibles fetch", zap.String("address", gocommon.TruncateWithDot(as)), zap.Error(err)) } } } @@ -421,7 +426,8 @@ func (c *Controller) refetchOwnershipIfRecentTransfer(account common.Address, ch err := c.startPeriodicalOwnershipFetchForAccountAndChainID(account, chainID, true) c.commandsLock.Unlock() if err != nil { - logutils.ZapLogger().Error("Error starting periodical collectibles fetch", zap.Stringer("address", account), zap.Error(err)) + as := account.String() + logutils.ZapLogger().Error("Error starting periodical collectibles fetch", zap.String("address", gocommon.TruncateWithDot(as)), zap.Error(err)) } } } diff --git a/services/wallet/collectibles/manager.go b/services/wallet/collectibles/manager.go index 4ead12ddbdb..a916bbedd1c 100644 --- a/services/wallet/collectibles/manager.go +++ b/services/wallet/collectibles/manager.go @@ -720,7 +720,7 @@ func (o *Manager) processFullCollectibleData(ctx context.Context, assets []third } else { err := o.fetchCommunityAssets(communityID, communityAssets) if err != nil { - logutils.ZapLogger().Error("fetchCommunityAssets failed", zap.String("communityID", communityID), zap.Error(err)) + logutils.ZapLogger().Error("fetchCommunityAssets failed", zap.String("communityID", gocommon.TruncateWithDot(communityID)), zap.Error(err)) continue } for _, asset := range communityAssets { @@ -808,7 +808,7 @@ func (o *Manager) fillCommunityID(asset *thirdparty.FullCollectibleData) error { func (o *Manager) fetchCommunityAssets(communityID string, communityAssets []*thirdparty.FullCollectibleData) error { communityFound, err := o.communityManager.FillCollectiblesMetadata(communityID, communityAssets) if err != nil { - logutils.ZapLogger().Error("FillCollectiblesMetadata failed", zap.String("communityID", communityID), zap.Error(err)) + logutils.ZapLogger().Error("FillCollectiblesMetadata failed", zap.String("communityID", gocommon.TruncateWithDot(communityID)), zap.Error(err)) } else if !communityFound { logutils.ZapLogger().Warn("fetchCommunityAssets community not found", zap.String("communityID", communityID)) } @@ -829,13 +829,13 @@ func (o *Manager) fetchCommunityAssets(communityID string, communityAssets []*th err = o.collectiblesDataDB.SetData(collectiblesData, allowUpdate) if err != nil { - logutils.ZapLogger().Error("collectiblesDataDB SetData failed", zap.String("communityID", communityID), zap.Error(err)) + logutils.ZapLogger().Error("collectiblesDataDB SetData failed", zap.String("communityID", gocommon.TruncateWithDot(communityID)), zap.Error(err)) return err } err = o.collectionsDataDB.SetData(collectionsData, allowUpdate) if err != nil { - logutils.ZapLogger().Error("collectionsDataDB SetData failed", zap.String("communityID", communityID), zap.Error(err)) + logutils.ZapLogger().Error("collectionsDataDB SetData failed", zap.String("communityID", gocommon.TruncateWithDot(communityID)), zap.Error(err)) return err } @@ -843,7 +843,7 @@ func (o *Manager) fetchCommunityAssets(communityID string, communityAssets []*th if asset.CollectibleCommunityInfo != nil { err = o.collectiblesDataDB.SetCommunityInfo(asset.CollectibleData.ID, *asset.CollectibleCommunityInfo) if err != nil { - logutils.ZapLogger().Error("collectiblesDataDB SetCommunityInfo failed", zap.String("communityID", communityID), zap.Error(err)) + logutils.ZapLogger().Error("collectiblesDataDB SetCommunityInfo failed", zap.String("communityID", gocommon.TruncateWithDot(communityID)), zap.Error(err)) return err } } @@ -861,7 +861,7 @@ func (o *Manager) fetchCommunityAssetsAsync(_ context.Context, communityID strin defer gocommon.LogOnPanic() err := o.fetchCommunityAssets(communityID, communityAssets) if err != nil { - logutils.ZapLogger().Error("fetchCommunityAssets failed", zap.String("communityID", communityID), zap.Error(err)) + logutils.ZapLogger().Error("fetchCommunityAssets failed", zap.String("communityID", gocommon.TruncateWithDot(communityID)), zap.Error(err)) return } diff --git a/services/wallet/community/manager.go b/services/wallet/community/manager.go index 8253b3cb8f1..b3bd59803f3 100644 --- a/services/wallet/community/manager.go +++ b/services/wallet/community/manager.go @@ -74,7 +74,7 @@ func (cm *Manager) fetchCommunityInfo(communityID string, fetcher func() (*third if err != nil { dbErr := cm.setCommunityInfo(communityID, nil) if dbErr != nil { - logutils.ZapLogger().Error("SetCommunityInfo failed", zap.String("communityID", communityID), zap.Error(dbErr)) + logutils.ZapLogger().Error("SetCommunityInfo failed", zap.String("communityID", gocommon.TruncateWithDot(communityID)), zap.Error(dbErr)) } return nil, err } @@ -93,7 +93,7 @@ func (cm *Manager) FetchCommunityMetadataAsync(communityID string) { defer gocommon.LogOnPanic() communityInfo, err := cm.FetchCommunityMetadata(communityID) if err != nil { - logutils.ZapLogger().Error("FetchCommunityInfo failed", zap.String("communityID", communityID), zap.Error(err)) + logutils.ZapLogger().Error("FetchCommunityInfo failed", zap.String("communityID", gocommon.TruncateWithDot(communityID)), zap.Error(err)) } cm.signalUpdatedCommunityMetadata(communityID, communityInfo) }() diff --git a/services/wallet/router/pathprocessor/errors.go b/services/wallet/router/pathprocessor/errors.go index f16cd44b6ab..6c3bfaf5c9e 100644 --- a/services/wallet/router/pathprocessor/errors.go +++ b/services/wallet/router/pathprocessor/errors.go @@ -51,7 +51,7 @@ var ( ErrPriceImpactTooHigh = &errors.ErrorResponse{Code: errors.ErrorCode("WPP-039"), Details: "price impact too high"} ErrBurnAmountTooHigh = &errors.ErrorResponse{Code: errors.ErrorCode("WPP-040"), Details: "burn amount too high"} ErrCommunityTokenType = &errors.ErrorResponse{Code: errors.ErrorCode("WPP-041"), Details: "invalid community token type"} - ErrIncorrectSignatureFormat = &errors.ErrorResponse{Code: errors.ErrorCode("WPP-042"), Details: "incorrect signature: got %d, want %d"} + ErrIncorrectSignatureFormat = &errors.ErrorResponse{Code: errors.ErrorCode("WPP-042"), Details: "incorrect signature length: got %d, want %d"} ) func createErrorResponse(processorName string, err error) error { diff --git a/services/wallet/token/balancefetcher/balance_fetcher.go b/services/wallet/token/balancefetcher/balance_fetcher.go index 9a63267c6ed..3f26913960f 100644 --- a/services/wallet/token/balancefetcher/balance_fetcher.go +++ b/services/wallet/token/balancefetcher/balance_fetcher.go @@ -13,6 +13,8 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/contracts" "github.com/status-im/status-go/contracts/ethscan" "github.com/status-im/status-go/contracts/ierc20" @@ -169,7 +171,8 @@ func (bf *DefaultBalanceFetcher) FetchTokenBalancesWithScanContract(ctx context. BlockNumber: atBlock, }, account, chunk) if err != nil { - logutils.ZapLogger().Error("can't fetch erc20 token balance 6", zap.Stringer("account", account), zap.Error(err)) + as := account.String() + logutils.ZapLogger().Error("can't fetch erc20 token balance 6", zap.String("account", gocommon.TruncateWithDot(as)), zap.Error(err)) return nil, err } diff --git a/services/web3provider/api.go b/services/web3provider/api.go index fc476aac6e3..007fff6774b 100644 --- a/services/web3provider/api.go +++ b/services/web3provider/api.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" signercore "github.com/ethereum/go-ethereum/signer/core/apitypes" "github.com/status-im/status-go/account" + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/logutils" "github.com/status-im/status-go/services/typeddata" @@ -253,7 +254,7 @@ func (api *API) getVerifiedWalletAccount(address, password string) (*account.Sel key, err := api.s.accountsManager.VerifyAccountPassword(api.s.config.KeyStoreDir, address, password) if err != nil { - logutils.ZapLogger().Error("failed to verify account", zap.String("account", address), zap.Error(err)) + logutils.ZapLogger().Error("failed to verify account", zap.String("account", gocommon.TruncateWithDot(address)), zap.Error(err)) return nil, err }