func (b *BlockProcessor) Stop() {
	if err := b.blockOneQueueBarrier.Close(); err != nil {
		b.logger.Warnf("OneQueueBarrier error: %s", err)
	}
	close(b.stop)
	<-b.stopped
}
Stop stops the block processor
package blockprocessor
import (
	"sync"
	"github.com/hyperledger-labs/orion-server/internal/blockstore"
	"github.com/hyperledger-labs/orion-server/internal/mptrie"
	"github.com/hyperledger-labs/orion-server/internal/mtree"
	"github.com/hyperledger-labs/orion-server/internal/provenance"
	"github.com/hyperledger-labs/orion-server/internal/queue"
	"github.com/hyperledger-labs/orion-server/internal/worldstate"
	"github.com/hyperledger-labs/orion-server/pkg/logger"
	"github.com/hyperledger-labs/orion-server/pkg/types"
	"github.com/pkg/errors"
	"github.com/syndtr/goleveldb/leveldb"
)
type BlockProcessor struct {
	blockOneQueueBarrier *queue.OneQueueBarrier
	blockStore           *blockstore.Store
	validator            *validator
	committer            *committer
	listeners            *blockCommitListeners
	started              chan struct{}
	stop                 chan struct{}
	stopped              chan struct{}
	logger               *logger.SugarLogger
}
type Config struct {
	BlockOneQueueBarrier *queue.OneQueueBarrier
	BlockStore           *blockstore.Store
	DB                   worldstate.DB
	ProvenanceStore      *provenance.Store
	StateTrieStore       mptrie.Store
	Logger               *logger.SugarLogger
}
func New(conf *Config) *BlockProcessor {
	return &BlockProcessor{
		blockOneQueueBarrier: conf.BlockOneQueueBarrier,
		blockStore:           conf.BlockStore,
		validator:            newValidator(conf),
		committer:            newCommitter(conf),
		listeners:            newBlockCommitListeners(conf.Logger),
		started:              make(chan struct{}),
		stop:                 make(chan struct{}),
		stopped:              make(chan struct{}),
		logger:               conf.Logger,
	}
}
func (b *BlockProcessor) Bootstrap(configBlock *types.Block) error {
	if err := b.initAndRecoverStateTrieIfNeeded(); err != nil {
		return errors.WithMessage(err, "error while recovering node state trie")
	}
	return b.validateAndCommit(configBlock)
}
func (b *BlockProcessor) Start() {
	b.logger.Debug("starting the block processor")
	defer close(b.stopped)
	if err := b.recoverWorldStateDBIfNeeded(); err != nil {
		panic(errors.WithMessage(err, "error while recovering node"))
	}
	if err := b.initAndRecoverStateTrieIfNeeded(); err != nil {
		panic(errors.WithMessage(err, "error while recovering node state trie"))
	}
	b.logger.Debug("block processor has been started successfully")
	close(b.started)
	for {
		select {
		case <-b.stop:
			b.logger.Info("stopping block processing")
			return
		default:
			blockData, err := b.blockOneQueueBarrier.Dequeue()
			if err != nil {
				b.logger.Debugf("OneQueueBarrier error: %s", err)
				continue
			}
			block := blockData.(*types.Block)
			if err = b.validateAndCommit(block); err != nil {
				panic(err)
			}
			var reConfig interface{}
			switch block.Payload.(type) {
			case *types.Block_ConfigTxEnvelope:
				reConfig = block.GetConfigTxEnvelope().GetPayload().GetNewConfig()
			}
			err = b.blockOneQueueBarrier.Reply(reConfig)
			if err != nil {
				b.logger.Debugf("OneQueueBarrier error: %s", err)
				continue
			}
			if err = b.listeners.invoke(block); err != nil {
				panic(err)
			}
		}
	}
}
func (b *BlockProcessor) validateAndCommit(block *types.Block) error {
	b.logger.Debugf("validating and committing block %d", block.GetHeader().GetBaseHeader().GetNumber())
	validationInfo, err := b.validator.validateBlock(block)
	if err != nil {
		if block.GetHeader().GetBaseHeader().GetNumber() > 1 {
			panic(err)
		}
		return err
	}
	block.Header.ValidationInfo = validationInfo
	if err = b.blockStore.AddSkipListLinks(block); err != nil {
		panic(err)
	}
	root, err := mtree.BuildTreeForBlockTx(block)
	if err != nil {
		panic(err)
	}
	block.Header.TxMerkelTreeRootHash = root.Hash()
	if err = b.committer.commitBlock(block); err != nil {
		panic(err)
	}
	b.logger.Debugf("validated and committed block %d\n", block.GetHeader().GetBaseHeader().GetNumber())
	return err
}
func (b *BlockProcessor) WaitTillStart() {
	<-b.started
}