Skip to content

Commit

Permalink
prepare config for mainnet (#4679)
Browse files Browse the repository at this point in the history
config is extracted into a separate file so that we can track any accidental changes in protocol parameters easier
  • Loading branch information
dshulyak committed Jul 11, 2023
1 parent 78030cd commit 9c5e88b
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 19 deletions.
8 changes: 2 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion common/types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 0 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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),
Expand Down Expand Up @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion config/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion config/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
115 changes: 115 additions & 0 deletions config/mainnet.go
Original file line number Diff line number Diff line change
@@ -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(),
}
}
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion p2p/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9c5e88b

Please sign in to comment.