cmd/utils, core, params: explicitly pick reprice fork for fast sync

This commit is contained in:
Péter Szilágyi 2016-10-24 11:40:58 +03:00
parent 00665a0b72
commit 8639b0fae9
No known key found for this signature in database
GPG Key ID: 119A76381CCB7DD2
4 changed files with 32 additions and 7 deletions

View File

@ -804,6 +804,13 @@ func MakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfi
config.HomesteadGasRepriceBlock = params.MainNetHomesteadGasRepriceBlock config.HomesteadGasRepriceBlock = params.MainNetHomesteadGasRepriceBlock
} }
} }
if config.HomesteadGasRepriceHash == (common.Hash{}) {
if ctx.GlobalBool(TestNetFlag.Name) {
config.HomesteadGasRepriceHash = params.TestNetHomesteadGasRepriceHash
} else {
config.HomesteadGasRepriceHash = params.MainNetHomesteadGasRepriceHash
}
}
// Force override any existing configs if explicitly requested // Force override any existing configs if explicitly requested
switch { switch {
case ctx.GlobalBool(SupportDAOFork.Name): case ctx.GlobalBool(SupportDAOFork.Name):

View File

@ -248,7 +248,15 @@ func ValidateHeader(config *ChainConfig, pow pow.PoW, header *types.Header, pare
} }
} }
// If all checks passed, validate the extra-data field for hard forks // If all checks passed, validate the extra-data field for hard forks
return ValidateDAOHeaderExtraData(config, header) if err := ValidateDAOHeaderExtraData(config, header); err != nil {
return err
}
if config.HomesteadGasRepriceBlock != nil && config.HomesteadGasRepriceBlock.Cmp(header.Number) == 0 {
if config.HomesteadGasRepriceHash != (common.Hash{}) && config.HomesteadGasRepriceHash != header.Hash() {
return ValidationError("Homestead gas reprice fork hash mismatch: have 0x%x, want 0x%x", header.Hash(), config.HomesteadGasRepriceBlock)
}
}
return nil
} }
// CalcDifficulty is the difficulty adjustment algorithm. It returns // CalcDifficulty is the difficulty adjustment algorithm. It returns

View File

@ -20,6 +20,7 @@ import (
"errors" "errors"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
@ -37,6 +38,7 @@ type ChainConfig struct {
DAOForkSupport bool `json:"daoForkSupport"` // Whether the nodes supports or opposes the DAO hard-fork DAOForkSupport bool `json:"daoForkSupport"` // Whether the nodes supports or opposes the DAO hard-fork
HomesteadGasRepriceBlock *big.Int `json:"homesteadGasRepriceBlock"` // Homestead gas reprice switch block (nil = no fork) HomesteadGasRepriceBlock *big.Int `json:"homesteadGasRepriceBlock"` // Homestead gas reprice switch block (nil = no fork)
HomesteadGasRepriceHash common.Hash `json:"homesteadGasRepriceHash"` // Homestead gas reprice switch block hash (fast sync aid)
VmConfig vm.Config `json:"-"` VmConfig vm.Config `json:"-"`
} }

View File

@ -16,11 +16,19 @@
package params package params
import "math/big" import (
"math/big"
"github.com/ethereum/go-ethereum/common"
)
var ( var (
TestNetHomesteadBlock = big.NewInt(494000) // Testnet homestead block TestNetHomesteadBlock = big.NewInt(494000) // Testnet homestead block
MainNetHomesteadBlock = big.NewInt(1150000) // Mainnet homestead block MainNetHomesteadBlock = big.NewInt(1150000) // Mainnet homestead block
TestNetHomesteadGasRepriceBlock = big.NewInt(1783000) // Testnet gas reprice block TestNetHomesteadGasRepriceBlock = big.NewInt(1783000) // Testnet gas reprice block
MainNetHomesteadGasRepriceBlock = big.NewInt(2463000) // Mainnet gas reprice block MainNetHomesteadGasRepriceBlock = big.NewInt(2463000) // Mainnet gas reprice block
TestNetHomesteadGasRepriceHash = common.HexToHash("0xf376243aeff1f256d970714c3de9fd78fa4e63cf63e32a51fe1169e375d98145") // Testnet gas reprice block hash (used by fast sync)
MainNetHomesteadGasRepriceHash = common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0") // Mainnet gas reprice block hash (used by fast sync)
) )