From 0b2d90f8d9b2293a8cedb64c2b2d4ca1bf2cca66 Mon Sep 17 00:00:00 2001 From: Phi Date: Tue, 25 Feb 2025 10:30:37 +0100 Subject: [PATCH 1/5] feat: add env-var to disable F3 activation Adds a new environment variable LOTUS_DISABLE_F3_ACTIVATION that allows disabling F3 activation for specific contract addresses or epochs. Format: contract:address or epoch:number --- build/params_shared_funcs.go | 45 ++++++++++++++++++++++++++++++++++++ chain/lf3/manifest.go | 24 +++++++++++++++---- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/build/params_shared_funcs.go b/build/params_shared_funcs.go index 8fe0ee07e36..e68f8a01521 100644 --- a/build/params_shared_funcs.go +++ b/build/params_shared_funcs.go @@ -2,6 +2,7 @@ package build import ( "os" + "strconv" "strings" "github.com/libp2p/go-libp2p/core/protocol" @@ -65,3 +66,47 @@ func IsF3PassiveTestingEnabled() bool { return false } } + +// IsF3ActivationDisabledFor checks if F3 activation is disabled for the given contract address +// or epoch number based on environment variable configuration. +func IsF3ActivationDisabledFor(contractAddr string, epoch int64) bool { + if !IsF3Enabled() { + // If F3 is disabled entirely, then activation is also disabled + return true + } + + const F3DisableActivation = "LOTUS_DISABLE_F3_ACTIVATION" + + v, envVarSet := os.LookupEnv(F3DisableActivation) + if !envVarSet || strings.TrimSpace(v) == "" { + // Environment variable is not set or empty, activation is not disabled + return false + } + + // Parse the variable which can be in format "contract:addrs" or "epoch:epochnumber" or both + parts := strings.Split(v, ",") + for _, part := range parts { + kv := strings.SplitN(part, ":", 2) + if len(kv) != 2 { + continue + } + + key := strings.TrimSpace(strings.ToLower(kv[0])) + value := strings.TrimSpace(kv[1]) + + switch key { + case "contract": + // If contract address matches, disable activation + if value != "" && value == contractAddr { + return true + } + case "epoch": + parsedEpoch, err := strconv.ParseInt(value, 10, 64) + // If epoch matches, disable activation + if err == nil && parsedEpoch == epoch { + return true + } + } + } + return false +} diff --git a/chain/lf3/manifest.go b/chain/lf3/manifest.go index 06154604249..4333580b526 100644 --- a/chain/lf3/manifest.go +++ b/chain/lf3/manifest.go @@ -51,13 +51,29 @@ var MaxDynamicManifestChangesAllowed = 1000 func NewManifestProvider(mctx helpers.MetricsCtx, config *Config, cs *store.ChainStore, ps *pubsub.PubSub, mds dtypes.MetadataDS, stateCaller StateCaller) (prov manifest.ManifestProvider, err error) { var primaryManifest manifest.ManifestProvider - if config.StaticManifest != nil { - log.Infof("using static maniest as primary") + + // Check if static manifest activation is disabled + staticDisabled := false + if config.StaticManifest != nil && build.IsF3ActivationDisabledFor("", config.StaticManifest.BootstrapEpoch) { + log.Warnf("F3 activation disabled by environment configuration for bootstrap epoch %d", config.StaticManifest.BootstrapEpoch) + staticDisabled = true + } + + // Check if contract manifest activation is disabled + contractDisabled := false + if config.ContractAddress != "" && build.IsF3ActivationDisabledFor(config.ContractAddress, 0) { + log.Warnf("F3 activation disabled by environment configuration for contract %s", config.ContractAddress) + contractDisabled = true + } + + if config.StaticManifest != nil && !staticDisabled { + log.Infof("using static manifest as primary") primaryManifest, err = manifest.NewStaticManifestProvider(config.StaticManifest) - } else if config.ContractAddress != "" { - log.Infow("using contract maniest as primary", "address", config.ContractAddress) + } else if config.ContractAddress != "" && !contractDisabled { + log.Infow("using contract manifest as primary", "address", config.ContractAddress) primaryManifest, err = NewContractManifestProvider(mctx, config, stateCaller) } + if err != nil { return nil, fmt.Errorf("creating primary manifest: %w", err) } From 7936f1d9952cc9b8e995a2f47721e0400d27501e Mon Sep 17 00:00:00 2001 From: Phi Date: Tue, 25 Feb 2025 12:11:13 +0100 Subject: [PATCH 2/5] chore: add changelog entry chore: add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f520956174..1c236005122 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - `lotus send` now supports `--csv` option for sending multiple transactions. ([filecoin-project/lotus#12892](https://github.com/filecoin-project/lotus/pull/12892)) - chore: upgrade to the latest go-f3 and allow F3 chain exchange topics ([filecoin-project/lotus#12893](https://github.com/filecoin-project/lotus/pull/12893) - chore: upgrade to a minimum Golang version of `1.23.6` ([filecoin-project/lotus#12910](https://github.com/filecoin-project/lotus/pull/12910) +- feat: add enviroment variable allowing disabling F3 activation for a specific contract address or epoch ([filecoin-project/lotus#12920](https://github.com/filecoin-project/lotus/pull/12920)) # UNRELEASED v.1.32.0 From ebc04b8e880838d8b334ea09712bb2e1107b98e5 Mon Sep 17 00:00:00 2001 From: Phi Date: Thu, 27 Feb 2025 15:33:37 +0100 Subject: [PATCH 3/5] chore: rename LOTUS_DISABLE_F3 to LOTUS_DISABLE_F3_SUBSYSTEM chore: rename LOTUS_DISABLE_F3 to LOTUS_DISABLE_F3_SUBSYSTEM --- CHANGELOG.md | 2 +- build/params_shared_funcs.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c236005122..58e0c3c814a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ - `lotus send` now supports `--csv` option for sending multiple transactions. ([filecoin-project/lotus#12892](https://github.com/filecoin-project/lotus/pull/12892)) - chore: upgrade to the latest go-f3 and allow F3 chain exchange topics ([filecoin-project/lotus#12893](https://github.com/filecoin-project/lotus/pull/12893) - chore: upgrade to a minimum Golang version of `1.23.6` ([filecoin-project/lotus#12910](https://github.com/filecoin-project/lotus/pull/12910) -- feat: add enviroment variable allowing disabling F3 activation for a specific contract address or epoch ([filecoin-project/lotus#12920](https://github.com/filecoin-project/lotus/pull/12920)) +- feat: add a `LOTUS_DISABLE_F3_ACTIVATION` enviroment variable allowing disabling F3 activation for a specific contract address or epoch ([filecoin-project/lotus#12920](https://github.com/filecoin-project/lotus/pull/12920)). The `LOTUS_DISABLE_F3` env-var has been renamed to `LOTUS_DISABLE_F3_SUBSYSTEM` to distinguish it from the other F3-related environment variables: `LOTUS_DISABLE_F3_PASSIVE_TESTING` and `LOTUS_DISABLE_F3_ACTIVATION`. # UNRELEASED v.1.32.0 diff --git a/build/params_shared_funcs.go b/build/params_shared_funcs.go index e68f8a01521..ecdc65fdfad 100644 --- a/build/params_shared_funcs.go +++ b/build/params_shared_funcs.go @@ -26,7 +26,7 @@ var SetAddressNetwork = buildconstants.SetAddressNetwork var MustParseAddress = buildconstants.MustParseAddress func IsF3Enabled() bool { - const F3DisableEnvKey = "LOTUS_DISABLE_F3" + const F3DisableEnvKey = "LOTUS_DISABLE_F3_SUBSYSTEM" if !buildconstants.F3Enabled { // Build constant takes precedence over environment variable. return false From 35cb233b61a79939ae19604b550b7fd3cba71b7c Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 3 Mar 2025 17:26:31 +0100 Subject: [PATCH 4/5] Clenaup the code Signed-off-by: Jakub Sztandera --- build/params_shared_funcs.go | 46 ++++++++++++++++++++++++------------ chain/lf3/manifest.go | 4 ++-- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/build/params_shared_funcs.go b/build/params_shared_funcs.go index ecdc65fdfad..db2a50eb3d4 100644 --- a/build/params_shared_funcs.go +++ b/build/params_shared_funcs.go @@ -67,20 +67,13 @@ func IsF3PassiveTestingEnabled() bool { } } -// IsF3ActivationDisabledFor checks if F3 activation is disabled for the given contract address -// or epoch number based on environment variable configuration. -func IsF3ActivationDisabledFor(contractAddr string, epoch int64) bool { - if !IsF3Enabled() { - // If F3 is disabled entirely, then activation is also disabled - return true - } - +func parseF3DisableActivationEnv() (contractAddrs []string, epochs []int64) { const F3DisableActivation = "LOTUS_DISABLE_F3_ACTIVATION" v, envVarSet := os.LookupEnv(F3DisableActivation) if !envVarSet || strings.TrimSpace(v) == "" { // Environment variable is not set or empty, activation is not disabled - return false + return } // Parse the variable which can be in format "contract:addrs" or "epoch:epochnumber" or both @@ -97,16 +90,39 @@ func IsF3ActivationDisabledFor(contractAddr string, epoch int64) bool { switch key { case "contract": // If contract address matches, disable activation - if value != "" && value == contractAddr { - return true - } + contractAddrs = append(contractAddrs, value) case "epoch": parsedEpoch, err := strconv.ParseInt(value, 10, 64) - // If epoch matches, disable activation - if err == nil && parsedEpoch == epoch { - return true + if err == nil { + epochs = append(epochs, parsedEpoch) + } else { + log.Warnf("error parsing %s env variable, cannot parse epoch", F3DisableActivation) } } } + return contractAddrs, epochs +} + +// IsF3EpochActivationDisabledForEpoch checks if F3 activation is disabled for the given +// epoch number based on environment variable configuration. +func IsF3EpochActivationDisabled(epoch int64) bool { + _, epochs := parseF3DisableActivationEnv() + for _, e := range epochs { + if e == epoch { + return true + } + } + return false +} + +// IsF3EpochActivationDisabledForContract checks if F3 activation is disabled for the given contract address +// based on environment variable configuration. +func IsF3ContractActivationDisabled(contract string) bool { + contracts, _ := parseF3DisableActivationEnv() + for _, c := range contracts { + if c == contract { + return true + } + } return false } diff --git a/chain/lf3/manifest.go b/chain/lf3/manifest.go index 4333580b526..ac1f2b8bb41 100644 --- a/chain/lf3/manifest.go +++ b/chain/lf3/manifest.go @@ -54,14 +54,14 @@ func NewManifestProvider(mctx helpers.MetricsCtx, config *Config, cs *store.Chai // Check if static manifest activation is disabled staticDisabled := false - if config.StaticManifest != nil && build.IsF3ActivationDisabledFor("", config.StaticManifest.BootstrapEpoch) { + if config.StaticManifest != nil && build.IsF3EpochActivationDisabled(config.StaticManifest.BootstrapEpoch) { log.Warnf("F3 activation disabled by environment configuration for bootstrap epoch %d", config.StaticManifest.BootstrapEpoch) staticDisabled = true } // Check if contract manifest activation is disabled contractDisabled := false - if config.ContractAddress != "" && build.IsF3ActivationDisabledFor(config.ContractAddress, 0) { + if config.ContractAddress != "" && build.IsF3ContractActivationDisabled(config.ContractAddress) { log.Warnf("F3 activation disabled by environment configuration for contract %s", config.ContractAddress) contractDisabled = true } From 8a099913236813b56399a4c159b1882a23cd9b5f Mon Sep 17 00:00:00 2001 From: Phi Date: Mon, 3 Mar 2025 17:56:01 +0100 Subject: [PATCH 5/5] chore: address lint-error chore: address lint-error --- build/params_shared_funcs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/params_shared_funcs.go b/build/params_shared_funcs.go index db2a50eb3d4..2c4615033b4 100644 --- a/build/params_shared_funcs.go +++ b/build/params_shared_funcs.go @@ -103,7 +103,7 @@ func parseF3DisableActivationEnv() (contractAddrs []string, epochs []int64) { return contractAddrs, epochs } -// IsF3EpochActivationDisabledForEpoch checks if F3 activation is disabled for the given +// IsF3EpochActivationDisabled checks if F3 activation is disabled for the given // epoch number based on environment variable configuration. func IsF3EpochActivationDisabled(epoch int64) bool { _, epochs := parseF3DisableActivationEnv() @@ -115,7 +115,7 @@ func IsF3EpochActivationDisabled(epoch int64) bool { return false } -// IsF3EpochActivationDisabledForContract checks if F3 activation is disabled for the given contract address +// IsF3ContractActivationDisabled checks if F3 activation is disabled for the given contract address // based on environment variable configuration. func IsF3ContractActivationDisabled(contract string) bool { contracts, _ := parseF3DisableActivationEnv()