- Ensure you use geth that you have built, not geth installed somewhere in system.
- All nodes in your private network must have the same version of geth.
Here is the patch to mine 1 block per 1 second (I'm not sure, but I think it is as fast as possible):
diff --git a/core/block_validator.go b/core/block_validator.go
index 65f9753..2b19c64 100644
--- a/core/block_validator.go
+++ b/core/block_validator.go
@@ -263,11 +263,7 @@ func ValidateHeader(config *params.ChainConfig, pow pow.PoW, header *types.Heade
// the difficulty that a new block should have when created at time
// given the parent block's time and difficulty.
func CalcDifficulty(config *params.ChainConfig, time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
- if config.IsHomestead(new(big.Int).Add(parentNumber, common.Big1)) {
- return calcDifficultyHomestead(time, parentTime, parentNumber, parentDiff)
- } else {
- return calcDifficultyFrontier(time, parentTime, parentNumber, parentDiff)
- }
+ return big.NewInt(1)
}
func calcDifficultyHomestead(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
diff --git a/miner/worker.go b/miner/worker.go
index 77e4e02..e92ff62 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -422,7 +422,7 @@ func (self *worker) commitNewWork() {
tstamp = parent.Time().Int64() + 1
}
// this will ensure we're not going off too far in the future
- if now := time.Now().Unix(); tstamp > now+4 {
+ if now := time.Now().Unix(); tstamp > now {
wait := time.Duration(tstamp-now) * time.Second
glog.V(logger.Info).Infoln("We are too far in the future. Waiting for", wait)
time.Sleep(wait)
Mine with only thread
miner.start(1);
UPDATE
Diff for Geth 1.6.1
diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go
index 2930032..d141678 100644
--- a/consensus/ethash/consensus.go
+++ b/consensus/ethash/consensus.go
@@ -289,10 +289,11 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
//
// TODO (karalabe): Move the chain maker into this package and make this private!
func CalcDifficulty(config *params.ChainConfig, time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
- if config.IsHomestead(new(big.Int).Add(parentNumber, common.Big1)) {
- return calcDifficultyHomestead(time, parentTime, parentNumber, parentDiff)
- }
- return calcDifficultyFrontier(time, parentTime, parentNumber, parentDiff)
+ // if config.IsHomestead(new(big.Int).Add(parentNumber, common.Big1)) {
+ // return calcDifficultyHomestead(time, parentTime, parentNumber, parentDiff)
+ // }
+ // return calcDifficultyFrontier(time, parentTime, parentNumber, parentDiff)
+ return big.NewInt(1)
}
// Some weird constants to avoid constant memory allocs for them.
diff --git a/miner/worker.go b/miner/worker.go
index 01241b3..f1b3839 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -407,7 +407,7 @@ func (self *worker) commitNewWork() {
tstamp = parent.Time().Int64() + 1
}
// this will ensure we're not going off too far in the future
- if now := time.Now().Unix(); tstamp > now+1 {
+ if now := time.Now().Unix(); tstamp > now {
wait := time.Duration(tstamp-now) * time.Second
log.Info("Mining too far in the future", "wait", common.PrettyDuration(wait))
time.Sleep(wait)