Skip to content

Commit

Permalink
eth: clean out light node notions from eth
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Oct 19, 2015
1 parent a9d8dfc commit aa0538d
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 106 deletions.
4 changes: 1 addition & 3 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils.DataDirFlag,
utils.BlockchainVersionFlag,
utils.OlympicFlag,
utils.EthModeFlag,
utils.EthVersionFlag,
utils.FastSyncFlag,
utils.CacheFlag,
utils.JSpathFlag,
utils.ListenPortFlag,
Expand Down Expand Up @@ -361,7 +360,6 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils.SetupLogger(ctx)
utils.SetupNetwork(ctx)
utils.SetupVM(ctx)
utils.SetupEth(ctx)
if ctx.GlobalBool(utils.PProfEanbledFlag.Name) {
utils.StartPProf(ctx)
}
Expand Down
39 changes: 4 additions & 35 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"

"github.com/codegangsta/cli"
"github.com/ethereum/ethash"
Expand Down Expand Up @@ -149,15 +148,9 @@ var (
Name: "olympic",
Usage: "Use olympic style protocol",
}
EthModeFlag = cli.StringFlag{
Name: "mode",
Value: "archive",
Usage: "Client mode of operation (archive, full, light)",
}
EthVersionFlag = cli.IntFlag{
Name: "eth",
Value: 63,
Usage: "Highest eth protocol to advertise (temporary, dev option)",
FastSyncFlag = cli.BoolFlag{
Name: "fast",
Usage: "Enables fast syncing through state downloads",
}

// miner settings
Expand Down Expand Up @@ -431,25 +424,13 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
if err != nil {
glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default")
}
// Resolve the mode of opeation from the string flag
var clientMode eth.Mode
switch strings.ToLower(ctx.GlobalString(EthModeFlag.Name)) {
case "archive":
clientMode = eth.ArchiveMode
case "full":
clientMode = eth.FullMode
case "light":
clientMode = eth.LightMode
default:
glog.Fatalf("Unknown node type requested: %s", ctx.GlobalString(EthModeFlag.Name))
}
// Assemble the entire eth configuration and return
cfg := &eth.Config{
Name: common.MakeName(clientID, version),
DataDir: MustDataDir(ctx),
GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name),
GenesisFile: ctx.GlobalString(GenesisFileFlag.Name),
Mode: clientMode,
FastSync: ctx.GlobalBool(FastSyncFlag.Name),
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
DatabaseCache: ctx.GlobalInt(CacheFlag.Name),
SkipBcVersionCheck: false,
Expand Down Expand Up @@ -550,18 +531,6 @@ func SetupVM(ctx *cli.Context) {
vm.SetJITCacheSize(ctx.GlobalInt(VMJitCacheFlag.Name))
}

// SetupEth configures the eth packages global settings
func SetupEth(ctx *cli.Context) {
version := ctx.GlobalInt(EthVersionFlag.Name)
for len(eth.ProtocolVersions) > 0 && eth.ProtocolVersions[0] > uint(version) {
eth.ProtocolVersions = eth.ProtocolVersions[1:]
eth.ProtocolLengths = eth.ProtocolLengths[1:]
}
if len(eth.ProtocolVersions) == 0 {
Fatalf("No valid eth protocols remaining")
}
}

// MakeChain creates a chain manager from set command line flags.
func MakeChain(ctx *cli.Context) (chain *core.BlockChain, chainDb ethdb.Database) {
datadir := MustDataDir(ctx)
Expand Down
4 changes: 2 additions & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ type Config struct {
GenesisNonce int
GenesisFile string
GenesisBlock *types.Block // used by block tests
FastSync bool
Olympic bool
Mode Mode

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

eth.blockProcessor = core.NewBlockProcessor(chainDb, eth.pow, eth.blockchain, eth.EventMux())
eth.blockchain.SetProcessor(eth.blockProcessor)
if eth.protocolManager, err = NewProtocolManager(config.Mode, config.NetworkId, eth.eventMux, eth.txPool, eth.pow, eth.blockchain, chainDb); err != nil {
if eth.protocolManager, err = NewProtocolManager(config.FastSync, config.NetworkId, eth.eventMux, eth.txPool, eth.pow, eth.blockchain, chainDb); err != nil {
return nil, err
}
eth.miner = miner.New(eth, eth.EventMux(), eth.pow)
Expand Down
10 changes: 6 additions & 4 deletions eth/downloader/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,12 @@ func (q *queue) ReserveNodeData(p *peer, count int) *fetchRequest {
q.stateSchedLock.Lock()
defer q.stateSchedLock.Unlock()

for _, hash := range q.stateScheduler.Missing(max) {
q.stateTaskPool[hash] = q.stateTaskIndex
q.stateTaskQueue.Push(hash, -float32(q.stateTaskIndex))
q.stateTaskIndex++
if q.stateScheduler != nil {
for _, hash := range q.stateScheduler.Missing(max) {
q.stateTaskPool[hash] = q.stateTaskIndex
q.stateTaskQueue.Push(hash, -float32(q.stateTaskIndex))
q.stateTaskIndex++
}
}
}
return q.reserveHashes(p, count, q.stateTaskQueue, generator, q.statePendPool, count)
Expand Down
17 changes: 6 additions & 11 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type hashFetcherFn func(common.Hash) error
type blockFetcherFn func([]common.Hash) error

type ProtocolManager struct {
mode Mode
fastSync bool
txpool txPool
blockchain *core.BlockChain
chaindb ethdb.Database
Expand Down Expand Up @@ -83,10 +83,10 @@ type ProtocolManager struct {

// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
// with the ethereum network.
func NewProtocolManager(mode Mode, networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, blockchain *core.BlockChain, chaindb ethdb.Database) (*ProtocolManager, error) {
func NewProtocolManager(fastSync bool, networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, blockchain *core.BlockChain, chaindb ethdb.Database) (*ProtocolManager, error) {
// Create the protocol manager with the base fields
manager := &ProtocolManager{
mode: mode,
fastSync: fastSync,
eventMux: mux,
txpool: txpool,
blockchain: blockchain,
Expand All @@ -100,7 +100,7 @@ func NewProtocolManager(mode Mode, networkId int, mux *event.TypeMux, txpool txP
manager.SubProtocols = make([]p2p.Protocol, 0, len(ProtocolVersions))
for i, version := range ProtocolVersions {
// Skip protocol version if incompatible with the mode of operation
if minimumProtocolVersion[mode] > version {
if fastSync && version < eth63 {
continue
}
// Compatible, initialize the sub-protocol
Expand All @@ -120,14 +120,9 @@ func NewProtocolManager(mode Mode, networkId int, mux *event.TypeMux, txpool txP
return nil, errIncompatibleConfig
}
// Construct the different synchronisation mechanisms
var syncMode downloader.SyncMode
switch mode {
case ArchiveMode:
syncMode = downloader.FullSync
case FullMode:
syncMode := downloader.FullSync
if fastSync {
syncMode = downloader.FastSync
case LightMode:
syncMode = downloader.LightSync
}
manager.downloader = downloader.New(syncMode, chaindb, manager.eventMux, blockchain.HasHeader, blockchain.HasBlock, blockchain.GetHeader,
blockchain.GetBlock, blockchain.CurrentHeader, blockchain.CurrentBlock, blockchain.CurrentFastBlock, blockchain.FastSyncCommitHead,
Expand Down
27 changes: 11 additions & 16 deletions eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ func TestProtocolCompatibility(t *testing.T) {
// Define the compatibility chart
tests := []struct {
version uint
mode Mode
fastSync bool
compatible bool
}{
{61, ArchiveMode, true}, {62, ArchiveMode, true}, {63, ArchiveMode, true}, {64, ArchiveMode, true},
{61, FullMode, false}, {62, FullMode, false}, {63, FullMode, true}, {64, FullMode, true},
{61, LightMode, false}, {62, LightMode, false}, {63, LightMode, false}, {64, LightMode, true},
{61, false, true}, {62, false, true}, {63, false, true},
{61, true, false}, {62, true, false}, {63, true, true},
}
// Make sure anything we screw up is restored
backup := ProtocolVersions
Expand All @@ -37,7 +36,7 @@ func TestProtocolCompatibility(t *testing.T) {
for i, tt := range tests {
ProtocolVersions = []uint{tt.version}

pm, err := newTestProtocolManager(tt.mode, 0, nil, nil)
pm, err := newTestProtocolManager(tt.fastSync, 0, nil, nil)
if pm != nil {
defer pm.Stop()
}
Expand All @@ -52,7 +51,7 @@ func TestProtocolCompatibility(t *testing.T) {
func TestGetBlockHashes61(t *testing.T) { testGetBlockHashes(t, 61) }

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

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

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

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

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

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

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

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

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

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

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

func testGetNodeData(t *testing.T, protocol int) {
// Define three accounts to simulate transactions with
Expand Down Expand Up @@ -440,7 +436,7 @@ func testGetNodeData(t *testing.T, protocol int) {
}
}
// Assemble the test environment
pm := newTestProtocolManagerMust(t, ArchiveMode, 4, generator, nil)
pm := newTestProtocolManagerMust(t, false, 4, generator, nil)
peer, _ := newTestPeer("peer", protocol, pm, true)
defer peer.close()

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

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

func testGetReceipt(t *testing.T, protocol int) {
// Define three accounts to simulate transactions with
Expand Down Expand Up @@ -530,7 +525,7 @@ func testGetReceipt(t *testing.T, protocol int) {
}
}
// Assemble the test environment
pm := newTestProtocolManagerMust(t, ArchiveMode, 4, generator, nil)
pm := newTestProtocolManagerMust(t, false, 4, generator, nil)
peer, _ := newTestPeer("peer", protocol, pm, true)
defer peer.close()

Expand Down
8 changes: 4 additions & 4 deletions eth/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (
// newTestProtocolManager creates a new protocol manager for testing purposes,
// with the given number of blocks already known, and potential notification
// channels for different events.
func newTestProtocolManager(mode Mode, blocks int, generator func(int, *core.BlockGen), newtx chan<- []*types.Transaction) (*ProtocolManager, error) {
func newTestProtocolManager(fastSync bool, blocks int, generator func(int, *core.BlockGen), newtx chan<- []*types.Transaction) (*ProtocolManager, error) {
var (
evmux = new(event.TypeMux)
pow = new(core.FakePow)
Expand All @@ -42,7 +42,7 @@ func newTestProtocolManager(mode Mode, blocks int, generator func(int, *core.Blo
if _, err := blockchain.InsertChain(chain); err != nil {
panic(err)
}
pm, err := NewProtocolManager(mode, NetworkId, evmux, &testTxPool{added: newtx}, pow, blockchain, db)
pm, err := NewProtocolManager(fastSync, NetworkId, evmux, &testTxPool{added: newtx}, pow, blockchain, db)
if err != nil {
return nil, err
}
Expand All @@ -54,8 +54,8 @@ func newTestProtocolManager(mode Mode, blocks int, generator func(int, *core.Blo
// with the given number of blocks already known, and potential notification
// channels for different events. In case of an error, the constructor force-
// fails the test.
func newTestProtocolManagerMust(t *testing.T, mode Mode, blocks int, generator func(int, *core.BlockGen), newtx chan<- []*types.Transaction) *ProtocolManager {
pm, err := newTestProtocolManager(mode, blocks, generator, newtx)
func newTestProtocolManagerMust(t *testing.T, fastSync bool, blocks int, generator func(int, *core.BlockGen), newtx chan<- []*types.Transaction) *ProtocolManager {
pm, err := newTestProtocolManager(fastSync, blocks, generator, newtx)
if err != nil {
t.Fatalf("Failed to create protocol manager: %v", err)
}
Expand Down
27 changes: 2 additions & 25 deletions eth/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,18 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)

// Mode represents the mode of operation of the eth client.
type Mode int

const (
ArchiveMode Mode = iota // Maintain the entire blockchain history
FullMode // Maintain only a recent view of the blockchain
LightMode // Don't maintain any history, rather fetch on demand
)

// Constants to match up protocol versions and messages
const (
eth61 = 61
eth62 = 62
eth63 = 63
eth64 = 64
)

// minimumProtocolVersion is the minimum version of the protocol eth must run to
// support the desired mode of operation.
var minimumProtocolVersion = map[Mode]uint{
ArchiveMode: eth61,
FullMode: eth63,
LightMode: eth64,
}

// Supported versions of the eth protocol (first is primary).
var ProtocolVersions = []uint{eth64, eth63, eth62, eth61}
var ProtocolVersions = []uint{eth63, eth62, eth61}

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

const (
NetworkId = 1
Expand Down Expand Up @@ -90,11 +72,6 @@ const (
NodeDataMsg = 0x0e
GetReceiptsMsg = 0x0f
ReceiptsMsg = 0x10

// Protocol messages belonging to eth/64
GetAcctProofMsg = 0x11
GetStorageDataProof = 0x12
Proof = 0x13
)

type errCode int
Expand Down
Loading

0 comments on commit aa0538d

Please sign in to comment.