Skip to content

Commit aa0538d

Browse files
committed
eth: clean out light node notions from eth
1 parent a9d8dfc commit aa0538d

File tree

9 files changed

+39
-106
lines changed

9 files changed

+39
-106
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
304304
utils.DataDirFlag,
305305
utils.BlockchainVersionFlag,
306306
utils.OlympicFlag,
307-
utils.EthModeFlag,
308-
utils.EthVersionFlag,
307+
utils.FastSyncFlag,
309308
utils.CacheFlag,
310309
utils.JSpathFlag,
311310
utils.ListenPortFlag,
@@ -361,7 +360,6 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
361360
utils.SetupLogger(ctx)
362361
utils.SetupNetwork(ctx)
363362
utils.SetupVM(ctx)
364-
utils.SetupEth(ctx)
365363
if ctx.GlobalBool(utils.PProfEanbledFlag.Name) {
366364
utils.StartPProf(ctx)
367365
}

cmd/utils/flags.go

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"path/filepath"
2929
"runtime"
3030
"strconv"
31-
"strings"
3231

3332
"github.com/codegangsta/cli"
3433
"github.com/ethereum/ethash"
@@ -149,15 +148,9 @@ var (
149148
Name: "olympic",
150149
Usage: "Use olympic style protocol",
151150
}
152-
EthModeFlag = cli.StringFlag{
153-
Name: "mode",
154-
Value: "archive",
155-
Usage: "Client mode of operation (archive, full, light)",
156-
}
157-
EthVersionFlag = cli.IntFlag{
158-
Name: "eth",
159-
Value: 63,
160-
Usage: "Highest eth protocol to advertise (temporary, dev option)",
151+
FastSyncFlag = cli.BoolFlag{
152+
Name: "fast",
153+
Usage: "Enables fast syncing through state downloads",
161154
}
162155

163156
// miner settings
@@ -431,25 +424,13 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
431424
if err != nil {
432425
glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default")
433426
}
434-
// Resolve the mode of opeation from the string flag
435-
var clientMode eth.Mode
436-
switch strings.ToLower(ctx.GlobalString(EthModeFlag.Name)) {
437-
case "archive":
438-
clientMode = eth.ArchiveMode
439-
case "full":
440-
clientMode = eth.FullMode
441-
case "light":
442-
clientMode = eth.LightMode
443-
default:
444-
glog.Fatalf("Unknown node type requested: %s", ctx.GlobalString(EthModeFlag.Name))
445-
}
446427
// Assemble the entire eth configuration and return
447428
cfg := &eth.Config{
448429
Name: common.MakeName(clientID, version),
449430
DataDir: MustDataDir(ctx),
450431
GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name),
451432
GenesisFile: ctx.GlobalString(GenesisFileFlag.Name),
452-
Mode: clientMode,
433+
FastSync: ctx.GlobalBool(FastSyncFlag.Name),
453434
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
454435
DatabaseCache: ctx.GlobalInt(CacheFlag.Name),
455436
SkipBcVersionCheck: false,
@@ -550,18 +531,6 @@ func SetupVM(ctx *cli.Context) {
550531
vm.SetJITCacheSize(ctx.GlobalInt(VMJitCacheFlag.Name))
551532
}
552533

553-
// SetupEth configures the eth packages global settings
554-
func SetupEth(ctx *cli.Context) {
555-
version := ctx.GlobalInt(EthVersionFlag.Name)
556-
for len(eth.ProtocolVersions) > 0 && eth.ProtocolVersions[0] > uint(version) {
557-
eth.ProtocolVersions = eth.ProtocolVersions[1:]
558-
eth.ProtocolLengths = eth.ProtocolLengths[1:]
559-
}
560-
if len(eth.ProtocolVersions) == 0 {
561-
Fatalf("No valid eth protocols remaining")
562-
}
563-
}
564-
565534
// MakeChain creates a chain manager from set command line flags.
566535
func MakeChain(ctx *cli.Context) (chain *core.BlockChain, chainDb ethdb.Database) {
567536
datadir := MustDataDir(ctx)

eth/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ type Config struct {
8888
GenesisNonce int
8989
GenesisFile string
9090
GenesisBlock *types.Block // used by block tests
91+
FastSync bool
9192
Olympic bool
92-
Mode Mode
9393

9494
BlockChainVersion int
9595
SkipBcVersionCheck bool // e.g. blockchain export
@@ -399,7 +399,7 @@ func New(config *Config) (*Ethereum, error) {
399399

400400
eth.blockProcessor = core.NewBlockProcessor(chainDb, eth.pow, eth.blockchain, eth.EventMux())
401401
eth.blockchain.SetProcessor(eth.blockProcessor)
402-
if eth.protocolManager, err = NewProtocolManager(config.Mode, config.NetworkId, eth.eventMux, eth.txPool, eth.pow, eth.blockchain, chainDb); err != nil {
402+
if eth.protocolManager, err = NewProtocolManager(config.FastSync, config.NetworkId, eth.eventMux, eth.txPool, eth.pow, eth.blockchain, chainDb); err != nil {
403403
return nil, err
404404
}
405405
eth.miner = miner.New(eth, eth.EventMux(), eth.pow)

eth/downloader/queue.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,12 @@ func (q *queue) ReserveNodeData(p *peer, count int) *fetchRequest {
422422
q.stateSchedLock.Lock()
423423
defer q.stateSchedLock.Unlock()
424424

425-
for _, hash := range q.stateScheduler.Missing(max) {
426-
q.stateTaskPool[hash] = q.stateTaskIndex
427-
q.stateTaskQueue.Push(hash, -float32(q.stateTaskIndex))
428-
q.stateTaskIndex++
425+
if q.stateScheduler != nil {
426+
for _, hash := range q.stateScheduler.Missing(max) {
427+
q.stateTaskPool[hash] = q.stateTaskIndex
428+
q.stateTaskQueue.Push(hash, -float32(q.stateTaskIndex))
429+
q.stateTaskIndex++
430+
}
429431
}
430432
}
431433
return q.reserveHashes(p, count, q.stateTaskQueue, generator, q.statePendPool, count)

eth/handler.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type hashFetcherFn func(common.Hash) error
5555
type blockFetcherFn func([]common.Hash) error
5656

5757
type ProtocolManager struct {
58-
mode Mode
58+
fastSync bool
5959
txpool txPool
6060
blockchain *core.BlockChain
6161
chaindb ethdb.Database
@@ -83,10 +83,10 @@ type ProtocolManager struct {
8383

8484
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
8585
// with the ethereum network.
86-
func NewProtocolManager(mode Mode, networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, blockchain *core.BlockChain, chaindb ethdb.Database) (*ProtocolManager, error) {
86+
func NewProtocolManager(fastSync bool, networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, blockchain *core.BlockChain, chaindb ethdb.Database) (*ProtocolManager, error) {
8787
// Create the protocol manager with the base fields
8888
manager := &ProtocolManager{
89-
mode: mode,
89+
fastSync: fastSync,
9090
eventMux: mux,
9191
txpool: txpool,
9292
blockchain: blockchain,
@@ -100,7 +100,7 @@ func NewProtocolManager(mode Mode, networkId int, mux *event.TypeMux, txpool txP
100100
manager.SubProtocols = make([]p2p.Protocol, 0, len(ProtocolVersions))
101101
for i, version := range ProtocolVersions {
102102
// Skip protocol version if incompatible with the mode of operation
103-
if minimumProtocolVersion[mode] > version {
103+
if fastSync && version < eth63 {
104104
continue
105105
}
106106
// Compatible, initialize the sub-protocol
@@ -120,14 +120,9 @@ func NewProtocolManager(mode Mode, networkId int, mux *event.TypeMux, txpool txP
120120
return nil, errIncompatibleConfig
121121
}
122122
// Construct the different synchronisation mechanisms
123-
var syncMode downloader.SyncMode
124-
switch mode {
125-
case ArchiveMode:
126-
syncMode = downloader.FullSync
127-
case FullMode:
123+
syncMode := downloader.FullSync
124+
if fastSync {
128125
syncMode = downloader.FastSync
129-
case LightMode:
130-
syncMode = downloader.LightSync
131126
}
132127
manager.downloader = downloader.New(syncMode, chaindb, manager.eventMux, blockchain.HasHeader, blockchain.HasBlock, blockchain.GetHeader,
133128
blockchain.GetBlock, blockchain.CurrentHeader, blockchain.CurrentBlock, blockchain.CurrentFastBlock, blockchain.FastSyncCommitHead,

eth/handler_test.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ func TestProtocolCompatibility(t *testing.T) {
2222
// Define the compatibility chart
2323
tests := []struct {
2424
version uint
25-
mode Mode
25+
fastSync bool
2626
compatible bool
2727
}{
28-
{61, ArchiveMode, true}, {62, ArchiveMode, true}, {63, ArchiveMode, true}, {64, ArchiveMode, true},
29-
{61, FullMode, false}, {62, FullMode, false}, {63, FullMode, true}, {64, FullMode, true},
30-
{61, LightMode, false}, {62, LightMode, false}, {63, LightMode, false}, {64, LightMode, true},
28+
{61, false, true}, {62, false, true}, {63, false, true},
29+
{61, true, false}, {62, true, false}, {63, true, true},
3130
}
3231
// Make sure anything we screw up is restored
3332
backup := ProtocolVersions
@@ -37,7 +36,7 @@ func TestProtocolCompatibility(t *testing.T) {
3736
for i, tt := range tests {
3837
ProtocolVersions = []uint{tt.version}
3938

40-
pm, err := newTestProtocolManager(tt.mode, 0, nil, nil)
39+
pm, err := newTestProtocolManager(tt.fastSync, 0, nil, nil)
4140
if pm != nil {
4241
defer pm.Stop()
4342
}
@@ -52,7 +51,7 @@ func TestProtocolCompatibility(t *testing.T) {
5251
func TestGetBlockHashes61(t *testing.T) { testGetBlockHashes(t, 61) }
5352

5453
func testGetBlockHashes(t *testing.T, protocol int) {
55-
pm := newTestProtocolManagerMust(t, ArchiveMode, downloader.MaxHashFetch+15, nil, nil)
54+
pm := newTestProtocolManagerMust(t, false, downloader.MaxHashFetch+15, nil, nil)
5655
peer, _ := newTestPeer("peer", protocol, pm, true)
5756
defer peer.close()
5857

@@ -95,7 +94,7 @@ func testGetBlockHashes(t *testing.T, protocol int) {
9594
func TestGetBlockHashesFromNumber61(t *testing.T) { testGetBlockHashesFromNumber(t, 61) }
9695

9796
func testGetBlockHashesFromNumber(t *testing.T, protocol int) {
98-
pm := newTestProtocolManagerMust(t, ArchiveMode, downloader.MaxHashFetch+15, nil, nil)
97+
pm := newTestProtocolManagerMust(t, false, downloader.MaxHashFetch+15, nil, nil)
9998
peer, _ := newTestPeer("peer", protocol, pm, true)
10099
defer peer.close()
101100

@@ -135,7 +134,7 @@ func testGetBlockHashesFromNumber(t *testing.T, protocol int) {
135134
func TestGetBlocks61(t *testing.T) { testGetBlocks(t, 61) }
136135

137136
func testGetBlocks(t *testing.T, protocol int) {
138-
pm := newTestProtocolManagerMust(t, ArchiveMode, downloader.MaxHashFetch+15, nil, nil)
137+
pm := newTestProtocolManagerMust(t, false, downloader.MaxHashFetch+15, nil, nil)
139138
peer, _ := newTestPeer("peer", protocol, pm, true)
140139
defer peer.close()
141140

@@ -204,10 +203,9 @@ func testGetBlocks(t *testing.T, protocol int) {
204203
// Tests that block headers can be retrieved from a remote chain based on user queries.
205204
func TestGetBlockHeaders62(t *testing.T) { testGetBlockHeaders(t, 62) }
206205
func TestGetBlockHeaders63(t *testing.T) { testGetBlockHeaders(t, 63) }
207-
func TestGetBlockHeaders64(t *testing.T) { testGetBlockHeaders(t, 64) }
208206

209207
func testGetBlockHeaders(t *testing.T, protocol int) {
210-
pm := newTestProtocolManagerMust(t, ArchiveMode, downloader.MaxHashFetch+15, nil, nil)
208+
pm := newTestProtocolManagerMust(t, false, downloader.MaxHashFetch+15, nil, nil)
211209
peer, _ := newTestPeer("peer", protocol, pm, true)
212210
defer peer.close()
213211

@@ -330,10 +328,9 @@ func testGetBlockHeaders(t *testing.T, protocol int) {
330328
// Tests that block contents can be retrieved from a remote chain based on their hashes.
331329
func TestGetBlockBodies62(t *testing.T) { testGetBlockBodies(t, 62) }
332330
func TestGetBlockBodies63(t *testing.T) { testGetBlockBodies(t, 63) }
333-
func TestGetBlockBodies64(t *testing.T) { testGetBlockBodies(t, 64) }
334331

335332
func testGetBlockBodies(t *testing.T, protocol int) {
336-
pm := newTestProtocolManagerMust(t, ArchiveMode, downloader.MaxBlockFetch+15, nil, nil)
333+
pm := newTestProtocolManagerMust(t, false, downloader.MaxBlockFetch+15, nil, nil)
337334
peer, _ := newTestPeer("peer", protocol, pm, true)
338335
defer peer.close()
339336

@@ -402,7 +399,6 @@ func testGetBlockBodies(t *testing.T, protocol int) {
402399

403400
// Tests that the node state database can be retrieved based on hashes.
404401
func TestGetNodeData63(t *testing.T) { testGetNodeData(t, 63) }
405-
func TestGetNodeData64(t *testing.T) { testGetNodeData(t, 64) }
406402

407403
func testGetNodeData(t *testing.T, protocol int) {
408404
// Define three accounts to simulate transactions with
@@ -440,7 +436,7 @@ func testGetNodeData(t *testing.T, protocol int) {
440436
}
441437
}
442438
// Assemble the test environment
443-
pm := newTestProtocolManagerMust(t, ArchiveMode, 4, generator, nil)
439+
pm := newTestProtocolManagerMust(t, false, 4, generator, nil)
444440
peer, _ := newTestPeer("peer", protocol, pm, true)
445441
defer peer.close()
446442

@@ -492,7 +488,6 @@ func testGetNodeData(t *testing.T, protocol int) {
492488

493489
// Tests that the transaction receipts can be retrieved based on hashes.
494490
func TestGetReceipt63(t *testing.T) { testGetReceipt(t, 63) }
495-
func TestGetReceipt64(t *testing.T) { testGetReceipt(t, 64) }
496491

497492
func testGetReceipt(t *testing.T, protocol int) {
498493
// Define three accounts to simulate transactions with
@@ -530,7 +525,7 @@ func testGetReceipt(t *testing.T, protocol int) {
530525
}
531526
}
532527
// Assemble the test environment
533-
pm := newTestProtocolManagerMust(t, ArchiveMode, 4, generator, nil)
528+
pm := newTestProtocolManagerMust(t, false, 4, generator, nil)
534529
peer, _ := newTestPeer("peer", protocol, pm, true)
535530
defer peer.close()
536531

eth/helper_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var (
2828
// newTestProtocolManager creates a new protocol manager for testing purposes,
2929
// with the given number of blocks already known, and potential notification
3030
// channels for different events.
31-
func newTestProtocolManager(mode Mode, blocks int, generator func(int, *core.BlockGen), newtx chan<- []*types.Transaction) (*ProtocolManager, error) {
31+
func newTestProtocolManager(fastSync bool, blocks int, generator func(int, *core.BlockGen), newtx chan<- []*types.Transaction) (*ProtocolManager, error) {
3232
var (
3333
evmux = new(event.TypeMux)
3434
pow = new(core.FakePow)
@@ -42,7 +42,7 @@ func newTestProtocolManager(mode Mode, blocks int, generator func(int, *core.Blo
4242
if _, err := blockchain.InsertChain(chain); err != nil {
4343
panic(err)
4444
}
45-
pm, err := NewProtocolManager(mode, NetworkId, evmux, &testTxPool{added: newtx}, pow, blockchain, db)
45+
pm, err := NewProtocolManager(fastSync, NetworkId, evmux, &testTxPool{added: newtx}, pow, blockchain, db)
4646
if err != nil {
4747
return nil, err
4848
}
@@ -54,8 +54,8 @@ func newTestProtocolManager(mode Mode, blocks int, generator func(int, *core.Blo
5454
// with the given number of blocks already known, and potential notification
5555
// channels for different events. In case of an error, the constructor force-
5656
// fails the test.
57-
func newTestProtocolManagerMust(t *testing.T, mode Mode, blocks int, generator func(int, *core.BlockGen), newtx chan<- []*types.Transaction) *ProtocolManager {
58-
pm, err := newTestProtocolManager(mode, blocks, generator, newtx)
57+
func newTestProtocolManagerMust(t *testing.T, fastSync bool, blocks int, generator func(int, *core.BlockGen), newtx chan<- []*types.Transaction) *ProtocolManager {
58+
pm, err := newTestProtocolManager(fastSync, blocks, generator, newtx)
5959
if err != nil {
6060
t.Fatalf("Failed to create protocol manager: %v", err)
6161
}

eth/protocol.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,18 @@ import (
2626
"github.com/ethereum/go-ethereum/rlp"
2727
)
2828

29-
// Mode represents the mode of operation of the eth client.
30-
type Mode int
31-
32-
const (
33-
ArchiveMode Mode = iota // Maintain the entire blockchain history
34-
FullMode // Maintain only a recent view of the blockchain
35-
LightMode // Don't maintain any history, rather fetch on demand
36-
)
37-
3829
// Constants to match up protocol versions and messages
3930
const (
4031
eth61 = 61
4132
eth62 = 62
4233
eth63 = 63
43-
eth64 = 64
4434
)
4535

46-
// minimumProtocolVersion is the minimum version of the protocol eth must run to
47-
// support the desired mode of operation.
48-
var minimumProtocolVersion = map[Mode]uint{
49-
ArchiveMode: eth61,
50-
FullMode: eth63,
51-
LightMode: eth64,
52-
}
53-
5436
// Supported versions of the eth protocol (first is primary).
55-
var ProtocolVersions = []uint{eth64, eth63, eth62, eth61}
37+
var ProtocolVersions = []uint{eth63, eth62, eth61}
5638

5739
// Number of implemented message corresponding to different protocol versions.
58-
var ProtocolLengths = []uint64{19, 17, 8, 9}
40+
var ProtocolLengths = []uint64{17, 8, 9}
5941

6042
const (
6143
NetworkId = 1
@@ -90,11 +72,6 @@ const (
9072
NodeDataMsg = 0x0e
9173
GetReceiptsMsg = 0x0f
9274
ReceiptsMsg = 0x10
93-
94-
// Protocol messages belonging to eth/64
95-
GetAcctProofMsg = 0x11
96-
GetStorageDataProof = 0x12
97-
Proof = 0x13
9875
)
9976

10077
type errCode int

0 commit comments

Comments
 (0)