From f172f29aa2d8a2913dc8d64ef2371572d9abf3aa 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 | 5 +- account/accounts.go | 3 +- api/geth_backend.go | 14 +-- 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 +++-- protocol/communities/manager.go | 2 +- protocol/identity/utils.go | 8 +- protocol/linkpreview_unfurler_status.go | 11 ++- protocol/messenger.go | 12 +-- protocol/messenger_backup_handler.go | 4 +- protocol/messenger_communities.go | 16 +-- protocol/messenger_community_shard.go | 3 +- protocol/messenger_handler.go | 2 +- protocol/messenger_mention.go | 9 +- protocol/messenger_messages.go | 7 +- protocol/messenger_share_urls.go | 9 +- .../messenger_store_node_request_manager.go | 2 +- protocol/messenger_sync_settings.go | 4 +- protocol/storenodes/database.go | 2 +- protocol/v1/membership_update_message.go | 9 +- server/handlers.go | 41 ++++---- server/pairing/challenge_management.go | 6 +- server/pairing/client.go | 8 +- server/pairing/connection.go | 6 +- server/pairing/handlers.go | 6 +- services/communitytokens/service.go | 15 +-- .../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/wallet/transfer/helpers.go | 3 +- services/web3provider/api.go | 3 +- 38 files changed, 291 insertions(+), 130 deletions(-) create mode 100644 common/utils_test.go diff --git a/abi-spec/utils.go b/abi-spec/utils.go index 8353a606a6f..770fd8a6913 100644 --- a/abi-spec/utils.go +++ b/abi-spec/utils.go @@ -11,6 +11,7 @@ import ( "go.uber.org/zap" "github.com/ethereum/go-ethereum/common" + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/logutils" ) @@ -48,7 +49,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 { @@ -183,7 +184,7 @@ func ToChecksumAddress(address string) (string, error) { return "", nil } if !addressBasicPattern.MatchString(address) { - return "", fmt.Errorf("given address '%s' is not a valid Ethereum address", address) + return "", fmt.Errorf("given address '%s' is not a valid Ethereum address", gocommon.TruncateWithDot(address)) } address = strings.ToLower(address) diff --git a/account/accounts.go b/account/accounts.go index ad16f7dc345..b8ccc00ae35 100644 --- a/account/accounts.go +++ b/account/accounts.go @@ -20,6 +20,7 @@ import ( gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/status-im/status-go/account/generator" + 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/keystore" "github.com/status-im/status-go/eth-node/types" @@ -230,7 +231,7 @@ func (m *DefaultManager) VerifyAccountPassword(keyStoreDir, address, password st // avoid swap attack if key.Address != addressObj { - return nil, fmt.Errorf("account mismatch: have %s, want %s", key.Address.Hex(), addressObj.Hex()) + return nil, fmt.Errorf("account mismatch: have %s, want %s", gocommon.TruncateWithDot(key.Address.Hex()), gocommon.TruncateWithDot(addressObj.Hex())) } return key, nil diff --git a/api/geth_backend.go b/api/geth_backend.go index c76584d399e..62f6a7847d4 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -30,7 +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" - d_common "github.com/status-im/status-go/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" @@ -283,7 +283,7 @@ func (b *GethStatusBackend) getAccountByKeyUID(keyUID string) (*multiaccounts.Ac return &acc, nil } } - return nil, fmt.Errorf("account with keyUID %s not found", keyUID) + return nil, fmt.Errorf("account with keyUID %s not found", gocommon.TruncateWithDot(keyUID)) } func (b *GethStatusBackend) SaveAccount(account multiaccounts.Account) error { @@ -359,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 } @@ -586,7 +586,7 @@ func (b *GethStatusBackend) LoginAccount(request *requests.Login) error { // and choose to upgrade a higher version instead, after upgrading, user first attempt to login will fail because the node config migration will fail. // and second attempt to login will cause an empty node config saved in the db. func (b *GethStatusBackend) workaroundToFixBadMigration(request *requests.Login) (err error) { - if !d_common.IsMobilePlatform() { // this issue only happens on mobile platform + if !gocommon.IsMobilePlatform() { // this issue only happens on mobile platform return nil } @@ -2476,7 +2476,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 } @@ -2494,7 +2494,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 } @@ -2508,7 +2508,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 5085efb5972..c5080aa5819 100644 --- a/appdatabase/database.go +++ b/appdatabase/database.go @@ -128,7 +128,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)) @@ -250,7 +250,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..f9841a2ca60 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 + } + + const 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 e7e73824dff..e6087c1b792 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" @@ -474,13 +475,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)) @@ -654,7 +655,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)) @@ -763,7 +764,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)) @@ -790,7 +791,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)) @@ -2062,7 +2063,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 @@ -2095,6 +2096,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) } @@ -2108,6 +2110,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) } @@ -2155,6 +2158,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) } @@ -2174,7 +2178,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 } @@ -2186,7 +2190,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) @@ -2199,7 +2203,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) @@ -2212,7 +2216,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/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/identity/utils.go b/protocol/identity/utils.go index a957538193d..66b6376057c 100644 --- a/protocol/identity/utils.go +++ b/protocol/identity/utils.go @@ -7,6 +7,8 @@ import ( "testing" "github.com/ethereum/go-ethereum/crypto/secp256k1" + + gocommon "github.com/status-im/status-go/common" ) func ToColorID(pubkey string) (int64, error) { @@ -14,7 +16,7 @@ func ToColorID(pubkey string) (int64, error) { pubkeyValue, ok := new(big.Int).SetString(pubkey, 0) if !ok { - return 0, fmt.Errorf("invalid pubkey: %s", pubkey) + return 0, fmt.Errorf("invalid pubkey: %s", gocommon.TruncateWithDot(pubkey)) } colorID := new(big.Int).Mod(pubkeyValue, new(big.Int).SetInt64(colorPalletLength-1)).Int64() @@ -61,12 +63,12 @@ func Slices(compressedPubkey []byte) (res [4][]byte, err error) { func ToCompressedKey(pubkey string) ([]byte, error) { pubkeyValue, ok := new(big.Int).SetString(pubkey, 0) if !ok { - return nil, fmt.Errorf("invalid pubkey: %s", pubkey) + return nil, fmt.Errorf("invalid pubkey: %s", gocommon.TruncateWithDot(pubkey)) } x, y := secp256k1.S256().Unmarshal(pubkeyValue.Bytes()) if x == nil || !secp256k1.S256().IsOnCurve(x, y) { - return nil, fmt.Errorf("invalid pubkey: %s", pubkey) + return nil, fmt.Errorf("invalid pubkey: %s", gocommon.TruncateWithDot(pubkey)) } return secp256k1.CompressPubkey(x, y), nil diff --git a/protocol/linkpreview_unfurler_status.go b/protocol/linkpreview_unfurler_status.go index d4e6e8e4dd9..8bc256fbbb0 100644 --- a/protocol/linkpreview_unfurler_status.go +++ b/protocol/linkpreview_unfurler_status.go @@ -6,6 +6,7 @@ import ( "go.uber.org/zap" "github.com/status-im/status-go/api/multiformat" + gocommon "github.com/status-im/status-go/common" "github.com/status-im/status-go/images" "github.com/status-im/status-go/protocol/common" "github.com/status-im/status-go/protocol/common/shard" @@ -61,10 +62,10 @@ func (u *StatusUnfurler) buildContactData(publicKey string) (*common.StatusConta if contact == nil { contact, err = u.m.FetchContact(contactID, true) if err != nil { - return nil, fmt.Errorf("failed to request contact info from mailserver for public key '%s': %w", publicKey, err) + return nil, fmt.Errorf("failed to request contact info from mailserver for public key '%s': %w", gocommon.TruncateWithDot(publicKey), err) } if contact == nil { - return nil, fmt.Errorf("contact wasn't found at the store node %s", publicKey) + return nil, fmt.Errorf("contact wasn't found at the store node %s", gocommon.TruncateWithDot(publicKey)) } } @@ -93,7 +94,7 @@ func (u *StatusUnfurler) buildCommunityData(communityID string, shard *shard.Sha }) if err != nil { - return nil, nil, fmt.Errorf("failed to get community info for communityID '%s': %w", communityID, err) + return nil, nil, fmt.Errorf("failed to get community info for communityID '%s': %w", gocommon.TruncateWithDot(communityID), err) } if community == nil { @@ -102,7 +103,7 @@ func (u *StatusUnfurler) buildCommunityData(communityID string, shard *shard.Sha statusCommunityLinkPreviews, err := community.ToStatusLinkPreview() if err != nil { - return nil, nil, fmt.Errorf("failed to get status community link preview for communityID '%s': %w", communityID, err) + return nil, nil, fmt.Errorf("failed to get status community link preview for communityID '%s': %w", gocommon.TruncateWithDot(communityID), err) } return community, statusCommunityLinkPreviews, nil @@ -116,7 +117,7 @@ func (u *StatusUnfurler) buildChannelData(channelUUID string, communityID string channel, ok := community.Chats()[channelUUID] if !ok { - return nil, fmt.Errorf("channel with channelID '%s' not found in community '%s'", channelUUID, communityID) + return nil, fmt.Errorf("channel with channelID '%s' not found in community '%s'", gocommon.TruncateWithDot(channelUUID), gocommon.TruncateWithDot(communityID)) } return &common.StatusCommunityChannelLinkPreview{ diff --git a/protocol/messenger.go b/protocol/messenger.go index fb7616123cf..f9fd4ea7347 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -2038,7 +2038,7 @@ func (m *Messenger) dispatchMessage(ctx context.Context, rawMessage common.RawMe zap.String("chatName", chat.Name), zap.Any("messageType", rawMessage.MessageType), ) - return rawMessage, fmt.Errorf("can't post message type '%d' on chat '%s'", rawMessage.MessageType, chat.ID) + return rawMessage, fmt.Errorf("can't post message type '%d' on chat '%s'", rawMessage.MessageType, gocommon.TruncateWithDot(chat.ID)) } logger.Debug("sending community chat message", zap.String("chatName", chat.Name)) @@ -2184,7 +2184,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 { @@ -3023,12 +3023,12 @@ func (r *ReceivedMessageState) addNewMessageNotification(publicKey ecdsa.PublicK chat, ok := r.AllChats.Load(m.LocalChatID) if !ok { - return fmt.Errorf("chat ID '%s' not present", m.LocalChatID) + return fmt.Errorf("chat ID '%s' not present", gocommon.TruncateWithDot(m.LocalChatID)) } contact, ok := r.AllContacts.Load(contactID) if !ok { - return fmt.Errorf("contact ID '%s' not present", contactID) + return fmt.Errorf("contact ID '%s' not present", gocommon.TruncateWithDot(contactID)) } if !chat.Muted { @@ -3098,7 +3098,7 @@ func (r *ReceivedMessageState) addNewActivityCenterNotification(publicKey ecdsa. chat, ok := r.AllChats.Load(message.LocalChatID) if !ok { - return fmt.Errorf("chat ID '%s' not present", message.LocalChatID) + return fmt.Errorf("chat ID '%s' not present", gocommon.TruncateWithDot(message.LocalChatID)) } isNotification, notificationType := showMentionOrReplyActivityCenterNotification(publicKey, message, chat, responseTo) @@ -4283,7 +4283,7 @@ func (m *Messenger) MarkAllReadInCommunity(ctx context.Context, communityID stri m.allChats.Store(chat.ID, chat) response.AddChat(chat) } else { - err = fmt.Errorf("chat with chatID %s not found", chatID) + err = fmt.Errorf("chat with chatID %s not found", gocommon.TruncateWithDot(chatID)) } } return response, err diff --git a/protocol/messenger_backup_handler.go b/protocol/messenger_backup_handler.go index bc15e6f7fd1..c0165d9177c 100644 --- a/protocol/messenger_backup_handler.go +++ b/protocol/messenger_backup_handler.go @@ -540,7 +540,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 } @@ -561,7 +561,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..b22bca1ee66 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 @@ -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_handler.go b/protocol/messenger_handler.go index 322390473c5..41911e105e7 100644 --- a/protocol/messenger_handler.go +++ b/protocol/messenger_handler.go @@ -486,7 +486,7 @@ func (m *Messenger) syncContactRequestForInstallationContact(contact *Contact, s } if chat == nil { - return fmt.Errorf("no chat restored during the contact synchronisation, contact.ID = %s", contact.ID) + return fmt.Errorf("no chat restored during the contact synchronisation, contact.ID = %s", gocommon.TruncateWithDot(contact.ID)) } contactRequestID, err := m.persistence.LatestPendingContactRequestIDForContact(contact.ID) diff --git a/protocol/messenger_mention.go b/protocol/messenger_mention.go index d624d044876..1fbed2248e8 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" @@ -221,7 +222,7 @@ func (m *MentionManager) getMentionableUser(chatID string, pk string) (*Mentiona } user, ok := mentionableUsers[pk] if !ok { - return nil, fmt.Errorf("user not found when getting mentionable user, pk: %s", pk) + return nil, fmt.Errorf("user not found when getting mentionable user, pk: %s", gocommon.TruncateWithDot(pk)) } return user, nil } @@ -230,7 +231,7 @@ func (m *MentionManager) getMentionableUsers(chatID string) (map[string]*Mention mentionableUsers := make(map[string]*MentionableUser) chat, _ := m.allChats.Load(chatID) if chat == nil { - return nil, fmt.Errorf("chat not found when getting mentionable users, chatID: %s", chatID) + return nil, fmt.Errorf("chat not found when getting mentionable users, chatID: %s", gocommon.TruncateWithDot(chatID)) } var publicKeys []string @@ -290,7 +291,7 @@ func (m *MentionManager) addMentionableUser(mentionableUsers map[string]*Mention func (m *MentionManager) ReplaceWithPublicKey(chatID, text string) (string, error) { chat, _ := m.allChats.Load(chatID) if chat == nil { - return "", fmt.Errorf("chat not found when check mentions, chatID: %s", chatID) + return "", fmt.Errorf("chat not found when check mentions, chatID: %s", gocommon.TruncateWithDot(chatID)) } mentionableUsers, err := m.mentionableUserGetter.getMentionableUsers(chatID) if err != nil { @@ -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_share_urls.go b/protocol/messenger_share_urls.go index 238f06dbdc3..714fb7bbc16 100644 --- a/protocol/messenger_share_urls.go +++ b/protocol/messenger_share_urls.go @@ -12,6 +12,7 @@ import ( "github.com/andybalholm/brotli" "github.com/status-im/status-go/api/multiformat" + 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" @@ -224,7 +225,7 @@ func (m *Messenger) ShareCommunityChannelURLWithChatKey(request *requests.Commun } if !valid { - return "", fmt.Errorf("channelID should be UUID, got %s", request.ChannelID) + return "", fmt.Errorf("channelID should be UUID, got %s", gocommon.TruncateWithDot(request.ChannelID)) } return fmt.Sprintf("%s/cc/%s#%s", baseShareURL, request.ChannelID, shortKey), nil @@ -237,7 +238,7 @@ func parseCommunityChannelURLWithChatKey(channelID string, publicKey string) (*U } if !valid { - return nil, fmt.Errorf("channelID should be UUID, got %s", channelID) + return nil, fmt.Errorf("channelID should be UUID, got %s", gocommon.TruncateWithDot(channelID)) } communityID, err := decodeCommunityID(publicKey) @@ -313,7 +314,7 @@ func (m *Messenger) ShareCommunityChannelURLWithData(request *requests.Community } if !valid { - return "nil", fmt.Errorf("channelID should be UUID, got %s", request.ChannelID) + return "", fmt.Errorf("channelID should be UUID, got %s", gocommon.TruncateWithDot(request.ChannelID)) } community, err := m.GetCommunityByID(request.CommunityID) @@ -323,7 +324,7 @@ func (m *Messenger) ShareCommunityChannelURLWithData(request *requests.Community channel := community.Chats()[request.ChannelID] if channel == nil { - return "", fmt.Errorf("channel with channelID %s not found", request.ChannelID) + return "", fmt.Errorf("channel with channelID %s not found", gocommon.TruncateWithDot(request.ChannelID)) } data, shortKey, err := m.prepareEncodedCommunityChannelData(community, channel, request.ChannelID) diff --git a/protocol/messenger_store_node_request_manager.go b/protocol/messenger_store_node_request_manager.go index b406ba6d230..27086b2be35 100644 --- a/protocol/messenger_store_node_request_manager.go +++ b/protocol/messenger_store_node_request_manager.go @@ -149,7 +149,7 @@ func (m *StoreNodeRequestManager) FetchCommunities(ctx context.Context, communit for _, community := range communities { _, _, err := m.FetchCommunity(ctx, community, opts) if err != nil { - outErr = fmt.Errorf("%sfailed to create a request for community %s: %w", outErr, community.CommunityID, err) + outErr = fmt.Errorf("%sfailed to create a request for community %s: %w", outErr, gocommon.TruncateWithDot(community.CommunityID), err) } } 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/protocol/storenodes/database.go b/protocol/storenodes/database.go index e5f3d13a657..645793290bb 100644 --- a/protocol/storenodes/database.go +++ b/protocol/storenodes/database.go @@ -58,7 +58,7 @@ func (d *Database) syncSave(communityID types.HexBytes, snode []Storenode, clock for _, n := range snode { // defensively validate the communityID if len(n.CommunityID) == 0 || !bytes.Equal(communityID, n.CommunityID) { - err = fmt.Errorf("communityID mismatch %v != %v", communityID, n.CommunityID) + err = fmt.Errorf("communityID mismatch") return err } dbN := find(n, dbNodes) diff --git a/protocol/v1/membership_update_message.go b/protocol/v1/membership_update_message.go index 80c8c1a41a7..4834c85c0ae 100644 --- a/protocol/v1/membership_update_message.go +++ b/protocol/v1/membership_update_message.go @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" "github.com/pkg/errors" + 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/protobuf" @@ -309,17 +310,17 @@ func (g *Group) init() error { } valid := g.validateEvent(event) if !valid { - return fmt.Errorf("invalid event %#+v from %s", event, event.From) + return fmt.Errorf("invalid event, type: %s, from: %s, chatID: %s, name: %s", event.Type, gocommon.TruncateWithDot(event.From), gocommon.TruncateWithDot(event.ChatID), event.Name) } g.processEvent(event) } valid := g.validateChatID(g.chatID) if !valid { - return fmt.Errorf("invalid chat ID: %s", g.chatID) + return fmt.Errorf("invalid chat ID: %s", gocommon.TruncateWithDot(g.chatID)) } if chatID != g.chatID { - return fmt.Errorf("expected chat ID equal %s, got %s", g.chatID, chatID) + return fmt.Errorf("expected chat ID equal %s, got %s", gocommon.TruncateWithDot(g.chatID), gocommon.TruncateWithDot(chatID)) } return nil @@ -484,7 +485,7 @@ func (g *Group) ProcessEvents(events []MembershipUpdateEvent) error { func (g *Group) ProcessEvent(event MembershipUpdateEvent) error { if !g.validateEvent(event) { - return fmt.Errorf("invalid event %#+v", event) + return fmt.Errorf("invalid event when processing, type: %s, from: %s, chatID: %s, name: %s", event.Type, gocommon.TruncateWithDot(event.From), gocommon.TruncateWithDot(event.ChatID), event.Name) } // Check if exists g.events = append(g.events, event) 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..8b187bc072d 100644 --- a/server/pairing/client.go +++ b/server/pairing/client.go @@ -72,18 +72,16 @@ func findServerCert(c *ConnectionParams, reachableIPs []net.IP) (*url.URL, *x509 // Keep track of error counts errorCount := 0 - var combinedErrors string for { select { case success := <-successCh: baseAddress = success.u serverCert = success.cert return baseAddress, serverCert, nil - case ipErr := <-errCh: + case <-errCh: errorCount++ - combinedErrors += fmt.Sprintf("IP %s: %s; ", ipErr.ip, ipErr.err) if errorCount == len(reachableIPs) { - return nil, nil, fmt.Errorf(combinedErrors) + return nil, nil, fmt.Errorf("failed to connect to any of given ip addresses.") } } } @@ -97,7 +95,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/connection.go b/server/pairing/connection.go index 1d5cbc57b57..16166f65a05 100644 --- a/server/pairing/connection.go +++ b/server/pairing/connection.go @@ -154,11 +154,11 @@ func ParseNetIps(in []byte) ([]net.IP, error) { func (cp *ConnectionParams) FromString(s string) error { if len(s) < 2 { - return fmt.Errorf("connection string is too short: '%s'", s) + return fmt.Errorf("connection string is too short") } if s[:2] != connectionStringID { - return fmt.Errorf("connection string doesn't begin with identifier '%s'", connectionStringID) + return fmt.Errorf("connection string doesn't begin with identifier") } requiredParams := 5 @@ -166,7 +166,7 @@ func (cp *ConnectionParams) FromString(s string) error { sData := strings.Split(s[2:], ":") // NOTE: always allow extra parameters for forward compatibility, error on not enough required parameters or failing to parse if len(sData) < requiredParams { - return fmt.Errorf("expected data '%s' to have length of '%d', received '%d'", s, requiredParams, len(sData)) + return fmt.Errorf("expected connection string to have length of '%d', received '%d'", requiredParams, len(sData)) } netIpsBytes := base58.Decode(sData[1]) 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/communitytokens/service.go b/services/communitytokens/service.go index 3351f1c3c83..fa9f626e4ec 100644 --- a/services/communitytokens/service.go +++ b/services/communitytokens/service.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/p2p" ethRpc "github.com/ethereum/go-ethereum/rpc" "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" @@ -147,7 +148,7 @@ func (s *Service) handleWalletEvent(event walletevent.Event) { func (s *Service) handleAirdropCommunityToken(status string, toAddress common.Address, chainID walletCommon.ChainID) (*token.CommunityToken, error) { communityToken, err := s.Messenger.GetCommunityTokenByChainAndAddress(int(chainID), toAddress.String()) if communityToken == nil { - return nil, fmt.Errorf("token does not exist in database: chainId=%v, address=%v", chainID, toAddress.String()) + return nil, fmt.Errorf("token does not exist in database: chainId=%v, address=%v", chainID, gocommon.TruncateWithDot(toAddress.String())) } else { publishErr := s.publishTokenActionToPrivilegedMembers(communityToken.CommunityID, uint64(communityToken.ChainID), communityToken.Address, protobuf.CommunityTokenAction_AIRDROP) @@ -161,7 +162,7 @@ func (s *Service) handleAirdropCommunityToken(status string, toAddress common.Ad func (s *Service) handleRemoteDestructCollectible(status string, toAddress common.Address, chainID walletCommon.ChainID) (*token.CommunityToken, error) { communityToken, err := s.Messenger.GetCommunityTokenByChainAndAddress(int(chainID), toAddress.String()) if communityToken == nil { - return nil, fmt.Errorf("token does not exist in database: chainId=%v, address=%v", chainID, toAddress.String()) + return nil, fmt.Errorf("token does not exist in database: chainId=%v, address=%v", chainID, gocommon.TruncateWithDot(toAddress.String())) } else { publishErr := s.publishTokenActionToPrivilegedMembers(communityToken.CommunityID, uint64(communityToken.ChainID), communityToken.Address, protobuf.CommunityTokenAction_REMOTE_DESTRUCT) @@ -188,7 +189,7 @@ func (s *Service) handleBurnCommunityToken(status string, toAddress common.Addre communityToken, err := s.Messenger.GetCommunityTokenByChainAndAddress(int(chainID), toAddress.String()) if communityToken == nil { - return nil, fmt.Errorf("token does not exist in database: chainId=%v, address=%v", chainID, toAddress.String()) + return nil, fmt.Errorf("token does not exist in database: chainId=%v, address=%v", chainID, gocommon.TruncateWithDot(toAddress.String())) } else { publishErr := s.publishTokenActionToPrivilegedMembers(communityToken.CommunityID, uint64(communityToken.ChainID), communityToken.Address, protobuf.CommunityTokenAction_BURN) @@ -237,7 +238,7 @@ func (s *Service) updateStateAndAddTokenToCommunityDescription(status string, ch return nil, err } if tokenToUpdate == nil { - return nil, fmt.Errorf("token does not exist in database: chainID=%v, address=%v", chainID, address) + return nil, fmt.Errorf("token does not exist in database: chainID=%v, address=%v", chainID, gocommon.TruncateWithDot(address)) } if status == transactions.Success { @@ -269,7 +270,7 @@ func (s *Service) handleSetSignerPubKey(status string, toAddress common.Address, return nil, err } if communityToken == nil { - return nil, fmt.Errorf("token does not exist in database: chainId=%v, address=%v", chainID, toAddress.String()) + return nil, fmt.Errorf("token does not exist in database: chainId=%v, address=%v", chainID, gocommon.TruncateWithDot(toAddress.String())) } if status == transactions.Success { @@ -550,7 +551,7 @@ func (s *Service) GetMasterTokenContractAddressFromHash(ctx context.Context, cha return event.Arg0.Hex(), nil } } - return "", fmt.Errorf("can't find master token address in transaction: %v", txHash) + return "", fmt.Errorf("can't find master token address in transaction: %s", gocommon.TruncateWithDot(txHash)) } func (s *Service) GetOwnerTokenContractAddressFromHash(ctx context.Context, chainID uint64, txHash string) (string, error) { @@ -581,7 +582,7 @@ func (s *Service) GetOwnerTokenContractAddressFromHash(ctx context.Context, chai return event.Arg0.Hex(), nil } } - return "", fmt.Errorf("can't find owner token address in transaction: %v", txHash) + return "", fmt.Errorf("can't find owner token address in transaction: %s", gocommon.TruncateWithDot(txHash)) } func (s *Service) publishTokenActionToPrivilegedMembers(communityID string, chainID uint64, contractAddress string, actionType protobuf.CommunityTokenAction_ActionType) error { 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 cdc9db9e761..c706d674b37 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" @@ -949,7 +950,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 } @@ -961,7 +962,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 e87c013ea4e..72a1644662c 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/rpc/network" @@ -153,7 +155,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 } } @@ -300,14 +303,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)) } } } @@ -416,7 +421,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/wallet/transfer/helpers.go b/services/wallet/transfer/helpers.go index 96c2c7d5e84..9c459558866 100644 --- a/services/wallet/transfer/helpers.go +++ b/services/wallet/transfer/helpers.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "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" @@ -85,7 +86,7 @@ func addSignaturesToTransactions(transactions map[common.Hash]*TransactionDescri for hash, desc := range transactions { sigDetails, ok := signatures[hash.String()] if !ok { - return fmt.Errorf("missing signature for transaction %s", hash) + return fmt.Errorf("missing signature for transaction %s", gocommon.TruncateWithDot(hash.String())) } rBytes, _ := hex.DecodeString(sigDetails.R) 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 }