2016-11-09 04:01:56 +03:00
|
|
|
// Copyright 2016 The go-ethereum Authors
|
2016-10-14 06:51:29 +03: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 implements the Light Ethereum Subprotocol.
|
|
|
|
package les
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-04-09 12:55:32 +03:00
|
|
|
"time"
|
2016-10-14 06:51:29 +03:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
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 10:34:02 +03:00
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
2016-10-14 06:51:29 +03:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2016-12-17 17:39:55 +03:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2019-02-26 14:32:48 +03:00
|
|
|
"github.com/ethereum/go-ethereum/common/mclock"
|
2017-04-05 01:16:29 +03:00
|
|
|
"github.com/ethereum/go-ethereum/consensus"
|
2016-10-14 06:51:29 +03:00
|
|
|
"github.com/ethereum/go-ethereum/core"
|
2017-10-24 16:19:09 +03:00
|
|
|
"github.com/ethereum/go-ethereum/core/bloombits"
|
2018-05-07 14:35:06 +03:00
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
2016-10-14 06:51:29 +03:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/ethereum/go-ethereum/eth"
|
|
|
|
"github.com/ethereum/go-ethereum/eth/downloader"
|
|
|
|
"github.com/ethereum/go-ethereum/eth/filters"
|
|
|
|
"github.com/ethereum/go-ethereum/eth/gasprice"
|
|
|
|
"github.com/ethereum/go-ethereum/event"
|
|
|
|
"github.com/ethereum/go-ethereum/internal/ethapi"
|
2020-01-07 12:24:21 +03:00
|
|
|
"github.com/ethereum/go-ethereum/les/checkpointoracle"
|
2020-04-09 12:55:32 +03:00
|
|
|
lpc "github.com/ethereum/go-ethereum/les/lespay/client"
|
2016-10-14 06:51:29 +03:00
|
|
|
"github.com/ethereum/go-ethereum/light"
|
2017-02-22 15:10:07 +03:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2016-10-14 06:51:29 +03:00
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
2019-08-21 12:29:34 +03:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2016-10-20 14:36:29 +03:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
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 10:34:02 +03:00
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2016-10-14 06:51:29 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type LightEthereum struct {
|
2018-08-17 13:21:53 +03:00
|
|
|
lesCommons
|
2018-02-05 16:41:53 +03:00
|
|
|
|
2020-05-22 14:46:34 +03:00
|
|
|
peers *serverPeerSet
|
|
|
|
reqDist *requestDistributor
|
|
|
|
retriever *retrieveManager
|
|
|
|
odr *LesOdr
|
|
|
|
relay *lesTxRelay
|
|
|
|
handler *clientHandler
|
|
|
|
txPool *light.TxPool
|
|
|
|
blockchain *light.LightChain
|
|
|
|
serverPool *serverPool
|
|
|
|
valueTracker *lpc.ValueTracker
|
|
|
|
dialCandidates enode.Iterator
|
2020-07-13 12:02:54 +03:00
|
|
|
pruner *pruner
|
2018-08-17 13:21:53 +03:00
|
|
|
|
|
|
|
bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
|
2019-08-21 12:29:34 +03:00
|
|
|
bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports
|
2016-10-14 06:51:29 +03:00
|
|
|
|
2019-08-21 12:29:34 +03:00
|
|
|
ApiBackend *LesApiBackend
|
2016-10-14 06:51:29 +03:00
|
|
|
eventMux *event.TypeMux
|
2017-04-05 01:16:29 +03:00
|
|
|
engine consensus.Engine
|
2016-10-14 06:51:29 +03:00
|
|
|
accountManager *accounts.Manager
|
2019-08-21 12:29:34 +03:00
|
|
|
netRPCService *ethapi.PublicNetAPI
|
2016-10-14 06:51:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
|
2018-09-24 15:57:49 +03:00
|
|
|
chainDb, err := ctx.OpenDatabase("lightchaindata", config.DatabaseCache, config.DatabaseHandles, "eth/db/chaindata/")
|
2016-10-14 06:51:29 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-04-09 12:55:32 +03:00
|
|
|
lespayDb, err := ctx.OpenDatabase("lespay", 0, 0, "eth/db/lespay")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-04-20 12:46:38 +03:00
|
|
|
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlock(chainDb, config.Genesis)
|
2017-03-02 16:03:33 +03:00
|
|
|
if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat {
|
|
|
|
return nil, genesisErr
|
2016-10-14 06:51:29 +03:00
|
|
|
}
|
2017-03-02 16:03:33 +03:00
|
|
|
log.Info("Initialised chain configuration", "config", chainConfig)
|
|
|
|
|
2020-02-26 12:41:24 +03:00
|
|
|
peers := newServerPeerSet()
|
2017-10-24 16:19:09 +03:00
|
|
|
leth := &LightEthereum{
|
2018-08-17 13:21:53 +03:00
|
|
|
lesCommons: lesCommons{
|
2019-08-21 12:29:34 +03:00
|
|
|
genesis: genesisHash,
|
|
|
|
config: config,
|
|
|
|
chainConfig: chainConfig,
|
|
|
|
iConfig: light.DefaultClientIndexerConfig,
|
|
|
|
chainDb: chainDb,
|
|
|
|
closeCh: make(chan struct{}),
|
2018-08-17 13:21:53 +03:00
|
|
|
},
|
2020-02-26 12:41:24 +03:00
|
|
|
peers: peers,
|
2018-08-15 23:25:46 +03:00
|
|
|
eventMux: ctx.EventMux,
|
2019-08-21 12:29:34 +03:00
|
|
|
reqDist: newRequestDistributor(peers, &mclock.System{}),
|
2018-08-15 23:25:46 +03:00
|
|
|
accountManager: ctx.AccountManager,
|
2018-08-28 16:59:05 +03:00
|
|
|
engine: eth.CreateConsensusEngine(ctx, chainConfig, &config.Ethash, nil, false, chainDb),
|
2018-08-15 23:25:46 +03:00
|
|
|
bloomRequests: make(chan chan *bloombits.Retrieval),
|
2018-08-28 10:08:16 +03:00
|
|
|
bloomIndexer: eth.NewBloomIndexer(chainDb, params.BloomBitsBlocksClient, params.HelperTrieConfirmations),
|
2020-04-09 12:55:32 +03:00
|
|
|
valueTracker: lpc.NewValueTracker(lespayDb, &mclock.System{}, requestList, time.Minute, 1/float64(time.Hour), 1/float64(time.Hour*100), 1/float64(time.Hour*1000)),
|
2016-10-14 06:51:29 +03:00
|
|
|
}
|
2020-04-09 12:55:32 +03:00
|
|
|
peers.subscribe((*vtSubscription)(leth.valueTracker))
|
2020-05-22 14:46:34 +03:00
|
|
|
|
|
|
|
dnsdisc, err := leth.setupDiscovery(&ctx.Config.P2P)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
leth.serverPool = newServerPool(lespayDb, []byte("serverpool:"), leth.valueTracker, dnsdisc, time.Second, nil, &mclock.System{}, config.UltraLightServers)
|
|
|
|
peers.subscribe(leth.serverPool)
|
|
|
|
leth.dialCandidates = leth.serverPool.dialIterator
|
|
|
|
|
|
|
|
leth.retriever = newRetrieveManager(peers, leth.reqDist, leth.serverPool.getTimeout)
|
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 10:34:02 +03:00
|
|
|
leth.relay = newLesTxRelay(peers, leth.retriever)
|
2018-08-17 13:21:53 +03:00
|
|
|
|
2018-08-28 10:08:16 +03:00
|
|
|
leth.odr = NewLesOdr(chainDb, light.DefaultClientIndexerConfig, leth.retriever)
|
2020-07-13 12:02:54 +03:00
|
|
|
leth.chtIndexer = light.NewChtIndexer(chainDb, leth.odr, params.CHTFrequency, params.HelperTrieConfirmations, config.LightNoPrune)
|
|
|
|
leth.bloomTrieIndexer = light.NewBloomTrieIndexer(chainDb, leth.odr, params.BloomBitsBlocksClient, params.BloomTrieFrequency, config.LightNoPrune)
|
2018-08-15 23:25:46 +03:00
|
|
|
leth.odr.SetIndexers(leth.chtIndexer, leth.bloomTrieIndexer, leth.bloomIndexer)
|
2018-08-17 13:21:53 +03: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 10:34:02 +03:00
|
|
|
checkpoint := config.Checkpoint
|
|
|
|
if checkpoint == nil {
|
|
|
|
checkpoint = params.TrustedCheckpoints[genesisHash]
|
|
|
|
}
|
2018-08-15 23:25:46 +03:00
|
|
|
// Note: NewLightChain adds the trusted checkpoint so it needs an ODR with
|
|
|
|
// indexers already set but not started yet
|
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 10:34:02 +03:00
|
|
|
if leth.blockchain, err = light.NewLightChain(leth.odr, leth.chainConfig, leth.engine, checkpoint); err != nil {
|
2016-10-14 06:51:29 +03:00
|
|
|
return nil, err
|
|
|
|
}
|
2019-08-21 12:29:34 +03:00
|
|
|
leth.chainReader = leth.blockchain
|
|
|
|
leth.txPool = light.NewTxPool(leth.chainConfig, leth.blockchain, leth.relay)
|
|
|
|
|
|
|
|
// Set up checkpoint oracle.
|
|
|
|
oracle := config.CheckpointOracle
|
|
|
|
if oracle == nil {
|
|
|
|
oracle = params.CheckpointOracles[genesisHash]
|
|
|
|
}
|
2020-01-07 12:24:21 +03:00
|
|
|
leth.oracle = checkpointoracle.New(oracle, leth.localCheckpoint)
|
2019-08-21 12:29:34 +03:00
|
|
|
|
2018-08-15 23:25:46 +03:00
|
|
|
// Note: AddChildIndexer starts the update process for the child
|
|
|
|
leth.bloomIndexer.AddChildIndexer(leth.bloomTrieIndexer)
|
|
|
|
leth.chtIndexer.Start(leth.blockchain)
|
2017-10-24 16:19:09 +03:00
|
|
|
leth.bloomIndexer.Start(leth.blockchain)
|
2018-08-17 13:21:53 +03:00
|
|
|
|
2020-07-13 12:02:54 +03:00
|
|
|
// Start a light chain pruner to delete useless historical data.
|
|
|
|
leth.pruner = newPruner(chainDb, leth.chtIndexer, leth.bloomTrieIndexer)
|
|
|
|
|
2017-03-02 16:03:33 +03:00
|
|
|
// Rewind the chain in case of an incompatible config upgrade.
|
|
|
|
if compat, ok := genesisErr.(*params.ConfigCompatError); ok {
|
|
|
|
log.Warn("Rewinding chain to upgrade configuration", "err", compat)
|
2017-10-24 16:19:09 +03:00
|
|
|
leth.blockchain.SetHead(compat.RewindTo)
|
2018-05-07 14:35:06 +03:00
|
|
|
rawdb.WriteChainConfig(chainDb, genesisHash, chainConfig)
|
2017-03-02 16:03:33 +03:00
|
|
|
}
|
2016-10-14 06:51:29 +03:00
|
|
|
|
2019-04-04 14:03:10 +03:00
|
|
|
leth.ApiBackend = &LesApiBackend{ctx.ExtRPCEnabled(), leth, nil}
|
2017-04-12 17:27:23 +03:00
|
|
|
gpoParams := config.GPO
|
|
|
|
if gpoParams.Default == nil {
|
2019-04-23 10:08:51 +03:00
|
|
|
gpoParams.Default = config.Miner.GasPrice
|
2017-04-06 17:20:42 +03:00
|
|
|
}
|
2017-10-24 16:19:09 +03:00
|
|
|
leth.ApiBackend.gpo = gasprice.NewOracle(leth.ApiBackend, gpoParams)
|
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 10:34:02 +03:00
|
|
|
|
2020-05-22 14:46:34 +03:00
|
|
|
leth.handler = newClientHandler(config.UltraLightServers, config.UltraLightFraction, checkpoint, leth)
|
|
|
|
if leth.handler.ulc != nil {
|
|
|
|
log.Warn("Ultra light client is enabled", "trustedNodes", len(leth.handler.ulc.keys), "minTrustedFraction", leth.handler.ulc.fraction)
|
|
|
|
leth.blockchain.DisableCheckFreq()
|
|
|
|
}
|
2017-10-24 16:19:09 +03:00
|
|
|
return leth, nil
|
2016-10-14 06:51:29 +03:00
|
|
|
}
|
|
|
|
|
2020-04-09 12:55:32 +03:00
|
|
|
// vtSubscription implements serverPeerSubscriber
|
|
|
|
type vtSubscription lpc.ValueTracker
|
|
|
|
|
|
|
|
// registerPeer implements serverPeerSubscriber
|
|
|
|
func (v *vtSubscription) registerPeer(p *serverPeer) {
|
|
|
|
vt := (*lpc.ValueTracker)(v)
|
|
|
|
p.setValueTracker(vt, vt.Register(p.ID()))
|
|
|
|
p.updateVtParams()
|
|
|
|
}
|
|
|
|
|
|
|
|
// unregisterPeer implements serverPeerSubscriber
|
|
|
|
func (v *vtSubscription) unregisterPeer(p *serverPeer) {
|
|
|
|
vt := (*lpc.ValueTracker)(v)
|
|
|
|
vt.Unregister(p.ID())
|
|
|
|
p.setValueTracker(nil, nil)
|
|
|
|
}
|
|
|
|
|
2016-10-14 06:51:29 +03:00
|
|
|
type LightDummyAPI struct{}
|
|
|
|
|
|
|
|
// Etherbase is the address that mining rewards will be send to
|
|
|
|
func (s *LightDummyAPI) Etherbase() (common.Address, error) {
|
2019-04-03 10:15:15 +03:00
|
|
|
return common.Address{}, fmt.Errorf("mining is not supported in light mode")
|
2016-10-14 06:51:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Coinbase is the address that mining rewards will be send to (alias for Etherbase)
|
|
|
|
func (s *LightDummyAPI) Coinbase() (common.Address, error) {
|
2019-04-03 10:15:15 +03:00
|
|
|
return common.Address{}, fmt.Errorf("mining is not supported in light mode")
|
2016-10-14 06:51:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hashrate returns the POW hashrate
|
2016-12-17 17:39:55 +03:00
|
|
|
func (s *LightDummyAPI) Hashrate() hexutil.Uint {
|
|
|
|
return 0
|
2016-10-14 06:51:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mining returns an indication if this node is currently mining.
|
|
|
|
func (s *LightDummyAPI) Mining() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 *LightEthereum) APIs() []rpc.API {
|
2019-11-19 20:22:04 +03:00
|
|
|
apis := ethapi.GetAPIs(s.ApiBackend)
|
|
|
|
apis = append(apis, s.engine.APIs(s.BlockChain().HeaderChain())...)
|
|
|
|
return append(apis, []rpc.API{
|
2016-10-14 06:51:29 +03:00
|
|
|
{
|
|
|
|
Namespace: "eth",
|
|
|
|
Version: "1.0",
|
|
|
|
Service: &LightDummyAPI{},
|
|
|
|
Public: true,
|
|
|
|
}, {
|
|
|
|
Namespace: "eth",
|
|
|
|
Version: "1.0",
|
2019-08-21 12:29:34 +03:00
|
|
|
Service: downloader.NewPublicDownloaderAPI(s.handler.downloader, s.eventMux),
|
2016-10-14 06:51:29 +03:00
|
|
|
Public: true,
|
|
|
|
}, {
|
|
|
|
Namespace: "eth",
|
|
|
|
Version: "1.0",
|
|
|
|
Service: filters.NewPublicFilterAPI(s.ApiBackend, true),
|
|
|
|
Public: true,
|
|
|
|
}, {
|
|
|
|
Namespace: "net",
|
|
|
|
Version: "1.0",
|
|
|
|
Service: s.netRPCService,
|
|
|
|
Public: true,
|
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 10:34:02 +03:00
|
|
|
}, {
|
|
|
|
Namespace: "les",
|
|
|
|
Version: "1.0",
|
2019-08-21 12:29:34 +03: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 10:34:02 +03:00
|
|
|
Public: false,
|
2020-04-09 12:55:32 +03:00
|
|
|
}, {
|
|
|
|
Namespace: "lespay",
|
|
|
|
Version: "1.0",
|
|
|
|
Service: lpc.NewPrivateClientAPI(s.valueTracker),
|
|
|
|
Public: false,
|
2016-10-14 06:51:29 +03:00
|
|
|
},
|
|
|
|
}...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *LightEthereum) ResetWithGenesisBlock(gb *types.Block) {
|
|
|
|
s.blockchain.ResetWithGenesisBlock(gb)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *LightEthereum) BlockChain() *light.LightChain { return s.blockchain }
|
|
|
|
func (s *LightEthereum) TxPool() *light.TxPool { return s.txPool }
|
2017-04-12 16:38:31 +03:00
|
|
|
func (s *LightEthereum) Engine() consensus.Engine { return s.engine }
|
2018-08-17 13:21:53 +03:00
|
|
|
func (s *LightEthereum) LesVersion() int { return int(ClientProtocolVersions[0]) }
|
2019-08-21 12:29:34 +03:00
|
|
|
func (s *LightEthereum) Downloader() *downloader.Downloader { return s.handler.downloader }
|
2016-11-25 18:55:06 +03:00
|
|
|
func (s *LightEthereum) EventMux() *event.TypeMux { return s.eventMux }
|
2016-10-14 06:51:29 +03:00
|
|
|
|
|
|
|
// Protocols implements node.Service, returning all the currently configured
|
|
|
|
// network protocols to start.
|
|
|
|
func (s *LightEthereum) Protocols() []p2p.Protocol {
|
2019-08-21 12:29:34 +03:00
|
|
|
return s.makeProtocols(ClientProtocolVersions, s.handler.runPeer, func(id enode.ID) interface{} {
|
2020-02-26 12:41:24 +03:00
|
|
|
if p := s.peers.peer(peerIdToString(id)); p != nil {
|
2019-08-21 12:29:34 +03:00
|
|
|
return p.Info()
|
|
|
|
}
|
|
|
|
return nil
|
2020-05-22 14:46:34 +03:00
|
|
|
}, s.dialCandidates)
|
2016-10-14 06:51:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start implements node.Service, starting all internal goroutines needed by the
|
2019-08-21 12:29:34 +03:00
|
|
|
// light ethereum protocol implementation.
|
2016-10-14 06:51:29 +03:00
|
|
|
func (s *LightEthereum) Start(srvr *p2p.Server) error {
|
2017-03-03 12:41:52 +03:00
|
|
|
log.Warn("Light client mode is an experimental feature")
|
2019-08-21 12:29:34 +03:00
|
|
|
|
2020-05-22 14:46:34 +03:00
|
|
|
s.serverPool.start()
|
2019-08-21 12:29:34 +03:00
|
|
|
// Start bloom request workers.
|
|
|
|
s.wg.Add(bloomServiceThreads)
|
2018-08-28 10:08:16 +03:00
|
|
|
s.startBloomHandlers(params.BloomBitsBlocksClient)
|
2019-08-21 12:29:34 +03:00
|
|
|
|
|
|
|
s.netRPCService = ethapi.NewPublicNetAPI(srvr, s.config.NetworkId)
|
2016-10-14 06:51:29 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop implements node.Service, terminating all internal goroutines used by the
|
|
|
|
// Ethereum protocol.
|
|
|
|
func (s *LightEthereum) Stop() error {
|
2019-08-21 12:29:34 +03:00
|
|
|
close(s.closeCh)
|
2020-05-22 14:46:34 +03:00
|
|
|
s.serverPool.stop()
|
|
|
|
s.valueTracker.Stop()
|
2020-02-26 12:41:24 +03:00
|
|
|
s.peers.close()
|
2019-08-21 12:29:34 +03:00
|
|
|
s.reqDist.close()
|
2016-10-14 06:51:29 +03:00
|
|
|
s.odr.Stop()
|
2019-05-13 14:41:10 +03:00
|
|
|
s.relay.Stop()
|
2018-08-17 13:21:53 +03:00
|
|
|
s.bloomIndexer.Close()
|
|
|
|
s.chtIndexer.Close()
|
2016-10-14 06:51:29 +03:00
|
|
|
s.blockchain.Stop()
|
2019-08-21 12:29:34 +03:00
|
|
|
s.handler.stop()
|
2016-10-14 06:51:29 +03:00
|
|
|
s.txPool.Stop()
|
2018-08-03 11:33:37 +03:00
|
|
|
s.engine.Close()
|
2020-07-13 12:02:54 +03:00
|
|
|
s.pruner.close()
|
2016-10-14 06:51:29 +03:00
|
|
|
s.eventMux.Stop()
|
|
|
|
s.chainDb.Close()
|
2019-08-21 12:29:34 +03:00
|
|
|
s.wg.Wait()
|
|
|
|
log.Info("Light ethereum stopped")
|
2016-10-14 06:51:29 +03:00
|
|
|
return nil
|
|
|
|
}
|
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 10:34:02 +03:00
|
|
|
|
|
|
|
// SetClient sets the rpc client and binds the registrar contract.
|
|
|
|
func (s *LightEthereum) SetContractBackend(backend bind.ContractBackend) {
|
2019-08-21 12:29:34 +03:00
|
|
|
if s.oracle == nil {
|
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 10:34:02 +03:00
|
|
|
return
|
|
|
|
}
|
2020-01-07 12:24:21 +03: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 10:34:02 +03:00
|
|
|
}
|