From 9c5e88b01e57b4128108ef8439b4225820ffb33a Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Tue, 11 Jul 2023 18:20:42 +0000 Subject: [PATCH] prepare config for mainnet (#4679) config is extracted into a separate file so that we can track any accidental changes in protocol parameters easier --- cmd/root.go | 8 +-- common/types/address.go | 2 +- config/config.go | 8 --- config/genesis.go | 2 +- config/genesis_test.go | 2 +- config/mainnet.go | 115 ++++++++++++++++++++++++++++++++++++++++ node/node.go | 2 +- p2p/host.go | 2 +- 8 files changed, 122 insertions(+), 19 deletions(-) create mode 100644 config/mainnet.go diff --git a/cmd/root.go b/cmd/root.go index 6f0454502b..40eadee1a9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,10 +12,10 @@ import ( "github.com/spacemeshos/go-spacemesh/node/flags" ) -var cfg = config.DefaultConfig() +var cfg = config.MainnetConfig() func ResetConfig() { - cfg = config.DefaultConfig() + cfg = config.MainnetConfig() } // AddCommands adds cobra commands to the app. @@ -46,10 +46,6 @@ func AddCommands(cmd *cobra.Command) { cfg.MetricsPush, "Push metrics to url") cmd.PersistentFlags().IntVar(&cfg.MetricsPushPeriod, "metrics-push-period", cfg.MetricsPushPeriod, "Push period") - cmd.PersistentFlags().StringVar(&cfg.OracleServer, "oracle_server", - cfg.OracleServer, "The oracle server url. (temporary) ") - cmd.PersistentFlags().IntVar(&cfg.OracleServerWorldID, "oracle_server_worldid", - cfg.OracleServerWorldID, "The worldid to use with the oracle server (temporary) ") cmd.PersistentFlags().StringArrayVar(&cfg.PoETServers, "poet-server", cfg.PoETServers, "The poet server url. (temporary) Can be passed multiple times") cmd.PersistentFlags().StringVar(&cfg.Genesis.GenesisTime, "genesis-time", diff --git a/common/types/address.go b/common/types/address.go index 90a88c584b..ea112e17d8 100644 --- a/common/types/address.go +++ b/common/types/address.go @@ -33,7 +33,7 @@ var networkHrp = "sm" func SetNetworkHRP(update string) { networkHrp = update - log.With().Info("network hrp updated", log.String("hrp", update)) + log.With().Debug("network hrp updated", log.String("hrp", update)) } func NetworkHRP() string { diff --git a/config/config.go b/config/config.go index 1cec40c45d..b9cd5344d8 100644 --- a/config/config.go +++ b/config/config.go @@ -93,9 +93,6 @@ type BaseConfig struct { ProfilerName string `mapstructure:"profiler-name"` ProfilerURL string `mapstructure:"profiler-url"` - OracleServer string `mapstructure:"oracle_server"` - OracleServerWorldID int `mapstructure:"oracle_server_worldid"` - LayerDuration time.Duration `mapstructure:"layer-duration"` LayerAvgSize uint32 `mapstructure:"layer-average-size"` LayersPerEpoch uint32 `mapstructure:"layers-per-epoch"` @@ -104,8 +101,6 @@ type BaseConfig struct { PprofHTTPServer bool `mapstructure:"pprof-server"` - PublishEventsURL string `mapstructure:"events-url"` - TxsPerProposal int `mapstructure:"txs-per-proposal"` BlockGasLimit uint64 `mapstructure:"block-gas-limit"` // if the number of proposals with the same mesh state crosses this threshold (in percentage), @@ -170,10 +165,7 @@ func defaultBaseConfig() BaseConfig { MetricsPort: 1010, MetricsPush: "", // "" = doesn't push MetricsPushPeriod: 60, - ProfilerURL: "", ProfilerName: "gp-spacemesh", - OracleServer: "http://localhost:3030", - OracleServerWorldID: 0, LayerDuration: 30 * time.Second, LayersPerEpoch: 3, PoETServers: []string{"127.0.0.1"}, diff --git a/config/genesis.go b/config/genesis.go index de7cd87af6..b78cfc8060 100644 --- a/config/genesis.go +++ b/config/genesis.go @@ -42,7 +42,7 @@ func (g *GenesisConfig) GoldenATX() types.Hash32 { // Validate GenesisConfig. func (g *GenesisConfig) Validate() error { if len(g.ExtraData) == 0 { - return fmt.Errorf("wait until extra-data is available") + return fmt.Errorf("wait until genesis-extra-data is available") } if len(g.ExtraData) > 255 { return fmt.Errorf("extra-data is longer than 255 symbols: %s", g.ExtraData) diff --git a/config/genesis_test.go b/config/genesis_test.go index ca7d8282fb..8de7722aeb 100644 --- a/config/genesis_test.go +++ b/config/genesis_test.go @@ -18,7 +18,7 @@ func TestGenesisID(t *testing.T) { }) t.Run("require non-empty", func(t *testing.T) { cfg := GenesisConfig{GenesisTime: "2023-03-15T18:00:00Z"} - require.ErrorContains(t, cfg.Validate(), "wait until extra-data is available") + require.ErrorContains(t, cfg.Validate(), "wait until genesis-extra-data is available") }) t.Run("consistent", func(t *testing.T) { cfg := GenesisConfig{ExtraData: "one", GenesisTime: "2023-03-15T18:00:00Z"} diff --git a/config/mainnet.go b/config/mainnet.go new file mode 100644 index 0000000000..7ede97549b --- /dev/null +++ b/config/mainnet.go @@ -0,0 +1,115 @@ +package config + +import ( + "math/big" + "os" + "path/filepath" + "time" + + "github.com/spacemeshos/go-spacemesh/activation" + "github.com/spacemeshos/go-spacemesh/api/grpcserver" + "github.com/spacemeshos/go-spacemesh/beacon" + "github.com/spacemeshos/go-spacemesh/bootstrap" + "github.com/spacemeshos/go-spacemesh/checkpoint" + "github.com/spacemeshos/go-spacemesh/fetch" + hareConfig "github.com/spacemeshos/go-spacemesh/hare/config" + eligConfig "github.com/spacemeshos/go-spacemesh/hare/eligibility/config" + "github.com/spacemeshos/go-spacemesh/p2p" + "github.com/spacemeshos/go-spacemesh/syncer" + timeConfig "github.com/spacemeshos/go-spacemesh/timesync/config" + "github.com/spacemeshos/go-spacemesh/tortoise" +) + +func MainnetConfig() Config { + var postPowDifficulty activation.PowDifficulty + if err := postPowDifficulty.UnmarshalText([]byte("00037ec8ec25e6d2c00000000000000000000000000000000000000000000000")); err != nil { + panic(err) + } + + return Config{ + BaseConfig: BaseConfig{ + DataDirParent: defaultDataDir, + FileLock: filepath.Join(os.TempDir(), "spacemesh.lock"), + MetricsPort: 1010, + MetricsPushPeriod: 60, + DatabaseConnections: 16, + NetworkHRP: "sm", + + LayerDuration: 5 * time.Minute, + LayersPerEpoch: 4032, + + TxsPerProposal: 700, // https://github.com/spacemeshos/go-spacemesh/issues/4559 + BlockGasLimit: 100107000, // 3000 of spends + + OptFilterThreshold: 90, + + TickSize: 9331200, + }, + Genesis: &GenesisConfig{ + GenesisTime: "2023-07-14T08:00:00Z", + Accounts: map[string]uint64{}, + }, + Tortoise: tortoise.Config{ + Hdist: 200, + Zdist: 2, + WindowSize: 10000, + MaxExceptions: 1000, + BadBeaconVoteDelayLayers: 4032, + // TODO update it with safe but reasonble minimum weight in network before first ballot + MinimalActiveSetWeight: 1000 * 9331200, + }, + HARE: hareConfig.Config{ + N: 200, + ExpectedLeaders: 5, + RoundDuration: 25 * time.Second, + WakeupDelta: 25 * time.Second, + LimitConcurrent: 2, + LimitIterations: 4, + }, + HareEligibility: eligConfig.Config{ + ConfidenceParam: 200, + }, + Beacon: beacon.Config{ + Kappa: 40, + Q: big.NewRat(1, 3), + Theta: big.NewRat(1, 4), + GracePeriodDuration: 10 * time.Minute, + ProposalDuration: 4 * time.Minute, + FirstVotingRoundDuration: 30 * time.Minute, + RoundsNumber: 300, + VotingRoundDuration: 4 * time.Minute, + WeakCoinRoundDuration: 4 * time.Minute, + VotesLimit: 100, + BeaconSyncWeightUnits: 800, + }, + POET: activation.PoetConfig{ + PhaseShift: 240 * time.Hour, + CycleGap: 12 * time.Hour, + GracePeriod: 1 * time.Hour, + RequestRetryDelay: 10 * time.Second, + MaxRequestRetries: 10, + }, + POST: activation.PostConfig{ + MinNumUnits: 4, + LabelsPerUnit: 4294967296, + K1: 26, + K2: 37, + K3: 37, + PowDifficulty: postPowDifficulty, + }, + Bootstrap: bootstrap.Config{ + URL: "https://bootstrap.spacemesh.network/mainnet", + Version: "https://spacemesh.io/bootstrap.schema.json.1.0", + DataDir: os.TempDir(), + Interval: 30 * time.Second, + }, + P2P: p2p.DefaultConfig(), + API: grpcserver.DefaultConfig(), + TIME: timeConfig.DefaultConfig(), + SMESHING: DefaultSmeshingConfig(), + FETCH: fetch.DefaultConfig(), + LOGGING: defaultLoggingConfig(), + Sync: syncer.DefaultConfig(), + Recovery: checkpoint.DefaultConfig(), + } +} diff --git a/node/node.go b/node/node.go index 3b346ddf2b..80672e3da5 100644 --- a/node/node.go +++ b/node/node.go @@ -233,7 +233,7 @@ func LoadConfigFromFile() (*config.Config, error) { if err := config.LoadConfig(viper.GetString("config"), viper.GetViper()); err != nil { return nil, err } - conf := config.DefaultConfig() + conf := config.MainnetConfig() if name := viper.GetString("preset"); len(name) > 0 { preset, err := presets.Get(name) if err != nil { diff --git a/p2p/host.go b/p2p/host.go index 15d3f2b1fa..f0f9105533 100644 --- a/p2p/host.go +++ b/p2p/host.go @@ -31,7 +31,7 @@ func DefaultConfig() Config { return Config{ Listen: "/ip4/0.0.0.0/tcp/7513", Flood: false, - MinPeers: 6, + MinPeers: 20, LowPeers: 40, HighPeers: 100, GracePeersShutdown: 30 * time.Second,