From 30860491ba9f1fae2eb9e7dac1c35b679b20fbe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 15 Sep 2016 14:09:47 +0300 Subject: [PATCH 1/3] cmd, eth: drop the blockchain version from cli/eth configs --- cmd/geth/main.go | 1 - cmd/geth/usage.go | 1 - cmd/utils/flags.go | 6 ------ eth/backend.go | 7 +++---- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index b5e454d872..a7b332d0ff 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -133,7 +133,6 @@ participating. utils.BootnodesFlag, utils.DataDirFlag, utils.KeyStoreDirFlag, - utils.BlockchainVersionFlag, utils.OlympicFlag, utils.FastSyncFlag, utils.CacheFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index b08de247b1..dc1788aad2 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -74,7 +74,6 @@ var AppHelpFlagGroups = []flagGroup{ utils.FastSyncFlag, utils.LightKDFFlag, utils.CacheFlag, - utils.BlockchainVersionFlag, }, }, { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index a1f098f299..3ab556a8fc 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -146,11 +146,6 @@ var ( Usage: "Megabytes of memory allocated to internal caching (min 16MB / database forced)", Value: 128, } - BlockchainVersionFlag = cli.IntFlag{ - Name: "blockchainversion", - Usage: "Blockchain version (integer)", - Value: core.BlockChainVersion, - } FastSyncFlag = cli.BoolFlag{ Name: "fast", Usage: "Enable fast syncing through state downloads", @@ -681,7 +676,6 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) { Etherbase: MakeEtherbase(stack.AccountManager(), ctx), ChainConfig: MustMakeChainConfig(ctx), FastSync: ctx.GlobalBool(FastSyncFlag.Name), - BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name), DatabaseCache: ctx.GlobalInt(CacheFlag.Name), DatabaseHandles: MakeDatabaseHandles(), NetworkId: ctx.GlobalInt(NetworkIdFlag.Name), diff --git a/eth/backend.go b/eth/backend.go index e1d123a02a..c4a883c9e9 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -70,7 +70,6 @@ type Config struct { Genesis string // Genesis JSON to seed the chain database with FastSync bool // Enables the state download based fast synchronisation algorithm - BlockChainVersion int SkipBcVersionCheck bool // e.g. blockchain export DatabaseCache int DatabaseHandles int @@ -180,10 +179,10 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { if !config.SkipBcVersionCheck { bcVersion := core.GetBlockChainVersion(chainDb) - if bcVersion != config.BlockChainVersion && bcVersion != 0 { - return nil, fmt.Errorf("Blockchain DB version mismatch (%d / %d). Run geth upgradedb.\n", bcVersion, config.BlockChainVersion) + if bcVersion != core.BlockChainVersion && bcVersion != 0 { + return nil, fmt.Errorf("Blockchain DB version mismatch (%d / %d). Run geth upgradedb.\n", bcVersion, core.BlockChainVersion) } - core.WriteBlockChainVersion(chainDb, config.BlockChainVersion) + core.WriteBlockChainVersion(chainDb, core.BlockChainVersion) } // load the genesis block or write a new one if no genesis From 581b320b9dfb42c0c4842e0bc5aeb507267a8eba Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Mon, 19 Sep 2016 07:56:23 +0800 Subject: [PATCH 2/3] core/state: Fix memory expansion bug by not copying clean objects --- core/state/state_object.go | 2 +- core/state/state_test.go | 6 ++++-- core/state/statedb.go | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/state/state_object.go b/core/state/state_object.go index 769c63d42d..20da1006fc 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -187,7 +187,7 @@ func (self *StateObject) Copy() *StateObject { stateObject.codeHash = common.CopyBytes(self.codeHash) stateObject.nonce = self.nonce stateObject.trie = self.trie - stateObject.code = common.CopyBytes(self.code) + stateObject.code = self.code stateObject.initCode = common.CopyBytes(self.initCode) stateObject.storage = self.storage.Copy() stateObject.remove = self.remove diff --git a/core/state/state_test.go b/core/state/state_test.go index ce86a5b768..5a6cb0b501 100644 --- a/core/state/state_test.go +++ b/core/state/state_test.go @@ -149,10 +149,11 @@ func TestSnapshot2(t *testing.T) { so0.balance = big.NewInt(42) so0.nonce = 43 so0.SetCode([]byte{'c', 'a', 'f', 'e'}) - so0.remove = true + so0.remove = false so0.deleted = false - so0.dirty = false + so0.dirty = true state.SetStateObject(so0) + state.Commit() // and one with deleted == true so1 := state.GetStateObject(stateobjaddr1) @@ -173,6 +174,7 @@ func TestSnapshot2(t *testing.T) { state.Set(snapshot) so0Restored := state.GetStateObject(stateobjaddr0) + so0Restored.GetState(storageaddr) so1Restored := state.GetStateObject(stateobjaddr1) // non-deleted is equal (restored) compareStateObjects(so0Restored, so0, t) diff --git a/core/state/statedb.go b/core/state/statedb.go index 3e25e0c160..8ba81613d6 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -324,7 +324,9 @@ func (self *StateDB) Copy() *StateDB { state, _ := New(common.Hash{}, self.db) state.trie = self.trie for k, stateObject := range self.stateObjects { - state.stateObjects[k] = stateObject.Copy() + if stateObject.dirty { + state.stateObjects[k] = stateObject.Copy() + } } state.refund.Set(self.refund) @@ -364,7 +366,6 @@ func (s *StateDB) IntermediateRoot() common.Hash { stateObject.Update() s.UpdateStateObject(stateObject) } - stateObject.dirty = false } } return s.trie.Hash() From b6b17e5648ba2d8298d41c384d89caf82a27b271 Mon Sep 17 00:00:00 2001 From: Gustav Simonsson Date: Mon, 19 Sep 2016 02:07:20 -0400 Subject: [PATCH 3/3] core/state, light: remove unused StateObject.initCode --- core/state/state_object.go | 3 --- core/state/state_test.go | 3 --- light/state_object.go | 3 --- 3 files changed, 9 deletions(-) diff --git a/core/state/state_object.go b/core/state/state_object.go index 20da1006fc..c5462316dd 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -71,8 +71,6 @@ type StateObject struct { codeHash []byte // The code for this account code Code - // Temporarily initialisation code - initCode Code // Cached storage (flushed when updated) storage Storage @@ -188,7 +186,6 @@ func (self *StateObject) Copy() *StateObject { stateObject.nonce = self.nonce stateObject.trie = self.trie stateObject.code = self.code - stateObject.initCode = common.CopyBytes(self.initCode) stateObject.storage = self.storage.Copy() stateObject.remove = self.remove stateObject.dirty = self.dirty diff --git a/core/state/state_test.go b/core/state/state_test.go index 5a6cb0b501..69cf083cfa 100644 --- a/core/state/state_test.go +++ b/core/state/state_test.go @@ -200,9 +200,6 @@ func compareStateObjects(so0, so1 *StateObject, t *testing.T) { if !bytes.Equal(so0.code, so1.code) { t.Fatalf("Code mismatch: have %v, want %v", so0.code, so1.code) } - if !bytes.Equal(so0.initCode, so1.initCode) { - t.Fatalf("InitCode mismatch: have %v, want %v", so0.initCode, so1.initCode) - } for k, v := range so1.storage { if so0.storage[k] != v { diff --git a/light/state_object.go b/light/state_object.go index 030653c770..08c209d7d8 100644 --- a/light/state_object.go +++ b/light/state_object.go @@ -79,8 +79,6 @@ type StateObject struct { codeHash []byte // The code for this account code Code - // Temporarily initialisation code - initCode Code // Cached storage (flushed when updated) storage Storage @@ -189,7 +187,6 @@ func (self *StateObject) Copy() *StateObject { stateObject.nonce = self.nonce stateObject.trie = self.trie stateObject.code = common.CopyBytes(self.code) - stateObject.initCode = common.CopyBytes(self.initCode) stateObject.storage = self.storage.Copy() stateObject.remove = self.remove stateObject.dirty = self.dirty