cmd, les: remove stutter from les package type declarations

Removes the "Les" prefix from types declared in the les package in
accordance with golang best practices [1]

[1] "Avoid stutter": https://blog.golang.org/package-names
This commit is contained in:
Matthew Halpern 2019-02-05 09:39:46 -08:00
parent 520024dfd6
commit 39cfed2a2a
14 changed files with 116 additions and 116 deletions

View file

@ -1427,7 +1427,7 @@ func RegisterEthService(stack *node.Node, cfg *eth.Config) {
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
fullNode, err := eth.New(ctx, cfg) fullNode, err := eth.New(ctx, cfg)
if fullNode != nil && cfg.LightServ > 0 { if fullNode != nil && cfg.LightServ > 0 {
ls, _ := les.NewLesServer(fullNode, cfg) ls, _ := les.NewServer(fullNode, cfg)
fullNode.AddLesServer(ls) fullNode.AddLesServer(ls)
} }
return fullNode, err return fullNode, err

View file

@ -38,36 +38,36 @@ import (
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
) )
type LesApiBackend struct { type ApiBackend struct {
eth *LightEthereum eth *LightEthereum
gpo *gasprice.Oracle gpo *gasprice.Oracle
} }
func (b *LesApiBackend) ChainConfig() *params.ChainConfig { func (b *ApiBackend) ChainConfig() *params.ChainConfig {
return b.eth.chainConfig return b.eth.chainConfig
} }
func (b *LesApiBackend) CurrentBlock() *types.Block { func (b *ApiBackend) CurrentBlock() *types.Block {
return types.NewBlockWithHeader(b.eth.BlockChain().CurrentHeader()) return types.NewBlockWithHeader(b.eth.BlockChain().CurrentHeader())
} }
func (b *LesApiBackend) SetHead(number uint64) { func (b *ApiBackend) SetHead(number uint64) {
b.eth.protocolManager.downloader.Cancel() b.eth.protocolManager.downloader.Cancel()
b.eth.blockchain.SetHead(number) b.eth.blockchain.SetHead(number)
} }
func (b *LesApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) { func (b *ApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) {
if blockNr == rpc.LatestBlockNumber || blockNr == rpc.PendingBlockNumber { if blockNr == rpc.LatestBlockNumber || blockNr == rpc.PendingBlockNumber {
return b.eth.blockchain.CurrentHeader(), nil return b.eth.blockchain.CurrentHeader(), nil
} }
return b.eth.blockchain.GetHeaderByNumberOdr(ctx, uint64(blockNr)) return b.eth.blockchain.GetHeaderByNumberOdr(ctx, uint64(blockNr))
} }
func (b *LesApiBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { func (b *ApiBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
return b.eth.blockchain.GetHeaderByHash(hash), nil return b.eth.blockchain.GetHeaderByHash(hash), nil
} }
func (b *LesApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error) { func (b *ApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error) {
header, err := b.HeaderByNumber(ctx, blockNr) header, err := b.HeaderByNumber(ctx, blockNr)
if header == nil || err != nil { if header == nil || err != nil {
return nil, err return nil, err
@ -75,7 +75,7 @@ func (b *LesApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumb
return b.GetBlock(ctx, header.Hash()) return b.GetBlock(ctx, header.Hash())
} }
func (b *LesApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) { func (b *ApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) {
header, err := b.HeaderByNumber(ctx, blockNr) header, err := b.HeaderByNumber(ctx, blockNr)
if header == nil || err != nil { if header == nil || err != nil {
return nil, nil, err return nil, nil, err
@ -83,111 +83,111 @@ func (b *LesApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.
return light.NewState(ctx, header, b.eth.odr), header, nil return light.NewState(ctx, header, b.eth.odr), header, nil
} }
func (b *LesApiBackend) GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error) { func (b *ApiBackend) GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error) {
return b.eth.blockchain.GetBlockByHash(ctx, blockHash) return b.eth.blockchain.GetBlockByHash(ctx, blockHash)
} }
func (b *LesApiBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) { func (b *ApiBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
if number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash); number != nil { if number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash); number != nil {
return light.GetBlockReceipts(ctx, b.eth.odr, hash, *number) return light.GetBlockReceipts(ctx, b.eth.odr, hash, *number)
} }
return nil, nil return nil, nil
} }
func (b *LesApiBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) { func (b *ApiBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) {
if number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash); number != nil { if number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash); number != nil {
return light.GetBlockLogs(ctx, b.eth.odr, hash, *number) return light.GetBlockLogs(ctx, b.eth.odr, hash, *number)
} }
return nil, nil return nil, nil
} }
func (b *LesApiBackend) GetTd(hash common.Hash) *big.Int { func (b *ApiBackend) GetTd(hash common.Hash) *big.Int {
return b.eth.blockchain.GetTdByHash(hash) return b.eth.blockchain.GetTdByHash(hash)
} }
func (b *LesApiBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error) { func (b *ApiBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error) {
state.SetBalance(msg.From(), math.MaxBig256) state.SetBalance(msg.From(), math.MaxBig256)
context := core.NewEVMContext(msg, header, b.eth.blockchain, nil) context := core.NewEVMContext(msg, header, b.eth.blockchain, nil)
return vm.NewEVM(context, state, b.eth.chainConfig, vm.Config{}), state.Error, nil return vm.NewEVM(context, state, b.eth.chainConfig, vm.Config{}), state.Error, nil
} }
func (b *LesApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error { func (b *ApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error {
return b.eth.txPool.Add(ctx, signedTx) return b.eth.txPool.Add(ctx, signedTx)
} }
func (b *LesApiBackend) RemoveTx(txHash common.Hash) { func (b *ApiBackend) RemoveTx(txHash common.Hash) {
b.eth.txPool.RemoveTx(txHash) b.eth.txPool.RemoveTx(txHash)
} }
func (b *LesApiBackend) GetPoolTransactions() (types.Transactions, error) { func (b *ApiBackend) GetPoolTransactions() (types.Transactions, error) {
return b.eth.txPool.GetTransactions() return b.eth.txPool.GetTransactions()
} }
func (b *LesApiBackend) GetPoolTransaction(txHash common.Hash) *types.Transaction { func (b *ApiBackend) GetPoolTransaction(txHash common.Hash) *types.Transaction {
return b.eth.txPool.GetTransaction(txHash) return b.eth.txPool.GetTransaction(txHash)
} }
func (b *LesApiBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) { func (b *ApiBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) {
return b.eth.txPool.GetNonce(ctx, addr) return b.eth.txPool.GetNonce(ctx, addr)
} }
func (b *LesApiBackend) Stats() (pending int, queued int) { func (b *ApiBackend) Stats() (pending int, queued int) {
return b.eth.txPool.Stats(), 0 return b.eth.txPool.Stats(), 0
} }
func (b *LesApiBackend) TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) { func (b *ApiBackend) TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) {
return b.eth.txPool.Content() return b.eth.txPool.Content()
} }
func (b *LesApiBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription { func (b *ApiBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription {
return b.eth.txPool.SubscribeNewTxsEvent(ch) return b.eth.txPool.SubscribeNewTxsEvent(ch)
} }
func (b *LesApiBackend) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription { func (b *ApiBackend) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription {
return b.eth.blockchain.SubscribeChainEvent(ch) return b.eth.blockchain.SubscribeChainEvent(ch)
} }
func (b *LesApiBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription { func (b *ApiBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription {
return b.eth.blockchain.SubscribeChainHeadEvent(ch) return b.eth.blockchain.SubscribeChainHeadEvent(ch)
} }
func (b *LesApiBackend) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription { func (b *ApiBackend) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription {
return b.eth.blockchain.SubscribeChainSideEvent(ch) return b.eth.blockchain.SubscribeChainSideEvent(ch)
} }
func (b *LesApiBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription { func (b *ApiBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription {
return b.eth.blockchain.SubscribeLogsEvent(ch) return b.eth.blockchain.SubscribeLogsEvent(ch)
} }
func (b *LesApiBackend) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription { func (b *ApiBackend) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription {
return b.eth.blockchain.SubscribeRemovedLogsEvent(ch) return b.eth.blockchain.SubscribeRemovedLogsEvent(ch)
} }
func (b *LesApiBackend) Downloader() *downloader.Downloader { func (b *ApiBackend) Downloader() *downloader.Downloader {
return b.eth.Downloader() return b.eth.Downloader()
} }
func (b *LesApiBackend) ProtocolVersion() int { func (b *ApiBackend) ProtocolVersion() int {
return b.eth.LesVersion() + 10000 return b.eth.LesVersion() + 10000
} }
func (b *LesApiBackend) SuggestPrice(ctx context.Context) (*big.Int, error) { func (b *ApiBackend) SuggestPrice(ctx context.Context) (*big.Int, error) {
return b.gpo.SuggestPrice(ctx) return b.gpo.SuggestPrice(ctx)
} }
func (b *LesApiBackend) ChainDb() ethdb.Database { func (b *ApiBackend) ChainDb() ethdb.Database {
return b.eth.chainDb return b.eth.chainDb
} }
func (b *LesApiBackend) EventMux() *event.TypeMux { func (b *ApiBackend) EventMux() *event.TypeMux {
return b.eth.eventMux return b.eth.eventMux
} }
func (b *LesApiBackend) AccountManager() *accounts.Manager { func (b *ApiBackend) AccountManager() *accounts.Manager {
return b.eth.accountManager return b.eth.accountManager
} }
func (b *LesApiBackend) BloomStatus() (uint64, uint64) { func (b *ApiBackend) BloomStatus() (uint64, uint64) {
if b.eth.bloomIndexer == nil { if b.eth.bloomIndexer == nil {
return 0, 0 return 0, 0
} }
@ -195,7 +195,7 @@ func (b *LesApiBackend) BloomStatus() (uint64, uint64) {
return params.BloomBitsBlocksClient, sections return params.BloomBitsBlocksClient, sections
} }
func (b *LesApiBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) { func (b *ApiBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) {
for i := 0; i < bloomFilterThreads; i++ { for i := 0; i < bloomFilterThreads; i++ {
go session.Multiplex(bloomRetrievalBatch, bloomRetrievalWait, b.eth.bloomRequests) go session.Multiplex(bloomRetrievalBatch, bloomRetrievalWait, b.eth.bloomRequests)
} }

View file

@ -46,10 +46,10 @@ import (
) )
type LightEthereum struct { type LightEthereum struct {
lesCommons commons
odr *LesOdr odr *Odr
relay *LesTxRelay relay *TxRelay
chainConfig *params.ChainConfig chainConfig *params.ChainConfig
// Channel for shutting down the service // Channel for shutting down the service
shutdownChan chan bool shutdownChan chan bool
@ -65,7 +65,7 @@ type LightEthereum struct {
bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
bloomIndexer *core.ChainIndexer bloomIndexer *core.ChainIndexer
ApiBackend *LesApiBackend ApiBackend *ApiBackend
eventMux *event.TypeMux eventMux *event.TypeMux
engine consensus.Engine engine consensus.Engine
@ -92,7 +92,7 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
quitSync := make(chan struct{}) quitSync := make(chan struct{})
leth := &LightEthereum{ leth := &LightEthereum{
lesCommons: lesCommons{ commons: commons{
chainDb: chainDb, chainDb: chainDb,
config: config, config: config,
iConfig: light.DefaultClientIndexerConfig, iConfig: light.DefaultClientIndexerConfig,
@ -113,11 +113,11 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
if leth.config.ULC != nil { if leth.config.ULC != nil {
trustedNodes = leth.config.ULC.TrustedServers trustedNodes = leth.config.ULC.TrustedServers
} }
leth.relay = NewLesTxRelay(peers, leth.reqDist) leth.relay = NewTxRelay(peers, leth.reqDist)
leth.serverPool = newServerPool(chainDb, quitSync, &leth.wg, trustedNodes) leth.serverPool = newServerPool(chainDb, quitSync, &leth.wg, trustedNodes)
leth.retriever = newRetrieveManager(peers, leth.reqDist, leth.serverPool) leth.retriever = newRetrieveManager(peers, leth.reqDist, leth.serverPool)
leth.odr = NewLesOdr(chainDb, light.DefaultClientIndexerConfig, leth.retriever) leth.odr = NewOdr(chainDb, light.DefaultClientIndexerConfig, leth.retriever)
leth.chtIndexer = light.NewChtIndexer(chainDb, leth.odr, params.CHTFrequencyClient, params.HelperTrieConfirmations) leth.chtIndexer = light.NewChtIndexer(chainDb, leth.odr, params.CHTFrequencyClient, params.HelperTrieConfirmations)
leth.bloomTrieIndexer = light.NewBloomTrieIndexer(chainDb, leth.odr, params.BloomBitsBlocksClient, params.BloomTrieFrequency) leth.bloomTrieIndexer = light.NewBloomTrieIndexer(chainDb, leth.odr, params.BloomBitsBlocksClient, params.BloomTrieFrequency)
leth.odr.SetIndexers(leth.chtIndexer, leth.bloomTrieIndexer, leth.bloomIndexer) leth.odr.SetIndexers(leth.chtIndexer, leth.bloomTrieIndexer, leth.bloomIndexer)
@ -165,7 +165,7 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
log.Warn("Ultra light client is enabled", "trustedNodes", len(leth.protocolManager.ulc.trustedKeys), "minTrustedFraction", leth.protocolManager.ulc.minTrustedFraction) log.Warn("Ultra light client is enabled", "trustedNodes", len(leth.protocolManager.ulc.trustedKeys), "minTrustedFraction", leth.protocolManager.ulc.minTrustedFraction)
leth.blockchain.DisableCheckFreq() leth.blockchain.DisableCheckFreq()
} }
leth.ApiBackend = &LesApiBackend{leth, nil} leth.ApiBackend = &ApiBackend{leth, nil}
gpoParams := config.GPO gpoParams := config.GPO
if gpoParams.Default == nil { if gpoParams.Default == nil {

View file

@ -30,8 +30,8 @@ import (
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
// lesCommons contains fields needed by both server and client. // commons contains fields needed by both server and client.
type lesCommons struct { type commons struct {
config *eth.Config config *eth.Config
iConfig *light.IndexerConfig iConfig *light.IndexerConfig
chainDb ethdb.Database chainDb ethdb.Database
@ -51,7 +51,7 @@ type NodeInfo struct {
} }
// makeProtocols creates protocol descriptors for the given LES versions. // makeProtocols creates protocol descriptors for the given LES versions.
func (c *lesCommons) makeProtocols(versions []uint) []p2p.Protocol { func (c *commons) makeProtocols(versions []uint) []p2p.Protocol {
protos := make([]p2p.Protocol, len(versions)) protos := make([]p2p.Protocol, len(versions))
for i, version := range versions { for i, version := range versions {
version := version version := version
@ -75,7 +75,7 @@ func (c *lesCommons) makeProtocols(versions []uint) []p2p.Protocol {
} }
// nodeInfo retrieves some protocol metadata about the running host node. // nodeInfo retrieves some protocol metadata about the running host node.
func (c *lesCommons) nodeInfo() interface{} { func (c *commons) nodeInfo() interface{} {
var cht params.TrustedCheckpoint var cht params.TrustedCheckpoint
sections, _, _ := c.chtIndexer.Sections() sections, _, _ := c.chtIndexer.Sections()
sections2, _, _ := c.bloomTrieIndexer.Sections() sections2, _, _ := c.bloomTrieIndexer.Sections()

View file

@ -42,7 +42,7 @@ const (
// and announced that block. // and announced that block.
type lightFetcher struct { type lightFetcher struct {
pm *ProtocolManager pm *ProtocolManager
odr *LesOdr odr *Odr
chain lightChain chain lightChain
lock sync.Mutex // lock protects access to the fetcher's internal state variables except sent requests lock sync.Mutex // lock protects access to the fetcher's internal state variables except sent requests

View file

@ -92,14 +92,14 @@ type txPool interface {
type ProtocolManager struct { type ProtocolManager struct {
lightSync bool lightSync bool
txpool txPool txpool txPool
txrelay *LesTxRelay txrelay *TxRelay
networkId uint64 networkId uint64
chainConfig *params.ChainConfig chainConfig *params.ChainConfig
iConfig *light.IndexerConfig iConfig *light.IndexerConfig
blockchain BlockChain blockchain BlockChain
chainDb ethdb.Database chainDb ethdb.Database
odr *LesOdr odr *Odr
server *LesServer server *Server
serverPool *serverPool serverPool *serverPool
clientPool *freeClientPool clientPool *freeClientPool
lesTopic discv5.Topic lesTopic discv5.Topic
@ -137,8 +137,8 @@ func NewProtocolManager(
blockchain BlockChain, blockchain BlockChain,
txpool txPool, txpool txPool,
chainDb ethdb.Database, chainDb ethdb.Database,
odr *LesOdr, odr *Odr,
txrelay *LesTxRelay, txrelay *TxRelay,
serverPool *serverPool, serverPool *serverPool,
quitSync chan struct{}, quitSync chan struct{},
wg *sync.WaitGroup, wg *sync.WaitGroup,

View file

@ -146,7 +146,7 @@ func testRCL() RequestCostList {
// newTestProtocolManager creates a new protocol manager for testing purposes, // newTestProtocolManager creates a new protocol manager for testing purposes,
// with the given number of blocks already known, potential notification // with the given number of blocks already known, potential notification
// channels for different events and relative chain indexers array. // channels for different events and relative chain indexers array.
func newTestProtocolManager(lightSync bool, blocks int, generator func(int, *core.BlockGen), odr *LesOdr, peers *peerSet, db ethdb.Database, ulcConfig *eth.ULCConfig) (*ProtocolManager, error) { func newTestProtocolManager(lightSync bool, blocks int, generator func(int, *core.BlockGen), odr *Odr, peers *peerSet, db ethdb.Database, ulcConfig *eth.ULCConfig) (*ProtocolManager, error) {
var ( var (
evmux = new(event.TypeMux) evmux = new(event.TypeMux)
engine = ethash.NewFaker() engine = ethash.NewFaker()
@ -181,7 +181,7 @@ func newTestProtocolManager(lightSync bool, blocks int, generator func(int, *cor
return nil, err return nil, err
} }
if !lightSync { if !lightSync {
srv := &LesServer{lesCommons: lesCommons{protocolManager: pm}} srv := &Server{commons: commons{protocolManager: pm}}
pm.server = srv pm.server = srv
srv.defParams = &flowcontrol.ServerParams{ srv.defParams = &flowcontrol.ServerParams{
@ -200,7 +200,7 @@ func newTestProtocolManager(lightSync bool, blocks int, generator func(int, *cor
// with the given number of blocks already known, potential notification // with the given number of blocks already known, potential notification
// channels for different events and relative chain indexers array. In case of an error, the constructor force- // channels for different events and relative chain indexers array. In case of an error, the constructor force-
// fails the test. // fails the test.
func newTestProtocolManagerMust(t *testing.T, lightSync bool, blocks int, generator func(int, *core.BlockGen), odr *LesOdr, peers *peerSet, db ethdb.Database, ulcConfig *eth.ULCConfig) *ProtocolManager { func newTestProtocolManagerMust(t *testing.T, lightSync bool, blocks int, generator func(int, *core.BlockGen), odr *Odr, peers *peerSet, db ethdb.Database, ulcConfig *eth.ULCConfig) *ProtocolManager {
pm, err := newTestProtocolManager(lightSync, blocks, generator, odr, peers, db, ulcConfig) pm, err := newTestProtocolManager(lightSync, blocks, generator, odr, peers, db, ulcConfig)
if err != nil { if err != nil {
t.Fatalf("Failed to create protocol manager: %v", err) t.Fatalf("Failed to create protocol manager: %v", err)
@ -377,7 +377,7 @@ func newClientServerEnv(t *testing.T, blocks int, protocol int, waitIndexers fun
dist := newRequestDistributor(lPeers, make(chan struct{})) dist := newRequestDistributor(lPeers, make(chan struct{}))
rm := newRetrieveManager(lPeers, dist, nil) rm := newRetrieveManager(lPeers, dist, nil)
odr := NewLesOdr(ldb, light.TestClientIndexerConfig, rm) odr := NewOdr(ldb, light.TestClientIndexerConfig, rm)
cIndexer, bIndexer, btIndexer := testIndexers(db, nil, light.TestServerIndexerConfig) cIndexer, bIndexer, btIndexer := testIndexers(db, nil, light.TestServerIndexerConfig)
lcIndexer, lbIndexer, lbtIndexer := testIndexers(ldb, odr, light.TestClientIndexerConfig) lcIndexer, lbIndexer, lbtIndexer := testIndexers(ldb, odr, light.TestClientIndexerConfig)

View file

@ -25,8 +25,8 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
// LesOdr implements light.OdrBackend // Odr implements light.OdrBackend
type LesOdr struct { type Odr struct {
db ethdb.Database db ethdb.Database
indexerConfig *light.IndexerConfig indexerConfig *light.IndexerConfig
chtIndexer, bloomTrieIndexer, bloomIndexer *core.ChainIndexer chtIndexer, bloomTrieIndexer, bloomIndexer *core.ChainIndexer
@ -34,8 +34,8 @@ type LesOdr struct {
stop chan struct{} stop chan struct{}
} }
func NewLesOdr(db ethdb.Database, config *light.IndexerConfig, retriever *retrieveManager) *LesOdr { func NewOdr(db ethdb.Database, config *light.IndexerConfig, retriever *retrieveManager) *Odr {
return &LesOdr{ return &Odr{
db: db, db: db,
indexerConfig: config, indexerConfig: config,
retriever: retriever, retriever: retriever,
@ -44,39 +44,39 @@ func NewLesOdr(db ethdb.Database, config *light.IndexerConfig, retriever *retrie
} }
// Stop cancels all pending retrievals // Stop cancels all pending retrievals
func (odr *LesOdr) Stop() { func (odr *Odr) Stop() {
close(odr.stop) close(odr.stop)
} }
// Database returns the backing database // Database returns the backing database
func (odr *LesOdr) Database() ethdb.Database { func (odr *Odr) Database() ethdb.Database {
return odr.db return odr.db
} }
// SetIndexers adds the necessary chain indexers to the ODR backend // SetIndexers adds the necessary chain indexers to the ODR backend
func (odr *LesOdr) SetIndexers(chtIndexer, bloomTrieIndexer, bloomIndexer *core.ChainIndexer) { func (odr *Odr) SetIndexers(chtIndexer, bloomTrieIndexer, bloomIndexer *core.ChainIndexer) {
odr.chtIndexer = chtIndexer odr.chtIndexer = chtIndexer
odr.bloomTrieIndexer = bloomTrieIndexer odr.bloomTrieIndexer = bloomTrieIndexer
odr.bloomIndexer = bloomIndexer odr.bloomIndexer = bloomIndexer
} }
// ChtIndexer returns the CHT chain indexer // ChtIndexer returns the CHT chain indexer
func (odr *LesOdr) ChtIndexer() *core.ChainIndexer { func (odr *Odr) ChtIndexer() *core.ChainIndexer {
return odr.chtIndexer return odr.chtIndexer
} }
// BloomTrieIndexer returns the bloom trie chain indexer // BloomTrieIndexer returns the bloom trie chain indexer
func (odr *LesOdr) BloomTrieIndexer() *core.ChainIndexer { func (odr *Odr) BloomTrieIndexer() *core.ChainIndexer {
return odr.bloomTrieIndexer return odr.bloomTrieIndexer
} }
// BloomIndexer returns the bloombits chain indexer // BloomIndexer returns the bloombits chain indexer
func (odr *LesOdr) BloomIndexer() *core.ChainIndexer { func (odr *Odr) BloomIndexer() *core.ChainIndexer {
return odr.bloomIndexer return odr.bloomIndexer
} }
// IndexerConfig returns the indexer config. // IndexerConfig returns the indexer config.
func (odr *LesOdr) IndexerConfig() *light.IndexerConfig { func (odr *Odr) IndexerConfig() *light.IndexerConfig {
return odr.indexerConfig return odr.indexerConfig
} }
@ -99,8 +99,8 @@ type Msg struct {
// Retrieve tries to fetch an object from the LES network. // Retrieve tries to fetch an object from the LES network.
// If the network retrieval was successful, it stores the object in local db. // If the network retrieval was successful, it stores the object in local db.
func (odr *LesOdr) Retrieve(ctx context.Context, req light.OdrRequest) (err error) { func (odr *Odr) Retrieve(ctx context.Context, req light.OdrRequest) (err error) {
lreq := LesRequest(req) lreq := Request(req)
reqID := genReqID() reqID := genReqID()
rq := &distReq{ rq := &distReq{

View file

@ -47,14 +47,14 @@ var (
errUselessNodes = errors.New("useless nodes in merkle proof nodeset") errUselessNodes = errors.New("useless nodes in merkle proof nodeset")
) )
type LesOdrRequest interface { type OdrRequest interface {
GetCost(*peer) uint64 GetCost(*peer) uint64
CanSend(*peer) bool CanSend(*peer) bool
Request(uint64, *peer) error Request(uint64, *peer) error
Validate(ethdb.Database, *Msg) error Validate(ethdb.Database, *Msg) error
} }
func LesRequest(req light.OdrRequest) LesOdrRequest { func Request(req light.OdrRequest) OdrRequest {
switch r := req.(type) { switch r := req.(type) {
case *light.BlockRequest: case *light.BlockRequest:
return (*BlockRequest)(r) return (*BlockRequest)(r)
@ -77,7 +77,7 @@ func LesRequest(req light.OdrRequest) LesOdrRequest {
type BlockRequest light.BlockRequest type BlockRequest light.BlockRequest
// GetCost returns the cost of the given ODR request according to the serving // GetCost returns the cost of the given ODR request according to the serving
// peer's cost table (implementation of LesOdrRequest) // peer's cost table (implementation of OdrRequest)
func (r *BlockRequest) GetCost(peer *peer) uint64 { func (r *BlockRequest) GetCost(peer *peer) uint64 {
return peer.GetRequestCost(GetBlockBodiesMsg, 1) return peer.GetRequestCost(GetBlockBodiesMsg, 1)
} }
@ -87,7 +87,7 @@ func (r *BlockRequest) CanSend(peer *peer) bool {
return peer.HasBlock(r.Hash, r.Number, false) return peer.HasBlock(r.Hash, r.Number, false)
} }
// Request sends an ODR request to the LES network (implementation of LesOdrRequest) // Request sends an ODR request to the LES network (implementation of OdrRequest)
func (r *BlockRequest) Request(reqID uint64, peer *peer) error { func (r *BlockRequest) Request(reqID uint64, peer *peer) error {
peer.Log().Debug("Requesting block body", "hash", r.Hash) peer.Log().Debug("Requesting block body", "hash", r.Hash)
return peer.RequestBodies(reqID, r.GetCost(peer), []common.Hash{r.Hash}) return peer.RequestBodies(reqID, r.GetCost(peer), []common.Hash{r.Hash})
@ -95,7 +95,7 @@ func (r *BlockRequest) Request(reqID uint64, peer *peer) error {
// Valid processes an ODR request reply message from the LES network // Valid processes an ODR request reply message from the LES network
// returns true and stores results in memory if the message was a valid reply // returns true and stores results in memory if the message was a valid reply
// to the request (implementation of LesOdrRequest) // to the request (implementation of OdrRequest)
func (r *BlockRequest) Validate(db ethdb.Database, msg *Msg) error { func (r *BlockRequest) Validate(db ethdb.Database, msg *Msg) error {
log.Debug("Validating block body", "hash", r.Hash) log.Debug("Validating block body", "hash", r.Hash)
@ -133,7 +133,7 @@ func (r *BlockRequest) Validate(db ethdb.Database, msg *Msg) error {
type ReceiptsRequest light.ReceiptsRequest type ReceiptsRequest light.ReceiptsRequest
// GetCost returns the cost of the given ODR request according to the serving // GetCost returns the cost of the given ODR request according to the serving
// peer's cost table (implementation of LesOdrRequest) // peer's cost table (implementation of OdrRequest)
func (r *ReceiptsRequest) GetCost(peer *peer) uint64 { func (r *ReceiptsRequest) GetCost(peer *peer) uint64 {
return peer.GetRequestCost(GetReceiptsMsg, 1) return peer.GetRequestCost(GetReceiptsMsg, 1)
} }
@ -143,7 +143,7 @@ func (r *ReceiptsRequest) CanSend(peer *peer) bool {
return peer.HasBlock(r.Hash, r.Number, false) return peer.HasBlock(r.Hash, r.Number, false)
} }
// Request sends an ODR request to the LES network (implementation of LesOdrRequest) // Request sends an ODR request to the LES network (implementation of OdrRequest)
func (r *ReceiptsRequest) Request(reqID uint64, peer *peer) error { func (r *ReceiptsRequest) Request(reqID uint64, peer *peer) error {
peer.Log().Debug("Requesting block receipts", "hash", r.Hash) peer.Log().Debug("Requesting block receipts", "hash", r.Hash)
return peer.RequestReceipts(reqID, r.GetCost(peer), []common.Hash{r.Hash}) return peer.RequestReceipts(reqID, r.GetCost(peer), []common.Hash{r.Hash})
@ -151,7 +151,7 @@ func (r *ReceiptsRequest) Request(reqID uint64, peer *peer) error {
// Valid processes an ODR request reply message from the LES network // Valid processes an ODR request reply message from the LES network
// returns true and stores results in memory if the message was a valid reply // returns true and stores results in memory if the message was a valid reply
// to the request (implementation of LesOdrRequest) // to the request (implementation of OdrRequest)
func (r *ReceiptsRequest) Validate(db ethdb.Database, msg *Msg) error { func (r *ReceiptsRequest) Validate(db ethdb.Database, msg *Msg) error {
log.Debug("Validating block receipts", "hash", r.Hash) log.Debug("Validating block receipts", "hash", r.Hash)
@ -184,11 +184,11 @@ type ProofReq struct {
FromLevel uint FromLevel uint
} }
// ODR request type for state/storage trie entries, see LesOdrRequest interface // ODR request type for state/storage trie entries, see OdrRequest interface
type TrieRequest light.TrieRequest type TrieRequest light.TrieRequest
// GetCost returns the cost of the given ODR request according to the serving // GetCost returns the cost of the given ODR request according to the serving
// peer's cost table (implementation of LesOdrRequest) // peer's cost table (implementation of OdrRequest)
func (r *TrieRequest) GetCost(peer *peer) uint64 { func (r *TrieRequest) GetCost(peer *peer) uint64 {
switch peer.version { switch peer.version {
case lpv1: case lpv1:
@ -205,7 +205,7 @@ func (r *TrieRequest) CanSend(peer *peer) bool {
return peer.HasBlock(r.Id.BlockHash, r.Id.BlockNumber, true) return peer.HasBlock(r.Id.BlockHash, r.Id.BlockNumber, true)
} }
// Request sends an ODR request to the LES network (implementation of LesOdrRequest) // Request sends an ODR request to the LES network (implementation of OdrRequest)
func (r *TrieRequest) Request(reqID uint64, peer *peer) error { func (r *TrieRequest) Request(reqID uint64, peer *peer) error {
peer.Log().Debug("Requesting trie proof", "root", r.Id.Root, "key", r.Key) peer.Log().Debug("Requesting trie proof", "root", r.Id.Root, "key", r.Key)
req := ProofReq{ req := ProofReq{
@ -218,7 +218,7 @@ func (r *TrieRequest) Request(reqID uint64, peer *peer) error {
// Valid processes an ODR request reply message from the LES network // Valid processes an ODR request reply message from the LES network
// returns true and stores results in memory if the message was a valid reply // returns true and stores results in memory if the message was a valid reply
// to the request (implementation of LesOdrRequest) // to the request (implementation of OdrRequest)
func (r *TrieRequest) Validate(db ethdb.Database, msg *Msg) error { func (r *TrieRequest) Validate(db ethdb.Database, msg *Msg) error {
log.Debug("Validating trie proof", "root", r.Id.Root, "key", r.Key) log.Debug("Validating trie proof", "root", r.Id.Root, "key", r.Key)
@ -261,11 +261,11 @@ type CodeReq struct {
AccKey []byte AccKey []byte
} }
// ODR request type for node data (used for retrieving contract code), see LesOdrRequest interface // ODR request type for node data (used for retrieving contract code), see OdrRequest interface
type CodeRequest light.CodeRequest type CodeRequest light.CodeRequest
// GetCost returns the cost of the given ODR request according to the serving // GetCost returns the cost of the given ODR request according to the serving
// peer's cost table (implementation of LesOdrRequest) // peer's cost table (implementation of OdrRequest)
func (r *CodeRequest) GetCost(peer *peer) uint64 { func (r *CodeRequest) GetCost(peer *peer) uint64 {
return peer.GetRequestCost(GetCodeMsg, 1) return peer.GetRequestCost(GetCodeMsg, 1)
} }
@ -275,7 +275,7 @@ func (r *CodeRequest) CanSend(peer *peer) bool {
return peer.HasBlock(r.Id.BlockHash, r.Id.BlockNumber, true) return peer.HasBlock(r.Id.BlockHash, r.Id.BlockNumber, true)
} }
// Request sends an ODR request to the LES network (implementation of LesOdrRequest) // Request sends an ODR request to the LES network (implementation of OdrRequest)
func (r *CodeRequest) Request(reqID uint64, peer *peer) error { func (r *CodeRequest) Request(reqID uint64, peer *peer) error {
peer.Log().Debug("Requesting code data", "hash", r.Hash) peer.Log().Debug("Requesting code data", "hash", r.Hash)
req := CodeReq{ req := CodeReq{
@ -287,7 +287,7 @@ func (r *CodeRequest) Request(reqID uint64, peer *peer) error {
// Valid processes an ODR request reply message from the LES network // Valid processes an ODR request reply message from the LES network
// returns true and stores results in memory if the message was a valid reply // returns true and stores results in memory if the message was a valid reply
// to the request (implementation of LesOdrRequest) // to the request (implementation of OdrRequest)
func (r *CodeRequest) Validate(db ethdb.Database, msg *Msg) error { func (r *CodeRequest) Validate(db ethdb.Database, msg *Msg) error {
log.Debug("Validating code data", "hash", r.Hash) log.Debug("Validating code data", "hash", r.Hash)
@ -344,11 +344,11 @@ type ChtResp struct {
Proof []rlp.RawValue Proof []rlp.RawValue
} }
// ODR request type for requesting headers by Canonical Hash Trie, see LesOdrRequest interface // ODR request type for requesting headers by Canonical Hash Trie, see OdrRequest interface
type ChtRequest light.ChtRequest type ChtRequest light.ChtRequest
// GetCost returns the cost of the given ODR request according to the serving // GetCost returns the cost of the given ODR request according to the serving
// peer's cost table (implementation of LesOdrRequest) // peer's cost table (implementation of OdrRequest)
func (r *ChtRequest) GetCost(peer *peer) uint64 { func (r *ChtRequest) GetCost(peer *peer) uint64 {
switch peer.version { switch peer.version {
case lpv1: case lpv1:
@ -368,7 +368,7 @@ func (r *ChtRequest) CanSend(peer *peer) bool {
return peer.headInfo.Number >= r.Config.ChtConfirms && r.ChtNum <= (peer.headInfo.Number-r.Config.ChtConfirms)/r.Config.ChtSize return peer.headInfo.Number >= r.Config.ChtConfirms && r.ChtNum <= (peer.headInfo.Number-r.Config.ChtConfirms)/r.Config.ChtSize
} }
// Request sends an ODR request to the LES network (implementation of LesOdrRequest) // Request sends an ODR request to the LES network (implementation of OdrRequest)
func (r *ChtRequest) Request(reqID uint64, peer *peer) error { func (r *ChtRequest) Request(reqID uint64, peer *peer) error {
peer.Log().Debug("Requesting CHT", "cht", r.ChtNum, "block", r.BlockNum) peer.Log().Debug("Requesting CHT", "cht", r.ChtNum, "block", r.BlockNum)
var encNum [8]byte var encNum [8]byte
@ -398,7 +398,7 @@ func (r *ChtRequest) Request(reqID uint64, peer *peer) error {
// Valid processes an ODR request reply message from the LES network // Valid processes an ODR request reply message from the LES network
// returns true and stores results in memory if the message was a valid reply // returns true and stores results in memory if the message was a valid reply
// to the request (implementation of LesOdrRequest) // to the request (implementation of OdrRequest)
func (r *ChtRequest) Validate(db ethdb.Database, msg *Msg) error { func (r *ChtRequest) Validate(db ethdb.Database, msg *Msg) error {
log.Debug("Validating CHT", "cht", r.ChtNum, "block", r.BlockNum) log.Debug("Validating CHT", "cht", r.ChtNum, "block", r.BlockNum)
@ -481,11 +481,11 @@ type BloomReq struct {
BloomTrieNum, BitIdx, SectionIndex, FromLevel uint64 BloomTrieNum, BitIdx, SectionIndex, FromLevel uint64
} }
// ODR request type for requesting headers by Canonical Hash Trie, see LesOdrRequest interface // ODR request type for requesting headers by Canonical Hash Trie, see OdrRequest interface
type BloomRequest light.BloomRequest type BloomRequest light.BloomRequest
// GetCost returns the cost of the given ODR request according to the serving // GetCost returns the cost of the given ODR request according to the serving
// peer's cost table (implementation of LesOdrRequest) // peer's cost table (implementation of OdrRequest)
func (r *BloomRequest) GetCost(peer *peer) uint64 { func (r *BloomRequest) GetCost(peer *peer) uint64 {
return peer.GetRequestCost(GetHelperTrieProofsMsg, len(r.SectionIndexList)) return peer.GetRequestCost(GetHelperTrieProofsMsg, len(r.SectionIndexList))
} }
@ -501,7 +501,7 @@ func (r *BloomRequest) CanSend(peer *peer) bool {
return peer.headInfo.Number >= r.Config.BloomTrieConfirms && r.BloomTrieNum <= (peer.headInfo.Number-r.Config.BloomTrieConfirms)/r.Config.BloomTrieSize return peer.headInfo.Number >= r.Config.BloomTrieConfirms && r.BloomTrieNum <= (peer.headInfo.Number-r.Config.BloomTrieConfirms)/r.Config.BloomTrieSize
} }
// Request sends an ODR request to the LES network (implementation of LesOdrRequest) // Request sends an ODR request to the LES network (implementation of OdrRequest)
func (r *BloomRequest) Request(reqID uint64, peer *peer) error { func (r *BloomRequest) Request(reqID uint64, peer *peer) error {
peer.Log().Debug("Requesting BloomBits", "bloomTrie", r.BloomTrieNum, "bitIdx", r.BitIdx, "sections", r.SectionIndexList) peer.Log().Debug("Requesting BloomBits", "bloomTrie", r.BloomTrieNum, "bitIdx", r.BitIdx, "sections", r.SectionIndexList)
reqs := make([]HelperTrieReq, len(r.SectionIndexList)) reqs := make([]HelperTrieReq, len(r.SectionIndexList))
@ -522,7 +522,7 @@ func (r *BloomRequest) Request(reqID uint64, peer *peer) error {
// Valid processes an ODR request reply message from the LES network // Valid processes an ODR request reply message from the LES network
// returns true and stores results in memory if the message was a valid reply // returns true and stores results in memory if the message was a valid reply
// to the request (implementation of LesOdrRequest) // to the request (implementation of OdrRequest)
func (r *BloomRequest) Validate(db ethdb.Database, msg *Msg) error { func (r *BloomRequest) Validate(db ethdb.Database, msg *Msg) error {
log.Debug("Validating BloomBits", "bloomTrie", r.BloomTrieNum, "bitIdx", r.BitIdx, "sections", r.SectionIndexList) log.Debug("Validating BloomBits", "bloomTrie", r.BloomTrieNum, "bitIdx", r.BitIdx, "sections", r.SectionIndexList)

View file

@ -393,7 +393,7 @@ func (p *peer) sendReceiveHandshake(sendList keyValueList) (keyValueList, error)
// Handshake executes the les protocol handshake, negotiating version number, // Handshake executes the les protocol handshake, negotiating version number,
// network IDs, difficulties, head and genesis blocks. // network IDs, difficulties, head and genesis blocks.
func (p *peer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis common.Hash, server *LesServer) error { func (p *peer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis common.Hash, server *Server) error {
p.lock.Lock() p.lock.Lock()
defer p.lock.Unlock() defer p.lock.Unlock()

View file

@ -237,8 +237,8 @@ func TestPeerHandshakeClientReturnErrorOnUselessPeer(t *testing.T) {
} }
} }
func generateLesServer() *LesServer { func generateLesServer() *Server {
s := &LesServer{ s := &Server{
defParams: &flowcontrol.ServerParams{ defParams: &flowcontrol.ServerParams{
BufLimit: uint64(300000000), BufLimit: uint64(300000000),
MinRecharge: uint64(50000), MinRecharge: uint64(50000),

View file

@ -38,8 +38,8 @@ import (
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
) )
type LesServer struct { type Server struct {
lesCommons commons
fcManager *flowcontrol.ClientManager // nil if our node is client only fcManager *flowcontrol.ClientManager // nil if our node is client only
fcCostStats *requestCostStats fcCostStats *requestCostStats
@ -50,7 +50,7 @@ type LesServer struct {
onlyAnnounce bool onlyAnnounce bool
} }
func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) { func NewServer(eth *eth.Ethereum, config *eth.Config) (*Server, error) {
quitSync := make(chan struct{}) quitSync := make(chan struct{})
pm, err := NewProtocolManager( pm, err := NewProtocolManager(
eth.BlockChain().Config(), eth.BlockChain().Config(),
@ -78,8 +78,8 @@ func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) {
lesTopics[i] = lesTopic(eth.BlockChain().Genesis().Hash(), pv) lesTopics[i] = lesTopic(eth.BlockChain().Genesis().Hash(), pv)
} }
srv := &LesServer{ srv := &Server{
lesCommons: lesCommons{ commons: commons{
config: config, config: config,
chainDb: eth.ChainDb(), chainDb: eth.ChainDb(),
iConfig: light.DefaultServerIndexerConfig, iConfig: light.DefaultServerIndexerConfig,
@ -125,12 +125,12 @@ func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) {
return srv, nil return srv, nil
} }
func (s *LesServer) Protocols() []p2p.Protocol { func (s *Server) Protocols() []p2p.Protocol {
return s.makeProtocols(ServerProtocolVersions) return s.makeProtocols(ServerProtocolVersions)
} }
// Start starts the LES server // Start starts the LES server
func (s *LesServer) Start(srvr *p2p.Server) { func (s *Server) Start(srvr *p2p.Server) {
s.protocolManager.Start(s.config.LightPeers) s.protocolManager.Start(s.config.LightPeers)
if srvr.DiscV5 != nil { if srvr.DiscV5 != nil {
for _, topic := range s.lesTopics { for _, topic := range s.lesTopics {
@ -148,12 +148,12 @@ func (s *LesServer) Start(srvr *p2p.Server) {
s.protocolManager.blockLoop() s.protocolManager.blockLoop()
} }
func (s *LesServer) SetBloomBitsIndexer(bloomIndexer *core.ChainIndexer) { func (s *Server) SetBloomBitsIndexer(bloomIndexer *core.ChainIndexer) {
bloomIndexer.AddChildIndexer(s.bloomTrieIndexer) bloomIndexer.AddChildIndexer(s.bloomTrieIndexer)
} }
// Stop stops the LES service // Stop stops the LES service
func (s *LesServer) Stop() { func (s *Server) Stop() {
s.chtIndexer.Close() s.chtIndexer.Close()
// bloom trie indexer is closed by parent bloombits indexer // bloom trie indexer is closed by parent bloombits indexer
s.fcCostStats.store() s.fcCostStats.store()

View file

@ -28,7 +28,7 @@ type ltrInfo struct {
sentTo map[*peer]struct{} sentTo map[*peer]struct{}
} }
type LesTxRelay struct { type TxRelay struct {
txSent map[common.Hash]*ltrInfo txSent map[common.Hash]*ltrInfo
txPending map[common.Hash]struct{} txPending map[common.Hash]struct{}
ps *peerSet ps *peerSet
@ -39,8 +39,8 @@ type LesTxRelay struct {
reqDist *requestDistributor reqDist *requestDistributor
} }
func NewLesTxRelay(ps *peerSet, reqDist *requestDistributor) *LesTxRelay { func NewTxRelay(ps *peerSet, reqDist *requestDistributor) *TxRelay {
r := &LesTxRelay{ r := &TxRelay{
txSent: make(map[common.Hash]*ltrInfo), txSent: make(map[common.Hash]*ltrInfo),
txPending: make(map[common.Hash]struct{}), txPending: make(map[common.Hash]struct{}),
ps: ps, ps: ps,
@ -50,14 +50,14 @@ func NewLesTxRelay(ps *peerSet, reqDist *requestDistributor) *LesTxRelay {
return r return r
} }
func (self *LesTxRelay) registerPeer(p *peer) { func (self *TxRelay) registerPeer(p *peer) {
self.lock.Lock() self.lock.Lock()
defer self.lock.Unlock() defer self.lock.Unlock()
self.peerList = self.ps.AllPeers() self.peerList = self.ps.AllPeers()
} }
func (self *LesTxRelay) unregisterPeer(p *peer) { func (self *TxRelay) unregisterPeer(p *peer) {
self.lock.Lock() self.lock.Lock()
defer self.lock.Unlock() defer self.lock.Unlock()
@ -66,7 +66,7 @@ func (self *LesTxRelay) unregisterPeer(p *peer) {
// send sends a list of transactions to at most a given number of peers at // send sends a list of transactions to at most a given number of peers at
// once, never resending any particular transaction to the same peer twice // once, never resending any particular transaction to the same peer twice
func (self *LesTxRelay) send(txs types.Transactions, count int) { func (self *TxRelay) send(txs types.Transactions, count int) {
sendTo := make(map[*peer]types.Transactions) sendTo := make(map[*peer]types.Transactions)
self.peerStartPos++ // rotate the starting position of the peer list self.peerStartPos++ // rotate the starting position of the peer list
@ -134,14 +134,14 @@ func (self *LesTxRelay) send(txs types.Transactions, count int) {
} }
} }
func (self *LesTxRelay) Send(txs types.Transactions) { func (self *TxRelay) Send(txs types.Transactions) {
self.lock.Lock() self.lock.Lock()
defer self.lock.Unlock() defer self.lock.Unlock()
self.send(txs, 3) self.send(txs, 3)
} }
func (self *LesTxRelay) NewHead(head common.Hash, mined []common.Hash, rollback []common.Hash) { func (self *TxRelay) NewHead(head common.Hash, mined []common.Hash, rollback []common.Hash) {
self.lock.Lock() self.lock.Lock()
defer self.lock.Unlock() defer self.lock.Unlock()
@ -164,7 +164,7 @@ func (self *LesTxRelay) NewHead(head common.Hash, mined []common.Hash, rollback
} }
} }
func (self *LesTxRelay) Discard(hashes []common.Hash) { func (self *TxRelay) Discard(hashes []common.Hash) {
self.lock.Lock() self.lock.Lock()
defer self.lock.Unlock() defer self.lock.Unlock()

View file

@ -221,7 +221,7 @@ func newLightPeer(t *testing.T, ulcConfig *eth.ULCConfig) pairPeer {
rm := newRetrieveManager(peers, dist, nil) rm := newRetrieveManager(peers, dist, nil)
ldb := ethdb.NewMemDatabase() ldb := ethdb.NewMemDatabase()
odr := NewLesOdr(ldb, light.DefaultClientIndexerConfig, rm) odr := NewOdr(ldb, light.DefaultClientIndexerConfig, rm)
pmLight := newTestProtocolManagerMust(t, true, 0, nil, odr, peers, ldb, ulcConfig) pmLight := newTestProtocolManagerMust(t, true, 0, nil, odr, peers, ldb, ulcConfig)
peerPairLight := pairPeer{ peerPairLight := pairPeer{