mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 19:50:36 +00:00
Downloader flag
This commit is contained in:
parent
fae6fe0775
commit
14b45ea50b
@ -109,6 +109,7 @@ var (
|
||||
utils.CacheTrieFlag,
|
||||
utils.CacheGCFlag,
|
||||
utils.TrieCacheGenFlag,
|
||||
utils.DownloaderFlag,
|
||||
utils.NoHistory,
|
||||
utils.ArchiveSyncInterval,
|
||||
utils.ListenPortFlag,
|
||||
|
@ -87,6 +87,7 @@ var AppHelpFlagGroups = []flagGroup{
|
||||
utils.IdentityFlag,
|
||||
utils.LightKDFFlag,
|
||||
utils.WhitelistFlag,
|
||||
utils.DownloaderFlag,
|
||||
utils.NoHistory,
|
||||
utils.ArchiveSyncInterval,
|
||||
},
|
||||
|
@ -297,6 +297,10 @@ var (
|
||||
Name: "ulc.onlyannounce",
|
||||
Usage: "Ultra light server sends announcements only",
|
||||
}
|
||||
DownloaderFlag = cli.BoolFlag{
|
||||
Name: "downloader",
|
||||
Usage: "Run in downloader mode - only fetch blocks but not process them",
|
||||
}
|
||||
// Dashboard settings
|
||||
DashboardEnabledFlag = cli.BoolFlag{
|
||||
Name: "dashboard",
|
||||
@ -1468,6 +1472,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
||||
cfg.BlocksToPrune = ctx.GlobalUint64(GCModeBlockToPruneFlag.Name)
|
||||
cfg.PruningTimeout = ctx.GlobalDuration(GCModeTickTimeout.Name)
|
||||
|
||||
cfg.DownloadOnly = ctx.GlobalBoolT(DownloaderFlag.Name)
|
||||
cfg.NoHistory = ctx.GlobalBoolT(NoHistory.Name)
|
||||
cfg.ArchiveSyncInterval = ctx.GlobalInt(ArchiveSyncInterval.Name)
|
||||
|
||||
|
@ -124,6 +124,7 @@ type CacheConfig struct {
|
||||
BlocksToPrune uint64
|
||||
PruneTimeout time.Duration
|
||||
ArchiveSyncInterval uint64
|
||||
DownloadOnly bool
|
||||
NoHistory bool
|
||||
}
|
||||
|
||||
@ -205,6 +206,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
|
||||
TrieCleanLimit: 256,
|
||||
TrieDirtyLimit: 256,
|
||||
TrieTimeLimit: 5 * time.Minute,
|
||||
DownloadOnly: false,
|
||||
NoHistory: false,
|
||||
}
|
||||
}
|
||||
@ -1243,7 +1245,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
|
||||
|
||||
// writeBlockWithState writes the block and all associated state to the database,
|
||||
// but is expects the chain mutex to be held.
|
||||
func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, state *state.IntraBlockState, tds *state.TrieDbState) (status WriteStatus, err error) {
|
||||
func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, stateDb *state.IntraBlockState, tds *state.TrieDbState) (status WriteStatus, err error) {
|
||||
bc.wg.Add(1)
|
||||
defer bc.wg.Done()
|
||||
|
||||
@ -1264,13 +1266,17 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
||||
}
|
||||
rawdb.WriteBlock(bc.db, block)
|
||||
|
||||
tds.SetBlockNr(block.NumberU64())
|
||||
if tds != nil {
|
||||
tds.SetBlockNr(block.NumberU64())
|
||||
}
|
||||
|
||||
ctx := bc.WithContext(context.Background(), block.Number())
|
||||
if err := state.CommitBlock(ctx, tds.DbStateWriter()); err != nil {
|
||||
return NonStatTy, err
|
||||
if stateDb != nil {
|
||||
if err := stateDb.CommitBlock(ctx, tds.DbStateWriter()); err != nil {
|
||||
return NonStatTy, err
|
||||
}
|
||||
}
|
||||
if bc.enableReceipts {
|
||||
if bc.enableReceipts && !bc.cacheConfig.DownloadOnly {
|
||||
rawdb.WriteReceipts(bc.db, block.Hash(), block.NumberU64(), receipts)
|
||||
}
|
||||
|
||||
@ -1300,8 +1306,12 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
||||
}
|
||||
}
|
||||
// Write the positional metadata for transaction/receipt lookups and preimages
|
||||
rawdb.WriteTxLookupEntries(bc.db, block)
|
||||
rawdb.WritePreimages(bc.db, state.Preimages())
|
||||
if !bc.cacheConfig.DownloadOnly {
|
||||
rawdb.WriteTxLookupEntries(bc.db, block)
|
||||
}
|
||||
if stateDb != nil {
|
||||
rawdb.WritePreimages(bc.db, stateDb.Preimages())
|
||||
}
|
||||
|
||||
status = CanonStatTy
|
||||
//} else {
|
||||
@ -1547,17 +1557,19 @@ func (bc *BlockChain) insertChain(ctx context.Context, chain types.Blocks, verif
|
||||
}
|
||||
readBlockNr := parentNumber
|
||||
var root common.Hash
|
||||
if bc.trieDbState == nil {
|
||||
if bc.trieDbState == nil && !bc.cacheConfig.DownloadOnly {
|
||||
if _, err = bc.GetTrieDbState(); err != nil {
|
||||
return k, events, coalescedLogs, err
|
||||
}
|
||||
}
|
||||
root = bc.trieDbState.LastRoot()
|
||||
if !bc.cacheConfig.DownloadOnly {
|
||||
root = bc.trieDbState.LastRoot()
|
||||
}
|
||||
var parentRoot common.Hash
|
||||
if parent != nil {
|
||||
parentRoot = parent.Root()
|
||||
}
|
||||
if parent != nil && root != parentRoot {
|
||||
if parent != nil && root != parentRoot && !bc.cacheConfig.DownloadOnly {
|
||||
log.Info("Rewinding from", "block", bc.CurrentBlock().NumberU64(), "to block", readBlockNr)
|
||||
if _, err = bc.db.Commit(); err != nil {
|
||||
log.Error("Could not commit chainDb before rewinding", "error", err)
|
||||
@ -1591,38 +1603,44 @@ func (bc *BlockChain) insertChain(ctx context.Context, chain types.Blocks, verif
|
||||
return 0, events, coalescedLogs, err
|
||||
}
|
||||
}
|
||||
stateDB := state.New(bc.trieDbState)
|
||||
// Process block using the parent state as reference point.
|
||||
//t0 := time.Now()
|
||||
receipts, logs, usedGas, err := bc.processor.Process(block, stateDB, bc.trieDbState, bc.vmConfig)
|
||||
//t1 := time.Now()
|
||||
if err != nil {
|
||||
bc.db.Rollback()
|
||||
bc.trieDbState = nil
|
||||
bc.reportBlock(block, receipts, err)
|
||||
return k, events, coalescedLogs, err
|
||||
}
|
||||
// Update the metrics touched during block processing
|
||||
/*
|
||||
accountReadTimer.Update(statedb.AccountReads) // Account reads are complete, we can mark them
|
||||
storageReadTimer.Update(statedb.StorageReads) // Storage reads are complete, we can mark them
|
||||
accountUpdateTimer.Update(statedb.AccountUpdates) // Account updates are complete, we can mark them
|
||||
storageUpdateTimer.Update(statedb.StorageUpdates) // Storage updates are complete, we can mark them
|
||||
var stateDB *state.IntraBlockState
|
||||
var receipts types.Receipts
|
||||
var logs []*types.Log
|
||||
var usedGas uint64
|
||||
if !bc.cacheConfig.DownloadOnly {
|
||||
stateDB = state.New(bc.trieDbState)
|
||||
// Process block using the parent state as reference point.
|
||||
//t0 := time.Now()
|
||||
receipts, logs, usedGas, err = bc.processor.Process(block, stateDB, bc.trieDbState, bc.vmConfig)
|
||||
//t1 := time.Now()
|
||||
if err != nil {
|
||||
bc.db.Rollback()
|
||||
bc.trieDbState = nil
|
||||
bc.reportBlock(block, receipts, err)
|
||||
return k, events, coalescedLogs, err
|
||||
}
|
||||
// Update the metrics touched during block processing
|
||||
/*
|
||||
accountReadTimer.Update(statedb.AccountReads) // Account reads are complete, we can mark them
|
||||
storageReadTimer.Update(statedb.StorageReads) // Storage reads are complete, we can mark them
|
||||
accountUpdateTimer.Update(statedb.AccountUpdates) // Account updates are complete, we can mark them
|
||||
storageUpdateTimer.Update(statedb.StorageUpdates) // Storage updates are complete, we can mark them
|
||||
|
||||
triehash := statedb.AccountHashes + statedb.StorageHashes // Save to not double count in validation
|
||||
trieproc := statedb.AccountReads + statedb.AccountUpdates
|
||||
trieproc += statedb.StorageReads + statedb.StorageUpdates
|
||||
triehash := statedb.AccountHashes + statedb.StorageHashes // Save to not double count in validation
|
||||
trieproc := statedb.AccountReads + statedb.AccountUpdates
|
||||
trieproc += statedb.StorageReads + statedb.StorageUpdates
|
||||
|
||||
blockExecutionTimer.Update(time.Since(substart) - trieproc - triehash)
|
||||
*/
|
||||
blockExecutionTimer.Update(time.Since(substart) - trieproc - triehash)
|
||||
*/
|
||||
|
||||
// Validate the state using the default validator
|
||||
err = bc.Validator().ValidateState(block, parent, stateDB, bc.trieDbState, receipts, usedGas)
|
||||
if err != nil {
|
||||
bc.db.Rollback()
|
||||
bc.trieDbState = nil
|
||||
bc.reportBlock(block, receipts, err)
|
||||
return k, events, coalescedLogs, err
|
||||
// Validate the state using the default validator
|
||||
err = bc.Validator().ValidateState(block, parent, stateDB, bc.trieDbState, receipts, usedGas)
|
||||
if err != nil {
|
||||
bc.db.Rollback()
|
||||
bc.trieDbState = nil
|
||||
bc.reportBlock(block, receipts, err)
|
||||
return k, events, coalescedLogs, err
|
||||
}
|
||||
}
|
||||
proctime := time.Since(start)
|
||||
|
||||
@ -1693,7 +1711,9 @@ func (bc *BlockChain) insertChain(ctx context.Context, chain types.Blocks, verif
|
||||
bc.trieDbState = nil
|
||||
return 0, events, coalescedLogs, err
|
||||
}
|
||||
bc.trieDbState.PruneTries(false)
|
||||
if bc.trieDbState != nil {
|
||||
bc.trieDbState.PruneTries(false)
|
||||
}
|
||||
log.Info("Database", "size", bc.db.Size(), "written", written)
|
||||
}
|
||||
}
|
||||
|
@ -186,6 +186,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||
TrieDirtyLimit: config.TrieDirtyCache,
|
||||
TrieCleanNoPrefetch: config.NoPrefetch,
|
||||
TrieTimeLimit: config.TrieTimeout,
|
||||
DownloadOnly: config.DownloadOnly,
|
||||
NoHistory: config.NoHistory,
|
||||
ArchiveSyncInterval: uint64(config.ArchiveSyncInterval),
|
||||
}
|
||||
|
@ -98,7 +98,10 @@ type Config struct {
|
||||
NoPruning bool // Whether to disable pruning and flush everything to disk
|
||||
NoPrefetch bool // Whether to disable prefetching and only load state on demand
|
||||
|
||||
NoHistory bool
|
||||
NoHistory bool
|
||||
// DownloadOnly is set when the node does not need to process the blocks, but simply
|
||||
// download them
|
||||
DownloadOnly bool
|
||||
ArchiveSyncInterval int
|
||||
BlocksBeforePruning uint64
|
||||
BlocksToPrune uint64
|
||||
|
Loading…
Reference in New Issue
Block a user