diff --git a/cmd/waku/node.go b/cmd/waku/node.go index 648fc213..e9d38f16 100644 --- a/cmd/waku/node.go +++ b/cmd/waku/node.go @@ -110,7 +110,7 @@ func Execute(options NodeOptions) error { var migrationFn func(*sql.DB) error if requiresDB(options) && options.Store.Migration { dbSettings := dbutils.DBSettings{} - db, migrationFn, err = dbutils.ExtractDBAndMigration(options.Store.DatabaseURL, dbSettings, logger) + db, migrationFn, err = dbutils.ParseURL(options.Store.DatabaseURL, dbSettings, logger) if err != nil { return nonRecoverErrorMsg("could not connect to DB: %w", err) } diff --git a/examples/basic2/go.mod b/examples/basic2/go.mod index 91e1b873..23d3f42a 100644 --- a/examples/basic2/go.mod +++ b/examples/basic2/go.mod @@ -15,6 +15,7 @@ require ( require ( github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect + github.com/avast/retry-go/v4 v4.5.1 // indirect github.com/beevik/ntp v0.3.0 // indirect github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/examples/basic2/go.sum b/examples/basic2/go.sum index c855d722..044c13a3 100644 --- a/examples/basic2/go.sum +++ b/examples/basic2/go.sum @@ -54,6 +54,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0= +github.com/avast/retry-go/v4 v4.5.1 h1:AxIx0HGi4VZ3I02jr78j5lZ3M6x1E0Ivxa6b0pUUh7o= +github.com/avast/retry-go/v4 v4.5.1/go.mod h1:/sipNsvNB3RRuT5iNcb6h73nw3IBmXJ/H3XrCQYSOpc= github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo= github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y= github.com/aws/aws-sdk-go-v2/credentials v1.1.1/go.mod h1:mM2iIjwl7LULWtS6JCACyInboHirisUUdkBPoTHMOUo= diff --git a/examples/chat2/go.mod b/examples/chat2/go.mod index 3681d83a..41bc2ec3 100644 --- a/examples/chat2/go.mod +++ b/examples/chat2/go.mod @@ -25,6 +25,7 @@ require ( github.com/BurntSushi/toml v1.2.1 // indirect github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect github.com/atotto/clipboard v0.1.4 // indirect + github.com/avast/retry-go/v4 v4.5.1 // indirect github.com/beevik/ntp v0.3.0 // indirect github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/examples/chat2/go.sum b/examples/chat2/go.sum index ffdd7150..c1276d64 100644 --- a/examples/chat2/go.sum +++ b/examples/chat2/go.sum @@ -58,6 +58,8 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYU github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= +github.com/avast/retry-go/v4 v4.5.1 h1:AxIx0HGi4VZ3I02jr78j5lZ3M6x1E0Ivxa6b0pUUh7o= +github.com/avast/retry-go/v4 v4.5.1/go.mod h1:/sipNsvNB3RRuT5iNcb6h73nw3IBmXJ/H3XrCQYSOpc= github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo= github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y= github.com/aws/aws-sdk-go-v2/credentials v1.1.1/go.mod h1:mM2iIjwl7LULWtS6JCACyInboHirisUUdkBPoTHMOUo= diff --git a/examples/filter2/go.mod b/examples/filter2/go.mod index 40bfee1a..23c8cce9 100644 --- a/examples/filter2/go.mod +++ b/examples/filter2/go.mod @@ -15,6 +15,7 @@ require ( require ( github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect + github.com/avast/retry-go/v4 v4.5.1 // indirect github.com/beevik/ntp v0.3.0 // indirect github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/examples/filter2/go.sum b/examples/filter2/go.sum index c855d722..044c13a3 100644 --- a/examples/filter2/go.sum +++ b/examples/filter2/go.sum @@ -54,6 +54,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0= +github.com/avast/retry-go/v4 v4.5.1 h1:AxIx0HGi4VZ3I02jr78j5lZ3M6x1E0Ivxa6b0pUUh7o= +github.com/avast/retry-go/v4 v4.5.1/go.mod h1:/sipNsvNB3RRuT5iNcb6h73nw3IBmXJ/H3XrCQYSOpc= github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo= github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y= github.com/aws/aws-sdk-go-v2/credentials v1.1.1/go.mod h1:mM2iIjwl7LULWtS6JCACyInboHirisUUdkBPoTHMOUo= diff --git a/examples/noise/go.mod b/examples/noise/go.mod index ed04768c..ab84231e 100644 --- a/examples/noise/go.mod +++ b/examples/noise/go.mod @@ -17,6 +17,7 @@ require ( require ( github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect + github.com/avast/retry-go/v4 v4.5.1 // indirect github.com/beevik/ntp v0.3.0 // indirect github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/examples/noise/go.sum b/examples/noise/go.sum index 590766a3..02dab495 100644 --- a/examples/noise/go.sum +++ b/examples/noise/go.sum @@ -54,6 +54,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0= +github.com/avast/retry-go/v4 v4.5.1 h1:AxIx0HGi4VZ3I02jr78j5lZ3M6x1E0Ivxa6b0pUUh7o= +github.com/avast/retry-go/v4 v4.5.1/go.mod h1:/sipNsvNB3RRuT5iNcb6h73nw3IBmXJ/H3XrCQYSOpc= github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo= github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y= github.com/aws/aws-sdk-go-v2/credentials v1.1.1/go.mod h1:mM2iIjwl7LULWtS6JCACyInboHirisUUdkBPoTHMOUo= diff --git a/examples/rln/go.mod b/examples/rln/go.mod index 26790509..6e494046 100644 --- a/examples/rln/go.mod +++ b/examples/rln/go.mod @@ -15,6 +15,7 @@ require ( require ( github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect + github.com/avast/retry-go/v4 v4.5.1 // indirect github.com/beevik/ntp v0.3.0 // indirect github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/examples/rln/go.sum b/examples/rln/go.sum index c855d722..044c13a3 100644 --- a/examples/rln/go.sum +++ b/examples/rln/go.sum @@ -54,6 +54,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0= +github.com/avast/retry-go/v4 v4.5.1 h1:AxIx0HGi4VZ3I02jr78j5lZ3M6x1E0Ivxa6b0pUUh7o= +github.com/avast/retry-go/v4 v4.5.1/go.mod h1:/sipNsvNB3RRuT5iNcb6h73nw3IBmXJ/H3XrCQYSOpc= github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo= github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y= github.com/aws/aws-sdk-go-v2/credentials v1.1.1/go.mod h1:mM2iIjwl7LULWtS6JCACyInboHirisUUdkBPoTHMOUo= diff --git a/flake.nix b/flake.nix index 170ad597..dc02d66e 100644 --- a/flake.nix +++ b/flake.nix @@ -29,7 +29,7 @@ ]; doCheck = false; # FIXME: This needs to be manually changed when updating modules. - vendorSha256 = "sha256-cVczNEnsHha1aOMY6BllWKZ2+/BY88mBjZCp2txmb8U="; + vendorSha256 = "sha256-kW9xdZ1JWUWpFVJzSFL3F349pVbtIOQ0Qz1OlbhBzn8="; # Fix for 'nix run' trying to execute 'go-waku'. meta = { mainProgram = "waku"; }; }; diff --git a/go.mod b/go.mod index d1aa1f57..b7cd18c1 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( ) require ( + github.com/avast/retry-go/v4 v4.5.1 github.com/cenkalti/backoff/v4 v4.1.2 github.com/go-chi/chi/v5 v5.0.0 github.com/jackc/pgx/v5 v5.4.1 diff --git a/go.sum b/go.sum index d77778d4..f66b5b37 100644 --- a/go.sum +++ b/go.sum @@ -160,6 +160,8 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5 github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= +github.com/avast/retry-go/v4 v4.5.1 h1:AxIx0HGi4VZ3I02jr78j5lZ3M6x1E0Ivxa6b0pUUh7o= +github.com/avast/retry-go/v4 v4.5.1/go.mod h1:/sipNsvNB3RRuT5iNcb6h73nw3IBmXJ/H3XrCQYSOpc= github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0= github.com/aws/aws-sdk-go v1.17.7/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo= diff --git a/library/node.go b/library/node.go index 0ebbde99..408461bc 100644 --- a/library/node.go +++ b/library/node.go @@ -203,7 +203,7 @@ func NewNode(instance *WakuInstance, configJSON string) error { if *config.EnableStore { var db *sql.DB var migrationFn func(*sql.DB) error - db, migrationFn, err = dbutils.ExtractDBAndMigration(*config.DatabaseURL, dbutils.DBSettings{}, utils.Logger()) + db, migrationFn, err = dbutils.ParseURL(*config.DatabaseURL, dbutils.DBSettings{}, utils.Logger()) if err != nil { return err } diff --git a/waku/persistence/utils/db.go b/waku/persistence/utils/db.go index 22d348b5..57a3c0e6 100644 --- a/waku/persistence/utils/db.go +++ b/waku/persistence/utils/db.go @@ -25,8 +25,8 @@ type DBSettings struct { // TODO: add any DB specific setting here } -// ExtractDBAndMigration will return a database connection, and migration function that should be used depending on a database connection string -func ExtractDBAndMigration(databaseURL string, dbSettings DBSettings, logger *zap.Logger) (*sql.DB, func(*sql.DB) error, error) { +// ParseURL will return a database connection, and migration function that should be used depending on a database connection string +func ParseURL(databaseURL string, dbSettings DBSettings, logger *zap.Logger) (*sql.DB, func(*sql.DB) error, error) { var db *sql.DB var migrationFn func(*sql.DB) error var err error diff --git a/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go b/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go index 8faf29d1..b9e9d266 100644 --- a/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go +++ b/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go @@ -8,6 +8,7 @@ import ( "sync" "time" + "github.com/avast/retry-go/v4" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -130,19 +131,27 @@ func NewDynamicGroupManager( } func (gm *DynamicGroupManager) getMembershipFee(ctx context.Context) (*big.Int, error) { - fee, err := gm.web3Config.RLNContract.MEMBERSHIPDEPOSIT(&bind.CallOpts{Context: ctx}) - if err != nil { - return nil, fmt.Errorf("could not check if credential exits in contract: %w", err) - } - return fee, nil + return retry.DoWithData( + func() (*big.Int, error) { + fee, err := gm.web3Config.RLNContract.MEMBERSHIPDEPOSIT(&bind.CallOpts{Context: ctx}) + if err != nil { + return nil, fmt.Errorf("could not check if credential exits in contract: %w", err) + } + return fee, nil + }, retry.Attempts(3), + ) } func (gm *DynamicGroupManager) memberExists(ctx context.Context, idCommitment rln.IDCommitment) (bool, error) { - exists, err := gm.web3Config.RLNContract.MemberExists(&bind.CallOpts{Context: ctx}, rln.Bytes32ToBigInt(idCommitment)) - if err != nil { - return false, fmt.Errorf("could not check if credential exits in contract: %w", err) - } - return exists, nil + return retry.DoWithData( + func() (bool, error) { + exists, err := gm.web3Config.RLNContract.MemberExists(&bind.CallOpts{Context: ctx}, rln.Bytes32ToBigInt(idCommitment)) + if err != nil { + return false, fmt.Errorf("could not check if credential exits in contract: %w", err) + } + return exists, nil + }, retry.Attempts(3), + ) } func (gm *DynamicGroupManager) Start(ctx context.Context) error { diff --git a/waku/v2/protocol/rln/group_manager/dynamic/membership_fetcher.go b/waku/v2/protocol/rln/group_manager/dynamic/membership_fetcher.go index a418dde2..3b99850b 100644 --- a/waku/v2/protocol/rln/group_manager/dynamic/membership_fetcher.go +++ b/waku/v2/protocol/rln/group_manager/dynamic/membership_fetcher.go @@ -7,6 +7,7 @@ import ( "sync" "time" + "github.com/avast/retry-go/v4" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" @@ -207,26 +208,30 @@ func (mf *MembershipFetcher) getEvents(ctx context.Context, fromBlock uint64, to } func (mf *MembershipFetcher) fetchEvents(ctx context.Context, from uint64, to uint64) ([]*contracts.RLNMemberRegistered, error) { - logIterator, err := mf.web3Config.RLNContract.FilterMemberRegistered(&bind.FilterOpts{Start: from, End: &to, Context: ctx}) - if err != nil { - return nil, err - } + return retry.DoWithData( + func() ([]*contracts.RLNMemberRegistered, error) { + logIterator, err := mf.web3Config.RLNContract.FilterMemberRegistered(&bind.FilterOpts{Start: from, End: &to, Context: ctx}) + if err != nil { + return nil, err + } - var results []*contracts.RLNMemberRegistered + var results []*contracts.RLNMemberRegistered - for { - if !logIterator.Next() { - break - } + for { + if !logIterator.Next() { + break + } - if logIterator.Error() != nil { - return nil, logIterator.Error() - } + if logIterator.Error() != nil { + return nil, logIterator.Error() + } - results = append(results, logIterator.Event) - } + results = append(results, logIterator.Event) + } - return results, nil + return results, nil + }, retry.Attempts(3), + ) } // GetMetadata retrieves metadata from the zerokit's RLN database