Skip to content

Commit 6ec13e7

Browse files
committed
Merge pull request #1701 from karalabe/eth62-sync-rebase
eth: implement eth/62 synchronization logic
2 parents 79b644c + 17f65cd commit 6ec13e7

23 files changed

+3347
-1274
lines changed

cmd/geth/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
283283
utils.DataDirFlag,
284284
utils.BlockchainVersionFlag,
285285
utils.OlympicFlag,
286+
utils.EthVersionFlag,
286287
utils.CacheFlag,
287288
utils.JSpathFlag,
288289
utils.ListenPortFlag,
@@ -333,6 +334,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
333334
app.Before = func(ctx *cli.Context) error {
334335
utils.SetupLogger(ctx)
335336
utils.SetupVM(ctx)
337+
utils.SetupEth(ctx)
336338
if ctx.GlobalBool(utils.PProfEanbledFlag.Name) {
337339
utils.StartPProf(ctx)
338340
}

cmd/geth/monitorcmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func updateChart(metric string, data []float64, base *int, chart *termui.LineCha
289289
}
290290
}
291291
unit, scale := 0, 1.0
292-
for high >= 1000 {
292+
for high >= 1000 && unit+1 < len(dataUnits) {
293293
high, unit, scale = high/1000, unit+1, scale*1000
294294
}
295295
// If the unit changes, re-create the chart (hack to set max height...)

cmd/utils/flags.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ var (
138138
Name: "olympic",
139139
Usage: "Use olympic style protocol",
140140
}
141+
EthVersionFlag = cli.IntFlag{
142+
Name: "eth",
143+
Value: 62,
144+
Usage: "Highest eth protocol to advertise (temporary, dev option)",
145+
}
141146

142147
// miner settings
143148
MinerThreadsFlag = cli.IntFlag{
@@ -459,6 +464,18 @@ func SetupVM(ctx *cli.Context) {
459464
vm.SetJITCacheSize(ctx.GlobalInt(VMJitCacheFlag.Name))
460465
}
461466

467+
// SetupEth configures the eth packages global settings
468+
func SetupEth(ctx *cli.Context) {
469+
version := ctx.GlobalInt(EthVersionFlag.Name)
470+
for len(eth.ProtocolVersions) > 0 && eth.ProtocolVersions[0] > uint(version) {
471+
eth.ProtocolVersions = eth.ProtocolVersions[1:]
472+
eth.ProtocolLengths = eth.ProtocolLengths[1:]
473+
}
474+
if len(eth.ProtocolVersions) == 0 {
475+
Fatalf("No valid eth protocols remaining")
476+
}
477+
}
478+
462479
// MakeChain creates a chain manager from set command line flags.
463480
func MakeChain(ctx *cli.Context) (chain *core.ChainManager, chainDb common.Database) {
464481
datadir := ctx.GlobalString(DataDirFlag.Name)

core/types/block.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,20 @@ func (b *Block) WithMiningResult(nonce uint64, mixDigest common.Hash) *Block {
360360
}
361361
}
362362

363+
// WithBody returns a new block with the given transaction and uncle contents.
364+
func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block {
365+
block := &Block{
366+
header: copyHeader(b.header),
367+
transactions: make([]*Transaction, len(transactions)),
368+
uncles: make([]*Header, len(uncles)),
369+
}
370+
copy(block.transactions, transactions)
371+
for i := range uncles {
372+
block.uncles[i] = copyHeader(uncles[i])
373+
}
374+
return block
375+
}
376+
363377
// Implement pow.Block
364378

365379
func (b *Block) Hash() common.Hash {

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ func New(config *Config) (*Ethereum, error) {
373373

374374
eth.blockProcessor = core.NewBlockProcessor(chainDb, eth.pow, eth.chainManager, eth.EventMux())
375375
eth.chainManager.SetProcessor(eth.blockProcessor)
376-
eth.protocolManager = NewProtocolManager(config.NetworkId, eth.eventMux, eth.txPool, eth.pow, eth.chainManager)
376+
eth.protocolManager = NewProtocolManager(config.NetworkId, eth.eventMux, eth.txPool, eth.pow, eth.chainManager, chainDb)
377377

378378
eth.miner = miner.New(eth, eth.EventMux(), eth.pow)
379379
eth.miner.SetGasPrice(config.GasPrice)

0 commit comments

Comments
 (0)