aboutsummaryrefslogtreecommitdiffstats
path: root/core/chain_makers.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-03-02 06:32:43 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2016-04-01 07:01:10 +0800
commitf0cbebb19f3137ee3ba0e66dadd1b5b9dbf98b1c (patch)
tree02e31a0e31040980e30e3a835ff9eba73e419439 /core/chain_makers.go
parent10d3466c934bd425a8c941270749a652a588527d (diff)
downloadgo-tangerine-f0cbebb19f3137ee3ba0e66dadd1b5b9dbf98b1c.tar
go-tangerine-f0cbebb19f3137ee3ba0e66dadd1b5b9dbf98b1c.tar.gz
go-tangerine-f0cbebb19f3137ee3ba0e66dadd1b5b9dbf98b1c.tar.bz2
go-tangerine-f0cbebb19f3137ee3ba0e66dadd1b5b9dbf98b1c.tar.lz
go-tangerine-f0cbebb19f3137ee3ba0e66dadd1b5b9dbf98b1c.tar.xz
go-tangerine-f0cbebb19f3137ee3ba0e66dadd1b5b9dbf98b1c.tar.zst
go-tangerine-f0cbebb19f3137ee3ba0e66dadd1b5b9dbf98b1c.zip
core: added basic chain configuration
Added chain configuration options and write out during genesis database insertion. If no "config" was found, nothing is written to the database. Configurations are written on a per genesis base. This means that any chain (which is identified by it's genesis hash) can have their own chain settings.
Diffstat (limited to 'core/chain_makers.go')
-rw-r--r--core/chain_makers.go27
1 files changed, 23 insertions, 4 deletions
diff --git a/core/chain_makers.go b/core/chain_makers.go
index 7ae3c98b0..c740f9c37 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -23,11 +23,30 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
+ "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/pow"
)
+/*
+ * TODO: move this to another package.
+ */
+
+// MakeChainConfig returns a new ChainConfig with the ethereum default chain settings.
+func MakeChainConfig(testnet bool) *ChainConfig {
+ homesteadBlock := params.MainNetHomesteadBlock
+ // set a different default homestead block for the testnet
+ if testnet {
+ homesteadBlock = params.TestNetHomesteadBlock
+ }
+
+ return &ChainConfig{
+ HomesteadBlock: homesteadBlock,
+ }
+}
+
// FakePow is a non-validating proof of work implementation.
// It returns true from Verify for any block.
type FakePow struct{}
@@ -91,7 +110,7 @@ func (b *BlockGen) AddTx(tx *types.Transaction) {
b.SetCoinbase(common.Address{})
}
b.statedb.StartRecord(tx.Hash(), common.Hash{}, len(b.txs))
- receipt, _, _, err := ApplyTransaction(nil, b.gasPool, b.statedb, b.header, tx, b.header.GasUsed, nil)
+ receipt, _, _, err := ApplyTransaction(MakeChainConfig(true), nil, b.gasPool, b.statedb, b.header, tx, b.header.GasUsed, vm.Config{})
if err != nil {
panic(err)
}
@@ -148,7 +167,7 @@ func (b *BlockGen) OffsetTime(seconds int64) {
if b.header.Time.Cmp(b.parent.Header().Time) <= 0 {
panic("block time out of range")
}
- b.header.Difficulty = CalcDifficulty(b.header.Time.Uint64(), b.parent.Time().Uint64(), b.parent.Number(), b.parent.Difficulty())
+ b.header.Difficulty = CalcDifficulty(MakeChainConfig(true), b.header.Time.Uint64(), b.parent.Time().Uint64(), b.parent.Number(), b.parent.Difficulty())
}
// GenerateChain creates a chain of n blocks. The first block's
@@ -203,7 +222,7 @@ func makeHeader(parent *types.Block, state *state.StateDB) *types.Header {
Root: state.IntermediateRoot(),
ParentHash: parent.Hash(),
Coinbase: parent.Coinbase(),
- Difficulty: CalcDifficulty(time.Uint64(), new(big.Int).Sub(time, big.NewInt(10)).Uint64(), parent.Number(), parent.Difficulty()),
+ Difficulty: CalcDifficulty(MakeChainConfig(true), time.Uint64(), new(big.Int).Sub(time, big.NewInt(10)).Uint64(), parent.Number(), parent.Difficulty()),
GasLimit: CalcGasLimit(parent),
GasUsed: new(big.Int),
Number: new(big.Int).Add(parent.Number(), common.Big1),
@@ -222,7 +241,7 @@ func newCanonical(n int, full bool) (ethdb.Database, *BlockChain, error) {
// Initialize a fresh chain with only a genesis block
genesis, _ := WriteTestNetGenesisBlock(db)
- blockchain, _ := NewBlockChain(db, FakePow{}, evmux)
+ blockchain, _ := NewBlockChain(db, MakeChainConfig(false), FakePow{}, evmux)
// Create and inject the requested chain
if n == 0 {
return db, blockchain, nil