Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support snapnet #4702

Merged
merged 2 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 5 additions & 138 deletions cmd/daemon.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,32 @@
package cmd

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"github.com/filecoin-project/venus/fixtures/networks"
"io/ioutil"
"net/http"
"net/url"
"os"

"github.com/filecoin-project/venus/pkg/constants"
"github.com/filecoin-project/venus/pkg/util/ulimit"
"github.com/filecoin-project/venus/venus-shared/types"

paramfetch "github.com/filecoin-project/go-paramfetch"
"github.com/filecoin-project/venus/fixtures/asset"

"golang.org/x/xerrors"

_ "net/http/pprof" // nolint: golint

blockstore "github.com/ipfs/go-ipfs-blockstore"
cmds "github.com/ipfs/go-ipfs-cmds"
cbor "github.com/ipfs/go-ipld-cbor"
logging "github.com/ipfs/go-log/v2"
"github.com/ipld/go-car"
"github.com/libp2p/go-libp2p-core/crypto"
_ "net/http/pprof" // nolint: golint

"github.com/filecoin-project/venus/app/node"
"github.com/filecoin-project/venus/app/paths"
"github.com/filecoin-project/venus/fixtures/networks"
"github.com/filecoin-project/venus/pkg/config"
"github.com/filecoin-project/venus/pkg/genesis"
"github.com/filecoin-project/venus/pkg/journal"
"github.com/filecoin-project/venus/pkg/migration"
"github.com/filecoin-project/venus/pkg/repo"
gengen "github.com/filecoin-project/venus/tools/gengen/util"
)

var log = logging.Logger("daemon")
Expand Down Expand Up @@ -65,7 +54,7 @@ var daemonCmd = &cmds.Command{
cmds.StringOption(GenesisFile, "path of file or HTTP(S) URL containing archive of genesis block DAG data"),
cmds.StringOption(PeerKeyFile, "path of file containing key to use for new node's libp2p identity"),
cmds.StringOption(WalletKeyFile, "path of file containing keys to import into the wallet on initialization"),
cmds.StringOption(Network, "when set, populates config with network specific parameters, eg. 2k,cali,interop,mainnet").WithDefault("mainnet"),
cmds.StringOption(Network, "when set, populates config with network specific parameters, eg. mainnet,2k,cali,interop,butterfly").WithDefault("mainnet"),
cmds.StringOption(Password, "set wallet password"),
},
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error {
Expand Down Expand Up @@ -143,7 +132,7 @@ func initRun(req *cmds.Request) error {
var genesisFunc genesis.InitFunc
cfg := rep.Config()
network, _ := req.Options[Network].(string)
if err := setConfigFromOptions(cfg, network); err != nil {
if err := networks.SetConfigFromOptions(cfg, network); err != nil {
log.Errorf("Error setting config %s", err)
return err
}
Expand All @@ -158,7 +147,7 @@ func initRun(req *cmds.Request) error {
genesisFunc = genesis.MakeGenesis(req.Context, rep, mkGen, preTp.(string), cfg.NetworkParams.ForkUpgradeParam)
} else {
genesisFileSource, _ := req.Options[GenesisFile].(string)
genesisFunc, err = loadGenesis(req.Context, rep, genesisFileSource, network)
genesisFunc, err = networks.LoadGenesis(req.Context, rep, genesisFileSource, network)
if err != nil {
return err
}
Expand Down Expand Up @@ -305,82 +294,6 @@ func getRepo(req *cmds.Request) (repo.Repo, error) {
return repo.OpenFSRepo(repoDir, repo.LatestVersion)
}

func setConfigFromOptions(cfg *config.Config, network string) error {
// Setup specific config options.
var netcfg *networks.NetworkConf
switch network {
case "mainnet":
netcfg = networks.Mainnet()
case "force":
netcfg = networks.ForceNet()
case "integrationnet":
netcfg = networks.IntegrationNet()
case "2k":
netcfg = networks.Net2k()
case "cali":
netcfg = networks.Calibration()
case "interop":
netcfg = networks.InteropNet()
default:
return fmt.Errorf("unknown network name %s", network)
}

if netcfg != nil {
cfg.Bootstrap = &netcfg.Bootstrap
cfg.NetworkParams = &netcfg.Network
}

return nil
}

func loadGenesis(ctx context.Context, rep repo.Repo, sourceName string, network string) (genesis.InitFunc, error) {
var (
source io.ReadCloser
err error
)

if sourceName == "" {
var bs []byte
var err error
switch network {
case "nerpa":
bs, err = asset.Asset("fixtures/_assets/car/nerpanet.car")
case "cali":
bs, err = asset.Asset("fixtures/_assets/car/calibnet.car")
case "interop":
bs, err = asset.Asset("fixtures/_assets/car/interopnet.car")
case "force":
bs, err = asset.Asset("fixtures/_assets/car/forcenet.car")
default:
bs, err = asset.Asset("fixtures/_assets/car/devnet.car")
}
if err != nil {
return gengen.MakeGenesisFunc(), nil
}
source = ioutil.NopCloser(bytes.NewReader(bs))
// return gengen.MakeGenesisFunc(), nil
} else {
source, err = openGenesisSource(sourceName)
if err != nil {
return nil, err
}
}

defer func() { _ = source.Close() }()

genesisBlk, err := extractGenesisBlock(ctx, source, rep)
if err != nil {
return nil, err
}

gif := func(cst cbor.IpldStore, bs blockstore.Blockstore) (*types.BlockHeader, error) {
return genesisBlk, err
}

return gif, nil

}

func getNodeInitOpts(peerKeyFile string, walletKeyFile string) ([]node.InitOpt, error) {
var initOpts []node.InitOpt
if peerKeyFile != "" {
Expand Down Expand Up @@ -417,49 +330,3 @@ func getNodeInitOpts(peerKeyFile string, walletKeyFile string) ([]node.InitOpt,

return initOpts, nil
}

func openGenesisSource(sourceName string) (io.ReadCloser, error) {
sourceURL, err := url.Parse(sourceName)
if err != nil {
return nil, fmt.Errorf("invalid filepath or URL for genesis file: %s", sourceURL)
}
var source io.ReadCloser
if sourceURL.Scheme == "http" || sourceURL.Scheme == "https" {
// NOTE: This code is temporary. It allows downloading a genesis block via HTTP(S) to be able to join a
// recently deployed staging devnet.
response, err := http.Get(sourceName)
if err != nil {
return nil, err
}
source = response.Body
} else if sourceURL.Scheme != "" {
return nil, fmt.Errorf("unsupported protocol for genesis file: %s", sourceURL.Scheme)
} else {
file, err := os.Open(sourceName)
if err != nil {
return nil, err
}
source = file
}
return source, nil
}

func extractGenesisBlock(ctx context.Context, source io.ReadCloser, rep repo.Repo) (*types.BlockHeader, error) {
bs := rep.Datastore()
ch, err := car.LoadCar(ctx, bs, source)
if err != nil {
return nil, err
}

// need to check if we are being handed a car file with a single genesis block or an entire chain.
bsBlk, err := bs.Get(ctx, ch.Roots[0])
if err != nil {
return nil, err
}
cur, err := types.DecodeBlock(bsBlk.RawData())
if err != nil {
return nil, err
}

return cur, nil
}
Binary file added fixtures/_assets/car/butterflynet.car
Binary file not shown.
File renamed without changes.
94 changes: 63 additions & 31 deletions fixtures/asset/asset.go

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions fixtures/networks/butterfly.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package networks

import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/venus/pkg/config"
"github.com/filecoin-project/venus/pkg/constants"
)

func ButterflySnapNet() *NetworkConf {
return &NetworkConf{
Bootstrap: config.BootstrapConfig{
Addresses: []string{
"/dns4/bootstrap-0.butterfly.fildev.network/tcp/1347/p2p/12D3KooWBdRCBLUeKvoy22u5DcXs61adFn31v8WWCZgmBjDCjbsC",
"/dns4/bootstrap-1.butterfly.fildev.network/tcp/1347/p2p/12D3KooWDUQJBA18njjXnG9RtLxoN3muvdU7PEy55QorUEsdAqdy",
},
MinPeerThreshold: 0,
Period: "30s",
},
Network: config.NetworkParamsConfig{
DevNet: true,
ReplaceProofTypes: []abi.RegisteredSealProof{
abi.RegisteredSealProof_StackedDrg512MiBV1,
abi.RegisteredSealProof_StackedDrg32GiBV1,
abi.RegisteredSealProof_StackedDrg64GiBV1,
},
NetworkType: constants.NetworkButterfly,
GenesisNetworkVersion: network.Version14,
BlockDelay: 30,
ConsensusMinerMinPower: 2 << 30,
ForkUpgradeParam: &config.ForkUpgradeConfig{
UpgradeBreezeHeight: -1,
UpgradeSmokeHeight: -2,
UpgradeIgnitionHeight: -3,
UpgradeRefuelHeight: -4,
UpgradeAssemblyHeight: -5,
UpgradeTapeHeight: -6,
UpgradeLiftoffHeight: -7,
UpgradeKumquatHeight: -8,
UpgradeCalicoHeight: -9,
UpgradePersianHeight: -10,
UpgradeOrangeHeight: -12,
UpgradeTrustHeight: -13,
UpgradeNorwegianHeight: -14,
UpgradeTurboHeight: -15,
UpgradeHyperdriveHeight: -16,
UpgradeChocolateHeight: -17,
UpgradeOhSnapHeight: 30262,

BreezeGasTampingDuration: 120,
UpgradeClausHeight: -11,
},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: 1},
AddressNetwork: address.Testnet,
},
}
}
33 changes: 16 additions & 17 deletions fixtures/networks/calibration.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,26 @@ func Calibration() *NetworkConf {
abi.RegisteredSealProof_StackedDrg64GiBV1,
},
ForkUpgradeParam: &config.ForkUpgradeConfig{
UpgradeBreezeHeight: -1,
UpgradeSmokeHeight: -2,
UpgradeIgnitionHeight: -3,
UpgradeRefuelHeight: -4,
UpgradeAssemblyHeight: 30,
UpgradeTapeHeight: 60,
UpgradeLiftoffHeight: -5,
UpgradeKumquatHeight: 90,
UpgradePriceListOopsHeight: 119,
UpgradeCalicoHeight: 120,
UpgradePersianHeight: 100 + (120 * 1),
UpgradeOrangeHeight: 300,
UpgradeTrustHeight: 330,
UpgradeNorwegianHeight: 360,
UpgradeTurboHeight: 390,
UpgradeHyperdriveHeight: 420,
UpgradeBreezeHeight: -1,
UpgradeSmokeHeight: -2,
UpgradeIgnitionHeight: -3,
UpgradeRefuelHeight: -4,
UpgradeAssemblyHeight: 30,
UpgradeTapeHeight: 60,
UpgradeLiftoffHeight: -5,
UpgradeKumquatHeight: 90,
UpgradeCalicoHeight: 120,
UpgradePersianHeight: 100 + (120 * 1),
UpgradeOrangeHeight: 300,
UpgradeTrustHeight: 330,
UpgradeNorwegianHeight: 360,
UpgradeTurboHeight: 390,
UpgradeHyperdriveHeight: 420,

BreezeGasTampingDuration: 120,
UpgradeClausHeight: 270,
UpgradeChocolateHeight: 312746,
UpgradeSnapDealsHeight: 99999999,
UpgradeOhSnapHeight: 99999999,
},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: 1},
AddressNetwork: address.Testnet,
Expand Down
33 changes: 16 additions & 17 deletions fixtures/networks/forcenet.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,27 @@ func ForceNet() *NetworkConf {
ForkUpgradeParam: &config.ForkUpgradeConfig{
UpgradeBreezeHeight: -1,
BreezeGasTampingDuration: 0,
UpgradeSmokeHeight: -1,
UpgradeIgnitionHeight: -2,
UpgradeRefuelHeight: -3,
UpgradeTapeHeight: -4,
UpgradeSmokeHeight: -2,
UpgradeIgnitionHeight: -3,
UpgradeRefuelHeight: -4,
UpgradeTapeHeight: -5,
UpgradeLiftoffHeight: -6,
// This signals our tentative epoch for mainnet launch. Can make it later, but not earlier.
// Miners, clients, developers, custodians all need time to prepare.
// We still have upgrades and state changes to do, but can happen after signaling timing here.

UpgradeAssemblyHeight: -5, // critical: the network can bootstrap from v1 only
UpgradeKumquatHeight: -7,
UpgradePriceListOopsHeight: -8,
UpgradeCalicoHeight: -9,
UpgradePersianHeight: -10,
UpgradeOrangeHeight: -11,
UpgradeClausHeight: -12,
UpgradeTrustHeight: -13,
UpgradeNorwegianHeight: -14,
UpgradeTurboHeight: -15,
UpgradeHyperdriveHeight: -16,
UpgradeChocolateHeight: -17,
UpgradeSnapDealsHeight: -18,
UpgradeAssemblyHeight: -7, // critical: the network can bootstrap from v1 only
UpgradeKumquatHeight: -8,
UpgradeCalicoHeight: -9,
UpgradePersianHeight: -10,
UpgradeOrangeHeight: -11,
UpgradeClausHeight: -12,
UpgradeTrustHeight: -13,
UpgradeNorwegianHeight: -14,
UpgradeTurboHeight: -15,
UpgradeHyperdriveHeight: -16,
UpgradeChocolateHeight: -17,
UpgradeOhSnapHeight: -18,
},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: config.DrandMainnet},
AddressNetwork: address.Testnet,
Expand Down
Loading