Skip to content

Commit

Permalink
cmd/geth, core, light, mobile: removed state account StartingNonce
Browse files Browse the repository at this point in the history
All account's nonce start at 0.
  • Loading branch information
obscuren committed Nov 23, 2016
1 parent a0e42aa commit aad4890
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 33 deletions.
3 changes: 0 additions & 3 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ func importChain(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
utils.Fatalf("This command requires an argument.")
}
if ctx.GlobalBool(utils.TestNetFlag.Name) {
state.StartingNonce = 1048576 // (2**20)
}
stack := makeFullNode(ctx)
chain, chainDb := utils.MakeChain(ctx, stack)
defer chainDb.Close()
Expand Down
5 changes: 0 additions & 5 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/ethereum/go-ethereum/console"
"github.com/ethereum/go-ethereum/contracts/release"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/logger"
Expand Down Expand Up @@ -237,10 +236,6 @@ func initGenesis(ctx *cli.Context) error {
utils.Fatalf("must supply path to genesis JSON file")
}

if ctx.GlobalBool(utils.TestNetFlag.Name) {
state.StartingNonce = 1048576 // (2**20)
}

stack := makeFullNode(ctx)
chaindb := utils.MakeChainDatabase(ctx, stack)

Expand Down
3 changes: 0 additions & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/metrics"
Expand Down Expand Up @@ -754,8 +753,6 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
ethConf.NetworkId = 2
}
ethConf.Genesis = core.TestNetGenesisBlock()
state.StartingNonce = 1048576 // (2**20)
light.StartingNonce = 1048576 // (2**20)

case ctx.GlobalBool(DevModeFlag.Name):
ethConf.Genesis = core.OlympicGenesisBlock()
Expand Down
4 changes: 2 additions & 2 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func WriteGenesisBlock(chainDb ethdb.Database, reader io.Reader) (*types.Block,
}

var genesis struct {
ChainConfig *params.ChainConfig `json:"config"`
ChainConfig params.ChainConfig `json:"config"`
Nonce string
Timestamp string
ParentHash string
Expand Down Expand Up @@ -115,7 +115,7 @@ func WriteGenesisBlock(chainDb ethdb.Database, reader io.Reader) (*types.Block,
if err := WriteHeadBlockHash(chainDb, block.Hash()); err != nil {
return nil, err
}
if err := WriteChainConfig(chainDb, block.Hash(), genesis.ChainConfig); err != nil {
if err := WriteChainConfig(chainDb, block.Hash(), &genesis.ChainConfig); err != nil {
return nil, err
}

Expand Down
8 changes: 2 additions & 6 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ import (
lru "github.com/hashicorp/golang-lru"
)

// The starting nonce determines the default nonce when new accounts are being
// created.
var StartingNonce uint64

// Trie cache generation limit after which to evic trie nodes from memory.
var MaxTrieCacheGen = uint16(120)

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

return StartingNonce
return 0
}

func (self *StateDB) GetCode(addr common.Address) []byte {
Expand Down Expand Up @@ -423,7 +419,7 @@ func (self *StateDB) MarkStateObjectDirty(addr common.Address) {
func (self *StateDB) createObject(addr common.Address) (newobj, prev *StateObject) {
prev = self.GetStateObject(addr)
newobj = newObject(self, addr, Account{}, self.MarkStateObjectDirty)
newobj.setNonce(StartingNonce) // sets the object to dirty
newobj.setNonce(0) // sets the object to dirty
if prev == nil {
if glog.V(logger.Core) {
glog.Infof("(+) %x\n", addr)
Expand Down
5 changes: 1 addition & 4 deletions light/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import (
"golang.org/x/net/context"
)

// StartingNonce determines the default nonce when new accounts are being created.
var StartingNonce uint64

// LightState is a memory representation of a state.
// This version is ODR capable, caching only the already accessed part of the
// state, retrieving unknown parts on-demand from the ODR backend. Changes are
Expand Down Expand Up @@ -238,7 +235,7 @@ func (self *LightState) newStateObject(addr common.Address) *StateObject {
}

stateObject := NewStateObject(addr, self.odr)
stateObject.SetNonce(StartingNonce)
stateObject.SetNonce(0)
self.stateObjects[addr.Str()] = stateObject

return stateObject
Expand Down
10 changes: 0 additions & 10 deletions mobile/geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ import (
"path/filepath"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -63,10 +61,6 @@ type NodeConfig struct {
// empty genesis state is equivalent to using the mainnet's state.
EthereumGenesis string

// EthereumTestnetNonces specifies whether to use account nonces from the testnet
// range (2^20) or from the mainnet one (0).
EthereumTestnetNonces bool

// EthereumDatabaseCache is the system memory in MB to allocate for database caching.
// A minimum of 16MB is always reserved.
EthereumDatabaseCache int
Expand Down Expand Up @@ -151,10 +145,6 @@ func NewNode(datadir string, config *NodeConfig) (*Node, error) {
GpobaseStepUp: 100,
GpobaseCorrectionFactor: 110,
}
if config.EthereumTestnetNonces {
state.StartingNonce = 1048576 // (2**20)
light.StartingNonce = 1048576 // (2**20)
}
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
return les.New(ctx, ethConf)
}); err != nil {
Expand Down

0 comments on commit aad4890

Please sign in to comment.