From 735b029db95bf72c3105674c0f2b4f111e5ccdf5 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 29 Apr 2015 14:00:24 +0200 Subject: core: return the index of the block that failed when inserting a chain --- eth/downloader/downloader.go | 9 ++++----- eth/handler.go | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'eth') diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index a3917854f..a7e83a532 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -37,7 +37,7 @@ var ( ) type hashCheckFn func(common.Hash) bool -type chainInsertFn func(types.Blocks) error +type chainInsertFn func(types.Blocks) (int, error) type hashIterFn func() (common.Hash, error) type blockPack struct { @@ -432,12 +432,11 @@ func (d *Downloader) process(peer *peer) error { // TODO check for parent error. When there's a parent error we should stop // processing and start requesting the `block.hash` so that it's parent and // grandparents can be requested and queued. - err = d.insertChain(blocks[:max]) + var i int + i, err = d.insertChain(blocks[:max]) if err != nil && core.IsParentErr(err) { - glog.V(logger.Debug).Infoln("Aborting process due to missing parent.") + glog.V(logger.Debug).Infof("Aborting process due to missing parent (%d)\n", i) - // XXX this needs a lot of attention - blocks = nil break } else if err != nil { // immediatly unregister the false peer but do not disconnect diff --git a/eth/handler.go b/eth/handler.go index 61149049e..2dd4c74db 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -376,7 +376,7 @@ func (self *ProtocolManager) handleMsg(p *peer) error { // if the parent exists we process the block and propagate to our peers // if the parent does not exists we delegate to the downloader. if self.chainman.HasBlock(request.Block.ParentHash()) { - if err := self.chainman.InsertChain(types.Blocks{request.Block}); err != nil { + if _, err := self.chainman.InsertChain(types.Blocks{request.Block}); err != nil { // handle error return nil } -- cgit From dfbf580354711af3b542b8c6f5608852d7b90ce3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 29 Apr 2015 14:49:37 +0200 Subject: eth/downloader: ignore orphan blocks in the downloader. When blocks have been sorted and are being processed, orphan blocks should be ignored and thrown out. The protocol handler is responsible for downloading blocks which have missing parents. --- eth/downloader/downloader.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'eth') diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index a7e83a532..81808b4f8 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -418,14 +418,16 @@ func (d *Downloader) process(peer *peer) error { // link). We should at least check whihc queue match. This code could move // to a seperate goroutine where it periodically checks for linked pieces. types.BlockBy(types.Number).Sort(d.queue.blocks) - blocks := d.queue.blocks - if len(blocks) == 0 { + if len(d.queue.blocks) == 0 { return nil } + var ( + blocks = d.queue.blocks + err error + ) glog.V(logger.Debug).Infof("Inserting chain with %d blocks (#%v - #%v)\n", len(blocks), blocks[0].Number(), blocks[len(blocks)-1].Number()) - var err error // Loop untill we're out of blocks for len(blocks) != 0 { max := int(math.Min(float64(len(blocks)), 256)) @@ -435,9 +437,11 @@ func (d *Downloader) process(peer *peer) error { var i int i, err = d.insertChain(blocks[:max]) if err != nil && core.IsParentErr(err) { - glog.V(logger.Debug).Infof("Aborting process due to missing parent (%d)\n", i) + // Ignore the missing blocks. Handler should take care of anything that's missing. + glog.V(logger.Debug).Infof("Ignored block with missing parent (%d)\n", i) + blocks = blocks[i:] - break + continue } else if err != nil { // immediatly unregister the false peer but do not disconnect d.UnregisterPeer(d.activePeer) -- cgit From c9300458344e9024b4d18171f87b7e0edb3b6859 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 29 Apr 2015 15:09:37 +0200 Subject: core: fixed tetst to reflect (int, error) return by insertChain --- eth/downloader/downloader_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'eth') diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index 8843ca0c7..5518163ca 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -62,10 +62,10 @@ func (dl *downloadTester) hasBlock(hash common.Hash) bool { return false } -func (dl *downloadTester) insertChain(blocks types.Blocks) error { +func (dl *downloadTester) insertChain(blocks types.Blocks) (int, error) { dl.insertedBlocks += len(blocks) - return nil + return 0, nil } func (dl *downloadTester) getHashes(hash common.Hash) error { -- cgit From f8c27d7159c3f93f0ca05ab1df86cca98d86e52e Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 29 Apr 2015 19:55:04 +0200 Subject: eth/downloader: drop block --- eth/downloader/downloader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'eth') diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 81808b4f8..4cd927fd5 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -439,7 +439,7 @@ func (d *Downloader) process(peer *peer) error { if err != nil && core.IsParentErr(err) { // Ignore the missing blocks. Handler should take care of anything that's missing. glog.V(logger.Debug).Infof("Ignored block with missing parent (%d)\n", i) - blocks = blocks[i:] + blocks = blocks[i+1:] continue } else if err != nil { -- cgit From 9e63798d0362a27b3ef45345d93f4a01c3349516 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 29 Apr 2015 19:55:30 +0200 Subject: core/types, eth: meassure and display propagation times --- eth/handler.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'eth') diff --git a/eth/handler.go b/eth/handler.go index 2dd4c74db..f7610e9e3 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -346,6 +346,8 @@ func (self *ProtocolManager) handleMsg(p *peer) error { if err := request.Block.ValidateFields(); err != nil { return errResp(ErrDecode, "block validation %v: %v", msg, err) } + request.Block.ReceivedAt = time.Now() + hash := request.Block.Hash() // Add the block hash as a known hash to the peer. This will later be used to determine // who should receive this. @@ -419,7 +421,7 @@ func (pm *ProtocolManager) BroadcastBlock(hash common.Hash, block *types.Block) for _, peer := range peers { peer.sendNewBlock(block) } - glog.V(logger.Detail).Infoln("broadcast block to", len(peers), "peers") + glog.V(logger.Detail).Infoln("broadcast block to", len(peers), "peers. Total propagation time:", time.Since(block.ReceivedAt)) } // BroadcastTx will propagate the block to its connected peers. It will sort -- cgit From 04c209980bdecb848ae6e397e808e62aecaece39 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 29 Apr 2015 22:50:58 +0200 Subject: eth: rely on p2p to determine block propagation --- eth/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'eth') diff --git a/eth/handler.go b/eth/handler.go index f7610e9e3..fecd71632 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -346,7 +346,7 @@ func (self *ProtocolManager) handleMsg(p *peer) error { if err := request.Block.ValidateFields(); err != nil { return errResp(ErrDecode, "block validation %v: %v", msg, err) } - request.Block.ReceivedAt = time.Now() + request.Block.ReceivedAt = msg.ReceivedAt hash := request.Block.Hash() // Add the block hash as a known hash to the peer. This will later be used to determine -- cgit