mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-22 19:19:09 +00:00
blockchainer: drop the package completely
It's not an ideal solution, but at least it solves the problem for now. Caveats: * consensus only needs one method, so it's mirrored to Blockchain * rpcsrv uses core.* definition of the StateRoot (so technically it might as well not have an internal Ledger), but it uses core already unfortunately
This commit is contained in:
parent
5ee7ea34b1
commit
88542630ac
6 changed files with 25 additions and 35 deletions
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/mpt"
|
||||
|
@ -293,11 +292,6 @@ func (chain *FakeChain) GetEnrollments() ([]state.Validator, error) {
|
|||
panic("TODO")
|
||||
}
|
||||
|
||||
// GetStateModule implements the Blockchainer interface.
|
||||
func (chain *FakeChain) GetStateModule() blockchainer.StateRoot {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetStorageItem implements the Blockchainer interface.
|
||||
func (chain *FakeChain) GetStorageItem(id int32, key []byte) state.StorageItem {
|
||||
panic("TODO")
|
||||
|
|
|
@ -13,9 +13,9 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||
coreb "github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
|
@ -50,7 +50,7 @@ type Ledger interface {
|
|||
GetConfig() config.ProtocolConfiguration
|
||||
GetMemPool() *mempool.Pool
|
||||
GetNextBlockValidators() ([]*keys.PublicKey, error)
|
||||
GetStateModule() blockchainer.StateRoot
|
||||
GetStateRoot(height uint32) (*state.MPTRoot, error)
|
||||
GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error)
|
||||
GetValidators() ([]*keys.PublicKey, error)
|
||||
PoolTx(t *transaction.Transaction, pools ...*mempool.Pool) error
|
||||
|
@ -250,7 +250,7 @@ func (s *service) newPrepareRequest() payload.PrepareRequest {
|
|||
r := new(prepareRequest)
|
||||
if s.ProtocolConfiguration.StateRootInHeader {
|
||||
r.stateRootEnabled = true
|
||||
if sr, err := s.Chain.GetStateModule().GetStateRoot(s.dbft.BlockIndex - 1); err == nil {
|
||||
if sr, err := s.Chain.GetStateRoot(s.dbft.BlockIndex - 1); err == nil {
|
||||
r.stateRoot = sr.Root
|
||||
} else {
|
||||
panic(err)
|
||||
|
@ -535,7 +535,7 @@ func (s *service) verifyRequest(p payload.ConsensusPayload) error {
|
|||
return errInvalidVersion
|
||||
}
|
||||
if s.ProtocolConfiguration.StateRootInHeader {
|
||||
sr, err := s.Chain.GetStateModule().GetStateRoot(s.dbft.BlockIndex - 1)
|
||||
sr, err := s.Chain.GetStateRoot(s.dbft.BlockIndex - 1)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if sr.Root != req.stateRoot {
|
||||
|
@ -689,7 +689,7 @@ func (s *service) newBlockFromContext(ctx *dbft.Context) block.Block {
|
|||
block.Block.Nonce = ctx.Nonce
|
||||
block.Block.Index = ctx.BlockIndex
|
||||
if s.ProtocolConfiguration.StateRootInHeader {
|
||||
sr, err := s.Chain.GetStateModule().GetStateRoot(ctx.BlockIndex - 1)
|
||||
sr, err := s.Chain.GetStateRoot(ctx.BlockIndex - 1)
|
||||
if err != nil {
|
||||
s.log.Fatal(fmt.Sprintf("failed to get state root: %s", err.Error()))
|
||||
}
|
||||
|
|
|
@ -321,7 +321,7 @@ func TestService_PrepareRequest(t *testing.T) {
|
|||
prevHash: prevHash,
|
||||
})
|
||||
|
||||
sr, err := srv.Chain.GetStateModule().GetStateRoot(srv.dbft.BlockIndex - 1)
|
||||
sr, err := srv.Chain.GetStateRoot(srv.dbft.BlockIndex - 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
checkRequest(t, errInvalidTransactionsCount, &prepareRequest{stateRootEnabled: true,
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||
"github.com/nspcc-dev/neo-go/pkg/config/limits"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/contract"
|
||||
|
@ -181,6 +180,18 @@ type Blockchain struct {
|
|||
unsubCh chan interface{}
|
||||
}
|
||||
|
||||
// StateRoot represents local state root module.
|
||||
type StateRoot interface {
|
||||
CurrentLocalHeight() uint32
|
||||
CurrentLocalStateRoot() util.Uint256
|
||||
CurrentValidatedHeight() uint32
|
||||
FindStates(root util.Uint256, prefix, start []byte, max int) ([]storage.KeyValue, error)
|
||||
GetState(root util.Uint256, key []byte) ([]byte, error)
|
||||
GetStateProof(root util.Uint256, key []byte) ([][]byte, error)
|
||||
GetStateRoot(height uint32) (*state.MPTRoot, error)
|
||||
GetLatestStateHeight(root util.Uint256) (uint32, error)
|
||||
}
|
||||
|
||||
// bcEvent is an internal event generated by the Blockchain and then
|
||||
// broadcasted to other parties. It joins the new block and associated
|
||||
// invocation logs, all the other events visible from outside can be produced
|
||||
|
@ -995,8 +1006,13 @@ func (bc *Blockchain) addHeaders(verify bool, headers ...*block.Header) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetStateRoot returns state root for the given height.
|
||||
func (bc *Blockchain) GetStateRoot(height uint32) (*state.MPTRoot, error) {
|
||||
return bc.stateRoot.GetStateRoot(height)
|
||||
}
|
||||
|
||||
// GetStateModule returns state root service instance.
|
||||
func (bc *Blockchain) GetStateModule() blockchainer.StateRoot {
|
||||
func (bc *Blockchain) GetStateModule() StateRoot {
|
||||
return bc.stateRoot
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package blockchainer
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
)
|
||||
|
||||
// StateRoot represents local state root module.
|
||||
type StateRoot interface {
|
||||
CurrentLocalHeight() uint32
|
||||
CurrentLocalStateRoot() util.Uint256
|
||||
CurrentValidatedHeight() uint32
|
||||
FindStates(root util.Uint256, prefix, start []byte, max int) ([]storage.KeyValue, error)
|
||||
GetState(root util.Uint256, key []byte) ([]byte, error)
|
||||
GetStateProof(root util.Uint256, key []byte) ([][]byte, error)
|
||||
GetStateRoot(height uint32) (*state.MPTRoot, error)
|
||||
GetLatestStateHeight(root util.Uint256) (uint32, error)
|
||||
}
|
|
@ -25,7 +25,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/iterator"
|
||||
|
@ -87,7 +86,7 @@ type (
|
|||
GetNextBlockValidators() ([]*keys.PublicKey, error)
|
||||
GetNotaryContractScriptHash() util.Uint160
|
||||
GetNotaryServiceFeePerKey() int64
|
||||
GetStateModule() blockchainer.StateRoot
|
||||
GetStateModule() core.StateRoot
|
||||
GetStorageItem(id int32, key []byte) state.StorageItem
|
||||
GetTestHistoricVM(t trigger.Type, tx *transaction.Transaction, b *block.Block) (*interop.Context, error)
|
||||
GetTestVM(t trigger.Type, tx *transaction.Transaction, b *block.Block) *interop.Context
|
||||
|
|
Loading…
Reference in a new issue