Skip to content

Commit

Permalink
feat:miner support no wait when develop difficulty mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lochjin committed Nov 18, 2024
1 parent 1bef1d1 commit 1f30c54
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Config struct {
Miner bool `long:"miner" description:"Enable miner module"`
Generate bool `long:"generate" description:"Generate (mine) coins using the CPU"`
GenerateOnTx bool `long:"generateontx" description:"Generate (mine) coins using the CPU when there is a new transaction"`
GenerateNoDevGap bool `long:"generatenodevgap" description:"Generate (mine) coins using the CPU on develop mode whithout gap"`
MiningAddrs []string `long:"miningaddr" description:"Add the specified payment address to the list of addresses to use for generated blocks -- At least one address is required if the generate option is set"`
MiningTimeOffset int `long:"miningtimeoffset" description:"Offset the mining timestamp of a block by this many seconds (positive values are in the past)"`
BlockMinSize uint32 `long:"blockminsize" description:"Mininum block size in bytes to be used when creating a block"`
Expand Down Expand Up @@ -142,7 +143,7 @@ type Config struct {
AutoCollectEvm bool `long:"autocollectevm" description:"auto collect utxo to evm"`

// TODO: It will soon be discarded in the near future
DevSnapSync bool `long:"dev_snapsync" description:"Enable snap sync for P2P that only exist in development mode"`
DevSnapSync bool `long:"devsnapsync" description:"Enable snap sync for P2P that only exist in development mode"`
}

func (c *Config) GetMinningAddrs() []types.Address {
Expand Down
6 changes: 6 additions & 0 deletions services/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,12 @@ var (
Value: true,
Destination: &cfg.DevSnapSync,
},
&cli.BoolFlag{
Name: "generatenodevgap",
Usage: "Generate (mine) coins using the CPU on develop mode whithout gap",
Value: true,
Destination: &cfg.GenerateNoDevGap,
},
}
)

Expand Down
2 changes: 1 addition & 1 deletion services/miner/cpuworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ out:
}
if params.ActiveNetParams.Params.IsDevelopDiff() {
w.miner.updateBlockTemplate(true)
if !w.miner.NoDevelopGap {
if !w.miner.cfg.GenerateNoDevGap {
time.Sleep(params.ActiveNetParams.Params.TargetTimePerBlock)
}
}
Expand Down
2 changes: 1 addition & 1 deletion testutils/mocknode.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func DefaultConfig(pb *testprivatekey.Builder) (*config.Config, error) {
cfg.SubmitNoSynced = true
cfg.AcctMode = true
cfg.EVMEnv = "--nodiscover --v5disc=false --rpc.allow-unprotected-txs"
cfg.GenerateNoDevGap = true

params.ActiveNetParams = &params.PrivNetParam
coinbasePKHex := pb.GetHex(testprivatekey.CoinbaseIdx)
Expand Down Expand Up @@ -177,7 +178,6 @@ func (mn *MockNode) setup() error {

log.Info("Import default key", "addr", account.String())

mn.Node().GetQitmeerFull().GetMiner().NoDevelopGap = true
params.ActiveNetParams.PowConfig.DifficultyMode = pow.DIFFICULTY_MODE_DEVELOP
return nil
}
Expand Down

0 comments on commit 1f30c54

Please sign in to comment.