Skip to content
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
2 changes: 2 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Config struct {
MempoolDumpDirectory string
TXIndex bool
Regtest bool
RegtestAccelerated bool
PostgresURI string

// Peers
Expand Down Expand Up @@ -114,6 +115,7 @@ func LoadConfig() *Config {
config.MempoolDumpDirectory = viper.GetString("mempool-dump-dir")
config.TXIndex = viper.GetBool("txindex")
config.Regtest = viper.GetBool("regtest")
config.RegtestAccelerated = viper.GetBool("regtest-accelerated")
config.PostgresURI = viper.GetString("postgres-uri")
config.HyperSync = viper.GetBool("hypersync")
config.ForceChecksum = viper.GetBool("force-checksum")
Expand Down
2 changes: 1 addition & 1 deletion cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (node *Node) Start(exitChannels ...*chan struct{}) {

// Check for regtest mode
if node.Config.Regtest {
node.Params.EnableRegtest()
node.Params.EnableRegtest(node.Config.RegtestAccelerated)
}

// Validate params
Expand Down
3 changes: 3 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func SetupRunFlags(cmd *cobra.Command) {
cmd.PersistentFlags().Bool("regtest", false,
"Can only be used in conjunction with --testnet. Creates a private testnet node with fast block times"+
"and instantly spendable block rewards.")
cmd.PersistentFlags().Bool("regtest-accelerated", false, "Can only be used in conjunction with --regtest. "+
"Accelerates the regtest network by lowering PoS cutover height, lowering epoch duration, and seeding "+
"some balances. Useful for testing purposes.")
cmd.PersistentFlags().String("postgres-uri", "", "BETA: Use Postgres as the backing store for chain data."+
"When enabled, most data is stored in postgres although badger is still currently used for some state. Run your "+
"Postgres instance on the same machine as your node for optimal performance.")
Expand Down
2 changes: 1 addition & 1 deletion integration_testing/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ func simplePosNode(t *testing.T, port uint32, id string, regtest bool) *cmd.Node
if regtest {
node.Config.MinerPublicKeys = []string{seedPhraseToPublicKeyBase58Check(t, blsSeedPhrase, node.Params)}
node.Config.Regtest = true
node.Params.EnableRegtest()
node.Params.EnableRegtest(false)
}
return node
}
Expand Down
29 changes: 28 additions & 1 deletion lib/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,11 @@ type DeSoParams struct {

EncoderMigrationHeights *EncoderMigrationHeights
EncoderMigrationHeightsList []*MigrationHeight

// The interval at which we check for the transition from PoW to PoS consensus.
// This is 60 seconds for mainnet and testnet, but can be set to a lower value
// for regtest to get a faster cutover.
FastHotStuffConsensusTransitionCheckDuration time.Duration
}

var RegtestForkHeights = ForkHeights{
Expand Down Expand Up @@ -884,11 +889,12 @@ var RegtestForkHeights = ForkHeights{

// EnableRegtest allows for local development and testing with incredibly fast blocks with block rewards that
// can be spent as soon as they are mined. It also removes the default testnet seeds
func (params *DeSoParams) EnableRegtest() {
func (params *DeSoParams) EnableRegtest(isAcceleratedRegtest bool) {
if params.NetworkType != NetworkType_TESTNET {
glog.Error("Regtest mode can only be enabled in testnet mode")
return
}
glog.Infof("Enabling regtest mode: accelerated=%v", isAcceleratedRegtest)

// Add a key defined in n0_test to the ParamUpdater set when running in regtest mode.
// Seed: verb find card ship another until version devote guilt strong lemon six
Expand All @@ -911,9 +917,24 @@ func (params *DeSoParams) EnableRegtest() {
// Set the PoS default jail inactive validator grace period epochs to 3.
params.DefaultJailInactiveValidatorGracePeriodEpochs = 3

// Check for consensus transition every second.
params.FastHotStuffConsensusTransitionCheckDuration = 1 * time.Second

// In regtest, we start all the fork heights at zero. These can be adjusted
// for testing purposes to ensure that a transition does not cause issues.
params.ForkHeights = RegtestForkHeights
if isAcceleratedRegtest {
params.ForkHeights.ProofOfStake2ConsensusCutoverBlockHeight = 30
params.DefaultEpochDurationNumBlocks = uint64(5)
params.DefaultBlockProductionIntervalMillisecondsPoS = 1000 // 1s
params.DefaultTimeoutIntervalMillisecondsPoS = 2000 // 2s
newSeedBalance := &DeSoOutput{
PublicKey: MustBase58CheckDecode("tBCKVERmG9nZpHTk2AVPqknWc1Mw9HHAnqrTpW1RnXpXMQ4PsQgnmV"),
AmountNanos: 1e14,
}

params.SeedBalances = append(params.SeedBalances, newSeedBalance)
}
params.EncoderMigrationHeights = GetEncoderMigrationHeights(&params.ForkHeights)
params.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(&params.ForkHeights)
params.DefaultStakingRewardsAPYBasisPoints = 100000 * 100 // 100000% for regtest
Expand Down Expand Up @@ -1383,6 +1404,9 @@ var DeSoMainnetParams = DeSoParams{
ForkHeights: MainnetForkHeights,
EncoderMigrationHeights: GetEncoderMigrationHeights(&MainnetForkHeights),
EncoderMigrationHeightsList: GetEncoderMigrationHeightsList(&MainnetForkHeights),

// Check every 60 seconds if the FastHotStuffConsensus is ready to start.
FastHotStuffConsensusTransitionCheckDuration: 60 * time.Second,
}

func mustDecodeHexBlockHashBitcoin(ss string) *BlockHash {
Expand Down Expand Up @@ -1697,6 +1721,9 @@ var DeSoTestnetParams = DeSoParams{
ForkHeights: TestnetForkHeights,
EncoderMigrationHeights: GetEncoderMigrationHeights(&TestnetForkHeights),
EncoderMigrationHeightsList: GetEncoderMigrationHeightsList(&TestnetForkHeights),

// Check every 60 seconds if the FastHotStuffConsensus is ready to start.
FastHotStuffConsensusTransitionCheckDuration: 60 * time.Second,
}

// GetDataDir gets the user data directory where we store files
Expand Down
5 changes: 3 additions & 2 deletions lib/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3071,8 +3071,9 @@ func (srv *Server) getFastHotStuffConsensusEventChannel() chan *consensus.FastHo
}

func (srv *Server) resetFastHotStuffConsensusTransitionCheckTime() {
// Check once every 60 seconds if the FastHotStuffConsensus is ready to start.
srv.fastHotStuffConsensusTransitionCheckTime = time.Now().Add(60 * time.Second)
// Check if the FastHotStuffConsensus is ready to start based on the FastHotStuffConsensusTransitionCheckDuration.
srv.fastHotStuffConsensusTransitionCheckTime = time.Now().Add(
srv.params.FastHotStuffConsensusTransitionCheckDuration)
}

func (srv *Server) getFastHotStuffTransitionCheckTime() <-chan time.Time {
Expand Down