Skip to content

Commit

Permalink
Nuke remnants of non-staged-sync modes (#1664)
Browse files Browse the repository at this point in the history
  • Loading branch information
vorot93 authored and AskAlexSharov committed Apr 6, 2021
1 parent 7f7375d commit b48f0e8
Show file tree
Hide file tree
Showing 18 changed files with 223 additions and 689 deletions.
3 changes: 0 additions & 3 deletions common/dbutils/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ var (
// Transaction senders - stored separately from the block bodies
Senders = "txSenders"

// fastTrieProgressKey tracks the number of trie entries imported during fast sync.
FastTrieProgressKey = "TrieSync"
// headBlockKey tracks the latest know full block's hash.
HeadBlockKey = "LastBlock"
// headFastBlockKey tracks the latest known incomplete block's hash during fast sync.
Expand Down Expand Up @@ -272,7 +270,6 @@ var Buckets = []string{
PlainAccountChangeSetBucket,
PlainStorageChangeSetBucket,
Senders,
FastTrieProgressKey,
HeadBlockKey,
HeadFastBlockKey,
HeadHeaderKey,
Expand Down
21 changes: 0 additions & 21 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,27 +171,6 @@ func WriteHeadFastBlockHash(db DatabaseWriter, hash common.Hash) {
}
}

// ReadFastTrieProgress retrieves the number of tries nodes fast synced to allow
// reporting correct numbers across restarts.
func ReadFastTrieProgress(db databaseReader) uint64 {
data, err := db.Get(dbutils.FastTrieProgressKey, []byte(dbutils.FastTrieProgressKey))
if err != nil && !errors.Is(err, ethdb.ErrKeyNotFound) {
log.Error("ReadFastTrieProgress failed", "err", err)
}
if len(data) == 0 {
return 0
}
return new(big.Int).SetBytes(data).Uint64()
}

// WriteFastTrieProgress stores the fast sync trie process counter to support
// retrieving it across restarts.
func WriteFastTrieProgress(db DatabaseWriter, count uint64) {
if err := db.Put(dbutils.FastTrieProgressKey, []byte(dbutils.FastTrieProgressKey), new(big.Int).SetUint64(count).Bytes()); err != nil {
log.Crit("Failed to store fast sync trie progress", "err", err)
}
}

// ReadHeaderRLP retrieves a block header in its raw RLP database encoding.
func ReadHeaderRLP(db databaseReader, hash common.Hash, number uint64) rlp.RawValue {
data, err := db.Get(dbutils.HeadersBucket, dbutils.HeaderKey(number, hash))
Expand Down
40 changes: 2 additions & 38 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ type Ethereum struct {
// New creates a new Ethereum object (including the
// initialisation of the common Ethereum object)
func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
// Ensure configuration values are compatible and sane
if !config.SyncMode.IsValid() {
return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode)
}
if config.Miner.GasPrice == nil || config.Miner.GasPrice.Cmp(common.Big0) <= 0 {
log.Warn("Sanitizing invalid miner gas price", "provided", config.Miner.GasPrice, "updated", ethconfig.Defaults.Miner.GasPrice)
config.Miner.GasPrice = new(big.Int).Set(ethconfig.Defaults.Miner.GasPrice)
Expand Down Expand Up @@ -162,7 +158,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
log.Info("Initialised chain configuration", "config", chainConfig)

var torrentClient *bittorrent.Client
if config.SyncMode == downloader.StagedSync && config.SnapshotMode != (snapshotsync.SnapshotMode{}) && config.NetworkID == params.MainnetChainConfig.ChainID.Uint64() {
if config.SnapshotMode != (snapshotsync.SnapshotMode{}) && config.NetworkID == params.MainnetChainConfig.ChainID.Uint64() {
if config.ExternalSnapshotDownloaderAddr != "" {
cli, cl, innerErr := snapshotsync.NewClient(config.ExternalSnapshotDownloaderAddr)
if innerErr != nil {
Expand Down Expand Up @@ -346,12 +342,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
if config.SyncMode != downloader.StagedSync {
_, err = eth.blockchain.GetTrieDbState()
if err != nil {
return nil, err
}
}

eth.blockchain.EnableReceipts(config.StorageMode.Receipts)
eth.blockchain.EnableTxLookupIndex(config.StorageMode.TxIndex)
Expand Down Expand Up @@ -446,7 +436,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
Chain: eth.blockchain,
TxPool: eth.txPool,
Network: config.NetworkID,
Sync: config.SyncMode,
EventMux: eth.eventMux,
Checkpoint: checkpoint,

Expand All @@ -455,10 +444,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
}); err != nil {
return nil, err
}
//if config.SyncMode != downloader.StagedSync {
//eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
//_ = eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
//}
eth.snapDialCandidates, _ = setupDiscovery(eth.config.SnapDiscoveryURLs) //nolint:staticcheck
eth.handler.SetTmpDir(tmpdir)
eth.handler.SetBatchSize(config.CacheSize, config.BatchSize)
Expand All @@ -476,27 +461,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
return nil, err
}

if config.SyncMode != downloader.StagedSync {
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
gpoParams := config.GPO
if gpoParams.Default == nil {
gpoParams.Default = config.Miner.GasPrice
}
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
}

eth.ethDialCandidates, err = setupDiscovery(eth.config.EthDiscoveryURLs)
if err != nil {
return nil, err
}
// Start the RPC service
if config.SyncMode != downloader.StagedSync {
id, err := eth.NetVersion()
if err != nil {
return nil, err
}
eth.netRPCService = ethapi.NewPublicNetAPI(eth.p2pServer, id)
}

// Register the backend on the node
stack.RegisterAPIs(eth.APIs())
Expand Down Expand Up @@ -690,7 +658,7 @@ func (s *Ethereum) StartMining(threads int) error {
th.SetThreads(threads)
}
// If the miner was not running, initialize it
if s.config.SyncMode == downloader.StagedSync || !s.IsMining() {
if !s.IsMining() {
// Propagate the initial price point to the transaction pool
s.lock.RLock()
price := s.gasPrice
Expand Down Expand Up @@ -731,10 +699,6 @@ func (s *Ethereum) StopMining() {
if th, ok := s.engine.(threaded); ok {
th.SetThreads(-1)
}
// Stop the block creating itself
if s.config.SyncMode != downloader.StagedSync {
s.miner.Stop()
}
}

func (s *Ethereum) IsMining() bool { return s.config.Miner.Enabled }
Expand Down
Loading

0 comments on commit b48f0e8

Please sign in to comment.