From 72e654332e83c86e8af67b3bd8f308f5c8066e5b Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 30 Jul 2021 17:29:49 +0300 Subject: [PATCH] core: refactor block queue It requires only two methods from Blockchainer: AddBlock and BlockHeight. New interface will allow to easily reuse the block queue for state exchange purposes. --- pkg/core/blockchainer/blockchainer.go | 2 +- pkg/core/blockchainer/blockqueuer.go | 9 +++++++++ pkg/network/blockqueue.go | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 pkg/core/blockchainer/blockqueuer.go diff --git a/pkg/core/blockchainer/blockchainer.go b/pkg/core/blockchainer/blockchainer.go index 73a5d36d5..a0d5af6f4 100644 --- a/pkg/core/blockchainer/blockchainer.go +++ b/pkg/core/blockchainer/blockchainer.go @@ -22,7 +22,7 @@ type Blockchainer interface { ApplyPolicyToTxSet([]*transaction.Transaction) []*transaction.Transaction GetConfig() config.ProtocolConfiguration AddHeaders(...*block.Header) error - AddBlock(*block.Block) error + Blockqueuer // Blockqueuer interface CalculateClaimable(h util.Uint160, endHeight uint32) (*big.Int, error) Close() InitVerificationVM(v *vm.VM, getContract func(util.Uint160) (*state.Contract, error), hash util.Uint160, witness *transaction.Witness) error diff --git a/pkg/core/blockchainer/blockqueuer.go b/pkg/core/blockchainer/blockqueuer.go new file mode 100644 index 000000000..384ccd489 --- /dev/null +++ b/pkg/core/blockchainer/blockqueuer.go @@ -0,0 +1,9 @@ +package blockchainer + +import "github.com/nspcc-dev/neo-go/pkg/core/block" + +// Blockqueuer is an interface for blockqueue. +type Blockqueuer interface { + AddBlock(block *block.Block) error + BlockHeight() uint32 +} diff --git a/pkg/network/blockqueue.go b/pkg/network/blockqueue.go index a5bb92c42..8a21cab1b 100644 --- a/pkg/network/blockqueue.go +++ b/pkg/network/blockqueue.go @@ -11,7 +11,7 @@ type blockQueue struct { log *zap.Logger queue *queue.PriorityQueue checkBlocks chan struct{} - chain blockchainer.Blockchainer + chain blockchainer.Blockqueuer relayF func(*block.Block) } @@ -21,7 +21,7 @@ const ( blockCacheSize = 2000 ) -func newBlockQueue(capacity int, bc blockchainer.Blockchainer, log *zap.Logger, relayer func(*block.Block)) *blockQueue { +func newBlockQueue(capacity int, bc blockchainer.Blockqueuer, log *zap.Logger, relayer func(*block.Block)) *blockQueue { if log == nil { return nil }