Add retries to mpool push message from lotus miner
This commit is contained in:
parent
cd5dd2727c
commit
a59f977db1
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
||||
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.
|
||||
|
||||
|
25
lib/retry/retry.go
Normal file
25
lib/retry/retry.go
Normal 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
|
||||
}
|
@ -56,6 +56,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/gen/slashfilter"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"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/dagstore"
|
||||
"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.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 {
|
||||
|
Loading…
Reference in New Issue
Block a user