aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
Diffstat (limited to 'eth')
-rw-r--r--eth/backend.go28
-rw-r--r--eth/handler.go18
-rw-r--r--eth/peer.go4
3 files changed, 20 insertions, 30 deletions
diff --git a/eth/backend.go b/eth/backend.go
index 391a610e3..9c661ad54 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -41,7 +41,6 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
- "github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
@@ -267,42 +266,21 @@ func New(config *Config) (*Ethereum, error) {
return nil, fmt.Errorf("blockchain db err: %v", err)
}
if db, ok := blockDb.(*ethdb.LDBDatabase); ok {
- db.GetTimer = metrics.NewTimer("eth/db/block/user/gets")
- db.PutTimer = metrics.NewTimer("eth/db/block/user/puts")
- db.MissMeter = metrics.NewMeter("eth/db/block/user/misses")
- db.ReadMeter = metrics.NewMeter("eth/db/block/user/reads")
- db.WriteMeter = metrics.NewMeter("eth/db/block/user/writes")
- db.CompTimeMeter = metrics.NewMeter("eth/db/block/compact/time")
- db.CompReadMeter = metrics.NewMeter("eth/db/block/compact/input")
- db.CompWriteMeter = metrics.NewMeter("eth/db/block/compact/output")
+ db.Meter("eth/db/block/")
}
stateDb, err := newdb(filepath.Join(config.DataDir, "state"))
if err != nil {
return nil, fmt.Errorf("state db err: %v", err)
}
if db, ok := stateDb.(*ethdb.LDBDatabase); ok {
- db.GetTimer = metrics.NewTimer("eth/db/state/user/gets")
- db.PutTimer = metrics.NewTimer("eth/db/state/user/puts")
- db.MissMeter = metrics.NewMeter("eth/db/state/user/misses")
- db.ReadMeter = metrics.NewMeter("eth/db/state/user/reads")
- db.WriteMeter = metrics.NewMeter("eth/db/state/user/writes")
- db.CompTimeMeter = metrics.NewMeter("eth/db/state/compact/time")
- db.CompReadMeter = metrics.NewMeter("eth/db/state/compact/input")
- db.CompWriteMeter = metrics.NewMeter("eth/db/state/compact/output")
+ db.Meter("eth/db/state/")
}
extraDb, err := newdb(filepath.Join(config.DataDir, "extra"))
if err != nil {
return nil, fmt.Errorf("extra db err: %v", err)
}
if db, ok := extraDb.(*ethdb.LDBDatabase); ok {
- db.GetTimer = metrics.NewTimer("eth/db/extra/user/gets")
- db.PutTimer = metrics.NewTimer("eth/db/extra/user/puts")
- db.MissMeter = metrics.NewMeter("eth/db/extra/user/misses")
- db.ReadMeter = metrics.NewMeter("eth/db/extra/user/reads")
- db.WriteMeter = metrics.NewMeter("eth/db/extra/user/writes")
- db.CompTimeMeter = metrics.NewMeter("eth/db/extra/compact/time")
- db.CompReadMeter = metrics.NewMeter("eth/db/extra/compact/input")
- db.CompWriteMeter = metrics.NewMeter("eth/db/extra/compact/output")
+ db.Meter("eth/db/extra/")
}
nodeDb := filepath.Join(config.DataDir, "nodes")
diff --git a/eth/handler.go b/eth/handler.go
index bbb251812..50e2ac99b 100644
--- a/eth/handler.go
+++ b/eth/handler.go
@@ -19,6 +19,7 @@ package eth
import (
"fmt"
"math"
+ "math/big"
"sync"
"time"
@@ -412,8 +413,10 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
pm.fetcher.Enqueue(p.id, request.Block)
// TODO: Schedule a sync to cover potential gaps (this needs proto update)
- p.SetTd(request.TD)
- go pm.synchronise(p)
+ if request.TD.Cmp(p.Td()) > 0 {
+ p.SetTd(request.TD)
+ go pm.synchronise(p)
+ }
case TxMsg:
// Transactions arrived, parse all of them and deliver to the pool
@@ -452,9 +455,18 @@ func (pm *ProtocolManager) BroadcastBlock(block *types.Block, propagate bool) {
// If propagation is requested, send to a subset of the peer
if propagate {
+ // Calculate the TD of the block (it's not imported yet, so block.Td is not valid)
+ var td *big.Int
+ if parent := pm.chainman.GetBlock(block.ParentHash()); parent != nil {
+ td = new(big.Int).Add(parent.Td, block.Difficulty())
+ } else {
+ glog.V(logger.Error).Infof("propagating dangling block #%d [%x]", block.NumberU64(), hash[:4])
+ return
+ }
+ // Send the block to a subset of our peers
transfer := peers[:int(math.Sqrt(float64(len(peers))))]
for _, peer := range transfer {
- peer.SendNewBlock(block)
+ peer.SendNewBlock(block, td)
}
glog.V(logger.Detail).Infof("propagated block %x to %d peers in %v", hash[:4], len(transfer), time.Since(block.ReceivedAt))
}
diff --git a/eth/peer.go b/eth/peer.go
index ccd5d3c6f..d70ad4c94 100644
--- a/eth/peer.go
+++ b/eth/peer.go
@@ -167,12 +167,12 @@ func (p *peer) SendNewBlockHashes(hashes []common.Hash) error {
}
// SendNewBlock propagates an entire block to a remote peer.
-func (p *peer) SendNewBlock(block *types.Block) error {
+func (p *peer) SendNewBlock(block *types.Block, td *big.Int) error {
propBlockOutPacketsMeter.Mark(1)
propBlockOutTrafficMeter.Mark(block.Size().Int64())
p.knownBlocks.Add(block.Hash())
- return p2p.Send(p.rw, NewBlockMsg, []interface{}{block, block.Td})
+ return p2p.Send(p.rw, NewBlockMsg, []interface{}{block, td})
}
// RequestHashes fetches a batch of hashes from a peer, starting at from, going