diff --git a/eth/backend.go b/eth/backend.go index 3e2694b36c..fbf4dd7bbc 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -480,7 +480,7 @@ func (s *Ethereum) IsListening() bool { return true } // Always func (s *Ethereum) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) } func (s *Ethereum) NetVersion() uint64 { return s.networkID } func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader } -func (s *Ethereum) IsSynced() bool { return atomic.LoadUint32(&s.protocolManager.acceptTxs) == 1 } +func (s *Ethereum) Synced() bool { return atomic.LoadUint32(&s.protocolManager.acceptTxs) == 1 } // Protocols implements node.Service, returning all the currently configured // network protocols to start. diff --git a/les/handler.go b/les/handler.go index 85192568d4..f53a4722f1 100644 --- a/les/handler.go +++ b/les/handler.go @@ -91,7 +91,7 @@ type ProtocolManager struct { chainConfig *params.ChainConfig iConfig *light.IndexerConfig - light bool // The indicator whether the node is light client + client bool // The indicator whether the node is light client maxPeers int // The maximum number peers allowed to connect. networkId uint64 // The identity of network. @@ -120,7 +120,7 @@ type ProtocolManager struct { eventMux *event.TypeMux // Callbacks - isSynced func() bool + synced func() bool } // NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable @@ -128,7 +128,7 @@ type ProtocolManager struct { func NewProtocolManager( chainConfig *params.ChainConfig, indexerConfig *light.IndexerConfig, - light bool, + client bool, networkId uint64, mux *event.TypeMux, engine consensus.Engine, @@ -141,10 +141,10 @@ func NewProtocolManager( serverPool *serverPool, quitSync chan struct{}, wg *sync.WaitGroup, - ulcConfig *eth.ULCConfig, isSynced func() bool) (*ProtocolManager, error) { + ulcConfig *eth.ULCConfig, synced func() bool) (*ProtocolManager, error) { // Create the protocol manager with the base fields manager := &ProtocolManager{ - light: light, + client: client, eventMux: mux, blockchain: blockchain, chainConfig: chainConfig, @@ -160,7 +160,7 @@ func NewProtocolManager( quitSync: quitSync, wg: wg, noMorePeers: make(chan struct{}), - isSynced: isSynced, + synced: synced, } if odr != nil { manager.retriever = odr.retriever @@ -177,7 +177,7 @@ func NewProtocolManager( if disableClientRemovePeer { removePeer = func(id string) {} } - if light { + if client { var checkpoint uint64 if cht, ok := params.TrustedCheckpoints[blockchain.Genesis().Hash()]; ok { checkpoint = (cht.SectionIndex+1)*params.CHTFrequency - 1 @@ -196,7 +196,7 @@ func (pm *ProtocolManager) removePeer(id string) { func (pm *ProtocolManager) Start(maxPeers int) { pm.maxPeers = maxPeers - if pm.light { + if pm.client { go pm.syncer() } else { go func() { @@ -271,11 +271,11 @@ func (pm *ProtocolManager) newPeer(pv int, nv uint64, p *p2p.Peer, rw p2p.MsgRea func (pm *ProtocolManager) handle(p *peer) error { // Ignore maxPeers if this is a trusted peer // In server mode we try to check into the client pool after handshake - if pm.light && pm.peers.Len() >= pm.maxPeers && !p.Peer.Info().Network.Trusted { + if pm.client && pm.peers.Len() >= pm.maxPeers && !p.Peer.Info().Network.Trusted { return p2p.DiscTooManyPeers } // Reject light clients if server is not synced. - if !pm.light && pm.isSynced != nil && !pm.isSynced() { + if !pm.client && !pm.synced() { return p2p.DiscRequested } p.Log().Debug("Light Ethereum peer connected", "name", p.Name()) @@ -310,7 +310,7 @@ func (pm *ProtocolManager) handle(p *peer) error { }() // Register the peer in the downloader. If the downloader considers it banned, we disconnect - if pm.light { + if pm.client { p.lock.Lock() head := p.headInfo p.lock.Unlock() diff --git a/les/helper_test.go b/les/helper_test.go index b16b128cf7..480fa154d6 100644 --- a/les/helper_test.go +++ b/les/helper_test.go @@ -170,7 +170,7 @@ func newTestProtocolManager(lightSync bool, blocks int, generator func(int, *cor if lightSync { indexConfig = light.TestClientIndexerConfig } - pm, err := NewProtocolManager(gspec.Config, indexConfig, lightSync, NetworkId, evmux, engine, peers, chain, pool, db, odr, nil, nil, make(chan struct{}), new(sync.WaitGroup), ulcConfig, nil) + pm, err := NewProtocolManager(gspec.Config, indexConfig, lightSync, NetworkId, evmux, engine, peers, chain, pool, db, odr, nil, nil, make(chan struct{}), new(sync.WaitGroup), ulcConfig, func() bool {return true}) if err != nil { return nil, err } diff --git a/les/server.go b/les/server.go index cb9ac0d322..6b93b846db 100644 --- a/les/server.go +++ b/les/server.go @@ -74,7 +74,7 @@ func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) { nil, quitSync, new(sync.WaitGroup), - config.ULC, eth.IsSynced) + config.ULC, eth.Synced) if err != nil { return nil, err } diff --git a/les/transactions.rlp b/les/transactions.rlp new file mode 100755 index 0000000000..e69de29bb2