Skip to content

Commit

Permalink
feat(f3): add a build parameter to set the initial power table cid
Browse files Browse the repository at this point in the history
This will be used post-bootstrap to hard-code the initial F3 power table
CID.

If and only if it has not already hard-coded, it can be specified by setting the
F3_INITIAL_POWERTABLE_CID environment variable.
  • Loading branch information
Stebalien committed Sep 22, 2024
1 parent 312fa3a commit a44276f
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 9 deletions.
3 changes: 3 additions & 0 deletions build/buildconstants/params_2k.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ var F3Enabled = true

var F3ManifestServerID = MustParseID("12D3KooWHcNBkqXEBrsjoveQvj6zDF3vK5S9tAfqyYaQF1LGSJwG")

// The initial F3 power table CID.
var F3InitialPowerTableCID cid.Cid = cid.Undef

var F3BootstrapEpoch abi.ChainEpoch = 1000

// F3Consensus set whether F3 should checkpoint tipsets finalized by F3. This
Expand Down
3 changes: 3 additions & 0 deletions build/buildconstants/params_butterfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const F3Enabled = true

var F3ManifestServerID = MustParseID("12D3KooWJr9jy4ngtJNR7JC1xgLFra3DjEtyxskRYWvBK9TC3Yn6")

// The initial F3 power table CID.
var F3InitialPowerTableCID cid.Cid = cid.Undef

const F3BootstrapEpoch abi.ChainEpoch = 1000

// F3Consensus set whether F3 should checkpoint tipsets finalized by F3. This
Expand Down
3 changes: 3 additions & 0 deletions build/buildconstants/params_calibnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ const F3Enabled = true

var F3ManifestServerID = MustParseID("12D3KooWS9vD9uwm8u2uPyJV32QBAhKAmPYwmziAgr3Xzk2FU1Mr")

// The initial F3 power table CID.
var F3InitialPowerTableCID cid.Cid = cid.Undef

const F3BootstrapEpoch abi.ChainEpoch = UpgradeWaffleHeight + 100

// F3Consensus set whether F3 should checkpoint tipsets finalized by F3. This
Expand Down
3 changes: 3 additions & 0 deletions build/buildconstants/params_interop.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ const F3Enabled = true

var F3ManifestServerID = MustParseID("12D3KooWQJ2rdVnG4okDUB6yHQhAjNutGNemcM7XzqC9Eo4z9Jce")

// The initial F3 power table CID.
var F3InitialPowerTableCID cid.Cid = cid.Undef

const F3BootstrapEpoch abi.ChainEpoch = 1000

// F3Consensus set whether F3 should checkpoint tipsets finalized by F3. This
Expand Down
3 changes: 3 additions & 0 deletions build/buildconstants/params_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ var WhitelistedBlock = cid.MustParse("bafy2bzaceapyg2uyzk7vueh3xccxkuwbz3nxewjyg
// The F3 manifest server ID, if any.
var F3ManifestServerID = MustParseID("12D3KooWENMwUF9YxvQxar7uBWJtZkA6amvK4xWmKXfSiHUo2Qq7")

// The initial F3 power table CID.
var F3InitialPowerTableCID cid.Cid = cid.Undef

const F3Enabled = true
const F3BootstrapEpoch abi.ChainEpoch = -1

Expand Down
12 changes: 12 additions & 0 deletions build/buildconstants/params_shared_vals.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"math/big"
"os"

"github.com/ipfs/go-cid"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
Expand Down Expand Up @@ -76,6 +78,16 @@ func init() {
if os.Getenv("LOTUS_ADDRESS_TYPE") == AddressMainnetEnvVar {
SetAddressNetwork(address.Mainnet)
}

if ptCid := os.Getenv("F3_INITIAL_POWERTABLE_CID"); ptCid != "" {
if k, err := cid.Parse(ptCid); err != nil {
log.Errorf("failed to parse F3_INITIAL_POWERTABLE_CID %q: %s", ptCid, err)
} else if F3InitialPowerTableCID.Defined() && k != F3InitialPowerTableCID {
log.Errorf("ignoring F3_INITIAL_POWERTABLE_CID as lotus has a hard-coded initial F3 power table")
} else {
F3InitialPowerTableCID = k
}
}
}

// Sync
Expand Down
13 changes: 7 additions & 6 deletions build/buildconstants/params_testground.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ var (

ZeroAddress = MustParseAddress("f3yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaby2smx7a")

WhitelistedBlock = cid.Undef
BootstrappersFile = ""
GenesisFile = ""
F3Enabled = false
F3ManifestServerID peer.ID = ""
F3BootstrapEpoch abi.ChainEpoch = -1
WhitelistedBlock = cid.Undef
BootstrappersFile = ""
GenesisFile = ""
F3Enabled = false
F3ManifestServerID peer.ID = ""
F3BootstrapEpoch abi.ChainEpoch = -1
F3InitialPowerTableCID = cid.Undef

// F3Consensus set whether F3 should checkpoint tipsets finalized by F3. This
// flag has no effect if F3 is not enabled.
Expand Down
4 changes: 3 additions & 1 deletion chain/lf3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lf3
import (
"time"

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

"github.com/filecoin-project/go-f3/gpbft"
Expand All @@ -19,7 +20,7 @@ type Config struct {
F3ConsensusEnabled bool
}

func NewConfig(manifestProvider peer.ID, consensusEnabled bool) func(dtypes.NetworkName) *Config {
func NewConfig(manifestProvider peer.ID, consensusEnabled bool, initialPowerTable cid.Cid) func(dtypes.NetworkName) *Config {
return func(nn dtypes.NetworkName) *Config {
m := manifest.LocalDevnetManifest()
m.NetworkName = gpbft.NetworkName(nn)
Expand All @@ -33,6 +34,7 @@ func NewConfig(manifestProvider peer.ID, consensusEnabled bool) func(dtypes.Netw
}
m.EC.Finality = int64(policy.ChainFinality)
m.CommitteeLookback = 5
m.InitialPowerTable = initialPowerTable

// TODO: We're forcing this to start paused for now. We need to remove this for the final
// mainnet launch.
Expand Down
3 changes: 2 additions & 1 deletion itests/kit/node_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math"
"time"

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

"github.com/filecoin-project/go-f3/manifest"
Expand Down Expand Up @@ -216,7 +217,7 @@ func MutateSealingConfig(mut func(sc *config.SealingConfig)) NodeOpt {
func F3Enabled(bootstrapEpoch abi.ChainEpoch, blockDelay time.Duration, finality abi.ChainEpoch, manifestProvider peer.ID) NodeOpt {
return ConstructorOpts(
node.Override(new(*lf3.Config), func(nn dtypes.NetworkName) *lf3.Config {
c := lf3.NewConfig(manifestProvider, true)(nn)
c := lf3.NewConfig(manifestProvider, true, cid.Undef)(nn)
c.InitialManifest.Pause = false
c.InitialManifest.EC.Period = blockDelay
c.InitialManifest.EC.Finality = int64(finality)
Expand Down
6 changes: 5 additions & 1 deletion node/builder_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ var ChainNode = Options(
),

If(build.IsF3Enabled(),
Override(new(*lf3.Config), lf3.NewConfig(buildconstants.F3ManifestServerID, buildconstants.F3Consensus)),
Override(new(*lf3.Config), lf3.NewConfig(
buildconstants.F3ManifestServerID,
buildconstants.F3Consensus,
buildconstants.F3InitialPowerTableCID,
)),
Override(new(manifest.ManifestProvider), lf3.NewManifestProvider),
Override(new(*lf3.F3), lf3.New),
),
Expand Down

0 comments on commit a44276f

Please sign in to comment.