From 9f8d192991c4f68fa14c91366722bbca601da117 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Fri, 14 Oct 2016 05:51:29 +0200 Subject: les: light client protocol and API --- eth/backend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'eth/backend.go') diff --git a/eth/backend.go b/eth/backend.go index 24419d6d8..9c5e11a59 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -312,7 +312,7 @@ func (s *Ethereum) APIs() []rpc.API { }, { Namespace: "eth", Version: "1.0", - Service: filters.NewPublicFilterAPI(s.chainDb, s.eventMux), + Service: filters.NewPublicFilterAPI(s.ApiBackend, false), Public: true, }, { Namespace: "admin", -- cgit v1.2.3 From 7db7109a5b53c339f00e9c05ac826b3dbd1f98e1 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Wed, 13 Jan 2016 19:35:48 +0100 Subject: cmd, eth: added light client and light server modes --- eth/backend.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 12 deletions(-) (limited to 'eth/backend.go') diff --git a/eth/backend.go b/eth/backend.go index 9c5e11a59..10018aeaa 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -66,9 +66,14 @@ var ( type Config struct { ChainConfig *core.ChainConfig // chain configuration - NetworkId int // Network ID to use for selecting peers to connect to - Genesis string // Genesis JSON to seed the chain database with - FastSync bool // Enables the state download based fast synchronisation algorithm + NetworkId int // Network ID to use for selecting peers to connect to + Genesis string // Genesis JSON to seed the chain database with + FastSync bool // Enables the state download based fast synchronisation algorithm + LightMode bool // Running in light client mode + NoDefSrv bool // No default LES server + LightServ int // Maximum percentage of time allowed for serving LES requests + LightPeers int // Maximum number of LES client peers + MaxPeers int // Maximum number of global peers SkipBcVersionCheck bool // e.g. blockchain export DatabaseCache int @@ -100,6 +105,12 @@ type Config struct { TestGenesisState ethdb.Database // Genesis state to seed the database with (testing only!) } +type LesServer interface { + Start() + Stop() + Protocols() []p2p.Protocol +} + // Ethereum implements the Ethereum full node service. type Ethereum struct { chainConfig *core.ChainConfig @@ -111,6 +122,7 @@ type Ethereum struct { txMu sync.Mutex blockchain *core.BlockChain protocolManager *ProtocolManager + lesServer LesServer // DB interfaces chainDb ethdb.Database // Block chain database @@ -119,7 +131,7 @@ type Ethereum struct { httpclient *httpclient.HTTPClient accountManager *accounts.Manager - apiBackend *EthApiBackend + ApiBackend *EthApiBackend miner *miner.Miner Mining bool @@ -135,10 +147,14 @@ type Ethereum struct { netRPCService *ethapi.PublicNetAPI } +func (s *Ethereum) AddLesServer(ls LesServer) { + s.lesServer = ls +} + // New creates a new Ethereum object (including the // initialisation of the common Ethereum object) func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { - chainDb, err := createDB(ctx, config) + chainDb, err := CreateDB(ctx, config, "chaindata") if err != nil { return nil, err } @@ -217,7 +233,18 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { newPool := core.NewTxPool(eth.chainConfig, eth.EventMux(), eth.blockchain.State, eth.blockchain.GasLimit) eth.txPool = newPool - if eth.protocolManager, err = NewProtocolManager(eth.chainConfig, config.FastSync, config.NetworkId, eth.eventMux, eth.txPool, eth.pow, eth.blockchain, chainDb); err != nil { + maxPeers := config.MaxPeers + if config.LightServ > 0 { + // if we are running a light server, limit the number of ETH peers so that we reserve some space for incoming LES connections + // temporary solution until the new peer connectivity API is finished + halfPeers := maxPeers / 2 + maxPeers -= config.LightPeers + if maxPeers < halfPeers { + maxPeers = halfPeers + } + } + + if eth.protocolManager, err = NewProtocolManager(eth.chainConfig, config.FastSync, config.NetworkId, maxPeers, eth.eventMux, eth.txPool, eth.pow, eth.blockchain, chainDb); err != nil { return nil, err } eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.pow) @@ -233,14 +260,14 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { GpobaseCorrectionFactor: config.GpobaseCorrectionFactor, } gpo := gasprice.NewGasPriceOracle(eth.blockchain, chainDb, eth.eventMux, gpoParams) - eth.apiBackend = &EthApiBackend{eth, gpo} + eth.ApiBackend = &EthApiBackend{eth, gpo} return eth, nil } -// createDB creates the chain database. -func createDB(ctx *node.ServiceContext, config *Config) (ethdb.Database, error) { - db, err := ctx.OpenDatabase("chaindata", config.DatabaseCache, config.DatabaseHandles) +// CreateDB creates the chain database. +func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Database, error) { + db, err := ctx.OpenDatabase(name, config.DatabaseCache, config.DatabaseHandles) if db, ok := db.(*ethdb.LDBDatabase); ok { db.Meter("eth/db/chaindata/") } @@ -288,7 +315,7 @@ func CreatePoW(config *Config) (*ethash.Ethash, error) { // APIs returns the collection of RPC services the ethereum package offers. // NOTE, some of these services probably need to be moved to somewhere else. func (s *Ethereum) APIs() []rpc.API { - return append(ethapi.GetAPIs(s.apiBackend, s.solcPath), []rpc.API{ + return append(ethapi.GetAPIs(s.ApiBackend, s.solcPath), []rpc.API{ { Namespace: "eth", Version: "1.0", @@ -391,7 +418,11 @@ func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManage // Protocols implements node.Service, returning all the currently configured // network protocols to start. func (s *Ethereum) Protocols() []p2p.Protocol { - return s.protocolManager.SubProtocols + if s.lesServer == nil { + return s.protocolManager.SubProtocols + } else { + return append(s.protocolManager.SubProtocols, s.lesServer.Protocols()...) + } } // Start implements node.Service, starting all internal goroutines needed by the @@ -402,6 +433,9 @@ func (s *Ethereum) Start(srvr *p2p.Server) error { s.StartAutoDAG() } s.protocolManager.Start() + if s.lesServer != nil { + s.lesServer.Start() + } return nil } @@ -413,6 +447,9 @@ func (s *Ethereum) Stop() error { } s.blockchain.Stop() s.protocolManager.Stop() + if s.lesServer != nil { + s.lesServer.Stop() + } s.txPool.Stop() s.miner.Stop() s.eventMux.Stop() -- cgit v1.2.3 From 49da42983af7a775695166689e5bf701bcec4f81 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Wed, 19 Oct 2016 13:04:55 +0200 Subject: p2p/discv5: added new topic discovery package --- eth/backend.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'eth/backend.go') diff --git a/eth/backend.go b/eth/backend.go index 10018aeaa..ec501043a 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -70,7 +70,6 @@ type Config struct { Genesis string // Genesis JSON to seed the chain database with FastSync bool // Enables the state download based fast synchronisation algorithm LightMode bool // Running in light client mode - NoDefSrv bool // No default LES server LightServ int // Maximum percentage of time allowed for serving LES requests LightPeers int // Maximum number of LES client peers MaxPeers int // Maximum number of global peers @@ -106,7 +105,7 @@ type Config struct { } type LesServer interface { - Start() + Start(srvr *p2p.Server) Stop() Protocols() []p2p.Protocol } @@ -434,7 +433,7 @@ func (s *Ethereum) Start(srvr *p2p.Server) error { } s.protocolManager.Start() if s.lesServer != nil { - s.lesServer.Start() + s.lesServer.Start(srvr) } return nil } -- cgit v1.2.3