github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/chain/consensus/neatcon/backend.go (about)

     1  package neatcon
     2  
     3  import (
     4  	"crypto/ecdsa"
     5  	"sync"
     6  
     7  	"github.com/neatio-net/neatio/chain/consensus"
     8  	"github.com/neatio-net/neatio/chain/consensus/neatcon/types"
     9  	"github.com/neatio-net/neatio/chain/core"
    10  	neatTypes "github.com/neatio-net/neatio/chain/core/types"
    11  	"github.com/neatio-net/neatio/chain/log"
    12  	"github.com/neatio-net/neatio/params"
    13  	"github.com/neatio-net/neatio/utilities/common"
    14  	"github.com/neatio-net/neatio/utilities/event"
    15  	"gopkg.in/urfave/cli.v1"
    16  )
    17  
    18  func New(chainConfig *params.ChainConfig, cliCtx *cli.Context,
    19  	privateKey *ecdsa.PrivateKey, cch core.CrossChainHelper) consensus.NeatCon {
    20  
    21  	config := GetNeatConConfig(chainConfig.NeatChainId, cliCtx)
    22  
    23  	backend := &backend{
    24  		chainConfig:     chainConfig,
    25  		neatconEventMux: new(event.TypeMux),
    26  		privateKey:      privateKey,
    27  		logger:          chainConfig.ChainLogger,
    28  		commitCh:        make(chan *neatTypes.Block, 1),
    29  		vcommitCh:       make(chan *types.IntermediateBlockResult, 1),
    30  		coreStarted:     false,
    31  	}
    32  	backend.core = MakeNeatConNode(backend, config, chainConfig, cch)
    33  	return backend
    34  }
    35  
    36  type backend struct {
    37  	chainConfig     *params.ChainConfig
    38  	neatconEventMux *event.TypeMux
    39  	privateKey      *ecdsa.PrivateKey
    40  	address         common.Address
    41  	core            *Node
    42  	logger          log.Logger
    43  	chain           consensus.ChainReader
    44  	currentBlock    func() *neatTypes.Block
    45  	hasBadBlock     func(hash common.Hash) bool
    46  
    47  	commitCh          chan *neatTypes.Block
    48  	vcommitCh         chan *types.IntermediateBlockResult
    49  	proposedBlockHash common.Hash
    50  	sealMu            sync.Mutex
    51  	shouldStart       bool
    52  	coreStarted       bool
    53  	coreMu            sync.RWMutex
    54  
    55  	broadcaster consensus.Broadcaster
    56  }
    57  
    58  func GetBackend() backend {
    59  	return backend{}
    60  }