Add retries to mpool push message from lotus miner

This commit is contained in:
Shrenuj Bansal 2022-08-17 14:22:31 -04:00
parent cd5dd2727c
commit a59f977db1
3 changed files with 28 additions and 2 deletions

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/filecoin-project/lotus module github.com/filecoin-project/lotus
go 1.17 go 1.18
retract v1.14.0 // Accidentally force-pushed tag, use v1.14.1+ instead. retract v1.14.0 // Accidentally force-pushed tag, use v1.14.1+ instead.

25
lib/retry/retry.go Normal file
View File

@ -0,0 +1,25 @@
package retry
import (
"time"
logging "github.com/ipfs/go-log/v2"
)
var log = logging.Logger("retry")
func Retry[T any](attempts int, sleep int, 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
}
result, err = f()
if err == nil {
return result, nil
}
}
log.Errorf("Failed after %d attempts, last error: %s", attempts, err)
return result, err
}

View File

@ -56,6 +56,7 @@ import (
"github.com/filecoin-project/lotus/chain/gen/slashfilter" "github.com/filecoin-project/lotus/chain/gen/slashfilter"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/journal" "github.com/filecoin-project/lotus/journal"
"github.com/filecoin-project/lotus/lib/retry"
"github.com/filecoin-project/lotus/markets" "github.com/filecoin-project/lotus/markets"
"github.com/filecoin-project/lotus/markets/dagstore" "github.com/filecoin-project/lotus/markets/dagstore"
"github.com/filecoin-project/lotus/markets/idxprov" "github.com/filecoin-project/lotus/markets/idxprov"
@ -89,7 +90,7 @@ func (a *UuidWrapper) MpoolPushMessage(ctx context.Context, msg *types.Message,
spec = new(api.MessageSendSpec) spec = new(api.MessageSendSpec)
} }
spec.MsgUuid = uuid.New() spec.MsgUuid = uuid.New()
return a.FullNode.MpoolPushMessage(ctx, msg, spec) return retry.Retry(5, 1, func() (*types.SignedMessage, error) { return a.FullNode.MpoolPushMessage(ctx, msg, spec) })
} }
func MakeUuidWrapper(a v1api.RawFullNodeAPI) v1api.FullNode { func MakeUuidWrapper(a v1api.RawFullNodeAPI) v1api.FullNode {