core: extend Blockchainer interface with StateHeight()

Allow to query current verified state root height.
This commit is contained in:
Evgenii Stratonikov 2020-06-22 10:49:48 +03:00
parent f665843887
commit f8051da0bd
5 changed files with 14 additions and 7 deletions

View file

@ -1776,6 +1776,12 @@ func (bc *Blockchain) isTxStillRelevant(t *transaction.Transaction) bool {
}
// StateHeight returns height of the verified state root.
func (bc *Blockchain) StateHeight() uint32 {
h, _ := bc.dao.GetCurrentStateRootHeight()
return h
}
// AddStateRoot add new (possibly unverified) state root to the blockchain.
func (bc *Blockchain) AddStateRoot(r *state.MPTRoot) error {
our, err := bc.GetStateRoot(r.Index)

View file

@ -49,6 +49,7 @@ type Blockchainer interface {
References(t *transaction.Transaction) ([]transaction.InOut, error)
mempool.Feer // fee interface
PoolTx(*transaction.Transaction) error
StateHeight() uint32
SubscribeForBlocks(ch chan<- *block.Block)
SubscribeForExecutions(ch chan<- *state.AppExecResult)
SubscribeForNotifications(ch chan<- *state.NotificationEvent)

View file

@ -154,7 +154,9 @@ func (chain testChain) IsLowPriority(util.Fixed8) bool {
func (chain testChain) PoolTx(*transaction.Transaction) error {
panic("TODO")
}
func (chain testChain) StateHeight() uint32 {
panic("TODO")
}
func (chain testChain) SubscribeForBlocks(ch chan<- *block.Block) {
panic("TODO")
}

View file

@ -745,10 +745,9 @@ func (s *Server) verifyProof(ps request.Params) (interface{}, *response.Error) {
}
func (s *Server) getStateHeight(_ request.Params) (interface{}, *response.Error) {
height := s.chain.BlockHeight()
return &result.StateHeight{
BlockHeight: height,
StateHeight: height,
BlockHeight: s.chain.BlockHeight(),
StateHeight: s.chain.StateHeight(),
}, nil
}

View file

@ -246,9 +246,8 @@ var rpcTestCases = map[string][]rpcTestCase{
sh, ok := res.(*result.StateHeight)
require.True(t, ok)
h := e.chain.BlockHeight()
require.Equal(t, h, sh.BlockHeight)
require.Equal(t, h, sh.StateHeight)
require.Equal(t, e.chain.BlockHeight(), sh.BlockHeight)
require.Equal(t, e.chain.StateHeight(), sh.StateHeight)
},
},
},