diff options
author | Determinant <[email protected]> | 2020-02-24 15:04:42 -0500 |
---|---|---|
committer | Determinant <[email protected]> | 2020-02-24 15:04:42 -0500 |
commit | a29ec3a0ae86185db68e9be6557e1c8dde89a92c (patch) | |
tree | 3eb097316717d5ca064f3a70350ea35980504aaa | |
parent | f0fdb5dfb215bebc54d2a62e54f0c7ae3e71ff91 (diff) |
minor change
-rw-r--r-- | core/genesis.go | 26 | ||||
-rw-r--r-- | coreth.go | 1 | ||||
-rw-r--r-- | eth/backend.go | 22 | ||||
-rw-r--r-- | eth/config.go | 5 | ||||
-rw-r--r-- | examples/counter/counter.sol | 2 |
5 files changed, 38 insertions, 18 deletions
diff --git a/core/genesis.go b/core/genesis.go index 149e3d0..78249a7 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -26,13 +26,14 @@ import ( "github.com/ava-labs/go-ethereum/common" "github.com/ava-labs/go-ethereum/common/hexutil" + "github.com/ava-labs/go-ethereum/core" "github.com/ava-labs/go-ethereum/core/rawdb" "github.com/ava-labs/go-ethereum/core/state" + "github.com/ava-labs/go-ethereum/crypto" "github.com/ava-labs/go-ethereum/ethdb" "github.com/ava-labs/go-ethereum/log" "github.com/ava-labs/go-ethereum/params" "github.com/ava-labs/go-ethereum/rlp" - "github.com/ava-labs/go-ethereum/core" ) var errGenesisNoConfig = errors.New("genesis has no chain configuration") @@ -62,6 +63,16 @@ func (h storageJSON) MarshalText() ([]byte, error) { return hexutil.Bytes(h[:]).MarshalText() } +// GenesisMismatchError is raised when trying to overwrite an existing +// genesis block with an incompatible one. +type GenesisMismatchError struct { + Stored, New common.Hash +} + +func (e *GenesisMismatchError) Error() string { + return fmt.Sprintf("database contains incompatible genesis (have %x, new %x)", e.Stored, e.New) +} + // SetupGenesisBlock writes or updates the genesis block in db. // The block that will be used is: // @@ -76,6 +87,10 @@ func (h storageJSON) MarshalText() ([]byte, error) { // // The returned chain configuration is never nil. func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) { + return SetupGenesisBlockWithOverride(db, genesis, nil) +} + +func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideIstanbul *big.Int) (*params.ChainConfig, common.Hash, error) { if genesis != nil && genesis.Config == nil { return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig } @@ -105,7 +120,7 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig // Ensure the stored genesis matches with the given one. hash := genesis.ToBlock(nil).Hash() if hash != stored { - return genesis.Config, hash, &core.GenesisMismatchError{stored, hash} + return genesis.Config, hash, &GenesisMismatchError{stored, hash} } block, err := genesis.Commit(db) if err != nil { @@ -118,12 +133,15 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig if genesis != nil { hash := genesis.ToBlock(nil).Hash() if hash != stored { - return genesis.Config, hash, &core.GenesisMismatchError{stored, hash} + return genesis.Config, hash, &GenesisMismatchError{stored, hash} } } // Get the existing chain configuration. newcfg := configOrDefault(genesis, stored) + if overrideIstanbul != nil { + newcfg.IstanbulBlock = overrideIstanbul + } storedcfg := rawdb.ReadChainConfig(db, stored) if storedcfg == nil { log.Warn("Found genesis block without chain config") @@ -222,7 +240,7 @@ func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis { // Assemble and return the genesis with the precompiles and faucet pre-funded return &Genesis{ Config: &config, - ExtraData: append(append(make([]byte, 32), faucet[:]...), make([]byte, 65)...), + ExtraData: append(append(make([]byte, 32), faucet[:]...), make([]byte, crypto.SignatureLength)...), GasLimit: 6283185, Difficulty: big.NewInt(1), Alloc: map[common.Address]GenesisAccount{ @@ -37,6 +37,7 @@ func isLocalBlock(block *types.Block) bool { return false } +// NewETHChain creates an Ethereum blockchain with the given configs. func NewETHChain(config *eth.Config, nodecfg *node.Config, etherBase *common.Address, chainDB ethdb.Database) *ETHChain { if config == nil { config = ð.DefaultConfig diff --git a/eth/backend.go b/eth/backend.go index 02a23cc..6d052e2 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -153,7 +153,7 @@ func New(ctx *node.ServiceContext, config *Config, return nil, err } } - chainConfig, genesisHash, genesisErr := core.SetupGenesisBlock(chainDb, config.Genesis) + chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideIstanbul) if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok { return nil, genesisErr } @@ -524,12 +524,10 @@ func (s *Ethereum) Start(srvr *p2p.Server) error { maxPeers -= s.config.LightPeers } // Start the networking layer and the light server if requested - if s.protocolManager != nil { - s.protocolManager.Start(maxPeers) - } - if s.lesServer != nil { - s.lesServer.Start(srvr) - } + //s.protocolManager.Start(maxPeers) + //if s.lesServer != nil { + // s.lesServer.Start(srvr) + //} return nil } @@ -539,12 +537,10 @@ func (s *Ethereum) Stop() error { s.bloomIndexer.Close() s.blockchain.Stop() s.engine.Close() - if s.protocolManager != nil { - s.protocolManager.Stop() - } - if s.lesServer != nil { - s.lesServer.Stop() - } + //s.protocolManager.Stop() + //if s.lesServer != nil { + // s.lesServer.Stop() + //} s.txPool.Stop() s.miner.Stop() s.eventMux.Stop() diff --git a/eth/config.go b/eth/config.go index 0313783..85abe7c 100644 --- a/eth/config.go +++ b/eth/config.go @@ -156,6 +156,11 @@ type Config struct { // CheckpointOracle is the configuration for checkpoint oracle. CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` + + // Istanbul block override (TODO: remove after the fork) + OverrideIstanbul *big.Int + + // Manually select and grow the canonical chain ManualCanonical bool } diff --git a/examples/counter/counter.sol b/examples/counter/counter.sol index c05bf23..b21c3bf 100644 --- a/examples/counter/counter.sol +++ b/examples/counter/counter.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.5.10; +pragma solidity ^0.6.0; contract Counter { uint256 x; |