2022-05-24 20:39:40 +02:00
|
|
|
// Copyright 2019 The go-ethereum Authors
|
2016-10-14 05:51:29 +02: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 (
|
optimism: historical Bedrock geth rollup changes
This commit squashes the op-geth fork history into a more maintainable
diff for rebasing upon upstream geth.
reference-optimistic-geth changes (origins of op-geth in early Bedrock
development stage):
- Deposit TX Type
- Enable deposit tx in EVM/tx pool
- Change deposit nonce to not be the max nonce
- Extend PayloadAttributesV1 with a Transactions field
- Force deposits at the start of each L2 block
- Fix height check
- noTxPool flag, reproduce block in verifier mode without tx pool interference
- Fix RPC json marshalling (ref op-geth PR 4)
- Deposit txs block height check in block body validation (ref op-geth PR 5)
- core: do not try to reinject deposit txs into tx-pool (ref-op-geth PR 6)
- deposit source hash field instead of L2 block height and tx index combination
- Include invalid deposits, rewind state, but always persist mint (#10)
- Provide gas to Call/Create in deposit transactions (#12)
- Add docker builds (ref-op-geth PR 16, 17)
- Don't panic on deposit transaction signature values or chain ID (ref-op-geth PR 18)
- core: Add version to DepositTx (ref-op-geth PR 19)
- Enable Geth build/lint/test in CircleCI (ref-op-geth PR 23)
- core: Include guaranteed gas in the gas pool (ref-op-geth PR 21)
- core: handle base fee, l1 availability fee, tx fee (ref-op-geth PR 27)
- fix: deposit tx hash
- fix l1 fee cache, rpc, tracing and tx pool
- core: remove deposit-tx sub-type (a.k.a. deposit version byte)
- eth/catalyst: allow engine user to reorg own chain
- miner: restore ability to reorg deep as block builder
- params: print Optimism consensus type in banner
- core/types: remove unused protected() method, see upstream PR 23376
- core: do not mutate original balance value in tx pool l1 cost adjustment
- core: subtract deposit gas from pool, so other txs do not use the same gas. And fail tx processing if deposits reach gas limit
- core/types: deposits do not tip, avoid basefee subtraction
- Unmeter the L1 Attributes Transaction
- miner: handle force tx errors as critical, clean up diff
- ci: Switch branch
- eth,miner: return STATUS_INVALID when failing to process forced transactions in request (ref-op-geth PR 40)
- verifier: forward tx to sequencer based on flag
- txpool: add flag to disable tx gossip (ref-op-geth PR 42)
- Add op-geth version in addition to geth version (ref-op-geth PR 43)
- ci: CircleCI improvements (ref-op-geth PR 44)
- Rename to op-geth
- Build latest tag on optimism branch
op-geth changes:
- Expose cache config in simulated backend (#2)
- Add EIP-1559 parameters
- eth/catalyst: update payload id computation (#1)
- make eip1559 configurable (#4)
- post-merge network should not log warnings about missing transition information (#5)
- Make the simulator more configurable (#6)
- fix OPB-6 - IsDepositTx check instead of artificial nonce value check (#7)
- Simulated backend - enable proof of stake consensus type and fix performance issue (#8)
- accounts: simulated backend consensus engine option and immediate tx indexing
- consensus/beacon: recognize all blocks as reached TTD with 0 TTD in chain config
- Add --rollup.historicalhttp CLI flag and fix backend iface
- Flags and interfaces for historical RPC requests (#12)
- Redirect historical RPC requests (#13)
- Use the pre-existing ethereum.NotFound error (#18)
- Add historical endpoint to TraceBlockByNumber and TraceBlockByHash (#19)
- Add historical endpoint to TraceTransaction (#20)
- Add historical endpoint to TraceCall (#21)
- optimism: fee params from info txi, update l1 cost func GPO params read (#15)
- add hardcoded addresses for fee payouts (#23)
- dynamic gas limit via engine API (#22)
Co-authored-by: Matthew Slipper <me@matthewslipper.com>
Co-authored-by: Joshua Gutow <jgutow@oplabs.co>
Co-authored-by: protolambda <proto@protolambda.com>
Co-authored-by: Mark Tyneway <mark.tyneway@gmail.com>
Co-authored-by: Maurelian <maurelian@protonmail.ch>
2022-03-10 12:13:11 -08:00
|
|
|
"context"
|
2016-10-14 05:51:29 +02:00
|
|
|
"fmt"
|
2022-06-07 13:49:07 +03:00
|
|
|
"strings"
|
2020-04-09 11:55:32 +02:00
|
|
|
"time"
|
2016-10-14 05:51:29 +02:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2016-12-17 15:39:55 +01:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2019-02-26 12:32:48 +01: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 05:51:29 +02:00
|
|
|
"github.com/ethereum/go-ethereum/core"
|
2017-10-24 15:19:09 +02: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 05:51:29 +02:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2021-02-05 20:51:15 +08:00
|
|
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
2016-10-14 05:51:29 +02:00
|
|
|
"github.com/ethereum/go-ethereum/eth/gasprice"
|
|
|
|
"github.com/ethereum/go-ethereum/event"
|
|
|
|
"github.com/ethereum/go-ethereum/internal/ethapi"
|
2021-12-17 17:48:51 +03:30
|
|
|
"github.com/ethereum/go-ethereum/internal/shutdowncheck"
|
2021-09-10 10:55:48 +03:00
|
|
|
"github.com/ethereum/go-ethereum/les/downloader"
|
2021-03-01 10:24:20 +01:00
|
|
|
"github.com/ethereum/go-ethereum/les/vflux"
|
2021-02-19 14:44:16 +01:00
|
|
|
vfc "github.com/ethereum/go-ethereum/les/vflux/client"
|
2016-10-14 05:51:29 +02:00
|
|
|
"github.com/ethereum/go-ethereum/light"
|
2017-02-22 14:10:07 +02:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2016-10-14 05:51:29 +02:00
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
2019-08-21 17:29:34 +08:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2021-03-01 10:24:20 +01:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enr"
|
2016-10-20 13:36:29 +02:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2021-03-01 10:24:20 +01:00
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
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 15:34:02 +08:00
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2022-11-28 21:31:28 +08:00
|
|
|
"github.com/ethereum/go-ethereum/trie"
|
2016-10-14 05:51:29 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type LightEthereum struct {
|
2018-08-17 12:21:53 +02:00
|
|
|
lesCommons
|
2018-02-05 14:41:53 +01:00
|
|
|
|
2021-03-01 10:24:20 +01:00
|
|
|
peers *serverPeerSet
|
|
|
|
reqDist *requestDistributor
|
|
|
|
retriever *retrieveManager
|
|
|
|
odr *LesOdr
|
|
|
|
relay *lesTxRelay
|
|
|
|
handler *clientHandler
|
|
|
|
txPool *light.TxPool
|
|
|
|
blockchain *light.LightChain
|
|
|
|
serverPool *vfc.ServerPool
|
|
|
|
serverPoolIterator enode.Iterator
|
|
|
|
pruner *pruner
|
all: core rework for the merge transition (#23761)
* all: work for eth1/2 transtition
* consensus/beacon, eth: change beacon difficulty to 0
* eth: updates
* all: add terminalBlockDifficulty config, fix rebasing issues
* eth: implemented merge interop spec
* internal/ethapi: update to v1.0.0.alpha.2
This commit updates the code to the new spec, moving payloadId into
it's own object. It also fixes an issue with finalizing an empty blockhash.
It also properly sets the basefee
* all: sync polishes, other fixes + refactors
* core, eth: correct semantics for LeavePoW, EnterPoS
* core: fixed rebasing artifacts
* core: light: performance improvements
* core: use keyed field (f)
* core: eth: fix compilation issues + tests
* eth/catalyst: dbetter error codes
* all: move Merger to consensus/, remove reliance on it in bc
* all: renamed EnterPoS and LeavePoW to ReachTDD and FinalizePoS
* core: make mergelogs a function
* core: use InsertChain instead of InsertBlock
* les: drop merger from lightchain object
* consensus: add merger
* core: recoverAncestors in catalyst mode
* core: fix nitpick
* all: removed merger from beacon, use TTD, nitpicks
* consensus: eth: add docstring, removed unnecessary code duplication
* consensus/beacon: better comment
* all: easy to fix nitpicks by karalabe
* consensus/beacon: verify known headers to be sure
* core: comments
* core: eth: don't drop peers who advertise blocks, nitpicks
* core: never add beacon blocks to the future queue
* core: fixed nitpicks
* consensus/beacon: simplify IsTTDReached check
* consensus/beacon: correct IsTTDReached check
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-11-26 12:23:02 +01:00
|
|
|
merger *consensus.Merger
|
2018-08-17 12:21:53 +02:00
|
|
|
|
optimism: historical Bedrock geth rollup changes
This commit squashes the op-geth fork history into a more maintainable
diff for rebasing upon upstream geth.
reference-optimistic-geth changes (origins of op-geth in early Bedrock
development stage):
- Deposit TX Type
- Enable deposit tx in EVM/tx pool
- Change deposit nonce to not be the max nonce
- Extend PayloadAttributesV1 with a Transactions field
- Force deposits at the start of each L2 block
- Fix height check
- noTxPool flag, reproduce block in verifier mode without tx pool interference
- Fix RPC json marshalling (ref op-geth PR 4)
- Deposit txs block height check in block body validation (ref op-geth PR 5)
- core: do not try to reinject deposit txs into tx-pool (ref-op-geth PR 6)
- deposit source hash field instead of L2 block height and tx index combination
- Include invalid deposits, rewind state, but always persist mint (#10)
- Provide gas to Call/Create in deposit transactions (#12)
- Add docker builds (ref-op-geth PR 16, 17)
- Don't panic on deposit transaction signature values or chain ID (ref-op-geth PR 18)
- core: Add version to DepositTx (ref-op-geth PR 19)
- Enable Geth build/lint/test in CircleCI (ref-op-geth PR 23)
- core: Include guaranteed gas in the gas pool (ref-op-geth PR 21)
- core: handle base fee, l1 availability fee, tx fee (ref-op-geth PR 27)
- fix: deposit tx hash
- fix l1 fee cache, rpc, tracing and tx pool
- core: remove deposit-tx sub-type (a.k.a. deposit version byte)
- eth/catalyst: allow engine user to reorg own chain
- miner: restore ability to reorg deep as block builder
- params: print Optimism consensus type in banner
- core/types: remove unused protected() method, see upstream PR 23376
- core: do not mutate original balance value in tx pool l1 cost adjustment
- core: subtract deposit gas from pool, so other txs do not use the same gas. And fail tx processing if deposits reach gas limit
- core/types: deposits do not tip, avoid basefee subtraction
- Unmeter the L1 Attributes Transaction
- miner: handle force tx errors as critical, clean up diff
- ci: Switch branch
- eth,miner: return STATUS_INVALID when failing to process forced transactions in request (ref-op-geth PR 40)
- verifier: forward tx to sequencer based on flag
- txpool: add flag to disable tx gossip (ref-op-geth PR 42)
- Add op-geth version in addition to geth version (ref-op-geth PR 43)
- ci: CircleCI improvements (ref-op-geth PR 44)
- Rename to op-geth
- Build latest tag on optimism branch
op-geth changes:
- Expose cache config in simulated backend (#2)
- Add EIP-1559 parameters
- eth/catalyst: update payload id computation (#1)
- make eip1559 configurable (#4)
- post-merge network should not log warnings about missing transition information (#5)
- Make the simulator more configurable (#6)
- fix OPB-6 - IsDepositTx check instead of artificial nonce value check (#7)
- Simulated backend - enable proof of stake consensus type and fix performance issue (#8)
- accounts: simulated backend consensus engine option and immediate tx indexing
- consensus/beacon: recognize all blocks as reached TTD with 0 TTD in chain config
- Add --rollup.historicalhttp CLI flag and fix backend iface
- Flags and interfaces for historical RPC requests (#12)
- Redirect historical RPC requests (#13)
- Use the pre-existing ethereum.NotFound error (#18)
- Add historical endpoint to TraceBlockByNumber and TraceBlockByHash (#19)
- Add historical endpoint to TraceTransaction (#20)
- Add historical endpoint to TraceCall (#21)
- optimism: fee params from info txi, update l1 cost func GPO params read (#15)
- add hardcoded addresses for fee payouts (#23)
- dynamic gas limit via engine API (#22)
Co-authored-by: Matthew Slipper <me@matthewslipper.com>
Co-authored-by: Joshua Gutow <jgutow@oplabs.co>
Co-authored-by: protolambda <proto@protolambda.com>
Co-authored-by: Mark Tyneway <mark.tyneway@gmail.com>
Co-authored-by: Maurelian <maurelian@protonmail.ch>
2022-03-10 12:13:11 -08:00
|
|
|
seqRPCService *rpc.Client
|
|
|
|
historicalRPCService *rpc.Client
|
|
|
|
|
2018-08-17 12:21:53 +02:00
|
|
|
bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
|
2019-08-21 17:29:34 +08:00
|
|
|
bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports
|
2016-10-14 05:51:29 +02:00
|
|
|
|
2019-08-21 17:29:34 +08:00
|
|
|
ApiBackend *LesApiBackend
|
2016-10-14 05:51:29 +02:00
|
|
|
eventMux *event.TypeMux
|
2017-04-05 01:16:29 +03:00
|
|
|
engine consensus.Engine
|
2016-10-14 05:51:29 +02:00
|
|
|
accountManager *accounts.Manager
|
2022-06-21 11:05:43 +02:00
|
|
|
netRPCService *ethapi.NetAPI
|
2020-08-03 19:40:46 +02:00
|
|
|
|
2021-03-16 12:53:54 +01:00
|
|
|
p2pServer *p2p.Server
|
|
|
|
p2pConfig *p2p.Config
|
|
|
|
udpEnabled bool
|
2021-12-17 17:48:51 +03:30
|
|
|
|
|
|
|
shutdownTracker *shutdowncheck.ShutdownTracker // Tracks if and when the node has shutdown ungracefully
|
2016-10-14 05:51:29 +02:00
|
|
|
}
|
|
|
|
|
2020-08-03 19:40:46 +02:00
|
|
|
// New creates an instance of the light client.
|
2021-02-05 20:51:15 +08:00
|
|
|
func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
|
2021-03-23 02:06:30 +08:00
|
|
|
chainDb, err := stack.OpenDatabase("lightchaindata", config.DatabaseCache, config.DatabaseHandles, "eth/db/chaindata/", false)
|
2016-10-14 05:51:29 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-03-23 02:06:30 +08:00
|
|
|
lesDb, err := stack.OpenDatabase("les.client", 0, 0, "eth/db/lesclient/", false)
|
2020-04-09 11:55:32 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-31 00:22:28 +08:00
|
|
|
var overrides core.ChainOverrides
|
2023-01-06 15:07:38 +02:00
|
|
|
if config.OverrideShanghai != nil {
|
|
|
|
overrides.OverrideShanghai = config.OverrideShanghai
|
2022-08-31 00:22:28 +08:00
|
|
|
}
|
2022-11-28 21:31:28 +08:00
|
|
|
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, trie.NewDatabase(chainDb), config.Genesis, &overrides)
|
2017-03-02 14:03:33 +01:00
|
|
|
if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat {
|
|
|
|
return nil, genesisErr
|
2016-10-14 05:51:29 +02:00
|
|
|
}
|
2022-06-07 13:49:07 +03:00
|
|
|
log.Info("")
|
|
|
|
log.Info(strings.Repeat("-", 153))
|
2022-09-17 21:27:10 +02:00
|
|
|
for _, line := range strings.Split(chainConfig.Description(), "\n") {
|
2022-06-07 13:49:07 +03:00
|
|
|
log.Info(line)
|
|
|
|
}
|
|
|
|
log.Info(strings.Repeat("-", 153))
|
|
|
|
log.Info("")
|
2017-03-02 14:03:33 +01:00
|
|
|
|
2020-02-26 17:41:24 +08:00
|
|
|
peers := newServerPeerSet()
|
all: core rework for the merge transition (#23761)
* all: work for eth1/2 transtition
* consensus/beacon, eth: change beacon difficulty to 0
* eth: updates
* all: add terminalBlockDifficulty config, fix rebasing issues
* eth: implemented merge interop spec
* internal/ethapi: update to v1.0.0.alpha.2
This commit updates the code to the new spec, moving payloadId into
it's own object. It also fixes an issue with finalizing an empty blockhash.
It also properly sets the basefee
* all: sync polishes, other fixes + refactors
* core, eth: correct semantics for LeavePoW, EnterPoS
* core: fixed rebasing artifacts
* core: light: performance improvements
* core: use keyed field (f)
* core: eth: fix compilation issues + tests
* eth/catalyst: dbetter error codes
* all: move Merger to consensus/, remove reliance on it in bc
* all: renamed EnterPoS and LeavePoW to ReachTDD and FinalizePoS
* core: make mergelogs a function
* core: use InsertChain instead of InsertBlock
* les: drop merger from lightchain object
* consensus: add merger
* core: recoverAncestors in catalyst mode
* core: fix nitpick
* all: removed merger from beacon, use TTD, nitpicks
* consensus: eth: add docstring, removed unnecessary code duplication
* consensus/beacon: better comment
* all: easy to fix nitpicks by karalabe
* consensus/beacon: verify known headers to be sure
* core: comments
* core: eth: don't drop peers who advertise blocks, nitpicks
* core: never add beacon blocks to the future queue
* core: fixed nitpicks
* consensus/beacon: simplify IsTTDReached check
* consensus/beacon: correct IsTTDReached check
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-11-26 12:23:02 +01:00
|
|
|
merger := consensus.NewMerger(chainDb)
|
2017-10-24 15:19:09 +02:00
|
|
|
leth := &LightEthereum{
|
2018-08-17 12:21:53 +02:00
|
|
|
lesCommons: lesCommons{
|
2019-08-21 17:29:34 +08:00
|
|
|
genesis: genesisHash,
|
|
|
|
config: config,
|
|
|
|
chainConfig: chainConfig,
|
|
|
|
iConfig: light.DefaultClientIndexerConfig,
|
|
|
|
chainDb: chainDb,
|
2021-02-19 15:53:12 +01:00
|
|
|
lesDb: lesDb,
|
2019-08-21 17:29:34 +08:00
|
|
|
closeCh: make(chan struct{}),
|
2018-08-17 12:21:53 +02:00
|
|
|
},
|
2021-12-17 17:48:51 +03:30
|
|
|
peers: peers,
|
|
|
|
eventMux: stack.EventMux(),
|
|
|
|
reqDist: newRequestDistributor(peers, &mclock.System{}),
|
|
|
|
accountManager: stack.AccountManager(),
|
|
|
|
merger: merger,
|
2022-08-31 00:22:28 +08:00
|
|
|
engine: ethconfig.CreateConsensusEngine(stack, &config.Ethash, chainConfig.Clique, nil, false, chainDb),
|
2021-12-17 17:48:51 +03:30
|
|
|
bloomRequests: make(chan chan *bloombits.Retrieval),
|
|
|
|
bloomIndexer: core.NewBloomIndexer(chainDb, params.BloomBitsBlocksClient, params.HelperTrieConfirmations),
|
|
|
|
p2pServer: stack.Server(),
|
|
|
|
p2pConfig: &stack.Config().P2P,
|
|
|
|
udpEnabled: stack.Config().P2P.DiscoveryV5,
|
|
|
|
shutdownTracker: shutdowncheck.NewShutdownTracker(chainDb),
|
2016-10-14 05:51:29 +02:00
|
|
|
}
|
2020-05-22 13:46:34 +02:00
|
|
|
|
2021-03-03 15:05:24 +01:00
|
|
|
var prenegQuery vfc.QueryFunc
|
2021-03-16 12:53:54 +01:00
|
|
|
if leth.udpEnabled {
|
2021-03-03 15:05:24 +01:00
|
|
|
prenegQuery = leth.prenegQuery
|
|
|
|
}
|
|
|
|
leth.serverPool, leth.serverPoolIterator = vfc.NewServerPool(lesDb, []byte("serverpool:"), time.Second, prenegQuery, &mclock.System{}, config.UltraLightServers, requestList)
|
2021-02-25 21:08:34 +01:00
|
|
|
leth.serverPool.AddMetrics(suggestedTimeoutGauge, totalValueGauge, serverSelectableGauge, serverConnectedGauge, sessionValueMeter, serverDialedMeter)
|
2020-05-22 13:46:34 +02:00
|
|
|
|
2021-02-25 21:08:34 +01:00
|
|
|
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 15:34:02 +08:00
|
|
|
leth.relay = newLesTxRelay(peers, leth.retriever)
|
2018-08-17 12:21:53 +02:00
|
|
|
|
2021-02-25 21:24:04 +08:00
|
|
|
leth.odr = NewLesOdr(chainDb, light.DefaultClientIndexerConfig, leth.peers, leth.retriever)
|
2020-07-13 17:02:54 +08: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 22:25:46 +02:00
|
|
|
leth.odr.SetIndexers(leth.chtIndexer, leth.bloomTrieIndexer, leth.bloomIndexer)
|
2018-08-17 12:21:53 +02: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 15:34:02 +08:00
|
|
|
checkpoint := config.Checkpoint
|
|
|
|
if checkpoint == nil {
|
|
|
|
checkpoint = params.TrustedCheckpoints[genesisHash]
|
|
|
|
}
|
2018-08-15 22:25:46 +02: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 15:34:02 +08:00
|
|
|
if leth.blockchain, err = light.NewLightChain(leth.odr, leth.chainConfig, leth.engine, checkpoint); err != nil {
|
2016-10-14 05:51:29 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
2019-08-21 17:29:34 +08:00
|
|
|
leth.chainReader = leth.blockchain
|
|
|
|
leth.txPool = light.NewTxPool(leth.chainConfig, leth.blockchain, leth.relay)
|
|
|
|
|
|
|
|
// Set up checkpoint oracle.
|
2020-08-03 19:40:46 +02:00
|
|
|
leth.oracle = leth.setupOracle(stack, genesisHash, config)
|
2019-08-21 17:29:34 +08:00
|
|
|
|
2018-08-15 22:25:46 +02:00
|
|
|
// Note: AddChildIndexer starts the update process for the child
|
|
|
|
leth.bloomIndexer.AddChildIndexer(leth.bloomTrieIndexer)
|
|
|
|
leth.chtIndexer.Start(leth.blockchain)
|
2017-10-24 15:19:09 +02:00
|
|
|
leth.bloomIndexer.Start(leth.blockchain)
|
2018-08-17 12:21:53 +02:00
|
|
|
|
2020-07-13 17:02:54 +08:00
|
|
|
// Start a light chain pruner to delete useless historical data.
|
|
|
|
leth.pruner = newPruner(chainDb, leth.chtIndexer, leth.bloomTrieIndexer)
|
|
|
|
|
2017-03-02 14:03:33 +01: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)
|
2022-12-15 09:40:33 +02:00
|
|
|
if compat.RewindToTime > 0 {
|
2022-12-16 14:06:22 +02:00
|
|
|
leth.blockchain.SetHeadWithTimestamp(compat.RewindToTime)
|
2022-12-15 09:40:33 +02:00
|
|
|
} else {
|
|
|
|
leth.blockchain.SetHead(compat.RewindToBlock)
|
|
|
|
}
|
2018-05-07 14:35:06 +03:00
|
|
|
rawdb.WriteChainConfig(chainDb, genesisHash, chainConfig)
|
2017-03-02 14:03:33 +01:00
|
|
|
}
|
2016-10-14 05:51:29 +02:00
|
|
|
|
2021-02-23 13:09:19 +01:00
|
|
|
leth.ApiBackend = &LesApiBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, leth, nil}
|
2017-04-12 16:27:23 +02:00
|
|
|
gpoParams := config.GPO
|
|
|
|
if gpoParams.Default == nil {
|
2019-04-23 15:08:51 +08:00
|
|
|
gpoParams.Default = config.Miner.GasPrice
|
2017-04-06 16:20:42 +02:00
|
|
|
}
|
2017-10-24 15:19:09 +02: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 15:34:02 +08:00
|
|
|
|
2020-05-22 13:46:34 +02: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()
|
|
|
|
}
|
2020-08-03 19:40:46 +02:00
|
|
|
|
optimism: historical Bedrock geth rollup changes
This commit squashes the op-geth fork history into a more maintainable
diff for rebasing upon upstream geth.
reference-optimistic-geth changes (origins of op-geth in early Bedrock
development stage):
- Deposit TX Type
- Enable deposit tx in EVM/tx pool
- Change deposit nonce to not be the max nonce
- Extend PayloadAttributesV1 with a Transactions field
- Force deposits at the start of each L2 block
- Fix height check
- noTxPool flag, reproduce block in verifier mode without tx pool interference
- Fix RPC json marshalling (ref op-geth PR 4)
- Deposit txs block height check in block body validation (ref op-geth PR 5)
- core: do not try to reinject deposit txs into tx-pool (ref-op-geth PR 6)
- deposit source hash field instead of L2 block height and tx index combination
- Include invalid deposits, rewind state, but always persist mint (#10)
- Provide gas to Call/Create in deposit transactions (#12)
- Add docker builds (ref-op-geth PR 16, 17)
- Don't panic on deposit transaction signature values or chain ID (ref-op-geth PR 18)
- core: Add version to DepositTx (ref-op-geth PR 19)
- Enable Geth build/lint/test in CircleCI (ref-op-geth PR 23)
- core: Include guaranteed gas in the gas pool (ref-op-geth PR 21)
- core: handle base fee, l1 availability fee, tx fee (ref-op-geth PR 27)
- fix: deposit tx hash
- fix l1 fee cache, rpc, tracing and tx pool
- core: remove deposit-tx sub-type (a.k.a. deposit version byte)
- eth/catalyst: allow engine user to reorg own chain
- miner: restore ability to reorg deep as block builder
- params: print Optimism consensus type in banner
- core/types: remove unused protected() method, see upstream PR 23376
- core: do not mutate original balance value in tx pool l1 cost adjustment
- core: subtract deposit gas from pool, so other txs do not use the same gas. And fail tx processing if deposits reach gas limit
- core/types: deposits do not tip, avoid basefee subtraction
- Unmeter the L1 Attributes Transaction
- miner: handle force tx errors as critical, clean up diff
- ci: Switch branch
- eth,miner: return STATUS_INVALID when failing to process forced transactions in request (ref-op-geth PR 40)
- verifier: forward tx to sequencer based on flag
- txpool: add flag to disable tx gossip (ref-op-geth PR 42)
- Add op-geth version in addition to geth version (ref-op-geth PR 43)
- ci: CircleCI improvements (ref-op-geth PR 44)
- Rename to op-geth
- Build latest tag on optimism branch
op-geth changes:
- Expose cache config in simulated backend (#2)
- Add EIP-1559 parameters
- eth/catalyst: update payload id computation (#1)
- make eip1559 configurable (#4)
- post-merge network should not log warnings about missing transition information (#5)
- Make the simulator more configurable (#6)
- fix OPB-6 - IsDepositTx check instead of artificial nonce value check (#7)
- Simulated backend - enable proof of stake consensus type and fix performance issue (#8)
- accounts: simulated backend consensus engine option and immediate tx indexing
- consensus/beacon: recognize all blocks as reached TTD with 0 TTD in chain config
- Add --rollup.historicalhttp CLI flag and fix backend iface
- Flags and interfaces for historical RPC requests (#12)
- Redirect historical RPC requests (#13)
- Use the pre-existing ethereum.NotFound error (#18)
- Add historical endpoint to TraceBlockByNumber and TraceBlockByHash (#19)
- Add historical endpoint to TraceTransaction (#20)
- Add historical endpoint to TraceCall (#21)
- optimism: fee params from info txi, update l1 cost func GPO params read (#15)
- add hardcoded addresses for fee payouts (#23)
- dynamic gas limit via engine API (#22)
Co-authored-by: Matthew Slipper <me@matthewslipper.com>
Co-authored-by: Joshua Gutow <jgutow@oplabs.co>
Co-authored-by: protolambda <proto@protolambda.com>
Co-authored-by: Mark Tyneway <mark.tyneway@gmail.com>
Co-authored-by: Maurelian <maurelian@protonmail.ch>
2022-03-10 12:13:11 -08:00
|
|
|
if config.RollupSequencerHTTP != "" {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
client, err := rpc.DialContext(ctx, config.RollupSequencerHTTP)
|
|
|
|
cancel()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
leth.seqRPCService = client
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.RollupHistoricalRPC != "" {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
client, err := rpc.DialContext(ctx, config.RollupHistoricalRPC)
|
|
|
|
cancel()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
leth.historicalRPCService = client
|
|
|
|
}
|
|
|
|
|
2022-06-21 11:05:43 +02:00
|
|
|
leth.netRPCService = ethapi.NewNetAPI(leth.p2pServer, leth.config.NetworkId)
|
2020-08-03 19:40:46 +02:00
|
|
|
|
|
|
|
// Register the backend on the node
|
|
|
|
stack.RegisterAPIs(leth.APIs())
|
|
|
|
stack.RegisterProtocols(leth.Protocols())
|
|
|
|
stack.RegisterLifecycle(leth)
|
|
|
|
|
2021-12-17 17:48:51 +03:30
|
|
|
// Successful startup; push a marker and check previous unclean shutdowns.
|
|
|
|
leth.shutdownTracker.MarkStartup()
|
|
|
|
|
2017-10-24 15:19:09 +02:00
|
|
|
return leth, nil
|
2016-10-14 05:51:29 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 10:24:20 +01:00
|
|
|
// VfluxRequest sends a batch of requests to the given node through discv5 UDP TalkRequest and returns the responses
|
|
|
|
func (s *LightEthereum) VfluxRequest(n *enode.Node, reqs vflux.Requests) vflux.Replies {
|
2021-03-16 12:53:54 +01:00
|
|
|
if !s.udpEnabled {
|
2021-03-03 15:05:24 +01:00
|
|
|
return nil
|
|
|
|
}
|
2021-03-01 10:24:20 +01:00
|
|
|
reqsEnc, _ := rlp.EncodeToBytes(&reqs)
|
|
|
|
repliesEnc, _ := s.p2pServer.DiscV5.TalkRequest(s.serverPool.DialNode(n), "vfx", reqsEnc)
|
|
|
|
var replies vflux.Replies
|
|
|
|
if len(repliesEnc) == 0 || rlp.DecodeBytes(repliesEnc, &replies) != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return replies
|
|
|
|
}
|
|
|
|
|
|
|
|
// vfxVersion returns the version number of the "les" service subdomain of the vflux UDP
|
|
|
|
// service, as advertised in the ENR record
|
|
|
|
func (s *LightEthereum) vfxVersion(n *enode.Node) uint {
|
|
|
|
if n.Seq() == 0 {
|
|
|
|
var err error
|
2021-03-16 12:53:54 +01:00
|
|
|
if !s.udpEnabled {
|
2021-03-03 15:05:24 +01:00
|
|
|
return 0
|
|
|
|
}
|
2021-03-01 10:24:20 +01:00
|
|
|
if n, err = s.p2pServer.DiscV5.RequestENR(n); n != nil && err == nil && n.Seq() != 0 {
|
|
|
|
s.serverPool.Persist(n)
|
|
|
|
} else {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var les []rlp.RawValue
|
|
|
|
if err := n.Load(enr.WithEntry("les", &les)); err != nil || len(les) < 1 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
var version uint
|
|
|
|
rlp.DecodeBytes(les[0], &version) // Ignore additional fields (for forward compatibility).
|
|
|
|
return version
|
|
|
|
}
|
|
|
|
|
|
|
|
// prenegQuery sends a capacity query to the given server node to determine whether
|
|
|
|
// a connection slot is immediately available
|
|
|
|
func (s *LightEthereum) prenegQuery(n *enode.Node) int {
|
|
|
|
if s.vfxVersion(n) < 1 {
|
|
|
|
// UDP query not supported, always try TCP connection
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
var requests vflux.Requests
|
|
|
|
requests.Add("les", vflux.CapacityQueryName, vflux.CapacityQueryReq{
|
|
|
|
Bias: 180,
|
|
|
|
AddTokens: []vflux.IntOrInf{{}},
|
|
|
|
})
|
|
|
|
replies := s.VfluxRequest(n, requests)
|
|
|
|
var cqr vflux.CapacityQueryReply
|
|
|
|
if replies.Get(0, &cqr) != nil || len(cqr) != 1 { // Note: Get returns an error if replies is nil
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
if cqr[0] > 0 {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2016-10-14 05:51:29 +02: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 09:15:15 +02:00
|
|
|
return common.Address{}, fmt.Errorf("mining is not supported in light mode")
|
2016-10-14 05:51:29 +02: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 09:15:15 +02:00
|
|
|
return common.Address{}, fmt.Errorf("mining is not supported in light mode")
|
2016-10-14 05:51:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hashrate returns the POW hashrate
|
2016-12-17 15:39:55 +01:00
|
|
|
func (s *LightDummyAPI) Hashrate() hexutil.Uint {
|
|
|
|
return 0
|
2016-10-14 05:51:29 +02: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 18:22:04 +01:00
|
|
|
apis := ethapi.GetAPIs(s.ApiBackend)
|
|
|
|
apis = append(apis, s.engine.APIs(s.BlockChain().HeaderChain())...)
|
|
|
|
return append(apis, []rpc.API{
|
2016-10-14 05:51:29 +02:00
|
|
|
{
|
|
|
|
Namespace: "eth",
|
|
|
|
Service: &LightDummyAPI{},
|
|
|
|
}, {
|
|
|
|
Namespace: "eth",
|
2022-06-21 11:05:43 +02:00
|
|
|
Service: downloader.NewDownloaderAPI(s.handler.downloader, s.eventMux),
|
2016-10-14 05:51:29 +02:00
|
|
|
}, {
|
|
|
|
Namespace: "net",
|
|
|
|
Service: s.netRPCService,
|
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 15:34:02 +08:00
|
|
|
}, {
|
|
|
|
Namespace: "les",
|
2022-06-21 11:05:43 +02:00
|
|
|
Service: NewLightAPI(&s.lesCommons),
|
2020-04-09 11:55:32 +02:00
|
|
|
}, {
|
2021-02-19 14:44:16 +01:00
|
|
|
Namespace: "vflux",
|
2021-02-25 21:08:34 +01:00
|
|
|
Service: s.serverPool.API(),
|
2016-10-14 05:51:29 +02: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 12:21:53 +02:00
|
|
|
func (s *LightEthereum) LesVersion() int { return int(ClientProtocolVersions[0]) }
|
2019-08-21 17:29:34 +08:00
|
|
|
func (s *LightEthereum) Downloader() *downloader.Downloader { return s.handler.downloader }
|
2016-11-25 17:55:06 +02:00
|
|
|
func (s *LightEthereum) EventMux() *event.TypeMux { return s.eventMux }
|
all: core rework for the merge transition (#23761)
* all: work for eth1/2 transtition
* consensus/beacon, eth: change beacon difficulty to 0
* eth: updates
* all: add terminalBlockDifficulty config, fix rebasing issues
* eth: implemented merge interop spec
* internal/ethapi: update to v1.0.0.alpha.2
This commit updates the code to the new spec, moving payloadId into
it's own object. It also fixes an issue with finalizing an empty blockhash.
It also properly sets the basefee
* all: sync polishes, other fixes + refactors
* core, eth: correct semantics for LeavePoW, EnterPoS
* core: fixed rebasing artifacts
* core: light: performance improvements
* core: use keyed field (f)
* core: eth: fix compilation issues + tests
* eth/catalyst: dbetter error codes
* all: move Merger to consensus/, remove reliance on it in bc
* all: renamed EnterPoS and LeavePoW to ReachTDD and FinalizePoS
* core: make mergelogs a function
* core: use InsertChain instead of InsertBlock
* les: drop merger from lightchain object
* consensus: add merger
* core: recoverAncestors in catalyst mode
* core: fix nitpick
* all: removed merger from beacon, use TTD, nitpicks
* consensus: eth: add docstring, removed unnecessary code duplication
* consensus/beacon: better comment
* all: easy to fix nitpicks by karalabe
* consensus/beacon: verify known headers to be sure
* core: comments
* core: eth: don't drop peers who advertise blocks, nitpicks
* core: never add beacon blocks to the future queue
* core: fixed nitpicks
* consensus/beacon: simplify IsTTDReached check
* consensus/beacon: correct IsTTDReached check
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-11-26 12:23:02 +01:00
|
|
|
func (s *LightEthereum) Merger() *consensus.Merger { return s.merger }
|
2016-10-14 05:51:29 +02:00
|
|
|
|
2020-08-03 19:40:46 +02:00
|
|
|
// Protocols returns all the currently configured network protocols to start.
|
2016-10-14 05:51:29 +02:00
|
|
|
func (s *LightEthereum) Protocols() []p2p.Protocol {
|
2019-08-21 17:29:34 +08:00
|
|
|
return s.makeProtocols(ClientProtocolVersions, s.handler.runPeer, func(id enode.ID) interface{} {
|
2020-07-28 23:02:35 +08:00
|
|
|
if p := s.peers.peer(id.String()); p != nil {
|
2019-08-21 17:29:34 +08:00
|
|
|
return p.Info()
|
|
|
|
}
|
|
|
|
return nil
|
2021-03-01 10:24:20 +01:00
|
|
|
}, s.serverPoolIterator)
|
2016-10-14 05:51:29 +02:00
|
|
|
}
|
|
|
|
|
2020-08-03 19:40:46 +02:00
|
|
|
// Start implements node.Lifecycle, starting all internal goroutines needed by the
|
2019-08-21 17:29:34 +08:00
|
|
|
// light ethereum protocol implementation.
|
2020-08-03 19:40:46 +02:00
|
|
|
func (s *LightEthereum) Start() error {
|
2017-03-03 11:41:52 +02:00
|
|
|
log.Warn("Light client mode is an experimental feature")
|
2019-08-21 17:29:34 +08:00
|
|
|
|
2021-12-17 17:48:51 +03:30
|
|
|
// Regularly update shutdown marker
|
|
|
|
s.shutdownTracker.Start()
|
|
|
|
|
2021-03-16 12:53:54 +01:00
|
|
|
if s.udpEnabled && s.p2pServer.DiscV5 == nil {
|
|
|
|
s.udpEnabled = false
|
|
|
|
log.Error("Discovery v5 is not initialized")
|
|
|
|
}
|
|
|
|
discovery, err := s.setupDiscovery()
|
2021-01-26 21:41:35 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-02-25 21:08:34 +01:00
|
|
|
s.serverPool.AddSource(discovery)
|
|
|
|
s.serverPool.Start()
|
2019-08-21 17:29:34 +08:00
|
|
|
// Start bloom request workers.
|
|
|
|
s.wg.Add(bloomServiceThreads)
|
2018-08-28 15:08:16 +08:00
|
|
|
s.startBloomHandlers(params.BloomBitsBlocksClient)
|
2020-07-28 23:02:35 +08:00
|
|
|
s.handler.start()
|
2019-08-21 17:29:34 +08:00
|
|
|
|
2016-10-14 05:51:29 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-03 19:40:46 +02:00
|
|
|
// Stop implements node.Lifecycle, terminating all internal goroutines used by the
|
2016-10-14 05:51:29 +02:00
|
|
|
// Ethereum protocol.
|
|
|
|
func (s *LightEthereum) Stop() error {
|
2019-08-21 17:29:34 +08:00
|
|
|
close(s.closeCh)
|
2021-02-25 21:08:34 +01:00
|
|
|
s.serverPool.Stop()
|
2020-02-26 17:41:24 +08:00
|
|
|
s.peers.close()
|
2019-08-21 17:29:34 +08:00
|
|
|
s.reqDist.close()
|
2016-10-14 05:51:29 +02:00
|
|
|
s.odr.Stop()
|
2019-05-13 13:41:10 +02:00
|
|
|
s.relay.Stop()
|
2018-08-17 12:21:53 +02:00
|
|
|
s.bloomIndexer.Close()
|
|
|
|
s.chtIndexer.Close()
|
2016-10-14 05:51:29 +02:00
|
|
|
s.blockchain.Stop()
|
2019-08-21 17:29:34 +08:00
|
|
|
s.handler.stop()
|
2016-10-14 05:51:29 +02:00
|
|
|
s.txPool.Stop()
|
2018-08-03 16:33:37 +08:00
|
|
|
s.engine.Close()
|
2020-07-13 17:02:54 +08:00
|
|
|
s.pruner.close()
|
2016-10-14 05:51:29 +02:00
|
|
|
s.eventMux.Stop()
|
2021-12-17 17:48:51 +03:30
|
|
|
// Clean shutdown marker as the last thing before closing db
|
|
|
|
s.shutdownTracker.Stop()
|
|
|
|
|
2016-10-14 05:51:29 +02:00
|
|
|
s.chainDb.Close()
|
2021-02-19 15:53:12 +01:00
|
|
|
s.lesDb.Close()
|
2019-08-21 17:29:34 +08:00
|
|
|
s.wg.Wait()
|
|
|
|
log.Info("Light ethereum stopped")
|
2016-10-14 05:51:29 +02:00
|
|
|
return nil
|
|
|
|
}
|