func (b *BlockCreator) WaitTillStart() {
	<-b.started
}
WaitTillStart waits till the block creator is started
package blockcreator
import (
	"github.com/hyperledger-labs/orion-server/internal/blockstore"
	ierrors "github.com/hyperledger-labs/orion-server/internal/errors"
	"github.com/hyperledger-labs/orion-server/internal/httputils"
	"github.com/hyperledger-labs/orion-server/internal/queue"
	"github.com/hyperledger-labs/orion-server/pkg/logger"
	"github.com/hyperledger-labs/orion-server/pkg/types"
	"github.com/pkg/errors"
)
type Replicator interface {
	Submit(block *types.Block) error
}
type BlockCreator struct {
	txBatchQueue                *queue.Queue
	blockReplicator             Replicator
	pendingTxs                  *queue.PendingTxs  
	nextBlockNumber             uint64
	previousBlockHeaderBaseHash []byte
	blockStore                  *blockstore.Store
	started chan struct{}
	stop    chan struct{}
	stopped chan struct{}
	logger *logger.SugarLogger
}
type Config struct {
	TxBatchQueue *queue.Queue
	BlockStore   *blockstore.Store
	PendingTxs   *queue.PendingTxs
	Logger       *logger.SugarLogger
}
func New(conf *Config) (*BlockCreator, error) {
	height, err := conf.BlockStore.Height()
	if err != nil {
		return nil, err
	}
	lastBlockBaseHash, err := conf.BlockStore.GetBaseHeaderHash(height)
	if err != nil {
		return nil, err
	}
	return &BlockCreator{
		txBatchQueue:                conf.TxBatchQueue,
		nextBlockNumber:             height + 1,
		logger:                      conf.Logger,
		blockStore:                  conf.BlockStore,
		pendingTxs:                  conf.PendingTxs,
		started:                     make(chan struct{}),
		stop:                        make(chan struct{}),
		stopped:                     make(chan struct{}),
		previousBlockHeaderBaseHash: lastBlockBaseHash,
	}, nil
}
func (b *BlockCreator) RegisterReplicator(blockReplicator Replicator) {
	b.blockReplicator = blockReplicator
}
func BootstrapBlock(tx *types.ConfigTxEnvelope) (*types.Block, error) {
	block := &types.Block{
		Header: &types.BlockHeader{
			BaseHeader: &types.BlockHeaderBase{
				Number: 1,
			},
		},
		Payload: &types.Block_ConfigTxEnvelope{
			ConfigTxEnvelope: tx,
		},
	}
	return block, nil
}
func (b *BlockCreator) Start() {
	defer close(b.stopped)
	b.logger.Info("starting the block creator")
	close(b.started)
	for {
		select {
		case <-b.stop:
			b.logger.Info("stopping the block creator")
			return
		default:
			txBatch := b.txBatchQueue.Dequeue()
			if txBatch == nil {
				continue
			}
			blkNum := b.nextBlockNumber  
			baseHeader, err := b.createBaseHeader(blkNum)
			if err != nil {
				b.logger.Panicf("Error while filling block header, possible problems with block indexes {%v}", err)
			}
			block := &types.Block{
				Header: &types.BlockHeader{
					BaseHeader: baseHeader,
				},
			}
			switch batch := txBatch.(type) {
			case *types.Block_DataTxEnvelopes:
				block.Payload = batch
				b.logger.Debugf("created block %d with %d data transactions\n",
					blkNum,
					len(batch.DataTxEnvelopes.Envelopes),
				)
			case *types.Block_UserAdministrationTxEnvelope:
				block.Payload = batch
				b.logger.Debugf("created block %d with an user administrative transaction", blkNum)
			case *types.Block_ConfigTxEnvelope:
				block.Payload = batch
				b.logger.Debugf("created block %d with a cluster config administrative transaction", blkNum)
			case *types.Block_DbAdministrationTxEnvelope:
				block.Payload = batch
				b.logger.Debugf("created block %d with a DB administrative transaction", blkNum)
			}
			err = b.blockReplicator.Submit(block)
			switch err.(type) {
			case nil:
			case *ierrors.ClosedError:
				b.logger.Warnf("block submission to block-replicator failed, dropping block, shutting down, because: %s", err)
				continue
			case *ierrors.NotLeaderError:
				b.logger.Warnf("block submission to block-replicator failed, because this node is not a leader: %s", err)
				if txIDs, errID := httputils.BlockPayloadToTxIDs(block.Payload); errID == nil {
					b.pendingTxs.ReleaseWithError(txIDs, err)
				} else {
					b.logger.Errorf("failed to extract TXIDs from block: %s", errID)
				}
				continue
			default:
				b.logger.Panicf("block submission to block-replicator failed: %v", err)
			}
			h, err := blockstore.ComputeBlockBaseHash(block)
			if err != nil {
				b.logger.Panicf("Error calculating block hash {%v}", err)
			}
			b.previousBlockHeaderBaseHash = h
			b.nextBlockNumber++
		}
	}
}