Skip to content

Commit

Permalink
Use IsF3Enabled() and remove the runtime stopping
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Kubuxu committed Jul 4, 2024
1 parent 43c9afa commit f87582d
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build/params_2k.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,5 @@ const Eip155ChainId = 31415926

var WhitelistedBlock = cid.Undef

const F3Enabled = true
const f3Enabled = true
const F3BootstrapEpoch abi.ChainEpoch = 100
2 changes: 1 addition & 1 deletion build/params_butterfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ const Eip155ChainId = 3141592

var WhitelistedBlock = cid.Undef

const F3Enabled = true
const f3Enabled = true
const F3BootstrapEpoch abi.ChainEpoch = 200
2 changes: 1 addition & 1 deletion build/params_calibnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,5 @@ const Eip155ChainId = 314159

var WhitelistedBlock = cid.Undef

const F3Enabled = false
const f3Enabled = false
const F3BootstrapEpoch abi.ChainEpoch = -1
2 changes: 1 addition & 1 deletion build/params_interop.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,5 @@ const Eip155ChainId = 3141592

var WhitelistedBlock = cid.Undef

const F3Enabled = true
const f3Enabled = true
const F3BootstrapEpoch abi.ChainEpoch = 1000
2 changes: 1 addition & 1 deletion build/params_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ const Eip155ChainId = 314
// WhitelistedBlock skips checks on message validity in this block to sidestep the zero-bls signature
var WhitelistedBlock = MustParseCid("bafy2bzaceapyg2uyzk7vueh3xccxkuwbz3nxewjyguoxvhx77malc2lzn2ybi")

const F3Enabled = false
const f3Enabled = false
const F3BootstrapEpoch abi.ChainEpoch = -1
7 changes: 7 additions & 0 deletions build/params_shared_funcs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package build

import (
"os"

"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p/core/protocol"

Expand Down Expand Up @@ -49,3 +51,8 @@ func MustParseCid(c string) cid.Cid {

return ret
}

func IsF3Enabled() bool {
const F3DisableEnvKey = "LOTUS_DISABLE_F3"
return f3Enabled && len(os.Getenv(F3DisableEnvKey)) == 0
}
24 changes: 0 additions & 24 deletions chain/lf3/f3.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package lf3
import (
"context"
"errors"
"os"
"time"

"github.com/ipfs/go-datastore"
Expand Down Expand Up @@ -47,12 +46,6 @@ type F3Params struct {

var log = logging.Logger("f3")

const (
F3DisableEnvKey = "DISABLE_F3"
F3DisableEnvValue = "1"
F3DisableCheckPeriod = 2 * time.Duration(build.BlockDelaySecs)
)

func New(mctx helpers.MetricsCtx, lc fx.Lifecycle, params F3Params) (*F3, error) {
manifest := f3.LocalnetManifest()
manifest.NetworkName = gpbft.NetworkName(params.NetworkName)
Expand Down Expand Up @@ -90,23 +83,6 @@ func New(mctx helpers.MetricsCtx, lc fx.Lifecycle, params F3Params) (*F3, error)
log.Errorf("running f3: %+v", err)
}
}()
go func() {
ticker := time.NewTicker(F3DisableCheckPeriod)
for {
select {
case <-ticker.C:
if os.Getenv(F3DisableEnvKey) == F3DisableEnvValue {
// TODO: Once https://github.com/filecoin-project/lotus/pull/12173 is merged
// we can use fff.inner.Stop() instead of calling cancel()
cancel()
log.Errorf("F3 has been disabled in runtime")
return
}
case <-lCtx.Done():
return
}
}
}()
}, cancel))

return fff, nil
Expand Down
4 changes: 1 addition & 3 deletions node/builder_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package node

import (
"errors"
"os"

"go.uber.org/fx"
"golang.org/x/xerrors"
Expand All @@ -14,7 +13,6 @@ import (
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/gen"
"github.com/filecoin-project/lotus/chain/gen/slashfilter"
"github.com/filecoin-project/lotus/chain/lf3"
"github.com/filecoin-project/lotus/lib/harmony/harmonydb"
"github.com/filecoin-project/lotus/miner"
"github.com/filecoin-project/lotus/node/config"
Expand Down Expand Up @@ -143,7 +141,7 @@ func ConfigStorageMiner(c interface{}) Option {
Override(new(config.HarmonyDB), cfg.HarmonyDB),
Override(new(harmonydb.ITestID), harmonydb.ITestID("")),
Override(new(*ctladdr.AddressSelector), modules.AddressSelector(&cfg.Addresses)),
If(build.F3Enabled && os.Getenv(lf3.F3DisableEnvKey) != lf3.F3DisableEnvValue, Override(F3Participation, modules.F3Participation)),
If(build.IsF3Enabled(), Override(F3Participation, modules.F3Participation)),
)
}

Expand Down
4 changes: 1 addition & 3 deletions node/modules/lp2p/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"net"
"os"
"time"

pubsub "github.com/libp2p/go-libp2p-pubsub"
Expand All @@ -20,7 +19,6 @@ import (
"github.com/filecoin-project/go-f3/gpbft"

"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/lf3"
"github.com/filecoin-project/lotus/metrics"
"github.com/filecoin-project/lotus/node/config"
"github.com/filecoin-project/lotus/node/modules/dtypes"
Expand Down Expand Up @@ -383,7 +381,7 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) {
build.IndexerIngestTopic(in.Nn),
}

if build.F3Enabled && os.Getenv(lf3.F3DisableEnvKey) != lf3.F3DisableEnvValue {
if build.IsF3Enabled() {
allowTopics = append(allowTopics, gpbft.NetworkName(in.Nn).PubSubTopic())
}

Expand Down

0 comments on commit f87582d

Please sign in to comment.