Skip to content

Commit 05318a5

Browse files
authored
feat: add env-var to disable F3 activation (#12920)
1 parent 00c1c59 commit 05318a5

File tree

3 files changed

+83
-5
lines changed

3 files changed

+83
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- `lotus send` now supports `--csv` option for sending multiple transactions. ([filecoin-project/lotus#12892](https://github.com/filecoin-project/lotus/pull/12892))
1919
- 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)
2020
- chore: upgrade to a minimum Golang version of `1.23.6` ([filecoin-project/lotus#12910](https://github.com/filecoin-project/lotus/pull/12910)
21+
- 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`.
2122
- feat: add `GenesisTimestamp` field to `StateGetNetworkParams` response ([filecoin-project/lotus#12925](https://github.com/filecoin-project/lotus/pull/12925))
2223

2324
# UNRELEASED v.1.32.0

build/params_shared_funcs.go

+62-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package build
22

33
import (
44
"os"
5+
"strconv"
56
"strings"
67

78
"github.com/libp2p/go-libp2p/core/protocol"
@@ -25,7 +26,7 @@ var SetAddressNetwork = buildconstants.SetAddressNetwork
2526
var MustParseAddress = buildconstants.MustParseAddress
2627

2728
func IsF3Enabled() bool {
28-
const F3DisableEnvKey = "LOTUS_DISABLE_F3"
29+
const F3DisableEnvKey = "LOTUS_DISABLE_F3_SUBSYSTEM"
2930
if !buildconstants.F3Enabled {
3031
// Build constant takes precedence over environment variable.
3132
return false
@@ -65,3 +66,63 @@ func IsF3PassiveTestingEnabled() bool {
6566
return false
6667
}
6768
}
69+
70+
func parseF3DisableActivationEnv() (contractAddrs []string, epochs []int64) {
71+
const F3DisableActivation = "LOTUS_DISABLE_F3_ACTIVATION"
72+
73+
v, envVarSet := os.LookupEnv(F3DisableActivation)
74+
if !envVarSet || strings.TrimSpace(v) == "" {
75+
// Environment variable is not set or empty, activation is not disabled
76+
return
77+
}
78+
79+
// Parse the variable which can be in format "contract:addrs" or "epoch:epochnumber" or both
80+
parts := strings.Split(v, ",")
81+
for _, part := range parts {
82+
kv := strings.SplitN(part, ":", 2)
83+
if len(kv) != 2 {
84+
continue
85+
}
86+
87+
key := strings.TrimSpace(strings.ToLower(kv[0]))
88+
value := strings.TrimSpace(kv[1])
89+
90+
switch key {
91+
case "contract":
92+
// If contract address matches, disable activation
93+
contractAddrs = append(contractAddrs, value)
94+
case "epoch":
95+
parsedEpoch, err := strconv.ParseInt(value, 10, 64)
96+
if err == nil {
97+
epochs = append(epochs, parsedEpoch)
98+
} else {
99+
log.Warnf("error parsing %s env variable, cannot parse epoch", F3DisableActivation)
100+
}
101+
}
102+
}
103+
return contractAddrs, epochs
104+
}
105+
106+
// IsF3EpochActivationDisabled checks if F3 activation is disabled for the given
107+
// epoch number based on environment variable configuration.
108+
func IsF3EpochActivationDisabled(epoch int64) bool {
109+
_, epochs := parseF3DisableActivationEnv()
110+
for _, e := range epochs {
111+
if e == epoch {
112+
return true
113+
}
114+
}
115+
return false
116+
}
117+
118+
// IsF3ContractActivationDisabled checks if F3 activation is disabled for the given contract address
119+
// based on environment variable configuration.
120+
func IsF3ContractActivationDisabled(contract string) bool {
121+
contracts, _ := parseF3DisableActivationEnv()
122+
for _, c := range contracts {
123+
if c == contract {
124+
return true
125+
}
126+
}
127+
return false
128+
}

chain/lf3/manifest.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,29 @@ var MaxDynamicManifestChangesAllowed = 1000
5151

5252
func NewManifestProvider(mctx helpers.MetricsCtx, config *Config, cs *store.ChainStore, ps *pubsub.PubSub, mds dtypes.MetadataDS, stateCaller StateCaller) (prov manifest.ManifestProvider, err error) {
5353
var primaryManifest manifest.ManifestProvider
54-
if config.StaticManifest != nil {
55-
log.Infof("using static maniest as primary")
54+
55+
// Check if static manifest activation is disabled
56+
staticDisabled := false
57+
if config.StaticManifest != nil && build.IsF3EpochActivationDisabled(config.StaticManifest.BootstrapEpoch) {
58+
log.Warnf("F3 activation disabled by environment configuration for bootstrap epoch %d", config.StaticManifest.BootstrapEpoch)
59+
staticDisabled = true
60+
}
61+
62+
// Check if contract manifest activation is disabled
63+
contractDisabled := false
64+
if config.ContractAddress != "" && build.IsF3ContractActivationDisabled(config.ContractAddress) {
65+
log.Warnf("F3 activation disabled by environment configuration for contract %s", config.ContractAddress)
66+
contractDisabled = true
67+
}
68+
69+
if config.StaticManifest != nil && !staticDisabled {
70+
log.Infof("using static manifest as primary")
5671
primaryManifest, err = manifest.NewStaticManifestProvider(config.StaticManifest)
57-
} else if config.ContractAddress != "" {
58-
log.Infow("using contract maniest as primary", "address", config.ContractAddress)
72+
} else if config.ContractAddress != "" && !contractDisabled {
73+
log.Infow("using contract manifest as primary", "address", config.ContractAddress)
5974
primaryManifest, err = NewContractManifestProvider(mctx, config, stateCaller)
6075
}
76+
6177
if err != nil {
6278
return nil, fmt.Errorf("creating primary manifest: %w", err)
6379
}

0 commit comments

Comments
 (0)