Skip to content

Commit aad4890

Browse files
committed
cmd/geth, core, light, mobile: removed state account StartingNonce
All account's nonce start at 0.
1 parent a0e42aa commit aad4890

File tree

7 files changed

+5
-33
lines changed

7 files changed

+5
-33
lines changed

cmd/geth/chaincmd.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ func importChain(ctx *cli.Context) error {
9999
if len(ctx.Args()) != 1 {
100100
utils.Fatalf("This command requires an argument.")
101101
}
102-
if ctx.GlobalBool(utils.TestNetFlag.Name) {
103-
state.StartingNonce = 1048576 // (2**20)
104-
}
105102
stack := makeFullNode(ctx)
106103
chain, chainDb := utils.MakeChain(ctx, stack)
107104
defer chainDb.Close()

cmd/geth/main.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"github.com/ethereum/go-ethereum/console"
3535
"github.com/ethereum/go-ethereum/contracts/release"
3636
"github.com/ethereum/go-ethereum/core"
37-
"github.com/ethereum/go-ethereum/core/state"
3837
"github.com/ethereum/go-ethereum/eth"
3938
"github.com/ethereum/go-ethereum/internal/debug"
4039
"github.com/ethereum/go-ethereum/logger"
@@ -237,10 +236,6 @@ func initGenesis(ctx *cli.Context) error {
237236
utils.Fatalf("must supply path to genesis JSON file")
238237
}
239238

240-
if ctx.GlobalBool(utils.TestNetFlag.Name) {
241-
state.StartingNonce = 1048576 // (2**20)
242-
}
243-
244239
stack := makeFullNode(ctx)
245240
chaindb := utils.MakeChainDatabase(ctx, stack)
246241

cmd/utils/flags.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"github.com/ethereum/go-ethereum/ethdb"
3939
"github.com/ethereum/go-ethereum/event"
4040
"github.com/ethereum/go-ethereum/les"
41-
"github.com/ethereum/go-ethereum/light"
4241
"github.com/ethereum/go-ethereum/logger"
4342
"github.com/ethereum/go-ethereum/logger/glog"
4443
"github.com/ethereum/go-ethereum/metrics"
@@ -754,8 +753,6 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
754753
ethConf.NetworkId = 2
755754
}
756755
ethConf.Genesis = core.TestNetGenesisBlock()
757-
state.StartingNonce = 1048576 // (2**20)
758-
light.StartingNonce = 1048576 // (2**20)
759756

760757
case ctx.GlobalBool(DevModeFlag.Name):
761758
ethConf.Genesis = core.OlympicGenesisBlock()

core/genesis.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func WriteGenesisBlock(chainDb ethdb.Database, reader io.Reader) (*types.Block,
4343
}
4444

4545
var genesis struct {
46-
ChainConfig *params.ChainConfig `json:"config"`
46+
ChainConfig params.ChainConfig `json:"config"`
4747
Nonce string
4848
Timestamp string
4949
ParentHash string
@@ -115,7 +115,7 @@ func WriteGenesisBlock(chainDb ethdb.Database, reader io.Reader) (*types.Block,
115115
if err := WriteHeadBlockHash(chainDb, block.Hash()); err != nil {
116116
return nil, err
117117
}
118-
if err := WriteChainConfig(chainDb, block.Hash(), genesis.ChainConfig); err != nil {
118+
if err := WriteChainConfig(chainDb, block.Hash(), &genesis.ChainConfig); err != nil {
119119
return nil, err
120120
}
121121

core/state/statedb.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ import (
3434
lru "github.com/hashicorp/golang-lru"
3535
)
3636

37-
// The starting nonce determines the default nonce when new accounts are being
38-
// created.
39-
var StartingNonce uint64
40-
4137
// Trie cache generation limit after which to evic trie nodes from memory.
4238
var MaxTrieCacheGen = uint16(120)
4339

@@ -239,7 +235,7 @@ func (self *StateDB) GetNonce(addr common.Address) uint64 {
239235
return stateObject.Nonce()
240236
}
241237

242-
return StartingNonce
238+
return 0
243239
}
244240

245241
func (self *StateDB) GetCode(addr common.Address) []byte {
@@ -423,7 +419,7 @@ func (self *StateDB) MarkStateObjectDirty(addr common.Address) {
423419
func (self *StateDB) createObject(addr common.Address) (newobj, prev *StateObject) {
424420
prev = self.GetStateObject(addr)
425421
newobj = newObject(self, addr, Account{}, self.MarkStateObjectDirty)
426-
newobj.setNonce(StartingNonce) // sets the object to dirty
422+
newobj.setNonce(0) // sets the object to dirty
427423
if prev == nil {
428424
if glog.V(logger.Core) {
429425
glog.Infof("(+) %x\n", addr)

light/state.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ import (
2626
"golang.org/x/net/context"
2727
)
2828

29-
// StartingNonce determines the default nonce when new accounts are being created.
30-
var StartingNonce uint64
31-
3229
// LightState is a memory representation of a state.
3330
// This version is ODR capable, caching only the already accessed part of the
3431
// state, retrieving unknown parts on-demand from the ODR backend. Changes are
@@ -238,7 +235,7 @@ func (self *LightState) newStateObject(addr common.Address) *StateObject {
238235
}
239236

240237
stateObject := NewStateObject(addr, self.odr)
241-
stateObject.SetNonce(StartingNonce)
238+
stateObject.SetNonce(0)
242239
self.stateObjects[addr.Str()] = stateObject
243240

244241
return stateObject

mobile/geth.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ import (
2525
"path/filepath"
2626

2727
"github.com/ethereum/go-ethereum/common"
28-
"github.com/ethereum/go-ethereum/core/state"
2928
"github.com/ethereum/go-ethereum/eth"
3029
"github.com/ethereum/go-ethereum/ethclient"
3130
"github.com/ethereum/go-ethereum/les"
32-
"github.com/ethereum/go-ethereum/light"
3331
"github.com/ethereum/go-ethereum/node"
3432
"github.com/ethereum/go-ethereum/p2p/nat"
3533
"github.com/ethereum/go-ethereum/params"
@@ -63,10 +61,6 @@ type NodeConfig struct {
6361
// empty genesis state is equivalent to using the mainnet's state.
6462
EthereumGenesis string
6563

66-
// EthereumTestnetNonces specifies whether to use account nonces from the testnet
67-
// range (2^20) or from the mainnet one (0).
68-
EthereumTestnetNonces bool
69-
7064
// EthereumDatabaseCache is the system memory in MB to allocate for database caching.
7165
// A minimum of 16MB is always reserved.
7266
EthereumDatabaseCache int
@@ -151,10 +145,6 @@ func NewNode(datadir string, config *NodeConfig) (*Node, error) {
151145
GpobaseStepUp: 100,
152146
GpobaseCorrectionFactor: 110,
153147
}
154-
if config.EthereumTestnetNonces {
155-
state.StartingNonce = 1048576 // (2**20)
156-
light.StartingNonce = 1048576 // (2**20)
157-
}
158148
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
159149
return les.New(ctx, ethConf)
160150
}); err != nil {

0 commit comments

Comments
 (0)