From f8051da0bd0e2dae25c34c1dd76d2501d0349c7a Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 22 Jun 2020 10:49:48 +0300 Subject: [PATCH] core: extend Blockchainer interface with StateHeight() Allow to query current verified state root height. --- pkg/core/blockchain.go | 6 ++++++ pkg/core/blockchainer.go | 1 + pkg/network/helper_test.go | 4 +++- pkg/rpc/server/server.go | 5 ++--- pkg/rpc/server/server_test.go | 5 ++--- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index e311db644..528002435 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -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) diff --git a/pkg/core/blockchainer.go b/pkg/core/blockchainer.go index db2d11abe..d32a3eb5e 100644 --- a/pkg/core/blockchainer.go +++ b/pkg/core/blockchainer.go @@ -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) diff --git a/pkg/network/helper_test.go b/pkg/network/helper_test.go index 2e2b697ad..0bc0b6637 100644 --- a/pkg/network/helper_test.go +++ b/pkg/network/helper_test.go @@ -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") } diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 6912c4e24..675efc9b7 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -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 } diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index e53687baf..509867121 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -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) }, }, },