|
|
@ -19,12 +19,13 @@ type StageStates struct { |
|
|
|
configs StageStatesCfg |
|
|
|
configs StageStatesCfg |
|
|
|
} |
|
|
|
} |
|
|
|
type StageStatesCfg struct { |
|
|
|
type StageStatesCfg struct { |
|
|
|
bc core.BlockChain |
|
|
|
bc core.BlockChain |
|
|
|
db kv.RwDB |
|
|
|
db kv.RwDB |
|
|
|
blockDBs []kv.RwDB |
|
|
|
blockDBs []kv.RwDB |
|
|
|
concurrency int |
|
|
|
concurrency int |
|
|
|
logger zerolog.Logger |
|
|
|
blockExecution bool |
|
|
|
logProgress bool |
|
|
|
logger zerolog.Logger |
|
|
|
|
|
|
|
logProgress bool |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func NewStageStates(cfg StageStatesCfg) *StageStates { |
|
|
|
func NewStageStates(cfg StageStatesCfg) *StageStates { |
|
|
@ -38,16 +39,18 @@ func NewStageStatesCfg( |
|
|
|
db kv.RwDB, |
|
|
|
db kv.RwDB, |
|
|
|
blockDBs []kv.RwDB, |
|
|
|
blockDBs []kv.RwDB, |
|
|
|
concurrency int, |
|
|
|
concurrency int, |
|
|
|
|
|
|
|
blockExecution bool, |
|
|
|
logger zerolog.Logger, |
|
|
|
logger zerolog.Logger, |
|
|
|
logProgress bool) StageStatesCfg { |
|
|
|
logProgress bool) StageStatesCfg { |
|
|
|
|
|
|
|
|
|
|
|
return StageStatesCfg{ |
|
|
|
return StageStatesCfg{ |
|
|
|
bc: bc, |
|
|
|
bc: bc, |
|
|
|
db: db, |
|
|
|
db: db, |
|
|
|
blockDBs: blockDBs, |
|
|
|
blockDBs: blockDBs, |
|
|
|
concurrency: concurrency, |
|
|
|
concurrency: concurrency, |
|
|
|
logger: logger, |
|
|
|
blockExecution: blockExecution, |
|
|
|
logProgress: logProgress, |
|
|
|
logger: logger, |
|
|
|
|
|
|
|
logProgress: logProgress, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -108,6 +111,8 @@ func (stg *StageStates) Exec(ctx context.Context, firstCycle bool, invalidBlockR |
|
|
|
fmt.Print("\033[s") // save the cursor position
|
|
|
|
fmt.Print("\033[s") // save the cursor position
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s.state.currentCycle.ReceiptHashes = make(map[uint64]common.Hash) |
|
|
|
|
|
|
|
|
|
|
|
for i := currProgress + 1; i <= targetHeight; i++ { |
|
|
|
for i := currProgress + 1; i <= targetHeight; i++ { |
|
|
|
blkKey := marshalData(i) |
|
|
|
blkKey := marshalData(i) |
|
|
|
loopID, streamID := gbm.GetDownloadDetails(i) |
|
|
|
loopID, streamID := gbm.GetDownloadDetails(i) |
|
|
@ -157,7 +162,7 @@ func (stg *StageStates) Exec(ctx context.Context, firstCycle bool, invalidBlockR |
|
|
|
return ErrInvalidBlockNumber |
|
|
|
return ErrInvalidBlockNumber |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := verifyAndInsertBlock(stg.configs.bc, block); err != nil { |
|
|
|
if err := verifyAndInsertBlock(stg.configs.bc, block, stg.configs.blockExecution); err != nil { |
|
|
|
stg.configs.logger.Warn().Err(err).Uint64("cycle target block", targetHeight). |
|
|
|
stg.configs.logger.Warn().Err(err).Uint64("cycle target block", targetHeight). |
|
|
|
Uint64("block number", block.NumberU64()). |
|
|
|
Uint64("block number", block.NumberU64()). |
|
|
|
Msg(WrapStagedSyncMsg("insert blocks failed in long range")) |
|
|
|
Msg(WrapStagedSyncMsg("insert blocks failed in long range")) |
|
|
@ -169,6 +174,10 @@ func (stg *StageStates) Exec(ctx context.Context, firstCycle bool, invalidBlockR |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: only for fast sync
|
|
|
|
|
|
|
|
// add receipt hash for next stage
|
|
|
|
|
|
|
|
s.state.currentCycle.ReceiptHashes[block.NumberU64()]=block.Header().ReceiptHash() |
|
|
|
|
|
|
|
|
|
|
|
if invalidBlockRevert { |
|
|
|
if invalidBlockRevert { |
|
|
|
if s.state.invalidBlock.Number == i { |
|
|
|
if s.state.invalidBlock.Number == i { |
|
|
|
s.state.invalidBlock.resolve() |
|
|
|
s.state.invalidBlock.resolve() |
|
|
|