From 2d271c720e2d7c561660cf4c96d3c7d87f9213ca Mon Sep 17 00:00:00 2001 From: Viraj Bhartiya Date: Wed, 11 Dec 2024 10:28:45 +0530 Subject: [PATCH] streamline migration progress log timeout handling --- chain/consensus/filcns/upgrades.go | 36 ++++++++++++++++++------------ extern/go-state-types | 1 - go.mod | 4 ++-- go.sum | 2 ++ 4 files changed, 26 insertions(+), 17 deletions(-) delete mode 160000 extern/go-state-types diff --git a/chain/consensus/filcns/upgrades.go b/chain/consensus/filcns/upgrades.go index 405053bb14..af51e12d09 100644 --- a/chain/consensus/filcns/upgrades.go +++ b/chain/consensus/filcns/upgrades.go @@ -2753,14 +2753,10 @@ func PreUpgradeActorsV16(ctx context.Context, sm *stmgr.StateManager, cache stmg if err != nil { return xerrors.Errorf("error getting lookback ts for premigration: %w", err) } - timeout := os.Getenv("LOTUS_MIGRATE_PROGRESS_LOG_SECONDS") - timeoutDuration, err := time.ParseDuration(timeout + "s") - if err != nil { - return xerrors.Errorf("error parsing LOTUS_MIGRATE_PROGRESS_LOG_SECONDS: %w", err) - } - if timeoutDuration == 0 { - timeoutDuration = time.Second * 2 + timeoutDuration, err := getMigrationProgressLogTimeout() + if err != nil { + return xerrors.Errorf("error getting progress log timeout: %w", err) } config := migration.Config{ @@ -2779,14 +2775,10 @@ func UpgradeActorsV16(ctx context.Context, sm *stmgr.StateManager, cache stmgr.M if workerCount <= 0 { workerCount = 1 } - timeout := os.Getenv("LOTUS_MIGRATE_PROGRESS_LOG_SECONDS") - timeoutDuration, err := time.ParseDuration(timeout + "s") - if err != nil { - return cid.Undef, xerrors.Errorf("error parsing LOTUS_MIGRATE_PROGRESS_LOG_SECONDS: %w", err) - } - if timeoutDuration == 0 { - timeoutDuration = time.Second * 2 + timeoutDuration, err := getMigrationProgressLogTimeout() + if err != nil { + return cid.Undef, xerrors.Errorf("error getting progress log timeout: %w", err) } config := migration.Config{ @@ -3024,3 +3016,19 @@ func (ml migrationLogger) Log(level rt.LogLevel, msg string, args ...interface{} log.Errorf(msg, args...) } } + +func getMigrationProgressLogTimeout() (time.Duration, error) { + timeoutDuration := time.Second * 2 // default timeout + timeout := os.Getenv("LOTUS_MIGRATE_PROGRESS_LOG_SECONDS") + if timeout != "" { + seconds, err := strconv.Atoi(timeout) + if err != nil { + return 0, xerrors.Errorf("LOTUS_MIGRATE_PROGRESS_LOG_SECONDS must be an integer: %w", err) + } + if seconds <= 0 { + return 0, xerrors.Errorf("LOTUS_MIGRATE_PROGRESS_LOG_SECONDS must be positive") + } + timeoutDuration = time.Duration(seconds) * time.Second + } + return timeoutDuration, nil +} diff --git a/extern/go-state-types b/extern/go-state-types deleted file mode 160000 index c3f3a3470c..0000000000 --- a/extern/go-state-types +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c3f3a3470c05abfbb72b4358bb9497381c16a6ac diff --git a/go.mod b/go.mod index 1abde78330..a229510bde 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ replace github.com/filecoin-project/test-vectors => ./extern/test-vectors // pro replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi // provided via a git submodule -replace github.com/filecoin-project/go-state-types => ./extern/go-state-types // provided via a git submodule +replace github.com/filecoin-project/go-state-types => github.com/filecoin-project/go-state-types v0.16.0-rc1 // provided via a git submodule require ( contrib.go.opencensus.io/exporter/prometheus v0.4.2 @@ -52,7 +52,7 @@ require ( github.com/filecoin-project/go-jsonrpc v0.7.0 github.com/filecoin-project/go-padreader v0.0.1 github.com/filecoin-project/go-paramfetch v0.0.4 - github.com/filecoin-project/go-state-types v0.16.0-dev + github.com/filecoin-project/go-state-types v0.16.0-rc1 github.com/filecoin-project/go-statemachine v1.0.3 github.com/filecoin-project/go-statestore v0.2.0 github.com/filecoin-project/go-storedcounter v0.1.0 diff --git a/go.sum b/go.sum index dbbae40068..7b635e7fbb 100644 --- a/go.sum +++ b/go.sum @@ -313,6 +313,8 @@ github.com/filecoin-project/go-padreader v0.0.1 h1:8h2tVy5HpoNbr2gBRr+WD6zV6VD6X github.com/filecoin-project/go-padreader v0.0.1/go.mod h1:VYVPJqwpsfmtoHnAmPx6MUwmrK6HIcDqZJiuZhtmfLQ= github.com/filecoin-project/go-paramfetch v0.0.4 h1:H+Me8EL8T5+79z/KHYQQcT8NVOzYVqXIi7nhb48tdm8= github.com/filecoin-project/go-paramfetch v0.0.4/go.mod h1:1FH85P8U+DUEmWk1Jkw3Bw7FrwTVUNHk/95PSPG+dts= +github.com/filecoin-project/go-state-types v0.16.0-rc1 h1:/51MhupBAjfmWygUKDZCdLOzAnKFcayPHX9ApTswgmo= +github.com/filecoin-project/go-state-types v0.16.0-rc1/go.mod h1:4rjTgHP6LWrkQXQCgx+dRGDa0gnk4WiJVCFwZtuDOGE= github.com/filecoin-project/go-statemachine v1.0.3 h1:N07o6alys+V1tNoSTi4WuuoeNC4erS/6jE74+NsgQuk= github.com/filecoin-project/go-statemachine v1.0.3/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54= github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI=