Skip to content

Commit 8f96d66

Browse files
committed
Merge branch 'develop' into release/1.4
2 parents 4b9de75 + 5782164 commit 8f96d66

File tree

21 files changed

+239
-100
lines changed

21 files changed

+239
-100
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ GOBIN = build/bin
1313
GO ?= latest
1414

1515
geth:
16-
build/env.sh go install -v $(shell build/flags.sh) ./cmd/geth
16+
build/env.sh go build -i -v $(shell build/flags.sh) -o $(GOBIN)/geth ./cmd/geth
1717
@echo "Done building."
1818
@echo "Run \"$(GOBIN)/geth\" to launch geth."
1919

@@ -103,7 +103,9 @@ evm:
103103
@echo "Run \"$(GOBIN)/evm to start the evm."
104104

105105
all:
106-
build/env.sh go install -v $(shell build/flags.sh) ./...
106+
for cmd in `ls ./cmd/`; do \
107+
build/env.sh go build -i -v $(shell build/flags.sh) -o $(GOBIN)/$$cmd ./cmd/$$cmd; \
108+
done
107109

108110
test: all
109111
build/env.sh go test ./...

build/win-ci-compile.bat

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@echo off
2+
if not exist .\build\win-ci-compile.bat (
3+
echo This script must be run from the root of the repository.
4+
exit /b
5+
)
6+
if not defined GOPATH (
7+
echo GOPATH is not set.
8+
exit /b
9+
)
10+
11+
set GOPATH=%GOPATH%;%cd%\Godeps\_workspace
12+
set GOBIN=%cd%\build\bin
13+
14+
rem set gitCommit when running from a Git checkout.
15+
set goLinkFlags=""
16+
if exist ".git\HEAD" (
17+
where /q git
18+
if not errorlevel 1 (
19+
for /f %%h in ('git rev-parse HEAD') do (
20+
set goLinkFlags="-X main.gitCommit=%%h"
21+
)
22+
)
23+
)
24+
25+
@echo on
26+
go install -v -ldflags %goLinkFlags% ./...

build/win-ci-test.bat

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@echo off
2+
if not exist .\build\win-ci-test.bat (
3+
echo This script must be run from the root of the repository.
4+
exit /b
5+
)
6+
if not defined GOPATH (
7+
echo GOPATH is not set.
8+
exit /b
9+
)
10+
11+
set GOPATH=%GOPATH%;%cd%\Godeps\_workspace
12+
set GOBIN=%cd%\build\bin
13+
14+
@echo on
15+
go test ./...

cmd/utils/cmd.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,13 @@ func StartNode(stack *node.Node) {
7373
<-sigc
7474
glog.V(logger.Info).Infoln("Got interrupt, shutting down...")
7575
go stack.Stop()
76-
logger.Flush()
7776
for i := 10; i > 0; i-- {
7877
<-sigc
7978
if i > 1 {
80-
glog.V(logger.Info).Infoln("Already shutting down, please be patient.")
81-
glog.V(logger.Info).Infoln("Interrupt", i-1, "more times to induce panic.")
79+
glog.V(logger.Info).Infof("Already shutting down, interrupt %d more times for panic.", i-1)
8280
}
8381
}
84-
glog.V(logger.Error).Infof("Force quitting: this might not end so well.")
82+
debug.Exit() // ensure trace and CPU profile data is flushed.
8583
debug.LoudPanic("boom")
8684
}()
8785
}

cmd/utils/fdlimit_freebsd.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2016 The go-ethereum Authors
2+
// This file is part of go-ethereum.
3+
//
4+
// go-ethereum is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// go-ethereum is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
16+
17+
// +build freebsd
18+
19+
package utils
20+
21+
import "syscall"
22+
23+
// This file is largely identical to fdlimit_unix.go,
24+
// but Rlimit fields have type int64 on FreeBSD so it needs
25+
// an extra conversion.
26+
27+
// raiseFdLimit tries to maximize the file descriptor allowance of this process
28+
// to the maximum hard-limit allowed by the OS.
29+
func raiseFdLimit(max uint64) error {
30+
// Get the current limit
31+
var limit syscall.Rlimit
32+
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
33+
return err
34+
}
35+
// Try to update the limit to the max allowance
36+
limit.Cur = limit.Max
37+
if limit.Cur > int64(max) {
38+
limit.Cur = int64(max)
39+
}
40+
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
41+
return err
42+
}
43+
return nil
44+
}
45+
46+
// getFdLimit retrieves the number of file descriptors allowed to be opened by this
47+
// process.
48+
func getFdLimit() (int, error) {
49+
var limit syscall.Rlimit
50+
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
51+
return 0, err
52+
}
53+
return int(limit.Cur), nil
54+
}

cmd/utils/fdlimit_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
1616

17-
// +build linux darwin
17+
// +build linux darwin netbsd openbsd solaris
1818

1919
package utils
2020

core/tx_pool.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ type stateFn func() (*state.StateDB, error)
6060
// two states over time as they are received and processed.
6161
type TxPool struct {
6262
config *ChainConfig
63-
quit chan bool // Quitting channel
64-
currentState stateFn // The state function which will allow us to do some pre checks
63+
currentState stateFn // The state function which will allow us to do some pre checks
6564
pendingState *state.ManagedState
6665
gasLimit func() *big.Int // The current gas limit function callback
6766
minGasPrice *big.Int
@@ -72,6 +71,8 @@ type TxPool struct {
7271
pending map[common.Hash]*types.Transaction // processable transactions
7372
queue map[common.Address]map[common.Hash]*types.Transaction
7473

74+
wg sync.WaitGroup // for shutdown sync
75+
7576
homestead bool
7677
}
7778

@@ -80,7 +81,6 @@ func NewTxPool(config *ChainConfig, eventMux *event.TypeMux, currentStateFn stat
8081
config: config,
8182
pending: make(map[common.Hash]*types.Transaction),
8283
queue: make(map[common.Address]map[common.Hash]*types.Transaction),
83-
quit: make(chan bool),
8484
eventMux: eventMux,
8585
currentState: currentStateFn,
8686
gasLimit: gasLimitFn,
@@ -90,12 +90,15 @@ func NewTxPool(config *ChainConfig, eventMux *event.TypeMux, currentStateFn stat
9090
events: eventMux.Subscribe(ChainHeadEvent{}, GasPriceChanged{}, RemovedTransactionEvent{}),
9191
}
9292

93+
pool.wg.Add(1)
9394
go pool.eventLoop()
9495

9596
return pool
9697
}
9798

9899
func (pool *TxPool) eventLoop() {
100+
defer pool.wg.Done()
101+
99102
// Track chain events. When a chain events occurs (new chain canon block)
100103
// we need to know the new state. The new state will help us determine
101104
// the nonces in the managed state
@@ -155,8 +158,8 @@ func (pool *TxPool) resetState() {
155158
}
156159

157160
func (pool *TxPool) Stop() {
158-
close(pool.quit)
159161
pool.events.Unsubscribe()
162+
pool.wg.Wait()
160163
glog.V(logger.Info).Infoln("Transaction pool stopped")
161164
}
162165

eth/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,15 +1841,15 @@ func (s *PrivateDebugAPI) TraceTransaction(txHash common.Hash, logger *vm.LogCon
18411841
}
18421842
// Mutate the state if we haven't reached the tracing transaction yet
18431843
if uint64(idx) < txIndex {
1844-
vmenv := core.NewEnv(stateDb, s.config, s.eth.BlockChain(), msg, parent.Header(), vm.Config{})
1844+
vmenv := core.NewEnv(stateDb, s.config, s.eth.BlockChain(), msg, block.Header(), vm.Config{})
18451845
_, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas()))
18461846
if err != nil {
18471847
return nil, fmt.Errorf("mutation failed: %v", err)
18481848
}
18491849
continue
18501850
}
18511851
// Otherwise trace the transaction and return
1852-
vmenv := core.NewEnv(stateDb, s.config, s.eth.BlockChain(), msg, parent.Header(), vm.Config{Debug: true, Logger: *logger})
1852+
vmenv := core.NewEnv(stateDb, s.config, s.eth.BlockChain(), msg, block.Header(), vm.Config{Debug: true, Logger: *logger})
18531853
ret, gas, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas()))
18541854
if err != nil {
18551855
return nil, fmt.Errorf("tracing failed: %v", err)

eth/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ func (s *Ethereum) Stop() error {
416416
s.blockchain.Stop()
417417
s.protocolManager.Stop()
418418
s.txPool.Stop()
419+
s.miner.Stop()
419420
s.eventMux.Stop()
420421

421422
s.StopAutoDAG()

eth/handler.go

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ type ProtocolManager struct {
7474
minedBlockSub event.Subscription
7575

7676
// channels for fetcher, syncer, txsyncLoop
77-
newPeerCh chan *peer
78-
txsyncCh chan *txsync
79-
quitSync chan struct{}
77+
newPeerCh chan *peer
78+
txsyncCh chan *txsync
79+
quitSync chan struct{}
80+
noMorePeers chan struct{}
8081

8182
// wait group is used for graceful shutdowns during downloading
8283
// and processing
83-
wg sync.WaitGroup
84-
quit bool
84+
wg sync.WaitGroup
8585
}
8686

8787
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
@@ -94,16 +94,17 @@ func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int,
9494
}
9595
// Create the protocol manager with the base fields
9696
manager := &ProtocolManager{
97-
networkId: networkId,
98-
fastSync: fastSync,
99-
eventMux: mux,
100-
txpool: txpool,
101-
blockchain: blockchain,
102-
chaindb: chaindb,
103-
peers: newPeerSet(),
104-
newPeerCh: make(chan *peer, 1),
105-
txsyncCh: make(chan *txsync),
106-
quitSync: make(chan struct{}),
97+
networkId: networkId,
98+
fastSync: fastSync,
99+
eventMux: mux,
100+
txpool: txpool,
101+
blockchain: blockchain,
102+
chaindb: chaindb,
103+
peers: newPeerSet(),
104+
newPeerCh: make(chan *peer),
105+
noMorePeers: make(chan struct{}),
106+
txsyncCh: make(chan *txsync),
107+
quitSync: make(chan struct{}),
107108
}
108109
// Initiate a sub-protocol for every implemented version we can handle
109110
manager.SubProtocols = make([]p2p.Protocol, 0, len(ProtocolVersions))
@@ -120,8 +121,14 @@ func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int,
120121
Length: ProtocolLengths[i],
121122
Run: func(p *p2p.Peer, rw p2p.MsgReadWriter) error {
122123
peer := manager.newPeer(int(version), p, rw)
123-
manager.newPeerCh <- peer
124-
return manager.handle(peer)
124+
select {
125+
case manager.newPeerCh <- peer:
126+
manager.wg.Add(1)
127+
defer manager.wg.Done()
128+
return manager.handle(peer)
129+
case <-manager.quitSync:
130+
return p2p.DiscQuitting
131+
}
125132
},
126133
NodeInfo: func() interface{} {
127134
return manager.NodeInfo()
@@ -187,16 +194,25 @@ func (pm *ProtocolManager) Start() {
187194
}
188195

189196
func (pm *ProtocolManager) Stop() {
190-
// Showing a log message. During download / process this could actually
191-
// take between 5 to 10 seconds and therefor feedback is required.
192197
glog.V(logger.Info).Infoln("Stopping ethereum protocol handler...")
193198

194-
pm.quit = true
195199
pm.txSub.Unsubscribe() // quits txBroadcastLoop
196200
pm.minedBlockSub.Unsubscribe() // quits blockBroadcastLoop
197-
close(pm.quitSync) // quits syncer, fetcher, txsyncLoop
198201

199-
// Wait for any process action
202+
// Quit the sync loop.
203+
// After this send has completed, no new peers will be accepted.
204+
pm.noMorePeers <- struct{}{}
205+
206+
// Quit fetcher, txsyncLoop.
207+
close(pm.quitSync)
208+
209+
// Disconnect existing sessions.
210+
// This also closes the gate for any new registrations on the peer set.
211+
// sessions which are already established but not added to pm.peers yet
212+
// will exit when they try to register.
213+
pm.peers.Close()
214+
215+
// Wait for all peer handler goroutines and the loops to come down.
200216
pm.wg.Wait()
201217

202218
glog.V(logger.Info).Infoln("Ethereum protocol handler stopped")

0 commit comments

Comments
 (0)