Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Upgrade] Go-Ethereum release v1.9.13 #1123

Merged
merged 125 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
542df88
core: initial version of state snapshots
karalabe Aug 6, 2019
e146fbe
core/state: lazy sorting, snapshot invalidation
holiman Oct 4, 2019
d7d81d7
core/state/snapshot: extract and split cap method, cover corners
karalabe Oct 17, 2019
cdf3f01
snapshot: iteration and buffering optimizations
holiman Oct 23, 2019
d754091
core/state/snapshot: unlink snapshots from blocks, quad->linear cleanup
karalabe Nov 22, 2019
f300c0d
core/state/snapshot: replace bigcache with fastcache
holiman Nov 25, 2019
351a590
core/rawdb, core/state/snapshot: runtime snapshot generation
karalabe Nov 26, 2019
d5d7c0c
core/state/snapshot: fix difflayer origin-initalization after flatten
holiman Dec 1, 2019
fd39f72
core: journal the snapshot inside leveldb, not a flat file
karalabe Dec 2, 2019
3ad4335
core/state/snapshot: node behavioural difference on bloom content
holiman Dec 2, 2019
22c494d
core/state/snapshot: bloom, metrics and prefetcher fixes
karalabe Dec 3, 2019
7e38996
core/state/snapshot: implement snapshot layer iteration
holiman Nov 5, 2019
e567675
core/state/snapshot: move iterator out into its own files
karalabe Dec 5, 2019
e570835
core/state/snapshot: implement iterator priority for fast direct data…
holiman Dec 6, 2019
6ddb92a
core/state/snapshot: full featured account iteration
karalabe Dec 10, 2019
1909942
core/state/snapshot: faster account iteration, CLI integration
holiman Jan 19, 2020
06d4470
core: fix broken tests due to API changes + linter
karalabe Feb 24, 2020
92ec07d
core/state: fix an account resurrection issue
karalabe Feb 27, 2020
361a6f0
core/tests: test for destroy+recreate contract with storage
holiman Mar 2, 2020
fe8347e
squashme
holiman Mar 2, 2020
6e05ccd
core/state/snapshot, tests: sync snap gen + snaps in consensus tests
karalabe Mar 3, 2020
a4cf279
core/state: extend snapshotter to handle account resurrections
karalabe Mar 3, 2020
dcb22a9
core/state: fix account root hash update point
karalabe Mar 3, 2020
328de18
core/state: fix resurrection state clearing and access
karalabe Mar 4, 2020
eff7cfb
core/state/snapshot: handle deleted accounts in fast iterator
holiman Mar 4, 2020
bc5d742
core: more blockchain tests
holiman Mar 4, 2020
fab0ee3
core/state/snapshot: fix various iteration issues due to destruct set
karalabe Mar 4, 2020
8d7aa90
params: begin v1.9.13 release cycle
karalabe Mar 16, 2020
efd92d8
cmd/checkpoint-admin: add some documentation (#20697)
rjl493456442 Mar 18, 2020
5dd0cd1
go.mod: update duktape to fix sprintf warnings (#20777)
moreati Mar 18, 2020
20a092f
core/rawdb: fix freezer table test error check
meowsbits Mar 18, 2020
6283391
core/rawdb: improve table database (#20703)
rjl493456442 Mar 18, 2020
dc6e98d
eth: when triggering a sync, check the head header TD, not block
karalabe Mar 18, 2020
4655b60
Merge pull request #20780 from karalabe/fix-eth-mine-sync-race
karalabe Mar 18, 2020
e6ca195
internal/web3ext: fix clique console apis to work on missing arguments
karalabe Mar 18, 2020
36e93d2
Merge pull request #20779 from meowsbits/patch-3
karalabe Mar 18, 2020
0e6ea91
Merge pull request #20781 from karalabe/fix-clique-console-apis
karalabe Mar 19, 2020
e943f07
whisper/whisperv6: delete failing tests (#20788)
gballet Mar 20, 2020
93ffb85
rpc: dont log an error if user configures --rpcapi=rpc... (#20776)
meowsbits Mar 21, 2020
074efe6
core: fix two snapshot iterator flaws, decollide snap storage prefix
holiman Mar 6, 2020
613af7c
Merge pull request #20152 from karalabe/snapshot-5
karalabe Mar 23, 2020
a75c061
core/blockchain: simplify atomic store after writeBlockWithState (#20…
meowsbits Mar 23, 2020
0734c4b
node, cmd/clef: report actual port used for http rpc (#20789)
holiman Mar 23, 2020
39f5023
internal/ethapi: don't set sender-balance to maxuint, fixes #16999 (#…
holiman Mar 23, 2020
42e02ac
metrics: disable CPU stats (gosigar) on iOS
karalabe Mar 26, 2020
4690912
Merge pull request #20816 from karalabe/disable-gosigar-ios
karalabe Mar 26, 2020
1583e7d
cmd/devp2p: tweak DNS TTLs (#20801)
fjl Mar 26, 2020
87a411b
cmd/devp2p: lower route53 change limit again (#20819)
fjl Mar 26, 2020
d3c1e65
cmd/devp2p: be very correct about route53 change splitting (#20820)
fjl Mar 26, 2020
d7851e6
graphql, node, rpc: fix typos in comments (#20824)
renaynay Mar 27, 2020
d6c5f24
eth: improve shutdown synchronization (#20695)
fjl Mar 27, 2020
62cd943
les: fix dead lock (#20828)
rjl493456442 Mar 27, 2020
5d7e5b0
eth/filters: fix typo on unindexedLogs function's comment (#20827)
hadv Mar 27, 2020
55a73f5
core: bump txpool tx max size to 128KB
holiman Mar 30, 2020
84f4975
Merge pull request #20835 from holiman/bump
karalabe Mar 30, 2020
76eed9e
snapshotter/tests: verify snapdb post-state against trie (#20812)
holiman Mar 31, 2020
8f05cfa
cmd, consensus: add option to disable mmap for DAG caches/datasets (#…
de1acr0ix Mar 31, 2020
c56f4fa
cmd/clef: add newaccount command (#20782)
holiman Mar 31, 2020
03fe9de
eth: add debug_accountRange API (#19645)
jsvisa Mar 31, 2020
300c35b
travis: allow cocoapods deploy to fail (#20833)
adamschmideg Mar 31, 2020
3b69c14
whisper/whisperv6: decrease pow requirement in tests (#20815)
holiman Mar 31, 2020
32d31c3
metrics: improve TestTimerFunc (#20818)
holiman Mar 31, 2020
f78ffc0
les: create utilities as common package (#20509)
rjl493456442 Mar 31, 2020
f0be151
README: update private network genesis spec with istanbul (#20841)
shoenseiwaso Mar 31, 2020
a5a9fea
whisper: fix whisper go routine leak with sync wait group (#20844)
ucwong Apr 1, 2020
d56dc03
cmd/evm: Rework execution stats (#20792)
chfast Apr 1, 2020
1e2e1b4
cmd/devp2p, cmd/wnode, whisper: add missing calls to Timer.Stop (#20843)
ucwong Apr 1, 2020
bf35e27
p2p/server: add UDP port mapping goroutine to wait group (#20846)
ucwong Apr 1, 2020
f15849c
accounts/abi faster unpacking of int256 (#20850)
MariusVanDerWijden Apr 1, 2020
c87cdd3
p2p/discv5: add missing Timer.Stop calls (#20853)
ucwong Apr 2, 2020
ad4b60e
miner/worker: add missing timer.Stop call (#20857)
ucwong Apr 2, 2020
228a297
cmd/geth: fix bad genesis test (#20860)
holiman Apr 2, 2020
47f7c73
eth/filters: add missing Ticker.Stop call (#20862)
ucwong Apr 2, 2020
66ed58b
eth/fetcher: add missing timer.Stop calls (#20861)
ucwong Apr 2, 2020
4d891f2
les: add missing Ticker.Stop call (#20864)
ucwong Apr 2, 2020
0893ee6
event: add missing timer.Stop call in TestFeed (#20868)
ucwong Apr 2, 2020
53e034c
metrics: add missing calls to Ticker.Stop in tests (#20866)
ucwong Apr 2, 2020
37d6357
ethstats: add missing Ticker.Stop call (#20867)
ucwong Apr 2, 2020
0c359e4
p2p/discv5, p2p/testing: add missing Timer.Stop calls in tests (#20869)
ucwong Apr 2, 2020
f98caba
core: add missing Timer.Stop call in TestLogReorgs (#20870)
ucwong Apr 2, 2020
f7b29ec
rpc: add missing timer.Stop calls in websocket tests (#20863)
ucwong Apr 2, 2020
462ddce
crypto/ecies: improve concatKDF (#20836)
lukechampine Apr 3, 2020
be9172a
rpc: metrics for JSON-RPC method calls (#20847)
rjl493456442 Apr 3, 2020
98eab2d
mobile: use bind.NewKeyedTransactor instead of duplicating (#20888)
MariusVanDerWijden Apr 3, 2020
be6078a
all: fix a bunch of inconsequential goroutine leaks (#20667)
BurtonQin Apr 3, 2020
3cf7d2e
internal/ethapi: add CallArgs.ToMessage method (#20854)
wjmelements Apr 3, 2020
f0b5eb0
eth, les: fix flaky tests (#20897)
rjl493456442 Apr 7, 2020
0bec6a4
cmd/geth: enable metrics for geth import command (#20738)
holiman Apr 7, 2020
8dc8941
core/vm: use a callcontext struct (#20761)
holiman Apr 7, 2020
094996b
docs/audits: add discv5 protocol audits from LA and C53 (#20898)
holiman Apr 7, 2020
6a3daa2
.github: change gitter reference to discord link in issue template (#…
adamschmideg Apr 7, 2020
671f22b
couple of fixes to docs in clef (#20900)
renaynay Apr 7, 2020
b7394d7
p2p/discover: add initial discovery v5 implementation (#20750)
fjl Apr 8, 2020
c8e9a91
build: upgrade to golangci-lint 1.24.0 (#20901)
fjl Apr 8, 2020
6975172
whisper/mailserver : recover corrupt db files before opening (#20891)
ucwong Apr 8, 2020
5065cde
accounts/abi/bind: Refactored topics (#20851)
MariusVanDerWijden Apr 8, 2020
07d909f
node: allow websocket and HTTP on the same port (#20810)
renaynay Apr 8, 2020
fe9ffa5
crypto: improve error messages in LoadECDSA (#20718)
adamschmideg Apr 8, 2020
1bad861
changed date of rpcstack.go since new file (#20904)
renaynay Apr 8, 2020
023b87b
accounts/abi/bind: fixed erroneous filtering of negative ints (#20865)
MariusVanDerWijden Apr 9, 2020
15540ae
cmd: deprecate --testnet, use named networks instead (#20852)
q9f Apr 9, 2020
0851646
les, les/lespay/client: add service value statistics and API (#20837)
zsfelfoldi Apr 9, 2020
5a20cc0
README: update min go version to 1.13 (#20911)
ligi Apr 14, 2020
eb2fd82
travis, appveyor, build, Dockerfile: bump Go to 1.14.2 (#20913)
karalabe Apr 14, 2020
2a836bb
core/rawdb: fix data race between Retrieve and Close (#20919)
MariusVanDerWijden Apr 14, 2020
00064dd
accounts/abi: implement new fallback functions (#20764)
rjl493456442 Apr 15, 2020
6402c42
all: simplify and fix database iteration with prefix/start (#20808)
holiman Apr 15, 2020
d77d35a
params: update CHTs for the 1.9.13 release
karalabe Apr 15, 2020
359d9c3
Merge pull request #20925 from karalabe/cht-1.9.13
karalabe Apr 15, 2020
cbc4ac2
params: release Geth v1.9.13
karalabe Apr 16, 2020
ea9eda5
backup
ricardolyn Feb 9, 2021
0cdce11
Merge branch 'public_master' into upgrade/go-ethereum/v1.9.13-2021204…
ricardolyn Feb 9, 2021
e54fc49
fix: apply valid test cases for core/genesis_test.go, that should wor…
ricardolyn Feb 9, 2021
f95ea04
lint: fix lint issues
ricardolyn Feb 9, 2021
712bfcc
Merge branch 'master' into upgrade/go-ethereum/v1.9.13-2021204155332
ricardolyn Feb 9, 2021
29dd4ef
test: fix TestTransactionAllowedTxSize by using the custom transactio…
ricardolyn Feb 9, 2021
78f1334
lint: increase timeout
ricardolyn Feb 9, 2021
9cb6332
Merge branch 'master' of github.com:ConsenSys/quorum into upgrade/go-…
ricardolyn Feb 10, 2021
8420dd2
Merge branch 'master' into upgrade/go-ethereum/v1.9.13-2021204155332
ricardolyn Feb 10, 2021
15c2473
improvement: Created NewDual function to create pub and priv state at…
ricardolyn Feb 10, 2021
151602e
workflow: add 2 new AT
ricardolyn Feb 10, 2021
695ed71
workflow: remove extra ATs
ricardolyn Feb 11, 2021
1171737
fix: comments from review
ricardolyn Feb 12, 2021
1f871ab
Merge branch 'public_master' into upgrade/go-ethereum/v1.9.13-2021204…
ricardolyn Feb 12, 2021
e87075f
fix: tests and build issues
ricardolyn Feb 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
eth: improve shutdown synchronization (#20695)
* eth: improve shutdown synchronization

Most goroutines started by eth.Ethereum didn't have any shutdown sync at
all, which lead to weird error messages when quitting the client.

This change improves the clean shutdown path by stopping all internal
components in dependency order and waiting for them to actually be
stopped before shutdown is considered done. In particular, we now stop
everything related to peers before stopping 'resident' parts such as
core.BlockChain.

* eth: rewrite sync controller

* eth: remove sync start debug message

* eth: notify chainSyncer about new peers after handshake

* eth: move downloader.Cancel call into chainSyncer

* eth: make post-sync block broadcast synchronous

* eth: add comments

* core: change blockchain stop message

* eth: change closeBloomHandler channel type
  • Loading branch information
fjl authored Mar 27, 2020
commit d6c5f2417c03e802f312d86fc40f33b53803c3eb
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ func (bc *BlockChain) Stop() {
log.Error("Dangling trie nodes after full cleanup")
}
}
log.Info("Blockchain manager stopped")
log.Info("Blockchain stopped")
}

func (bc *BlockChain) procFutureBlocks() {
Expand Down
44 changes: 22 additions & 22 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ type LesServer interface {
type Ethereum struct {
config *Config

// Channel for shutting down the service
shutdownChan chan bool

// Handlers
txPool *core.TxPool
blockchain *core.BlockChain
Expand All @@ -84,8 +81,9 @@ type Ethereum struct {
engine consensus.Engine
accountManager *accounts.Manager

bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports
bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports
closeBloomHandler chan struct{}

APIBackend *EthAPIBackend

Expand Down Expand Up @@ -145,17 +143,17 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
log.Info("Initialised chain configuration", "config", chainConfig)

eth := &Ethereum{
config: config,
chainDb: chainDb,
eventMux: ctx.EventMux,
accountManager: ctx.AccountManager,
engine: CreateConsensusEngine(ctx, chainConfig, &config.Ethash, config.Miner.Notify, config.Miner.Noverify, chainDb),
shutdownChan: make(chan bool),
networkID: config.NetworkId,
gasPrice: config.Miner.GasPrice,
etherbase: config.Miner.Etherbase,
bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms),
config: config,
chainDb: chainDb,
eventMux: ctx.EventMux,
accountManager: ctx.AccountManager,
engine: CreateConsensusEngine(ctx, chainConfig, &config.Ethash, config.Miner.Notify, config.Miner.Noverify, chainDb),
closeBloomHandler: make(chan struct{}),
networkID: config.NetworkId,
gasPrice: config.Miner.GasPrice,
etherbase: config.Miner.Etherbase,
bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms),
}

bcVersion := rawdb.ReadDatabaseVersion(chainDb)
Expand Down Expand Up @@ -557,18 +555,20 @@ func (s *Ethereum) Start(srvr *p2p.Server) error {
// Stop implements node.Service, terminating all internal goroutines used by the
// Ethereum protocol.
func (s *Ethereum) Stop() error {
s.bloomIndexer.Close()
s.blockchain.Stop()
s.engine.Close()
// Stop all the peer-related stuff first.
s.protocolManager.Stop()
if s.lesServer != nil {
s.lesServer.Stop()
}

// Then stop everything else.
s.bloomIndexer.Close()
close(s.closeBloomHandler)
s.txPool.Stop()
s.miner.Stop()
s.eventMux.Stop()

s.blockchain.Stop()
s.engine.Close()
s.chainDb.Close()
close(s.shutdownChan)
s.eventMux.Stop()
return nil
}
2 changes: 1 addition & 1 deletion eth/bloombits.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (eth *Ethereum) startBloomHandlers(sectionSize uint64) {
go func() {
for {
select {
case <-eth.shutdownChan:
case <-eth.closeBloomHandler:
return

case request := <-eth.bloomRequests:
Expand Down
95 changes: 46 additions & 49 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@ type ProtocolManager struct {
whitelist map[uint64]common.Hash

// channels for fetcher, syncer, txsyncLoop
newPeerCh chan *peer
txsyncCh chan *txsync
quitSync chan struct{}
noMorePeers chan struct{}
txsyncCh chan *txsync
quitSync chan struct{}

// wait group is used for graceful shutdowns during downloading
// and processing
wg sync.WaitGroup
chainSync *chainSyncer
wg sync.WaitGroup
peerWG sync.WaitGroup

// Test fields or hooks
broadcastTxAnnouncesOnly bool // Testing field, disable transaction propagation
Expand All @@ -105,18 +103,17 @@ type ProtocolManager struct {
func NewProtocolManager(config *params.ChainConfig, checkpoint *params.TrustedCheckpoint, mode downloader.SyncMode, networkID uint64, mux *event.TypeMux, txpool txPool, engine consensus.Engine, blockchain *core.BlockChain, chaindb ethdb.Database, cacheLimit int, whitelist map[uint64]common.Hash) (*ProtocolManager, error) {
// Create the protocol manager with the base fields
manager := &ProtocolManager{
networkID: networkID,
forkFilter: forkid.NewFilter(blockchain),
eventMux: mux,
txpool: txpool,
blockchain: blockchain,
peers: newPeerSet(),
whitelist: whitelist,
newPeerCh: make(chan *peer),
noMorePeers: make(chan struct{}),
txsyncCh: make(chan *txsync),
quitSync: make(chan struct{}),
networkID: networkID,
forkFilter: forkid.NewFilter(blockchain),
eventMux: mux,
txpool: txpool,
blockchain: blockchain,
peers: newPeerSet(),
whitelist: whitelist,
txsyncCh: make(chan *txsync),
quitSync: make(chan struct{}),
}

if mode == downloader.FullSync {
// The database seems empty as the current block is the genesis. Yet the fast
// block is ahead, so fast sync was enabled for this node at a certain point.
Expand All @@ -140,6 +137,7 @@ func NewProtocolManager(config *params.ChainConfig, checkpoint *params.TrustedCh
manager.fastSync = uint32(1)
}
}

// If we have trusted checkpoints, enforce them on the chain
if checkpoint != nil {
manager.checkpointNumber = (checkpoint.SectionIndex+1)*params.CHTFrequency - 1
Expand Down Expand Up @@ -199,6 +197,8 @@ func NewProtocolManager(config *params.ChainConfig, checkpoint *params.TrustedCh
}
manager.txFetcher = fetcher.NewTxFetcher(txpool.Has, txpool.AddRemotes, fetchTx)

manager.chainSync = newChainSyncer(manager)

return manager, nil
}

Expand All @@ -213,15 +213,7 @@ func (pm *ProtocolManager) makeProtocol(version uint) p2p.Protocol {
Version: version,
Length: length,
Run: func(p *p2p.Peer, rw p2p.MsgReadWriter) error {
peer := pm.newPeer(int(version), p, rw, pm.txpool.Get)
select {
case pm.newPeerCh <- peer:
pm.wg.Add(1)
defer pm.wg.Done()
return pm.handle(peer)
case <-pm.quitSync:
return p2p.DiscQuitting
}
return pm.runPeer(pm.newPeer(int(version), p, rw, pm.txpool.Get))
},
NodeInfo: func() interface{} {
return pm.NodeInfo()
Expand Down Expand Up @@ -260,40 +252,37 @@ func (pm *ProtocolManager) Start(maxPeers int) {
pm.maxPeers = maxPeers

// broadcast transactions
pm.wg.Add(1)
pm.txsCh = make(chan core.NewTxsEvent, txChanSize)
pm.txsSub = pm.txpool.SubscribeNewTxsEvent(pm.txsCh)
go pm.txBroadcastLoop()

// broadcast mined blocks
pm.wg.Add(1)
pm.minedBlockSub = pm.eventMux.Subscribe(core.NewMinedBlockEvent{})
go pm.minedBroadcastLoop()

// start sync handlers
go pm.syncer()
pm.wg.Add(2)
go pm.chainSync.loop()
go pm.txsyncLoop64() // TODO(karalabe): Legacy initial tx echange, drop with eth/64.
}

func (pm *ProtocolManager) Stop() {
log.Info("Stopping Ethereum protocol")

pm.txsSub.Unsubscribe() // quits txBroadcastLoop
pm.minedBlockSub.Unsubscribe() // quits blockBroadcastLoop

// Quit the sync loop.
// After this send has completed, no new peers will be accepted.
pm.noMorePeers <- struct{}{}

// Quit fetcher, txsyncLoop.
// Quit chainSync and txsync64.
// After this is done, no new peers will be accepted.
close(pm.quitSync)
pm.wg.Wait()

// Disconnect existing sessions.
// This also closes the gate for any new registrations on the peer set.
// sessions which are already established but not added to pm.peers yet
// will exit when they try to register.
pm.peers.Close()

// Wait for all peer handler goroutines and the loops to come down.
pm.wg.Wait()
pm.peerWG.Wait()

log.Info("Ethereum protocol stopped")
}
Expand All @@ -302,6 +291,15 @@ func (pm *ProtocolManager) newPeer(pv int, p *p2p.Peer, rw p2p.MsgReadWriter, ge
return newPeer(pv, p, rw, getPooledTx)
}

func (pm *ProtocolManager) runPeer(p *peer) error {
if !pm.chainSync.handlePeerEvent(p) {
return p2p.DiscQuitting
}
pm.peerWG.Add(1)
defer pm.peerWG.Done()
return pm.handle(p)
}

// handle is the callback invoked to manage the life cycle of an eth peer. When
// this function terminates, the peer is disconnected.
func (pm *ProtocolManager) handle(p *peer) error {
Expand All @@ -323,6 +321,7 @@ func (pm *ProtocolManager) handle(p *peer) error {
p.Log().Debug("Ethereum handshake failed", "err", err)
return err
}

// Register the peer locally
if err := pm.peers.Register(p); err != nil {
p.Log().Error("Ethereum peer registration failed", "err", err)
Expand All @@ -334,6 +333,8 @@ func (pm *ProtocolManager) handle(p *peer) error {
if err := pm.downloader.RegisterPeer(p.id, p.version, p); err != nil {
return err
}
pm.chainSync.handlePeerEvent(p)

// Propagate existing transactions. new transactions appearing
// after this will be sent via broadcasts.
pm.syncTransactions(p)
Expand Down Expand Up @@ -723,14 +724,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
// Update the peer's total difficulty if better than the previous
if _, td := p.Head(); trueTD.Cmp(td) > 0 {
p.SetHead(trueHead, trueTD)

// Schedule a sync if above ours. Note, this will not fire a sync for a gap of
// a single block (as the true TD is below the propagated block), however this
// scenario should easily be covered by the fetcher.
currentHeader := pm.blockchain.CurrentHeader()
if trueTD.Cmp(pm.blockchain.GetTd(currentHeader.Hash(), currentHeader.Number.Uint64())) > 0 {
go pm.synchronise(p)
}
pm.chainSync.handlePeerEvent(p)
}

case msg.Code == NewPooledTransactionHashesMsg && p.version >= eth65:
Expand Down Expand Up @@ -883,9 +877,10 @@ func (pm *ProtocolManager) BroadcastTransactions(txs types.Transactions, propaga
}
}

// Mined broadcast loop
// minedBroadcastLoop sends mined blocks to connected peers.
func (pm *ProtocolManager) minedBroadcastLoop() {
// automatically stops if unsubscribe
defer pm.wg.Done()

for obj := range pm.minedBlockSub.Chan() {
if ev, ok := obj.Data.(core.NewMinedBlockEvent); ok {
pm.BroadcastBlock(ev.Block, true) // First propagate block to peers
Expand All @@ -894,7 +889,10 @@ func (pm *ProtocolManager) minedBroadcastLoop() {
}
}

// txBroadcastLoop announces new transactions to connected peers.
func (pm *ProtocolManager) txBroadcastLoop() {
defer pm.wg.Done()

for {
select {
case event := <-pm.txsCh:
Expand All @@ -906,7 +904,6 @@ func (pm *ProtocolManager) txBroadcastLoop() {
pm.BroadcastTransactions(event.Txs, true) // First propagate transactions to peers
pm.BroadcastTransactions(event.Txs, false) // Only then announce to the rest

// Err() channel will be closed when unsubscribing.
case <-pm.txsSub.Err():
return
}
Expand Down
15 changes: 3 additions & 12 deletions eth/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,14 @@ func newTestPeer(name string, version int, pm *ProtocolManager, shake bool) (*te
// Create a message pipe to communicate through
app, net := p2p.MsgPipe()

// Generate a random id and create the peer
// Start the peer on a new thread
var id enode.ID
rand.Read(id[:])

peer := pm.newPeer(version, p2p.NewPeer(id, name, nil), net, pm.txpool.Get)

// Start the peer on a new thread
errc := make(chan error, 1)
go func() {
select {
case pm.newPeerCh <- peer:
errc <- pm.handle(peer)
case <-pm.quitSync:
errc <- p2p.DiscQuitting
}
}()
go func() { errc <- pm.runPeer(peer) }()
tp := &testPeer{app: app, net: net, peer: peer}

// Execute any implicitly requested handshakes and return
if shake {
var (
Expand Down
2 changes: 1 addition & 1 deletion eth/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func testSyncTransaction(t *testing.T, propagtion bool) {
go pmFetcher.handle(pmFetcher.newPeer(65, p2p.NewPeer(enode.ID{}, "fetcher", nil), io1, pmFetcher.txpool.Get))

time.Sleep(250 * time.Millisecond)
pmFetcher.synchronise(pmFetcher.peers.BestPeer())
pmFetcher.doSync(peerToSyncOp(downloader.FullSync, pmFetcher.peers.BestPeer()))
atomic.StoreUint32(&pmFetcher.acceptTxs, 1)

newTxs := make(chan core.NewTxsEvent, 1024)
Expand Down
Loading