2019-05-13 09:25:46 +00:00
|
|
|
package mailserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2020-01-21 07:11:24 +00:00
|
|
|
"errors"
|
2019-05-13 09:25:46 +00:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2020-01-21 07:11:24 +00:00
|
|
|
"github.com/lib/pq"
|
test_: Code Migration from status-cli-tests
author shashankshampi <shashank.sanket1995@gmail.com> 1729780155 +0530
committer shashankshampi <shashank.sanket1995@gmail.com> 1730274350 +0530
test: Code Migration from status-cli-tests
fix_: functional tests (#5979)
* fix_: generate on test-functional
* chore(test)_: fix functional test assertion
---------
Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com>
feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977)
* feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766)
The original GH issue https://github.com/status-im/status-mobile/issues/21113
came from a request from the Legal team. We must show to Status v1 users the new
terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2
from the stores.
The solution we use is to create a flag in the accounts table, named
hasAcceptedTerms. The flag will be set to true on the first account ever
created in v2 and we provide a native call in mobile/status.go#AcceptTerms,
which allows the client to persist the user's choice in case they are upgrading
(from v1 -> v2, or from a v2 older than this PR).
This solution is not the best because we should store the setting in a separate
table, not in the accounts table.
Related Mobile PR https://github.com/status-im/status-mobile/pull/21124
* fix(test)_: Compare addresses using uppercased strings
---------
Co-authored-by: Icaro Motta <icaro.ldm@gmail.com>
test_: restore account (#5960)
feat_: `LogOnPanic` linter (#5969)
* feat_: LogOnPanic linter
* fix_: add missing defer LogOnPanic
* chore_: make vendor
* fix_: tests, address pr comments
* fix_: address pr comments
fix(ci)_: remove workspace and tmp dir
This ensures we do not encounter weird errors like:
```
+ ln -s /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907 /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go
ln: failed to create symbolic link '/home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go': File exists
script returned exit code 1
```
Signed-off-by: Jakub Sokołowski <jakub@status.im>
chore_: enable windows and macos CI build (#5840)
- Added support for Windows and macOS in CI pipelines
- Added missing dependencies for Windows and x86-64-darwin
- Resolved macOS SDK version compatibility for darwin-x86_64
The `mkShell` override was necessary to ensure compatibility with the newer
macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures
because of the missing libs and frameworks. OverrideSDK creates a mapping from
the default SDK in all package categories to the requested SDK (11.0).
fix(contacts)_: fix trust status not being saved to cache when changed (#5965)
Fixes https://github.com/status-im/status-desktop/issues/16392
cleanup
added logger and cleanup
review comments changes
fix_: functional tests (#5979)
* fix_: generate on test-functional
* chore(test)_: fix functional test assertion
---------
Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com>
feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977)
* feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766)
The original GH issue https://github.com/status-im/status-mobile/issues/21113
came from a request from the Legal team. We must show to Status v1 users the new
terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2
from the stores.
The solution we use is to create a flag in the accounts table, named
hasAcceptedTerms. The flag will be set to true on the first account ever
created in v2 and we provide a native call in mobile/status.go#AcceptTerms,
which allows the client to persist the user's choice in case they are upgrading
(from v1 -> v2, or from a v2 older than this PR).
This solution is not the best because we should store the setting in a separate
table, not in the accounts table.
Related Mobile PR https://github.com/status-im/status-mobile/pull/21124
* fix(test)_: Compare addresses using uppercased strings
---------
Co-authored-by: Icaro Motta <icaro.ldm@gmail.com>
test_: restore account (#5960)
feat_: `LogOnPanic` linter (#5969)
* feat_: LogOnPanic linter
* fix_: add missing defer LogOnPanic
* chore_: make vendor
* fix_: tests, address pr comments
* fix_: address pr comments
chore_: enable windows and macos CI build (#5840)
- Added support for Windows and macOS in CI pipelines
- Added missing dependencies for Windows and x86-64-darwin
- Resolved macOS SDK version compatibility for darwin-x86_64
The `mkShell` override was necessary to ensure compatibility with the newer
macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures
because of the missing libs and frameworks. OverrideSDK creates a mapping from
the default SDK in all package categories to the requested SDK (11.0).
fix(contacts)_: fix trust status not being saved to cache when changed (#5965)
Fixes https://github.com/status-im/status-desktop/issues/16392
test_: remove port bind
chore(wallet)_: move route execution code to separate module
chore_: replace geth logger with zap logger (#5962)
closes: #6002
feat(telemetry)_: add metrics for message reliability (#5899)
* feat(telemetry)_: track message reliability
Add metrics for dial errors, missed messages,
missed relevant messages, and confirmed delivery.
* fix_: handle error from json marshal
chore_: use zap logger as request logger
iterates: status-im/status-desktop#16536
test_: unique project per run
test_: use docker compose v2, more concrete project name
fix(codecov)_: ignore folders without tests
Otherwise Codecov reports incorrect numbers when making changes.
https://docs.codecov.com/docs/ignoring-paths
Signed-off-by: Jakub Sokołowski <jakub@status.im>
test_: verify schema of signals during init; fix schema verification warnings (#5947)
fix_: update defaultGorushURL (#6011)
fix(tests)_: use non-standard port to avoid conflicts
We have observed `nimbus-eth2` build failures reporting this port:
```json
{
"lvl": "NTC",
"ts": "2024-10-28 13:51:32.308+00:00",
"msg": "REST HTTP server could not be started",
"topics": "beacnde",
"address": "127.0.0.1:5432",
"reason": "(98) Address already in use"
}
```
https://ci.status.im/job/nimbus-eth2/job/platforms/job/linux/job/x86_64/job/main/job/PR-6683/3/
Signed-off-by: Jakub Sokołowski <jakub@status.im>
fix_: create request logger ad-hoc in tests
Fixes `TestCall` failing when run concurrently.
chore_: configure codecov (#6005)
* chore_: configure codecov
* fix_: after_n_builds
2024-10-24 14:29:15 +00:00
|
|
|
"go.uber.org/zap"
|
2020-01-21 07:11:24 +00:00
|
|
|
|
2019-05-13 09:25:46 +00:00
|
|
|
// Import postgres driver
|
|
|
|
_ "github.com/lib/pq"
|
2019-06-09 07:24:20 +00:00
|
|
|
"github.com/status-im/migrate/v4"
|
|
|
|
"github.com/status-im/migrate/v4/database/postgres"
|
2019-10-28 13:50:33 +00:00
|
|
|
bindata "github.com/status-im/migrate/v4/source/go_bindata"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2024-09-26 22:37:32 +00:00
|
|
|
"github.com/status-im/status-go/common"
|
test_: Code Migration from status-cli-tests
author shashankshampi <shashank.sanket1995@gmail.com> 1729780155 +0530
committer shashankshampi <shashank.sanket1995@gmail.com> 1730274350 +0530
test: Code Migration from status-cli-tests
fix_: functional tests (#5979)
* fix_: generate on test-functional
* chore(test)_: fix functional test assertion
---------
Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com>
feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977)
* feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766)
The original GH issue https://github.com/status-im/status-mobile/issues/21113
came from a request from the Legal team. We must show to Status v1 users the new
terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2
from the stores.
The solution we use is to create a flag in the accounts table, named
hasAcceptedTerms. The flag will be set to true on the first account ever
created in v2 and we provide a native call in mobile/status.go#AcceptTerms,
which allows the client to persist the user's choice in case they are upgrading
(from v1 -> v2, or from a v2 older than this PR).
This solution is not the best because we should store the setting in a separate
table, not in the accounts table.
Related Mobile PR https://github.com/status-im/status-mobile/pull/21124
* fix(test)_: Compare addresses using uppercased strings
---------
Co-authored-by: Icaro Motta <icaro.ldm@gmail.com>
test_: restore account (#5960)
feat_: `LogOnPanic` linter (#5969)
* feat_: LogOnPanic linter
* fix_: add missing defer LogOnPanic
* chore_: make vendor
* fix_: tests, address pr comments
* fix_: address pr comments
fix(ci)_: remove workspace and tmp dir
This ensures we do not encounter weird errors like:
```
+ ln -s /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907 /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go
ln: failed to create symbolic link '/home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go': File exists
script returned exit code 1
```
Signed-off-by: Jakub Sokołowski <jakub@status.im>
chore_: enable windows and macos CI build (#5840)
- Added support for Windows and macOS in CI pipelines
- Added missing dependencies for Windows and x86-64-darwin
- Resolved macOS SDK version compatibility for darwin-x86_64
The `mkShell` override was necessary to ensure compatibility with the newer
macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures
because of the missing libs and frameworks. OverrideSDK creates a mapping from
the default SDK in all package categories to the requested SDK (11.0).
fix(contacts)_: fix trust status not being saved to cache when changed (#5965)
Fixes https://github.com/status-im/status-desktop/issues/16392
cleanup
added logger and cleanup
review comments changes
fix_: functional tests (#5979)
* fix_: generate on test-functional
* chore(test)_: fix functional test assertion
---------
Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com>
feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977)
* feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766)
The original GH issue https://github.com/status-im/status-mobile/issues/21113
came from a request from the Legal team. We must show to Status v1 users the new
terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2
from the stores.
The solution we use is to create a flag in the accounts table, named
hasAcceptedTerms. The flag will be set to true on the first account ever
created in v2 and we provide a native call in mobile/status.go#AcceptTerms,
which allows the client to persist the user's choice in case they are upgrading
(from v1 -> v2, or from a v2 older than this PR).
This solution is not the best because we should store the setting in a separate
table, not in the accounts table.
Related Mobile PR https://github.com/status-im/status-mobile/pull/21124
* fix(test)_: Compare addresses using uppercased strings
---------
Co-authored-by: Icaro Motta <icaro.ldm@gmail.com>
test_: restore account (#5960)
feat_: `LogOnPanic` linter (#5969)
* feat_: LogOnPanic linter
* fix_: add missing defer LogOnPanic
* chore_: make vendor
* fix_: tests, address pr comments
* fix_: address pr comments
chore_: enable windows and macos CI build (#5840)
- Added support for Windows and macOS in CI pipelines
- Added missing dependencies for Windows and x86-64-darwin
- Resolved macOS SDK version compatibility for darwin-x86_64
The `mkShell` override was necessary to ensure compatibility with the newer
macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures
because of the missing libs and frameworks. OverrideSDK creates a mapping from
the default SDK in all package categories to the requested SDK (11.0).
fix(contacts)_: fix trust status not being saved to cache when changed (#5965)
Fixes https://github.com/status-im/status-desktop/issues/16392
test_: remove port bind
chore(wallet)_: move route execution code to separate module
chore_: replace geth logger with zap logger (#5962)
closes: #6002
feat(telemetry)_: add metrics for message reliability (#5899)
* feat(telemetry)_: track message reliability
Add metrics for dial errors, missed messages,
missed relevant messages, and confirmed delivery.
* fix_: handle error from json marshal
chore_: use zap logger as request logger
iterates: status-im/status-desktop#16536
test_: unique project per run
test_: use docker compose v2, more concrete project name
fix(codecov)_: ignore folders without tests
Otherwise Codecov reports incorrect numbers when making changes.
https://docs.codecov.com/docs/ignoring-paths
Signed-off-by: Jakub Sokołowski <jakub@status.im>
test_: verify schema of signals during init; fix schema verification warnings (#5947)
fix_: update defaultGorushURL (#6011)
fix(tests)_: use non-standard port to avoid conflicts
We have observed `nimbus-eth2` build failures reporting this port:
```json
{
"lvl": "NTC",
"ts": "2024-10-28 13:51:32.308+00:00",
"msg": "REST HTTP server could not be started",
"topics": "beacnde",
"address": "127.0.0.1:5432",
"reason": "(98) Address already in use"
}
```
https://ci.status.im/job/nimbus-eth2/job/platforms/job/linux/job/x86_64/job/main/job/PR-6683/3/
Signed-off-by: Jakub Sokołowski <jakub@status.im>
fix_: create request logger ad-hoc in tests
Fixes `TestCall` failing when run concurrently.
chore_: configure codecov (#6005)
* chore_: configure codecov
* fix_: after_n_builds
2024-10-24 14:29:15 +00:00
|
|
|
"github.com/status-im/status-go/logutils"
|
2019-05-13 09:25:46 +00:00
|
|
|
"github.com/status-im/status-go/mailserver/migrations"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2021-05-13 16:05:34 +00:00
|
|
|
waku "github.com/status-im/status-go/waku/common"
|
2019-05-13 09:25:46 +00:00
|
|
|
)
|
|
|
|
|
2020-01-21 07:11:24 +00:00
|
|
|
type PostgresDB struct {
|
2020-04-07 08:21:39 +00:00
|
|
|
db *sql.DB
|
|
|
|
name string
|
|
|
|
done chan struct{}
|
2020-01-21 07:11:24 +00:00
|
|
|
}
|
|
|
|
|
2020-01-08 11:12:23 +00:00
|
|
|
func NewPostgresDB(uri string) (*PostgresDB, error) {
|
|
|
|
db, err := sql.Open("postgres", uri)
|
2019-05-13 09:25:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-04-07 08:21:39 +00:00
|
|
|
instance := &PostgresDB{
|
|
|
|
db: db,
|
|
|
|
done: make(chan struct{}),
|
|
|
|
}
|
2019-05-13 09:25:46 +00:00
|
|
|
if err := instance.setup(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-04-07 08:21:39 +00:00
|
|
|
// name is used for metrics labels
|
|
|
|
if name, err := instance.getDBName(uri); err == nil {
|
|
|
|
instance.name = name
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize the metric value
|
|
|
|
instance.updateArchivedEnvelopesCount()
|
|
|
|
// checking count on every insert is inefficient
|
|
|
|
go func() {
|
2024-09-26 22:37:32 +00:00
|
|
|
defer common.LogOnPanic()
|
2020-04-07 08:21:39 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-instance.done:
|
|
|
|
return
|
|
|
|
case <-time.After(time.Second * envelopeCountCheckInterval):
|
|
|
|
instance.updateArchivedEnvelopesCount()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2019-05-13 09:25:46 +00:00
|
|
|
return instance, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type postgresIterator struct {
|
|
|
|
*sql.Rows
|
|
|
|
}
|
|
|
|
|
2020-04-07 08:21:39 +00:00
|
|
|
func (i *PostgresDB) getDBName(uri string) (string, error) {
|
|
|
|
query := "SELECT current_database()"
|
|
|
|
var dbName string
|
|
|
|
return dbName, i.db.QueryRow(query).Scan(&dbName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *PostgresDB) envelopesCount() (int, error) {
|
|
|
|
query := "SELECT count(*) FROM envelopes"
|
|
|
|
var count int
|
|
|
|
return count, i.db.QueryRow(query).Scan(&count)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *PostgresDB) updateArchivedEnvelopesCount() {
|
|
|
|
if count, err := i.envelopesCount(); err != nil {
|
test_: Code Migration from status-cli-tests
author shashankshampi <shashank.sanket1995@gmail.com> 1729780155 +0530
committer shashankshampi <shashank.sanket1995@gmail.com> 1730274350 +0530
test: Code Migration from status-cli-tests
fix_: functional tests (#5979)
* fix_: generate on test-functional
* chore(test)_: fix functional test assertion
---------
Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com>
feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977)
* feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766)
The original GH issue https://github.com/status-im/status-mobile/issues/21113
came from a request from the Legal team. We must show to Status v1 users the new
terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2
from the stores.
The solution we use is to create a flag in the accounts table, named
hasAcceptedTerms. The flag will be set to true on the first account ever
created in v2 and we provide a native call in mobile/status.go#AcceptTerms,
which allows the client to persist the user's choice in case they are upgrading
(from v1 -> v2, or from a v2 older than this PR).
This solution is not the best because we should store the setting in a separate
table, not in the accounts table.
Related Mobile PR https://github.com/status-im/status-mobile/pull/21124
* fix(test)_: Compare addresses using uppercased strings
---------
Co-authored-by: Icaro Motta <icaro.ldm@gmail.com>
test_: restore account (#5960)
feat_: `LogOnPanic` linter (#5969)
* feat_: LogOnPanic linter
* fix_: add missing defer LogOnPanic
* chore_: make vendor
* fix_: tests, address pr comments
* fix_: address pr comments
fix(ci)_: remove workspace and tmp dir
This ensures we do not encounter weird errors like:
```
+ ln -s /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907 /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go
ln: failed to create symbolic link '/home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go': File exists
script returned exit code 1
```
Signed-off-by: Jakub Sokołowski <jakub@status.im>
chore_: enable windows and macos CI build (#5840)
- Added support for Windows and macOS in CI pipelines
- Added missing dependencies for Windows and x86-64-darwin
- Resolved macOS SDK version compatibility for darwin-x86_64
The `mkShell` override was necessary to ensure compatibility with the newer
macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures
because of the missing libs and frameworks. OverrideSDK creates a mapping from
the default SDK in all package categories to the requested SDK (11.0).
fix(contacts)_: fix trust status not being saved to cache when changed (#5965)
Fixes https://github.com/status-im/status-desktop/issues/16392
cleanup
added logger and cleanup
review comments changes
fix_: functional tests (#5979)
* fix_: generate on test-functional
* chore(test)_: fix functional test assertion
---------
Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com>
feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977)
* feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766)
The original GH issue https://github.com/status-im/status-mobile/issues/21113
came from a request from the Legal team. We must show to Status v1 users the new
terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2
from the stores.
The solution we use is to create a flag in the accounts table, named
hasAcceptedTerms. The flag will be set to true on the first account ever
created in v2 and we provide a native call in mobile/status.go#AcceptTerms,
which allows the client to persist the user's choice in case they are upgrading
(from v1 -> v2, or from a v2 older than this PR).
This solution is not the best because we should store the setting in a separate
table, not in the accounts table.
Related Mobile PR https://github.com/status-im/status-mobile/pull/21124
* fix(test)_: Compare addresses using uppercased strings
---------
Co-authored-by: Icaro Motta <icaro.ldm@gmail.com>
test_: restore account (#5960)
feat_: `LogOnPanic` linter (#5969)
* feat_: LogOnPanic linter
* fix_: add missing defer LogOnPanic
* chore_: make vendor
* fix_: tests, address pr comments
* fix_: address pr comments
chore_: enable windows and macos CI build (#5840)
- Added support for Windows and macOS in CI pipelines
- Added missing dependencies for Windows and x86-64-darwin
- Resolved macOS SDK version compatibility for darwin-x86_64
The `mkShell` override was necessary to ensure compatibility with the newer
macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures
because of the missing libs and frameworks. OverrideSDK creates a mapping from
the default SDK in all package categories to the requested SDK (11.0).
fix(contacts)_: fix trust status not being saved to cache when changed (#5965)
Fixes https://github.com/status-im/status-desktop/issues/16392
test_: remove port bind
chore(wallet)_: move route execution code to separate module
chore_: replace geth logger with zap logger (#5962)
closes: #6002
feat(telemetry)_: add metrics for message reliability (#5899)
* feat(telemetry)_: track message reliability
Add metrics for dial errors, missed messages,
missed relevant messages, and confirmed delivery.
* fix_: handle error from json marshal
chore_: use zap logger as request logger
iterates: status-im/status-desktop#16536
test_: unique project per run
test_: use docker compose v2, more concrete project name
fix(codecov)_: ignore folders without tests
Otherwise Codecov reports incorrect numbers when making changes.
https://docs.codecov.com/docs/ignoring-paths
Signed-off-by: Jakub Sokołowski <jakub@status.im>
test_: verify schema of signals during init; fix schema verification warnings (#5947)
fix_: update defaultGorushURL (#6011)
fix(tests)_: use non-standard port to avoid conflicts
We have observed `nimbus-eth2` build failures reporting this port:
```json
{
"lvl": "NTC",
"ts": "2024-10-28 13:51:32.308+00:00",
"msg": "REST HTTP server could not be started",
"topics": "beacnde",
"address": "127.0.0.1:5432",
"reason": "(98) Address already in use"
}
```
https://ci.status.im/job/nimbus-eth2/job/platforms/job/linux/job/x86_64/job/main/job/PR-6683/3/
Signed-off-by: Jakub Sokołowski <jakub@status.im>
fix_: create request logger ad-hoc in tests
Fixes `TestCall` failing when run concurrently.
chore_: configure codecov (#6005)
* chore_: configure codecov
* fix_: after_n_builds
2024-10-24 14:29:15 +00:00
|
|
|
logutils.ZapLogger().Warn("db query for envelopes count failed", zap.Error(err))
|
2020-04-07 08:21:39 +00:00
|
|
|
} else {
|
|
|
|
archivedEnvelopesGauge.WithLabelValues(i.name).Set(float64(count))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-13 09:25:46 +00:00
|
|
|
func (i *postgresIterator) DBKey() (*DBKey, error) {
|
|
|
|
var value []byte
|
|
|
|
var id []byte
|
|
|
|
if err := i.Scan(&id, &value); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &DBKey{raw: id}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *postgresIterator) Error() error {
|
2020-01-21 07:11:24 +00:00
|
|
|
return i.Err()
|
2019-05-13 09:25:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 07:11:24 +00:00
|
|
|
func (i *postgresIterator) Release() error {
|
|
|
|
return i.Close()
|
2019-05-13 09:25:46 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 11:51:22 +00:00
|
|
|
func (i *postgresIterator) GetEnvelopeByBloomFilter(bloom []byte) ([]byte, error) {
|
|
|
|
var value []byte
|
|
|
|
var id []byte
|
|
|
|
if err := i.Scan(&id, &value); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return value, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *postgresIterator) GetEnvelopeByTopicsMap(topics map[types.TopicType]bool) ([]byte, error) {
|
2019-05-13 09:25:46 +00:00
|
|
|
var value []byte
|
|
|
|
var id []byte
|
|
|
|
if err := i.Scan(&id, &value); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return value, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *PostgresDB) BuildIterator(query CursorQuery) (Iterator, error) {
|
2020-01-21 07:11:24 +00:00
|
|
|
var args []interface{}
|
|
|
|
|
|
|
|
stmtString := "SELECT id, data FROM envelopes"
|
|
|
|
|
2022-07-26 11:34:11 +00:00
|
|
|
var historyRange string
|
2019-05-13 09:25:46 +00:00
|
|
|
if len(query.cursor) > 0 {
|
2020-01-21 07:11:24 +00:00
|
|
|
args = append(args, query.start, query.cursor)
|
2019-05-13 09:25:46 +00:00
|
|
|
// If we have a cursor, we don't want to include that envelope in the result set
|
2020-01-21 07:11:24 +00:00
|
|
|
stmtString += " " + "WHERE id >= $1 AND id < $2"
|
2022-07-26 11:34:11 +00:00
|
|
|
historyRange = "partial" //nolint: goconst
|
2020-01-21 07:11:24 +00:00
|
|
|
} else {
|
|
|
|
args = append(args, query.start, query.end)
|
|
|
|
stmtString += " " + "WHERE id >= $1 AND id <= $2"
|
2022-07-26 11:34:11 +00:00
|
|
|
historyRange = "full" //nolint: goconst
|
2020-01-21 07:11:24 +00:00
|
|
|
}
|
2019-05-13 09:25:46 +00:00
|
|
|
|
2022-07-26 11:34:11 +00:00
|
|
|
var filterRange string
|
2020-01-21 07:11:24 +00:00
|
|
|
if len(query.topics) > 0 {
|
|
|
|
args = append(args, pq.Array(query.topics))
|
|
|
|
stmtString += " " + "AND topic = any($3)"
|
2022-07-26 11:34:11 +00:00
|
|
|
filterRange = "partial" //nolint: goconst
|
2019-05-13 09:25:46 +00:00
|
|
|
} else {
|
2020-01-21 07:11:24 +00:00
|
|
|
stmtString += " " + fmt.Sprintf("AND bloom & b'%s'::bit(512) = bloom", toBitString(query.bloom))
|
2022-07-26 11:34:11 +00:00
|
|
|
filterRange = "full" //nolint: goconst
|
2019-05-13 09:25:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 07:11:24 +00:00
|
|
|
// Positional argument depends on the fact whether the query uses topics or bloom filter.
|
|
|
|
// If topic is used, the list of topics is passed as an argument to the query.
|
|
|
|
// If bloom filter is used, it is included into the query statement.
|
|
|
|
args = append(args, query.limit)
|
|
|
|
stmtString += " " + fmt.Sprintf("ORDER BY ID DESC LIMIT $%d", len(args))
|
|
|
|
|
2019-05-13 09:25:46 +00:00
|
|
|
stmt, err := i.db.Prepare(stmtString)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-07-26 11:34:11 +00:00
|
|
|
|
|
|
|
envelopeQueriesCounter.WithLabelValues(filterRange, historyRange).Inc()
|
2020-01-21 07:11:24 +00:00
|
|
|
rows, err := stmt.Query(args...)
|
2019-05-13 09:25:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-07-26 11:34:11 +00:00
|
|
|
|
2019-05-13 09:25:46 +00:00
|
|
|
return &postgresIterator{rows}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *PostgresDB) setup() error {
|
|
|
|
resources := bindata.Resource(
|
|
|
|
migrations.AssetNames(),
|
2021-09-01 12:02:18 +00:00
|
|
|
migrations.Asset,
|
2019-05-13 09:25:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
source, err := bindata.WithInstance(resources)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
driver, err := postgres.WithInstance(i.db, &postgres.Config{})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
m, err := migrate.NewWithInstance(
|
|
|
|
"go-bindata",
|
|
|
|
source,
|
|
|
|
"postgres",
|
|
|
|
driver)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = m.Up(); err != migrate.ErrNoChange {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *PostgresDB) Close() error {
|
2020-04-07 08:21:39 +00:00
|
|
|
select {
|
|
|
|
case <-i.done:
|
|
|
|
default:
|
|
|
|
close(i.done)
|
|
|
|
}
|
2019-05-13 09:25:46 +00:00
|
|
|
return i.db.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *PostgresDB) GetEnvelope(key *DBKey) ([]byte, error) {
|
|
|
|
statement := `SELECT data FROM envelopes WHERE id = $1`
|
|
|
|
|
|
|
|
stmt, err := i.db.Prepare(statement)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
|
|
|
var envelope []byte
|
|
|
|
|
|
|
|
if err = stmt.QueryRow(key.Bytes()).Scan(&envelope); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return envelope, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *PostgresDB) Prune(t time.Time, batch int) (int, error) {
|
2019-11-23 17:57:05 +00:00
|
|
|
var zero types.Hash
|
|
|
|
var emptyTopic types.TopicType
|
2019-05-13 09:25:46 +00:00
|
|
|
kl := NewDBKey(0, emptyTopic, zero)
|
|
|
|
ku := NewDBKey(uint32(t.Unix()), emptyTopic, zero)
|
|
|
|
statement := "DELETE FROM envelopes WHERE id BETWEEN $1 AND $2"
|
|
|
|
|
|
|
|
stmt, err := i.db.Prepare(statement)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
2020-01-13 20:13:28 +00:00
|
|
|
result, err := stmt.Exec(kl.Bytes(), ku.Bytes())
|
|
|
|
if err != nil {
|
2019-05-13 09:25:46 +00:00
|
|
|
return 0, err
|
|
|
|
}
|
2020-01-13 20:13:28 +00:00
|
|
|
rows, err := result.RowsAffected()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return int(rows), nil
|
2019-05-13 09:25:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-08 11:12:23 +00:00
|
|
|
func (i *PostgresDB) SaveEnvelope(env types.Envelope) error {
|
|
|
|
topic := env.Topic()
|
|
|
|
key := NewDBKey(env.Expiry()-env.TTL(), topic, env.Hash())
|
2020-01-21 07:11:24 +00:00
|
|
|
rawEnvelope, err := rlp.EncodeToBytes(env.Unwrap())
|
2019-05-13 09:25:46 +00:00
|
|
|
if err != nil {
|
test_: Code Migration from status-cli-tests
author shashankshampi <shashank.sanket1995@gmail.com> 1729780155 +0530
committer shashankshampi <shashank.sanket1995@gmail.com> 1730274350 +0530
test: Code Migration from status-cli-tests
fix_: functional tests (#5979)
* fix_: generate on test-functional
* chore(test)_: fix functional test assertion
---------
Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com>
feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977)
* feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766)
The original GH issue https://github.com/status-im/status-mobile/issues/21113
came from a request from the Legal team. We must show to Status v1 users the new
terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2
from the stores.
The solution we use is to create a flag in the accounts table, named
hasAcceptedTerms. The flag will be set to true on the first account ever
created in v2 and we provide a native call in mobile/status.go#AcceptTerms,
which allows the client to persist the user's choice in case they are upgrading
(from v1 -> v2, or from a v2 older than this PR).
This solution is not the best because we should store the setting in a separate
table, not in the accounts table.
Related Mobile PR https://github.com/status-im/status-mobile/pull/21124
* fix(test)_: Compare addresses using uppercased strings
---------
Co-authored-by: Icaro Motta <icaro.ldm@gmail.com>
test_: restore account (#5960)
feat_: `LogOnPanic` linter (#5969)
* feat_: LogOnPanic linter
* fix_: add missing defer LogOnPanic
* chore_: make vendor
* fix_: tests, address pr comments
* fix_: address pr comments
fix(ci)_: remove workspace and tmp dir
This ensures we do not encounter weird errors like:
```
+ ln -s /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907 /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go
ln: failed to create symbolic link '/home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go': File exists
script returned exit code 1
```
Signed-off-by: Jakub Sokołowski <jakub@status.im>
chore_: enable windows and macos CI build (#5840)
- Added support for Windows and macOS in CI pipelines
- Added missing dependencies for Windows and x86-64-darwin
- Resolved macOS SDK version compatibility for darwin-x86_64
The `mkShell` override was necessary to ensure compatibility with the newer
macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures
because of the missing libs and frameworks. OverrideSDK creates a mapping from
the default SDK in all package categories to the requested SDK (11.0).
fix(contacts)_: fix trust status not being saved to cache when changed (#5965)
Fixes https://github.com/status-im/status-desktop/issues/16392
cleanup
added logger and cleanup
review comments changes
fix_: functional tests (#5979)
* fix_: generate on test-functional
* chore(test)_: fix functional test assertion
---------
Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com>
feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977)
* feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766)
The original GH issue https://github.com/status-im/status-mobile/issues/21113
came from a request from the Legal team. We must show to Status v1 users the new
terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2
from the stores.
The solution we use is to create a flag in the accounts table, named
hasAcceptedTerms. The flag will be set to true on the first account ever
created in v2 and we provide a native call in mobile/status.go#AcceptTerms,
which allows the client to persist the user's choice in case they are upgrading
(from v1 -> v2, or from a v2 older than this PR).
This solution is not the best because we should store the setting in a separate
table, not in the accounts table.
Related Mobile PR https://github.com/status-im/status-mobile/pull/21124
* fix(test)_: Compare addresses using uppercased strings
---------
Co-authored-by: Icaro Motta <icaro.ldm@gmail.com>
test_: restore account (#5960)
feat_: `LogOnPanic` linter (#5969)
* feat_: LogOnPanic linter
* fix_: add missing defer LogOnPanic
* chore_: make vendor
* fix_: tests, address pr comments
* fix_: address pr comments
chore_: enable windows and macos CI build (#5840)
- Added support for Windows and macOS in CI pipelines
- Added missing dependencies for Windows and x86-64-darwin
- Resolved macOS SDK version compatibility for darwin-x86_64
The `mkShell` override was necessary to ensure compatibility with the newer
macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures
because of the missing libs and frameworks. OverrideSDK creates a mapping from
the default SDK in all package categories to the requested SDK (11.0).
fix(contacts)_: fix trust status not being saved to cache when changed (#5965)
Fixes https://github.com/status-im/status-desktop/issues/16392
test_: remove port bind
chore(wallet)_: move route execution code to separate module
chore_: replace geth logger with zap logger (#5962)
closes: #6002
feat(telemetry)_: add metrics for message reliability (#5899)
* feat(telemetry)_: track message reliability
Add metrics for dial errors, missed messages,
missed relevant messages, and confirmed delivery.
* fix_: handle error from json marshal
chore_: use zap logger as request logger
iterates: status-im/status-desktop#16536
test_: unique project per run
test_: use docker compose v2, more concrete project name
fix(codecov)_: ignore folders without tests
Otherwise Codecov reports incorrect numbers when making changes.
https://docs.codecov.com/docs/ignoring-paths
Signed-off-by: Jakub Sokołowski <jakub@status.im>
test_: verify schema of signals during init; fix schema verification warnings (#5947)
fix_: update defaultGorushURL (#6011)
fix(tests)_: use non-standard port to avoid conflicts
We have observed `nimbus-eth2` build failures reporting this port:
```json
{
"lvl": "NTC",
"ts": "2024-10-28 13:51:32.308+00:00",
"msg": "REST HTTP server could not be started",
"topics": "beacnde",
"address": "127.0.0.1:5432",
"reason": "(98) Address already in use"
}
```
https://ci.status.im/job/nimbus-eth2/job/platforms/job/linux/job/x86_64/job/main/job/PR-6683/3/
Signed-off-by: Jakub Sokołowski <jakub@status.im>
fix_: create request logger ad-hoc in tests
Fixes `TestCall` failing when run concurrently.
chore_: configure codecov (#6005)
* chore_: configure codecov
* fix_: after_n_builds
2024-10-24 14:29:15 +00:00
|
|
|
logutils.ZapLogger().Error("rlp.EncodeToBytes failed", zap.Error(err))
|
2020-04-07 08:21:39 +00:00
|
|
|
archivedErrorsCounter.WithLabelValues(i.name).Inc()
|
2019-05-13 09:25:46 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-01-21 07:11:24 +00:00
|
|
|
if rawEnvelope == nil {
|
2020-04-07 08:21:39 +00:00
|
|
|
archivedErrorsCounter.WithLabelValues(i.name).Inc()
|
2020-01-21 07:11:24 +00:00
|
|
|
return errors.New("failed to encode envelope to bytes")
|
|
|
|
}
|
2019-05-13 09:25:46 +00:00
|
|
|
|
|
|
|
statement := "INSERT INTO envelopes (id, data, topic, bloom) VALUES ($1, $2, $3, B'"
|
|
|
|
statement += toBitString(env.Bloom())
|
|
|
|
statement += "'::bit(512)) ON CONFLICT (id) DO NOTHING;"
|
|
|
|
stmt, err := i.db.Prepare(statement)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
|
|
|
_, err = stmt.Exec(
|
|
|
|
key.Bytes(),
|
|
|
|
rawEnvelope,
|
2019-10-28 13:50:33 +00:00
|
|
|
topicToByte(topic),
|
2019-05-13 09:25:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
2020-04-07 08:21:39 +00:00
|
|
|
archivedErrorsCounter.WithLabelValues(i.name).Inc()
|
2019-05-13 09:25:46 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-07 08:21:39 +00:00
|
|
|
archivedEnvelopesGauge.WithLabelValues(i.name).Inc()
|
|
|
|
archivedEnvelopeSizeMeter.WithLabelValues(i.name).Observe(
|
2021-05-13 16:05:34 +00:00
|
|
|
float64(waku.EnvelopeHeaderLength + env.Size()))
|
2019-05-13 09:25:46 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
func topicToByte(t types.TopicType) []byte {
|
2019-05-13 09:25:46 +00:00
|
|
|
return []byte{t[0], t[1], t[2], t[3]}
|
|
|
|
}
|
|
|
|
|
|
|
|
func toBitString(bloom []byte) string {
|
|
|
|
val := ""
|
|
|
|
for _, n := range bloom {
|
|
|
|
val += fmt.Sprintf("%08b", n)
|
|
|
|
}
|
|
|
|
return val
|
|
|
|
}
|