rpcdaemon, stagedsync: make sure we update the current block number after a sync cycle (#1015)

* rpcdaemon, stagedsync: make sure we update the current block number after a sync cycle

fixes #1014

* linters
This commit is contained in:
Igor Mandrigin 2020-08-30 18:51:06 +02:00 committed by GitHub
parent 5365b8e402
commit a1a7f6607a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

@ -52,7 +52,7 @@ func NewAPI(db ethdb.KV, dbReader ethdb.Getter, eth ethdb.Backend, gascap uint64
} }
func (api *APIImpl) BlockNumber(ctx context.Context) (hexutil.Uint64, error) { func (api *APIImpl) BlockNumber(ctx context.Context) (hexutil.Uint64, error) {
execution, _, err := stages.GetStageProgress(api.dbReader, stages.Execution) execution, _, err := stages.GetStageProgress(api.dbReader, stages.Finish)
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@ -158,3 +158,8 @@ During this stage we start the transaction pool or update its state. For instanc
On unwinds, we add the transactions from the blocks we unwind, back to the pool. On unwinds, we add the transactions from the blocks we unwind, back to the pool.
This stage doesn't use a network connection. This stage doesn't use a network connection.
### Stage 12: Finish
This stage sets the current block number that is then used by [RPC calls](../../cmd/rpcdaemon/Readme.md), such as [`eth_blockNumber`](../../README.md).

View File

@ -170,6 +170,26 @@ func (*StagedSync) Prepare(
return unwindTxPool(u, s, tx, txPool, quitCh) return unwindTxPool(u, s, tx, txPool, quitCh)
}, },
}, },
{
ID: stages.Finish,
Description: "Final: update current block for the RPC API",
ExecFunc: func(s *StageState, _ Unwinder) error {
var executionAt uint64
var err error
if executionAt, err = s.ExecutionAt(tx); err != nil {
return err
}
return s.DoneAndUpdate(tx, executionAt)
},
UnwindFunc: func(u *UnwindState, s *StageState) error {
var executionAt uint64
var err error
if executionAt, err = s.ExecutionAt(tx); err != nil {
return err
}
return s.DoneAndUpdate(tx, executionAt)
},
},
} }
state := NewState(stages) state := NewState(stages)