mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-08 07:58:40 +00:00
eth,node: remove the remaining eventMux and event type
This commit is contained in:
parent
8b640a3b68
commit
4ed7a8a4a8
6 changed files with 17 additions and 54 deletions
|
|
@ -49,7 +49,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/eth/protocols/snap"
|
||||
"github.com/ethereum/go-ethereum/eth/tracers"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||
"github.com/ethereum/go-ethereum/internal/shutdowncheck"
|
||||
"github.com/ethereum/go-ethereum/internal/version"
|
||||
|
|
@ -105,7 +104,6 @@ type Ethereum struct {
|
|||
// DB interfaces
|
||||
chainDb ethdb.Database // Block chain database
|
||||
|
||||
eventMux *event.TypeMux
|
||||
engine consensus.Engine
|
||||
accountManager *accounts.Manager
|
||||
|
||||
|
|
@ -194,7 +192,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
eth := &Ethereum{
|
||||
config: config,
|
||||
chainDb: chainDb,
|
||||
eventMux: stack.EventMux(),
|
||||
accountManager: stack.AccountManager(),
|
||||
engine: engine,
|
||||
networkID: networkID,
|
||||
|
|
@ -343,7 +340,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
Network: networkID,
|
||||
Sync: config.SyncMode,
|
||||
BloomCache: uint64(cacheLimit),
|
||||
EventMux: eth.eventMux,
|
||||
RequiredBlocks: config.RequiredBlocks,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -599,7 +595,6 @@ func (s *Ethereum) Stop() error {
|
|||
s.shutdownTracker.Stop()
|
||||
|
||||
s.chainDb.Close()
|
||||
s.eventMux.Stop()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,11 +97,10 @@ type headerTask struct {
|
|||
}
|
||||
|
||||
type Downloader struct {
|
||||
mode atomic.Uint32 // Synchronisation mode defining the strategy used (per sync cycle), use d.getMode() to get the SyncMode
|
||||
moder *syncModer // Sync mode management, deliver the appropriate sync mode choice for each cycle
|
||||
mux *event.TypeMux // Event multiplexer to announce sync operation events
|
||||
mode atomic.Uint32 // Synchronisation mode defining the strategy used (per sync cycle), use d.getMode() to get the SyncMode
|
||||
moder *syncModer // Sync mode management, deliver the appropriate sync mode choice for each cycle
|
||||
|
||||
// New event feed for downloader events (alongside the existing TypeMux)
|
||||
// Event feed for downloader events
|
||||
feed event.FeedOf[SyncEvent]
|
||||
scope event.SubscriptionScope
|
||||
|
||||
|
|
@ -233,12 +232,11 @@ type BlockChain interface {
|
|||
}
|
||||
|
||||
// New creates a new downloader to fetch hashes and blocks from remote peers.
|
||||
func New(stateDb ethdb.Database, mode ethconfig.SyncMode, mux *event.TypeMux, chain BlockChain, dropPeer peerDropFn, success func()) *Downloader {
|
||||
func New(stateDb ethdb.Database, chain BlockChain, mode ethconfig.SyncMode, dropPeer peerDropFn, success func()) *Downloader {
|
||||
cutoffNumber, cutoffHash := chain.HistoryPruningCutoff()
|
||||
dl := &Downloader{
|
||||
stateDB: stateDb,
|
||||
moder: newSyncModer(mode, chain, stateDb),
|
||||
mux: mux,
|
||||
queue: newQueue(blockCacheMaxItems, blockCacheInitialItems),
|
||||
peers: newPeerSet(),
|
||||
blockchain: chain,
|
||||
|
|
@ -439,16 +437,13 @@ func (d *Downloader) SubscribeSyncEvents(ch chan<- SyncEvent) event.Subscription
|
|||
// syncToHead starts a block synchronization based on the hash chain from
|
||||
// the specified head hash.
|
||||
func (d *Downloader) syncToHead() (err error) {
|
||||
d.mux.Post(StartEvent{})
|
||||
d.feed.Send(SyncEvent{Type: SyncStarted})
|
||||
defer func() {
|
||||
// reset on error
|
||||
if err != nil {
|
||||
d.mux.Post(FailedEvent{err})
|
||||
d.feed.Send(SyncEvent{Type: SyncFailed, Err: err})
|
||||
} else {
|
||||
latest := d.blockchain.CurrentHeader()
|
||||
d.mux.Post(DoneEvent{latest})
|
||||
d.feed.Send(SyncEvent{Type: SyncCompleted, Latest: latest})
|
||||
}
|
||||
}()
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
||||
"github.com/ethereum/go-ethereum/eth/protocols/eth"
|
||||
"github.com/ethereum/go-ethereum/eth/protocols/snap"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
|
|
@ -75,7 +74,7 @@ func newTesterWithNotification(t *testing.T, mode ethconfig.SyncMode, success fu
|
|||
chain: chain,
|
||||
peers: make(map[string]*downloadTesterPeer),
|
||||
}
|
||||
tester.downloader = New(db, mode, new(event.TypeMux), tester.chain, tester.dropPeer, success)
|
||||
tester.downloader = New(db, tester.chain, mode, tester.dropPeer, success)
|
||||
return tester
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,12 +18,6 @@ package downloader
|
|||
|
||||
import "github.com/ethereum/go-ethereum/core/types"
|
||||
|
||||
type DoneEvent struct {
|
||||
Latest *types.Header
|
||||
}
|
||||
type StartEvent struct{}
|
||||
type FailedEvent struct{ Err error }
|
||||
|
||||
// SyncEventType represents the type of sync event
|
||||
type SyncEventType int
|
||||
|
||||
|
|
|
|||
|
|
@ -107,7 +107,6 @@ type handlerConfig struct {
|
|||
Network uint64 // Network identifier to advertise
|
||||
Sync ethconfig.SyncMode // Whether to snap or full sync
|
||||
BloomCache uint64 // Megabytes to alloc for snap sync bloom
|
||||
EventMux *event.TypeMux // Legacy event mux, deprecate for `feed`
|
||||
RequiredBlocks map[uint64]common.Hash // Hard coded map of required block hashes for sync challenges
|
||||
}
|
||||
|
||||
|
|
@ -126,7 +125,6 @@ type handler struct {
|
|||
peers *peerSet
|
||||
txBroadcastKey [16]byte
|
||||
|
||||
eventMux *event.TypeMux
|
||||
txsCh chan core.NewTxsEvent
|
||||
txsSub event.Subscription
|
||||
blockRange *blockRangeState
|
||||
|
|
@ -144,14 +142,9 @@ type handler struct {
|
|||
|
||||
// newHandler returns a handler for all Ethereum chain management protocol.
|
||||
func newHandler(config *handlerConfig) (*handler, error) {
|
||||
// Create the protocol manager with the base fields
|
||||
if config.EventMux == nil {
|
||||
config.EventMux = new(event.TypeMux) // Nicety initialization for tests
|
||||
}
|
||||
h := &handler{
|
||||
nodeID: config.NodeID,
|
||||
networkID: config.Network,
|
||||
eventMux: config.EventMux,
|
||||
database: config.Database,
|
||||
txpool: config.TxPool,
|
||||
chain: config.Chain,
|
||||
|
|
@ -163,7 +156,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
|
|||
handlerStartCh: make(chan struct{}),
|
||||
}
|
||||
// Construct the downloader (long sync)
|
||||
h.downloader = downloader.New(config.Database, config.Sync, h.eventMux, h.chain, h.removePeer, h.enableSyncedFeatures)
|
||||
h.downloader = downloader.New(config.Database, h.chain, config.Sync, h.removePeer, h.enableSyncedFeatures)
|
||||
|
||||
// If snap sync is requested but snapshots are disabled, fail loudly
|
||||
if h.downloader.ConfigSyncMode() == ethconfig.SnapSync && (config.Chain.Snapshots() == nil && config.Chain.TrieDB().Scheme() == rawdb.HashScheme) {
|
||||
|
|
@ -420,7 +413,7 @@ func (h *handler) Start(maxPeers int) {
|
|||
|
||||
// broadcast block range
|
||||
h.wg.Add(1)
|
||||
h.blockRange = newBlockRangeState(h.chain, h.eventMux)
|
||||
h.blockRange = newBlockRangeState(h.chain, h.downloader)
|
||||
go h.blockRangeLoop(h.blockRange)
|
||||
|
||||
// start sync handlers
|
||||
|
|
@ -536,16 +529,19 @@ type blockRangeState struct {
|
|||
next atomic.Pointer[eth.BlockRangeUpdatePacket]
|
||||
headCh chan core.ChainHeadEvent
|
||||
headSub event.Subscription
|
||||
syncSub *event.TypeMuxSubscription
|
||||
syncCh chan downloader.SyncEvent
|
||||
syncSub event.Subscription
|
||||
}
|
||||
|
||||
func newBlockRangeState(chain *core.BlockChain, typeMux *event.TypeMux) *blockRangeState {
|
||||
func newBlockRangeState(chain *core.BlockChain, dl *downloader.Downloader) *blockRangeState {
|
||||
headCh := make(chan core.ChainHeadEvent, chainHeadChanSize)
|
||||
headSub := chain.SubscribeChainHeadEvent(headCh)
|
||||
syncSub := typeMux.Subscribe(downloader.StartEvent{}, downloader.DoneEvent{}, downloader.FailedEvent{})
|
||||
syncCh := make(chan downloader.SyncEvent, 16)
|
||||
syncSub := dl.SubscribeSyncEvents(syncCh)
|
||||
st := &blockRangeState{
|
||||
headCh: headCh,
|
||||
headSub: headSub,
|
||||
syncCh: syncCh,
|
||||
syncSub: syncSub,
|
||||
}
|
||||
st.update(chain, chain.CurrentBlock())
|
||||
|
|
@ -561,11 +557,8 @@ func (h *handler) blockRangeLoop(st *blockRangeState) {
|
|||
|
||||
for {
|
||||
select {
|
||||
case ev := <-st.syncSub.Chan():
|
||||
if ev == nil {
|
||||
continue
|
||||
}
|
||||
if _, ok := ev.Data.(downloader.StartEvent); ok && h.downloader.ConfigSyncMode() == ethconfig.SnapSync {
|
||||
case ev := <-st.syncCh:
|
||||
if ev.Type == downloader.SyncStarted && h.downloader.ConfigSyncMode() == ethconfig.SnapSync {
|
||||
h.blockRangeWhileSnapSyncing(st)
|
||||
}
|
||||
case <-st.headCh:
|
||||
|
|
@ -593,12 +586,8 @@ func (h *handler) blockRangeWhileSnapSyncing(st *blockRangeState) {
|
|||
h.broadcastBlockRange(st)
|
||||
}
|
||||
// back to processing head block updates when sync is done
|
||||
case ev := <-st.syncSub.Chan():
|
||||
if ev == nil {
|
||||
continue
|
||||
}
|
||||
switch ev.Data.(type) {
|
||||
case downloader.FailedEvent, downloader.DoneEvent:
|
||||
case ev := <-st.syncCh:
|
||||
if ev.Type == downloader.SyncFailed || ev.Type == downloader.SyncCompleted {
|
||||
return
|
||||
}
|
||||
// ignore head updates, but exit when the subscription ends
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/ethdb/memorydb"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
|
|
@ -44,7 +43,6 @@ import (
|
|||
|
||||
// Node is a container on which services can be registered.
|
||||
type Node struct {
|
||||
eventmux *event.TypeMux
|
||||
config *Config
|
||||
accman *accounts.Manager
|
||||
log log.Logger
|
||||
|
|
@ -108,7 +106,6 @@ func New(conf *Config) (*Node, error) {
|
|||
node := &Node{
|
||||
config: conf,
|
||||
inprocHandler: server,
|
||||
eventmux: new(event.TypeMux),
|
||||
log: conf.Logger,
|
||||
stop: make(chan struct{}),
|
||||
server: &p2p.Server{Config: conf.P2P},
|
||||
|
|
@ -692,12 +689,6 @@ func (n *Node) WSAuthEndpoint() string {
|
|||
return "ws://" + n.wsAuth.listenAddr() + n.wsAuth.wsConfig.prefix
|
||||
}
|
||||
|
||||
// EventMux retrieves the event multiplexer used by all the network services in
|
||||
// the current protocol stack.
|
||||
func (n *Node) EventMux() *event.TypeMux {
|
||||
return n.eventmux
|
||||
}
|
||||
|
||||
// OpenDatabaseWithOptions opens an existing database with the given name (or creates one if no
|
||||
// previous can be found) from within the node's instance directory. If the node has no
|
||||
// data directory, an in-memory database is returned.
|
||||
|
|
|
|||
Loading…
Reference in a new issue