From 7d3f06b9820b40eda53cf81434c97b2d9942a3a7 Mon Sep 17 00:00:00 2001 From: Dan Turner Date: Sun, 15 May 2016 17:05:28 +1000 Subject: [PATCH] Implement fixed difficulty flag --- cmd/geth/main.go | 1 + cmd/utils/flags.go | 9 ++++++++- core/block_validator.go | 5 ++++- core/chain_makers.go | 2 +- core/config.go | 2 ++ eth/backend.go | 4 ++++ miner/miner.go | 4 +++- wercker.yml | 19 +++++++++++++++++++ 8 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 wercker.yml diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 5a2fc62873..f42b030ead 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -233,6 +233,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.GpobaseStepUpFlag, utils.GpobaseCorrectionFactorFlag, utils.ExtraDataFlag, + utils.FixedDifficultyFlag, } app.Flags = append(app.Flags, debug.Flags...) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 43dbc37f74..b00076904d 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -392,6 +392,11 @@ var ( Usage: "Suggested gas price base correction factor (%)", Value: 110, } + FixedDifficultyFlag = cli.IntFlag{ + Name: "difficulty", + Usage: "Specify a fixed difficulty.", + Value: -1, + } ) // MustMakeDataDir retrieves the currently requested data directory, terminating @@ -801,7 +806,9 @@ func MustMakeChainConfig(ctx *cli.Context) *core.ChainConfig { db := MakeChainDatabase(ctx) defer db.Close() - return MustMakeChainConfigFromDb(ctx, db) + config := MustMakeChainConfigFromDb(ctx, db) + config.FixedDifficulty = ctx.GlobalInt(FixedDifficultyFlag.Name) + return config } // MustMakeChainConfigFromDb reads the chain configuration from the given database. diff --git a/core/block_validator.go b/core/block_validator.go index 801d2572b6..0e58bf54e0 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -254,7 +254,10 @@ func ValidateHeader(config *ChainConfig, pow pow.PoW, header *types.Header, pare // the difficulty that a new block should have when created at time // given the parent block's time and difficulty. func CalcDifficulty(config *ChainConfig, time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int { - if config.IsHomestead(new(big.Int).Add(parentNumber, common.Big1)) { + if config.FixedDifficulty != -1 { + return big.NewInt(int64(config.FixedDifficulty)) + } + if config.IsHomestead(new(big.Int).Add(parentNumber, common.Big1)) { return calcDifficultyHomestead(time, parentTime, parentNumber, parentDiff) } else { return calcDifficultyFrontier(time, parentTime, parentNumber, parentDiff) diff --git a/core/chain_makers.go b/core/chain_makers.go index ef0ac66d1b..42328ee745 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -35,7 +35,7 @@ import ( // MakeChainConfig returns a new ChainConfig with the ethereum default chain settings. func MakeChainConfig() *ChainConfig { - return &ChainConfig{HomesteadBlock: big.NewInt(0)} + return &ChainConfig{HomesteadBlock: big.NewInt(0), FixedDifficulty: -1} } // FakePow is a non-validating proof of work implementation. diff --git a/core/config.go b/core/config.go index 81ca76aa31..506ba7ccc1 100644 --- a/core/config.go +++ b/core/config.go @@ -34,6 +34,8 @@ type ChainConfig struct { HomesteadBlock *big.Int // homestead switch block VmConfig vm.Config `json:"-"` + + FixedDifficulty int } // IsHomestead returns whether num is either equal to the homestead block or greater. diff --git a/eth/backend.go b/eth/backend.go index f43dea7775..96d22cd01e 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -100,6 +100,8 @@ type Config struct { TestGenesisBlock *types.Block // Genesis block to seed the chain database with (testing only!) TestGenesisState ethdb.Database // Genesis state to seed the database with (testing only!) + + FixedDifficulty int } type Ethereum struct { @@ -142,6 +144,8 @@ type Ethereum struct { etherbase common.Address netVersionId int netRPCService *PublicNetAPI + + fixedDifficulty int } func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { diff --git a/miner/miner.go b/miner/miner.go index b4a7657d50..68b90956ae 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -149,7 +149,9 @@ func (self *Miner) actuallyStart(coinbase common.Address, threads int) { } func (self *Miner) Stop() { - self.sub.Unsubscribe(); + if(self.sub != nil) { + self.sub.Unsubscribe(); + } self.worker.stop() atomic.StoreInt32(&self.mining, 0) atomic.StoreInt32(&self.shouldStart, 0) diff --git a/wercker.yml b/wercker.yml new file mode 100644 index 0000000000..8e265f92e9 --- /dev/null +++ b/wercker.yml @@ -0,0 +1,19 @@ +box: golang +build: + steps: + - setup-go-workspace + - script: + name: go build + code: | + make geth + BIN=/pipeline/source/build/bin/$WERCKER_GIT_BRANCH/`cat VERSION` + mkdir -p $BIN + cp build/bin/geth $BIN/geth +deploy: + steps: + - s3sync: + source_dir: build/bin + delete-removed: false + bucket-url: $AWS_BUCKET_URL + key-id: $AWS_ACCESS_KEY_ID + key-secret: $AWS_SECRET_ACCESS_KEY