Address comments

This commit is contained in:
Shrenuj Bansal 2022-08-22 17:32:43 -04:00
parent 8a19cd19d8
commit b972e079b8
6 changed files with 40 additions and 9 deletions

View File

@ -959,6 +959,11 @@ workflows:
suite: itest-paych_cli
target: "./itests/paych_cli_test.go"
- test:
name: test-itest-retry
suite: itest-retry
target: "./itests/retry_test.go"
- test:
name: test-itest-sdr_upgrade
suite: itest-sdr_upgrade

2
go.mod
View File

@ -38,7 +38,7 @@ require (
github.com/filecoin-project/go-fil-commcid v0.1.0
github.com/filecoin-project/go-fil-commp-hashhash v0.1.0
github.com/filecoin-project/go-fil-markets v1.24.0
github.com/filecoin-project/go-jsonrpc v0.1.7-0.20220818202438-3dabc3d89d31
github.com/filecoin-project/go-jsonrpc v0.1.7
github.com/filecoin-project/go-legs v0.4.4
github.com/filecoin-project/go-padreader v0.0.1
github.com/filecoin-project/go-paramfetch v0.0.4

4
go.sum
View File

@ -330,8 +330,8 @@ github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0/go.mod h1:7aWZdaQ1b16BVoQUYR+
github.com/filecoin-project/go-hamt-ipld/v3 v3.0.1/go.mod h1:gXpNmr3oQx8l3o7qkGyDjJjYSRX7hp/FGOStdqrWyDI=
github.com/filecoin-project/go-hamt-ipld/v3 v3.1.0 h1:rVVNq0x6RGQIzCo1iiJlGFm9AGIZzeifggxtKMU7zmI=
github.com/filecoin-project/go-hamt-ipld/v3 v3.1.0/go.mod h1:bxmzgT8tmeVQA1/gvBwFmYdT8SOFUwB3ovSUfG1Ux0g=
github.com/filecoin-project/go-jsonrpc v0.1.7-0.20220818202438-3dabc3d89d31 h1:rSi64b/nzAu4vdGVNxzfbWZiXQmeAv8RQJvcEJnuwz4=
github.com/filecoin-project/go-jsonrpc v0.1.7-0.20220818202438-3dabc3d89d31/go.mod h1:XBBpuKIMaXIIzeqzO1iucq4GvbF8CxmXRFoezRh+Cx4=
github.com/filecoin-project/go-jsonrpc v0.1.7 h1:Ti/QkQLI31v+6hvidA+i9Wv/NrS4CfHk0yXLntHX3Uk=
github.com/filecoin-project/go-jsonrpc v0.1.7/go.mod h1:XBBpuKIMaXIIzeqzO1iucq4GvbF8CxmXRFoezRh+Cx4=
github.com/filecoin-project/go-legs v0.4.4 h1:mpMmAOOnamaz0CV9rgeKhEWA8j9kMC+f+UGCGrxKaZo=
github.com/filecoin-project/go-legs v0.4.4/go.mod h1:JQ3hA6xpJdbR8euZ2rO0jkxaMxeidXf0LDnVuqPAe9s=
github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20/go.mod h1:mPn+LRRd5gEKNAtc+r3ScpW2JRU/pj4NBKdADYWHiak=

22
itests/retry_test.go Normal file
View File

@ -0,0 +1,22 @@
package itests
import (
"testing"
"github.com/stretchr/testify/require"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/lotus/lib/retry"
)
func TestRetryErrorIsInTrue(t *testing.T) {
errorsToRetry := []error{&jsonrpc.RPCConnectionError{}}
require.True(t, retry.ErrorIsIn(&jsonrpc.RPCConnectionError{}, errorsToRetry))
}
func TestRetryErrorIsInFalse(t *testing.T) {
errorsToRetry := []error{&jsonrpc.RPCConnectionError{}}
require.False(t, retry.ErrorIsIn(xerrors.Errorf("random error"), errorsToRetry))
}

View File

@ -10,7 +10,7 @@ import (
var log = logging.Logger("retry")
func errorIsIn(err error, errorTypes []error) bool {
func ErrorIsIn(err error, errorTypes []error) bool {
for _, etype := range errorTypes {
tmp := reflect.New(reflect.PointerTo(reflect.ValueOf(etype).Elem().Type())).Interface()
if errors.As(err, tmp) {
@ -20,15 +20,15 @@ func errorIsIn(err error, errorTypes []error) bool {
return false
}
func Retry[T any](attempts int, sleep int, errorTypes []error, f func() (T, error)) (result T, err error) {
func Retry[T any](attempts int, initialBackoff time.Duration, errorTypes []error, f func() (T, error)) (result T, err error) {
for i := 0; i < attempts; i++ {
if i > 0 {
log.Info("Retrying after error:", err)
time.Sleep(time.Duration(sleep) * time.Second)
sleep *= 2
time.Sleep(initialBackoff)
initialBackoff *= 2
}
result, err = f()
if err == nil || !errorIsIn(err, errorTypes) {
if err == nil || !ErrorIsIn(err, errorTypes) {
return result, err
}
}

View File

@ -92,7 +92,11 @@ func (a *UuidWrapper) MpoolPushMessage(ctx context.Context, msg *types.Message,
}
spec.MsgUuid = uuid.New()
errorsToRetry := []error{&jsonrpc.RPCConnectionError{}}
return retry.Retry(5, 1, errorsToRetry, func() (*types.SignedMessage, error) { return a.FullNode.MpoolPushMessage(ctx, msg, spec) })
initialBackoff, err := time.ParseDuration("1s")
if err != nil {
return nil, err
}
return retry.Retry(5, initialBackoff, errorsToRetry, func() (*types.SignedMessage, error) { return a.FullNode.MpoolPushMessage(ctx, msg, spec) })
}
func MakeUuidWrapper(a v1api.RawFullNodeAPI) v1api.FullNode {