Skip to content

Instantly share code, notes, and snippets.

@barkthins
Created March 10, 2016 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save barkthins/db1fc4b28f7781f0d3bf to your computer and use it in GitHub Desktop.
Save barkthins/db1fc4b28f7781f0d3bf to your computer and use it in GitHub Desktop.
A patch for geth that will cause it to mine every second. This is useful for accelerating unit test of solidity contracts. I will attempt to keep this patch up to date, no guarantees.
diff --git a/eth/fetcher/fetcher.go b/eth/fetcher/fetcher.go
index d88d919..f03fd30 100644
--- a/eth/fetcher/fetcher.go
+++ b/eth/fetcher/fetcher.go
@@ -34,7 +34,7 @@ import (
const (
arriveTimeout = 500 * time.Millisecond // Time allowance before an announced block is explicitlrd
gatherSlack = 100 * time.Millisecond // Interval used to collate almost-expired announces witfs
- fetchTimeout = 5 * time.Second // Maximum alloted time to return an explicitly requestebk
+ fetchTimeout = 1 * time.Second // Maximum alloted time to return an explicitly requestebk
maxUncleDist = 7 // Maximum allowed backward distance from the chain head
maxQueueDist = 32 // Maximum allowed distance from the chain head to queue
hashLimit = 256 // Maximum number of unique blocks a peer may have annoued
diff --git a/eth/peer.go b/eth/peer.go
index 15ba22f..0201057 100644
--- a/eth/peer.go
+++ b/eth/peer.go
@@ -41,7 +41,7 @@ var (
const (
maxKnownTxs = 32768 // Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownBlocks = 1024 // Maximum block hashes to keep in the known list (prevent DOS)
- handshakeTimeout = 5 * time.Second
+ handshakeTimeout = 1 * time.Second
)
// PeerInfo represents a short summary of the Ethereum sub-protocol metadata known
diff --git a/miner/worker.go b/miner/worker.go
index 754a6fc..2b62b59 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -466,7 +466,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)
diff --git a/p2p/rlpx.go b/p2p/rlpx.go
index aaa7338..ce82eb7 100644
--- a/p2p/rlpx.go
+++ b/p2p/rlpx.go
@@ -57,7 +57,7 @@ const (
// total timeout for encryption handshake and protocol
// handshake in both directions.
- handshakeTimeout = 5 * time.Second
+ handshakeTimeout = 2 * time.Second
// This is the timeout for sending the disconnect reason.
// This is shorter than the usual timeout because we don't want
diff --git a/params/protocol_params.go b/params/protocol_params.go
index dcc17e0..21a49c5 100755
--- a/params/protocol_params.go
+++ b/params/protocol_params.go
@@ -29,10 +29,10 @@ var (
CallNewAccountGas = big.NewInt(25000) // Paid for CALL when the destination address didn'e.
TxGas = big.NewInt(21000) // Per transaction. NOTE: Not payable on data of cas.
TxDataZeroGas = big.NewInt(4) // Per byte of data attached to a transaction that u.
- DifficultyBoundDivisor = big.NewInt(2048) // The bound divisor of the difficulty, used in thep.
+ DifficultyBoundDivisor = big.NewInt(1) // The bound divisor of the difficulty, used in thep.
QuadCoeffDiv = big.NewInt(512) // Divisor for the quadratic particle of the memoryo.
- GenesisDifficulty = big.NewInt(131072) // Difficulty of the Genesis block.
- DurationLimit = big.NewInt(13) // The decision boundary on the blocktime duration e.
+ GenesisDifficulty = big.NewInt(1) // Difficulty of the Genesis block.
+ DurationLimit = big.NewInt(1) // The decision boundary on the blocktime duration e.
SstoreSetGas = big.NewInt(20000) // Once per SLOAD operation.
LogDataGas = big.NewInt(8) // Per byte in a LOG* operation's data.
CallStipend = big.NewInt(2300) // Free gas given at beginning of call.
@@ -57,7 +57,7 @@ var (
CreateDataGas = big.NewInt(200) //
Ripemd160Gas = big.NewInt(600) //
Ripemd160WordGas = big.NewInt(120) //
- MinimumDifficulty = big.NewInt(131072) // The minimum that the difficulty may ever be.
+ MinimumDifficulty = big.NewInt(1) // The minimum that the difficulty may ever be.
CallCreateDepth = big.NewInt(1024) // Maximum depth of call/create stack.
ExpGas = big.NewInt(10) // Once per EXP instuction.
LogGas = big.NewInt(375) // Per LOG* operation.
@barkthins
Copy link
Author

Note, I haven't actually run this on a private network, I've only run this as a single node. My goal is to adjust the timeouts such that on a dedicated LAN it should run as fast as possible. I suspect the 1 second timeouts might have to move to 2 seconds. We'll see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment