diff --git a/config/config.go b/config/config.go index a035fb5762..3ebf4e9ec3 100644 --- a/config/config.go +++ b/config/config.go @@ -154,7 +154,7 @@ func DefaultConfig() Config { POET: activation.DefaultPoetConfig(), SMESHING: DefaultSmeshingConfig(), FETCH: fetch.DefaultConfig(), - LOGGING: defaultLoggingConfig(), + LOGGING: DefaultLoggingConfig(), Bootstrap: bootstrap.DefaultConfig(), Sync: syncer.DefaultConfig(), Recovery: checkpoint.DefaultConfig(), diff --git a/config/logging.go b/config/logging.go index 8ce5233046..b81f14e5da 100644 --- a/config/logging.go +++ b/config/logging.go @@ -47,7 +47,7 @@ type LoggerConfig struct { VMLogLevel string `mapstructure:"vm"` } -func defaultLoggingConfig() LoggerConfig { +func DefaultLoggingConfig() LoggerConfig { return LoggerConfig{ Encoder: ConsoleLogEncoder, AppLoggerLevel: defaultLoggingLevel.String(), diff --git a/config/mainnet.go b/config/mainnet.go index abee02a74b..601e4aa0d9 100644 --- a/config/mainnet.go +++ b/config/mainnet.go @@ -131,7 +131,7 @@ func MainnetConfig() Config { TIME: timeConfig.DefaultConfig(), SMESHING: smeshing, FETCH: fetch.DefaultConfig(), - LOGGING: defaultLoggingConfig(), + LOGGING: DefaultLoggingConfig(), Sync: syncer.Config{ Interval: time.Minute, EpochEndFraction: 0.8, diff --git a/config/presets/presets_test.go b/config/presets/presets_test.go index 74803c15e9..262569cae7 100644 --- a/config/presets/presets_test.go +++ b/config/presets/presets_test.go @@ -43,6 +43,4 @@ func TestCanGeneratePOST(t *testing.T) { } t.Run("fastnet", runTest(fastnet())) - - t.Run("testnet", runTest(testnet())) } diff --git a/config/presets/testnet.go b/config/presets/testnet.go index 1399550d2b..3152f10037 100644 --- a/config/presets/testnet.go +++ b/config/presets/testnet.go @@ -1,12 +1,29 @@ package presets import ( + "math" + "math/big" + "os" + "path/filepath" + "runtime" "time" "github.com/spacemeshos/post/initialization" - "github.com/spacemeshos/go-spacemesh/common/types" + "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/config" + "github.com/spacemeshos/go-spacemesh/datastore" + "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 init() { @@ -14,60 +31,115 @@ func init() { } func testnet() config.Config { - conf := config.DefaultConfig() + p2pconfig := p2p.DefaultConfig() - conf.NetworkHRP = "stest" - types.SetNetworkHRP(conf.NetworkHRP) // set to generate coinbase - - conf.HARE.N = 800 - conf.HARE.ExpectedLeaders = 10 - conf.HARE.LimitConcurrent = 5 - conf.HARE.LimitIterations = 10 - conf.HARE.RoundDuration = 10 * time.Second - conf.HARE.WakeupDelta = 10 * time.Second - - conf.P2P.MinPeers = 10 - - conf.Genesis = &config.GenesisConfig{ - ExtraData: "testnet", - Accounts: map[string]uint64{ - "stest1qqqqqqygdpsq62p4qxfyng8h2mm4f4d94vt7huqqu9mz3": 100000000000000000, - "stest1qqqqqqylzg8ypces4llx4gnat0dyntqfvr0h6mcprcz66": 100000000000000000, - "stest1qqqqqq90akdpc97206485eu4m0rmacd3mxfv0wsdrea6k": 100000000000000000, - "stest1qqqqqq9jpsarr7tnyv0qr0edddwqpg3vcya4cccauypts": 100000000000000000, - "stest1qqqqqq8lpq7f5ghqt569nvpl8kldv8r66ms2yzgudsd5t": 100000000000000000, - }, + smeshing := config.DefaultSmeshingConfig() + smeshing.Opts.ProviderID.SetInt64(int64(initialization.CPUProviderID())) + smeshing.ProvingOpts.Nonces = 288 + smeshing.ProvingOpts.Threads = uint(runtime.NumCPU() * 3 / 4) + if smeshing.ProvingOpts.Threads < 1 { + smeshing.ProvingOpts.Threads = 1 } + home, err := os.UserHomeDir() + if err != nil { + panic("can't read homedir: " + err.Error()) + } + defaultdir := filepath.Join(home, "spacemesh-testnet", "/") + return config.Config{ + BaseConfig: config.BaseConfig{ + DataDirParent: defaultdir, + FileLock: filepath.Join(os.TempDir(), "spacemesh.lock"), + MetricsPort: 1010, + DatabaseConnections: 16, + NetworkHRP: "smtest", - conf.LayerAvgSize = 50 - conf.LayerDuration = 120 * time.Second - conf.LayersPerEpoch = 60 - - conf.Tortoise.Hdist = 60 - conf.Tortoise.Zdist = 10 - conf.Tortoise.BadBeaconVoteDelayLayers = 30 + LayerDuration: 5 * time.Minute, + LayerAvgSize: 50, + LayersPerEpoch: 288, - conf.POST.K1 = 26 - conf.POST.K2 = 37 - conf.POST.K3 = 37 - conf.POST.LabelsPerUnit = 20 * 1024 / 16 // 20 kB units - conf.POST.MaxNumUnits = 4 - conf.POST.MinNumUnits = 2 + TxsPerProposal: 700, // https://github.com/spacemeshos/go-spacemesh/issues/4559 + BlockGasLimit: 100107000, // 3000 of spends - conf.SMESHING.CoinbaseAccount = types.GenerateAddress([]byte("1")).String() - conf.SMESHING.Start = false - conf.SMESHING.Opts.ProviderID.SetInt64(int64(initialization.CPUProviderID())) - conf.SMESHING.Opts.NumUnits = 2 - conf.SMESHING.Opts.Throttle = true + OptFilterThreshold: 90, - conf.Beacon.FirstVotingRoundDuration = 3 * time.Minute - conf.Beacon.GracePeriodDuration = 10 * time.Second - conf.Beacon.ProposalDuration = 30 * time.Second - conf.Beacon.RoundsNumber = 6 - conf.Beacon.BeaconSyncWeightUnits = 30 - conf.Beacon.VotesLimit = 100 - conf.Beacon.VotingRoundDuration = 50 * time.Second - conf.Beacon.WeakCoinRoundDuration = 10 * time.Second + TickSize: 666514, + PoETServers: []string{}, + }, + Genesis: &config.GenesisConfig{ + GenesisTime: "2023-09-13T18:00:00Z", + ExtraData: "0000000000000000000000c76c58ebac180989673fd6d237b40e66ed5c976ec3", + }, - return conf + Tortoise: tortoise.Config{ + Hdist: 10, + Zdist: 2, + WindowSize: 10000, + MaxExceptions: 1000, + BadBeaconVoteDelayLayers: 4032, + // 100 - is assumed minimal number of units + // 100 - half of the expected poet ticks + MinimalActiveSetWeight: 100 * 100, + }, + HARE: hareConfig.Config{ + N: 200, + ExpectedLeaders: 5, + RoundDuration: 25 * time.Second, + WakeupDelta: 25 * time.Second, + LimitConcurrent: 2, + LimitIterations: 4, + }, + HareEligibility: eligConfig.Config{ + ConfidenceParam: 20, + }, + 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: 20, + VotingRoundDuration: 4 * time.Minute, + WeakCoinRoundDuration: 4 * time.Minute, + VotesLimit: 100, + BeaconSyncWeightUnits: 800, + }, + POET: activation.PoetConfig{ + PhaseShift: 12 * time.Hour, + CycleGap: 2 * time.Hour, + GracePeriod: 10 * time.Minute, + RequestRetryDelay: 5 * time.Second, + MaxRequestRetries: 10, + }, + POST: activation.PostConfig{ + MinNumUnits: 2, + MaxNumUnits: math.MaxUint32, + LabelsPerUnit: 1024, + K1: 26, + K2: 37, + K3: 37, + PowDifficulty: activation.DefaultPostConfig().PowDifficulty, + }, + Bootstrap: bootstrap.Config{ + URL: "https://bootstrap.spacemesh.network/testnet06", + Version: "https://spacemesh.io/bootstrap.schema.json.1.0", + DataDir: os.TempDir(), + Interval: 30 * time.Second, + }, + P2P: p2pconfig, + API: grpcserver.DefaultConfig(), + TIME: timeConfig.DefaultConfig(), + SMESHING: smeshing, + FETCH: fetch.DefaultConfig(), + LOGGING: config.DefaultLoggingConfig(), + Sync: syncer.Config{ + Interval: time.Minute, + EpochEndFraction: 0.8, + MaxStaleDuration: time.Hour, + UseNewProtocol: true, + GossipDuration: 50 * time.Second, + }, + Recovery: checkpoint.DefaultConfig(), + Cache: datastore.DefaultConfig(), + } } diff --git a/node/adminservice_api_test.go b/node/adminservice_api_test.go index 70623fc76f..4c2e1b00b9 100644 --- a/node/adminservice_api_test.go +++ b/node/adminservice_api_test.go @@ -18,6 +18,7 @@ import ( func TestPeerInfoApi(t *testing.T) { cfg := config.DefaultTestConfig() + cfg.Genesis.Accounts = nil cfg.P2P.DisableNatPort = true cfg.P2P.Listen = "/ip4/127.0.0.1/tcp/0" diff --git a/node/util_test.go b/node/util_test.go index 095b4a7272..aa55b35990 100644 --- a/node/util_test.go +++ b/node/util_test.go @@ -46,6 +46,7 @@ func NewTestNetwork(t *testing.T, conf config.Config, l log.Log, size int) []*Te c.DataDirParent = dir c.SMESHING.Opts.DataDir = dir c.SMESHING.CoinbaseAccount = types.GenerateAddress([]byte(strconv.Itoa(i))).String() + c.FileLock = filepath.Join(c.DataDirParent, "LOCK") app := NewApp(t, &c, l)