mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
Implement fixed difficulty flag
This commit is contained in:
parent
45a259f105
commit
7d3f06b982
8 changed files with 42 additions and 4 deletions
|
|
@ -233,6 +233,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
|
||||||
utils.GpobaseStepUpFlag,
|
utils.GpobaseStepUpFlag,
|
||||||
utils.GpobaseCorrectionFactorFlag,
|
utils.GpobaseCorrectionFactorFlag,
|
||||||
utils.ExtraDataFlag,
|
utils.ExtraDataFlag,
|
||||||
|
utils.FixedDifficultyFlag,
|
||||||
}
|
}
|
||||||
app.Flags = append(app.Flags, debug.Flags...)
|
app.Flags = append(app.Flags, debug.Flags...)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -392,6 +392,11 @@ var (
|
||||||
Usage: "Suggested gas price base correction factor (%)",
|
Usage: "Suggested gas price base correction factor (%)",
|
||||||
Value: 110,
|
Value: 110,
|
||||||
}
|
}
|
||||||
|
FixedDifficultyFlag = cli.IntFlag{
|
||||||
|
Name: "difficulty",
|
||||||
|
Usage: "Specify a fixed difficulty.",
|
||||||
|
Value: -1,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// MustMakeDataDir retrieves the currently requested data directory, terminating
|
// MustMakeDataDir retrieves the currently requested data directory, terminating
|
||||||
|
|
@ -801,7 +806,9 @@ func MustMakeChainConfig(ctx *cli.Context) *core.ChainConfig {
|
||||||
db := MakeChainDatabase(ctx)
|
db := MakeChainDatabase(ctx)
|
||||||
defer db.Close()
|
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.
|
// MustMakeChainConfigFromDb reads the chain configuration from the given database.
|
||||||
|
|
|
||||||
|
|
@ -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
|
// the difficulty that a new block should have when created at time
|
||||||
// given the parent block's time and difficulty.
|
// given the parent block's time and difficulty.
|
||||||
func CalcDifficulty(config *ChainConfig, time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
|
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)
|
return calcDifficultyHomestead(time, parentTime, parentNumber, parentDiff)
|
||||||
} else {
|
} else {
|
||||||
return calcDifficultyFrontier(time, parentTime, parentNumber, parentDiff)
|
return calcDifficultyFrontier(time, parentTime, parentNumber, parentDiff)
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ import (
|
||||||
|
|
||||||
// MakeChainConfig returns a new ChainConfig with the ethereum default chain settings.
|
// MakeChainConfig returns a new ChainConfig with the ethereum default chain settings.
|
||||||
func MakeChainConfig() *ChainConfig {
|
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.
|
// FakePow is a non-validating proof of work implementation.
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ type ChainConfig struct {
|
||||||
HomesteadBlock *big.Int // homestead switch block
|
HomesteadBlock *big.Int // homestead switch block
|
||||||
|
|
||||||
VmConfig vm.Config `json:"-"`
|
VmConfig vm.Config `json:"-"`
|
||||||
|
|
||||||
|
FixedDifficulty int
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsHomestead returns whether num is either equal to the homestead block or greater.
|
// IsHomestead returns whether num is either equal to the homestead block or greater.
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,8 @@ type Config struct {
|
||||||
|
|
||||||
TestGenesisBlock *types.Block // Genesis block to seed the chain database with (testing only!)
|
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!)
|
TestGenesisState ethdb.Database // Genesis state to seed the database with (testing only!)
|
||||||
|
|
||||||
|
FixedDifficulty int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Ethereum struct {
|
type Ethereum struct {
|
||||||
|
|
@ -142,6 +144,8 @@ type Ethereum struct {
|
||||||
etherbase common.Address
|
etherbase common.Address
|
||||||
netVersionId int
|
netVersionId int
|
||||||
netRPCService *PublicNetAPI
|
netRPCService *PublicNetAPI
|
||||||
|
|
||||||
|
fixedDifficulty int
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,9 @@ func (self *Miner) actuallyStart(coinbase common.Address, threads int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Miner) Stop() {
|
func (self *Miner) Stop() {
|
||||||
self.sub.Unsubscribe();
|
if(self.sub != nil) {
|
||||||
|
self.sub.Unsubscribe();
|
||||||
|
}
|
||||||
self.worker.stop()
|
self.worker.stop()
|
||||||
atomic.StoreInt32(&self.mining, 0)
|
atomic.StoreInt32(&self.mining, 0)
|
||||||
atomic.StoreInt32(&self.shouldStart, 0)
|
atomic.StoreInt32(&self.shouldStart, 0)
|
||||||
|
|
|
||||||
19
wercker.yml
Normal file
19
wercker.yml
Normal file
|
|
@ -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
|
||||||
Loading…
Reference in a new issue