2016-11-08 19:01:56 -06:00
|
|
|
// Copyright 2016 The go-ethereum Authors
|
2016-10-13 22:51:29 -05:00
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package les
|
|
|
|
|
|
|
|
import (
|
2017-10-24 08:19:09 -05:00
|
|
|
"crypto/ecdsa"
|
2019-05-30 13:51:13 -05:00
|
|
|
"time"
|
2016-10-13 22:51:29 -05:00
|
|
|
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
2019-02-26 05:32:48 -06:00
|
|
|
"github.com/ethereum/go-ethereum/common/mclock"
|
2016-10-13 22:51:29 -05:00
|
|
|
"github.com/ethereum/go-ethereum/core"
|
|
|
|
"github.com/ethereum/go-ethereum/eth"
|
2020-01-07 03:24:21 -06:00
|
|
|
"github.com/ethereum/go-ethereum/les/checkpointoracle"
|
2016-10-13 22:51:29 -05:00
|
|
|
"github.com/ethereum/go-ethereum/les/flowcontrol"
|
|
|
|
"github.com/ethereum/go-ethereum/light"
|
2017-02-22 06:10:07 -06:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2016-10-13 22:51:29 -05:00
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
2017-06-21 05:27:38 -05:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/discv5"
|
2019-08-03 07:36:10 -05:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2019-10-02 06:14:27 -05:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enr"
|
2018-08-28 02:08:16 -05:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2019-02-26 05:32:48 -06:00
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2016-10-13 22:51:29 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type LesServer struct {
|
2018-08-17 05:21:53 -05:00
|
|
|
lesCommons
|
2017-10-24 08:19:09 -05:00
|
|
|
|
2019-06-11 02:40:32 -05:00
|
|
|
archiveMode bool // Flag whether the ethereum node runs in archive mode.
|
2020-02-26 03:41:24 -06:00
|
|
|
peers *clientPeerSet
|
2019-08-21 04:29:34 -05:00
|
|
|
handler *serverHandler
|
|
|
|
lesTopics []discv5.Topic
|
|
|
|
privateKey *ecdsa.PrivateKey
|
2019-06-11 02:40:32 -05:00
|
|
|
|
2019-08-21 04:29:34 -05:00
|
|
|
// Flow control and capacity management
|
|
|
|
fcManager *flowcontrol.ClientManager
|
2019-02-26 05:32:48 -06:00
|
|
|
costTracker *costTracker
|
|
|
|
defParams flowcontrol.ServerParams
|
2019-08-21 04:29:34 -05:00
|
|
|
servingQueue *servingQueue
|
|
|
|
clientPool *clientPool
|
2019-02-26 05:32:48 -06:00
|
|
|
|
2019-11-13 16:47:03 -06:00
|
|
|
minCapacity, maxCapacity, freeCapacity uint64
|
|
|
|
threadsIdle int // Request serving threads count when system is idle.
|
|
|
|
threadsBusy int // Request serving threads count when system is busy(block insertion).
|
2016-10-13 22:51:29 -05:00
|
|
|
}
|
|
|
|
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
func NewLesServer(e *eth.Ethereum, config *eth.Config) (*LesServer, error) {
|
2019-08-21 04:29:34 -05:00
|
|
|
// Collect les protocol version information supported by local node.
|
2018-01-22 06:38:34 -06:00
|
|
|
lesTopics := make([]discv5.Topic, len(AdvertiseProtocolVersions))
|
|
|
|
for i, pv := range AdvertiseProtocolVersions {
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
lesTopics[i] = lesTopic(e.BlockChain().Genesis().Hash(), pv)
|
2017-10-24 08:19:09 -05:00
|
|
|
}
|
2019-08-21 04:29:34 -05:00
|
|
|
// Calculate the number of threads used to service the light client
|
|
|
|
// requests based on the user-specified value.
|
|
|
|
threads := config.LightServ * 4 / 100
|
|
|
|
if threads < 4 {
|
|
|
|
threads = 4
|
|
|
|
}
|
2017-06-21 05:27:38 -05:00
|
|
|
srv := &LesServer{
|
2018-08-17 05:21:53 -05:00
|
|
|
lesCommons: lesCommons{
|
2019-08-21 04:29:34 -05:00
|
|
|
genesis: e.BlockChain().Genesis().Hash(),
|
2018-08-17 05:21:53 -05:00
|
|
|
config: config,
|
2019-08-21 04:29:34 -05:00
|
|
|
chainConfig: e.BlockChain().Config(),
|
2018-08-28 02:08:16 -05:00
|
|
|
iConfig: light.DefaultServerIndexerConfig,
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
chainDb: e.ChainDb(),
|
2019-08-21 04:29:34 -05:00
|
|
|
chainReader: e.BlockChain(),
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
chtIndexer: light.NewChtIndexer(e.ChainDb(), nil, params.CHTFrequency, params.HelperTrieProcessConfirmations),
|
|
|
|
bloomTrieIndexer: light.NewBloomTrieIndexer(e.ChainDb(), nil, params.BloomBitsBlocks, params.BloomTrieFrequency),
|
2019-08-21 04:29:34 -05:00
|
|
|
closeCh: make(chan struct{}),
|
2018-08-17 05:21:53 -05:00
|
|
|
},
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
archiveMode: e.ArchiveMode(),
|
2020-02-26 03:41:24 -06:00
|
|
|
peers: newClientPeerSet(),
|
2019-01-24 05:18:26 -06:00
|
|
|
lesTopics: lesTopics,
|
2019-08-21 04:29:34 -05:00
|
|
|
fcManager: flowcontrol.NewClientManager(nil, &mclock.System{}),
|
|
|
|
servingQueue: newServingQueue(int64(time.Millisecond*10), float64(config.LightServ)/100),
|
|
|
|
threadsBusy: config.LightServ/100 + 1,
|
|
|
|
threadsIdle: threads,
|
2017-10-24 08:19:09 -05:00
|
|
|
}
|
2019-08-21 04:29:34 -05:00
|
|
|
srv.handler = newServerHandler(srv, e.BlockChain(), e.ChainDb(), e.TxPool(), e.Synced)
|
2019-11-13 16:47:03 -06:00
|
|
|
srv.costTracker, srv.minCapacity = newCostTracker(e.ChainDb(), config)
|
|
|
|
srv.freeCapacity = srv.minCapacity
|
2018-08-17 05:21:53 -05:00
|
|
|
|
2019-08-21 04:29:34 -05:00
|
|
|
// Set up checkpoint oracle.
|
|
|
|
oracle := config.CheckpointOracle
|
|
|
|
if oracle == nil {
|
|
|
|
oracle = params.CheckpointOracles[e.BlockChain().Genesis().Hash()]
|
2019-02-26 05:32:48 -06:00
|
|
|
}
|
2020-01-07 03:24:21 -06:00
|
|
|
srv.oracle = checkpointoracle.New(oracle, srv.localCheckpoint)
|
2019-08-21 04:29:34 -05:00
|
|
|
|
|
|
|
// Initialize server capacity management fields.
|
|
|
|
srv.defParams = flowcontrol.ServerParams{
|
|
|
|
BufLimit: srv.freeCapacity * bufLimitRatio,
|
|
|
|
MinRecharge: srv.freeCapacity,
|
|
|
|
}
|
|
|
|
// LES flow control tries to more or less guarantee the possibility for the
|
|
|
|
// clients to send a certain amount of requests at any time and get a quick
|
|
|
|
// response. Most of the clients want this guarantee but don't actually need
|
|
|
|
// to send requests most of the time. Our goal is to serve as many clients as
|
|
|
|
// possible while the actually used server capacity does not exceed the limits
|
|
|
|
totalRecharge := srv.costTracker.totalRecharge()
|
2019-11-13 16:47:03 -06:00
|
|
|
srv.maxCapacity = srv.freeCapacity * uint64(srv.config.LightPeers)
|
|
|
|
if totalRecharge > srv.maxCapacity {
|
|
|
|
srv.maxCapacity = totalRecharge
|
2019-08-21 04:29:34 -05:00
|
|
|
}
|
2019-11-13 16:47:03 -06:00
|
|
|
srv.fcManager.SetCapacityLimits(srv.freeCapacity, srv.maxCapacity, srv.freeCapacity*2)
|
2020-02-26 03:41:24 -06:00
|
|
|
srv.clientPool = newClientPool(srv.chainDb, srv.freeCapacity, mclock.System{}, func(id enode.ID) { go srv.peers.unregister(peerIdToString(id)) })
|
2019-11-13 16:47:03 -06:00
|
|
|
srv.clientPool.setDefaultFactors(priceFactors{0, 1, 1}, priceFactors{0, 1, 1})
|
2017-10-24 08:19:09 -05:00
|
|
|
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
checkpoint := srv.latestLocalCheckpoint()
|
|
|
|
if !checkpoint.Empty() {
|
2019-08-21 04:29:34 -05:00
|
|
|
log.Info("Loaded latest checkpoint", "section", checkpoint.SectionIndex, "head", checkpoint.SectionHead,
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
"chtroot", checkpoint.CHTRoot, "bloomroot", checkpoint.BloomRoot)
|
2017-10-24 08:19:09 -05:00
|
|
|
}
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
srv.chtIndexer.Start(e.BlockChain())
|
2019-02-26 05:32:48 -06:00
|
|
|
return srv, nil
|
|
|
|
}
|
2016-10-13 22:51:29 -05:00
|
|
|
|
2019-02-26 05:32:48 -06:00
|
|
|
func (s *LesServer) APIs() []rpc.API {
|
|
|
|
return []rpc.API{
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
{
|
|
|
|
Namespace: "les",
|
|
|
|
Version: "1.0",
|
2019-08-21 04:29:34 -05:00
|
|
|
Service: NewPrivateLightAPI(&s.lesCommons),
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
Public: false,
|
|
|
|
},
|
2019-11-13 16:47:03 -06:00
|
|
|
{
|
|
|
|
Namespace: "les",
|
|
|
|
Version: "1.0",
|
|
|
|
Service: NewPrivateLightServerAPI(s),
|
|
|
|
Public: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Namespace: "debug",
|
|
|
|
Version: "1.0",
|
|
|
|
Service: NewPrivateDebugAPI(s),
|
|
|
|
Public: false,
|
|
|
|
},
|
2016-10-13 22:51:29 -05:00
|
|
|
}
|
2019-02-26 05:32:48 -06:00
|
|
|
}
|
|
|
|
|
2016-10-13 22:51:29 -05:00
|
|
|
func (s *LesServer) Protocols() []p2p.Protocol {
|
2019-10-02 06:14:27 -05:00
|
|
|
ps := s.makeProtocols(ServerProtocolVersions, s.handler.runPeer, func(id enode.ID) interface{} {
|
2020-02-26 03:41:24 -06:00
|
|
|
if p := s.peers.peer(peerIdToString(id)); p != nil {
|
2019-08-21 04:29:34 -05:00
|
|
|
return p.Info()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
2019-10-02 06:14:27 -05:00
|
|
|
// Add "les" ENR entries.
|
|
|
|
for i := range ps {
|
|
|
|
ps[i].Attributes = []enr.Entry{&lesEntry{}}
|
|
|
|
}
|
|
|
|
return ps
|
2016-10-13 22:51:29 -05:00
|
|
|
}
|
|
|
|
|
2017-01-22 19:35:46 -06:00
|
|
|
// Start starts the LES server
|
2016-10-19 06:04:55 -05:00
|
|
|
func (s *LesServer) Start(srvr *p2p.Server) {
|
2019-08-21 04:29:34 -05:00
|
|
|
s.privateKey = srvr.PrivateKey
|
|
|
|
s.handler.start()
|
|
|
|
|
|
|
|
s.wg.Add(1)
|
|
|
|
go s.capacityManagement()
|
2019-02-26 05:32:48 -06:00
|
|
|
|
2018-02-10 06:33:52 -06:00
|
|
|
if srvr.DiscV5 != nil {
|
|
|
|
for _, topic := range s.lesTopics {
|
|
|
|
topic := topic
|
|
|
|
go func() {
|
|
|
|
logger := log.New("topic", topic)
|
|
|
|
logger.Info("Starting topic registration")
|
|
|
|
defer logger.Info("Terminated topic registration")
|
|
|
|
|
2019-08-21 04:29:34 -05:00
|
|
|
srvr.DiscV5.RegisterTopic(topic, s.closeCh)
|
2018-02-10 06:33:52 -06:00
|
|
|
}()
|
|
|
|
}
|
2017-10-24 08:19:09 -05:00
|
|
|
}
|
2019-08-21 04:29:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop stops the LES service
|
|
|
|
func (s *LesServer) Stop() {
|
|
|
|
close(s.closeCh)
|
|
|
|
|
|
|
|
// Disconnect existing sessions.
|
|
|
|
// This also closes the gate for any new registrations on the peer set.
|
|
|
|
// sessions which are already established but not added to pm.peers yet
|
|
|
|
// will exit when they try to register.
|
2020-02-26 03:41:24 -06:00
|
|
|
s.peers.close()
|
2019-08-21 04:29:34 -05:00
|
|
|
|
|
|
|
s.fcManager.Stop()
|
|
|
|
s.costTracker.stop()
|
|
|
|
s.handler.stop()
|
2019-11-02 07:02:35 -05:00
|
|
|
s.clientPool.stop() // client pool should be closed after handler.
|
2019-08-21 04:29:34 -05:00
|
|
|
s.servingQueue.stop()
|
|
|
|
|
|
|
|
// Note, bloom trie indexer is closed by parent bloombits indexer.
|
|
|
|
s.chtIndexer.Close()
|
|
|
|
s.wg.Wait()
|
|
|
|
log.Info("Les server stopped")
|
2017-10-24 08:19:09 -05:00
|
|
|
}
|
2017-06-21 05:27:38 -05:00
|
|
|
|
2017-10-24 08:19:09 -05:00
|
|
|
func (s *LesServer) SetBloomBitsIndexer(bloomIndexer *core.ChainIndexer) {
|
|
|
|
bloomIndexer.AddChildIndexer(s.bloomTrieIndexer)
|
2016-10-13 22:51:29 -05:00
|
|
|
}
|
|
|
|
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
// SetClient sets the rpc client and starts running checkpoint contract if it is not yet watched.
|
|
|
|
func (s *LesServer) SetContractBackend(backend bind.ContractBackend) {
|
2019-08-21 04:29:34 -05:00
|
|
|
if s.oracle == nil {
|
|
|
|
return
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
}
|
2020-01-07 03:24:21 -06:00
|
|
|
s.oracle.Start(backend)
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
}
|
|
|
|
|
2019-08-21 04:29:34 -05:00
|
|
|
// capacityManagement starts an event handler loop that updates the recharge curve of
|
|
|
|
// the client manager and adjusts the client pool's size according to the total
|
|
|
|
// capacity updates coming from the client manager
|
|
|
|
func (s *LesServer) capacityManagement() {
|
|
|
|
defer s.wg.Done()
|
2016-10-13 22:51:29 -05:00
|
|
|
|
2019-08-21 04:29:34 -05:00
|
|
|
processCh := make(chan bool, 100)
|
|
|
|
sub := s.handler.blockchain.SubscribeBlockProcessingEvent(processCh)
|
|
|
|
defer sub.Unsubscribe()
|
2016-11-13 05:34:50 -06:00
|
|
|
|
2019-08-21 04:29:34 -05:00
|
|
|
totalRechargeCh := make(chan uint64, 100)
|
|
|
|
totalRecharge := s.costTracker.subscribeTotalRecharge(totalRechargeCh)
|
2016-11-13 05:34:50 -06:00
|
|
|
|
2019-08-21 04:29:34 -05:00
|
|
|
totalCapacityCh := make(chan uint64, 100)
|
|
|
|
totalCapacity := s.fcManager.SubscribeTotalCapacity(totalCapacityCh)
|
|
|
|
s.clientPool.setLimits(s.config.LightPeers, totalCapacity)
|
2017-10-24 08:19:09 -05:00
|
|
|
|
2019-08-21 04:29:34 -05:00
|
|
|
var (
|
|
|
|
busy bool
|
|
|
|
freePeers uint64
|
|
|
|
blockProcess mclock.AbsTime
|
|
|
|
)
|
|
|
|
updateRecharge := func() {
|
|
|
|
if busy {
|
|
|
|
s.servingQueue.setThreads(s.threadsBusy)
|
|
|
|
s.fcManager.SetRechargeCurve(flowcontrol.PieceWiseLinear{{0, 0}, {totalRecharge, totalRecharge}})
|
|
|
|
} else {
|
|
|
|
s.servingQueue.setThreads(s.threadsIdle)
|
|
|
|
s.fcManager.SetRechargeCurve(flowcontrol.PieceWiseLinear{{0, 0}, {totalRecharge / 10, totalRecharge}, {totalRecharge, totalRecharge}})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateRecharge()
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case busy = <-processCh:
|
|
|
|
if busy {
|
|
|
|
blockProcess = mclock.Now()
|
|
|
|
} else {
|
|
|
|
blockProcessingTimer.Update(time.Duration(mclock.Now() - blockProcess))
|
2016-10-13 22:51:29 -05:00
|
|
|
}
|
2019-08-21 04:29:34 -05:00
|
|
|
updateRecharge()
|
|
|
|
case totalRecharge = <-totalRechargeCh:
|
|
|
|
totalRechargeGauge.Update(int64(totalRecharge))
|
|
|
|
updateRecharge()
|
|
|
|
case totalCapacity = <-totalCapacityCh:
|
|
|
|
totalCapacityGauge.Update(int64(totalCapacity))
|
|
|
|
newFreePeers := totalCapacity / s.freeCapacity
|
|
|
|
if newFreePeers < freePeers && newFreePeers < uint64(s.config.LightPeers) {
|
|
|
|
log.Warn("Reduced free peer connections", "from", freePeers, "to", newFreePeers)
|
|
|
|
}
|
|
|
|
freePeers = newFreePeers
|
|
|
|
s.clientPool.setLimits(s.config.LightPeers, totalCapacity)
|
|
|
|
case <-s.closeCh:
|
|
|
|
return
|
2016-10-13 22:51:29 -05:00
|
|
|
}
|
2019-08-21 04:29:34 -05:00
|
|
|
}
|
2016-10-13 22:51:29 -05:00
|
|
|
}
|