github.com/intfoundation/intchain@v0.0.0-20220727031208-4316ad31ca73/consensus/ipbft/backend.go (about) 1 package ipbft 2 3 import ( 4 "crypto/ecdsa" 5 "github.com/intfoundation/intchain/common" 6 "github.com/intfoundation/intchain/consensus" 7 "github.com/intfoundation/intchain/consensus/ipbft/types" 8 "github.com/intfoundation/intchain/core" 9 ethTypes "github.com/intfoundation/intchain/core/types" 10 "github.com/intfoundation/intchain/event" 11 "github.com/intfoundation/intchain/log" 12 "github.com/intfoundation/intchain/params" 13 "gopkg.in/urfave/cli.v1" 14 "sync" 15 ) 16 17 // New creates an Ethereum backend for Tendermint core engine. 18 func New(chainConfig *params.ChainConfig, cliCtx *cli.Context, 19 privateKey *ecdsa.PrivateKey, cch core.CrossChainHelper) consensus.IPBFT { 20 // Allocate the snapshot caches and create the engine 21 //recents, _ := lru.NewARC(inmemorySnapshots) 22 //recentMessages, _ := lru.NewARC(inmemoryPeers) 23 //knownMessages, _ := lru.NewARC(inmemoryMessages) 24 25 config := GetTendermintConfig(chainConfig.IntChainId, cliCtx) 26 27 backend := &backend{ 28 //config: config, 29 chainConfig: chainConfig, 30 tendermintEventMux: new(event.TypeMux), 31 privateKey: privateKey, 32 //address: crypto.PubkeyToAddress(privateKey.PublicKey), 33 //core: node, 34 //chain: chain, 35 logger: chainConfig.ChainLogger, 36 commitCh: make(chan *ethTypes.Block, 1), 37 vcommitCh: make(chan *types.IntermediateBlockResult, 1), 38 //recents: recents, 39 //candidates: make(map[common.Address]bool), 40 coreStarted: false, 41 //recentMessages: recentMessages, 42 //knownMessages: knownMessages, 43 } 44 backend.core = MakeTendermintNode(backend, config, chainConfig, cch) 45 return backend 46 } 47 48 type backend struct { 49 //config cfg.Config 50 chainConfig *params.ChainConfig 51 tendermintEventMux *event.TypeMux 52 privateKey *ecdsa.PrivateKey 53 address common.Address 54 core *Node 55 logger log.Logger 56 chain consensus.ChainReader 57 currentBlock func() *ethTypes.Block 58 hasBadBlock func(hash common.Hash) bool 59 60 // the channels for istanbul engine notifications 61 commitCh chan *ethTypes.Block 62 vcommitCh chan *types.IntermediateBlockResult 63 proposedBlockHash common.Hash 64 sealMu sync.Mutex 65 shouldStart bool 66 coreStarted bool 67 coreMu sync.RWMutex 68 69 // Current list of candidates we are pushing 70 //candidates map[common.Address]bool 71 // Protects the signer fields 72 //candidatesLock sync.RWMutex 73 // Snapshots for recent block to speed up reorgs 74 //recents *lru.ARCCache 75 76 // event subscription for ChainHeadEvent event 77 broadcaster consensus.Broadcaster 78 79 //recentMessages *lru.ARCCache // the cache of peer's messages 80 //knownMessages *lru.ARCCache // the cache of self messages 81 } 82 83 // WaitForTxs returns true if the consensus should wait for transactions before entering the propose step 84 //func (b *backend) WaitForTxs() bool { 85 // 86 // return !b.config.GetBool("create_empty_blocks") || b.config.GetInt("create_empty_blocks_interval") > 0 87 //} 88 // 89 //func (b *backend) GetCreateEmptyBlocks() bool { 90 // return b.config.GetBool("create_empty_blocks") 91 //} 92 // 93 //func (b *backend) GetCreateEmptyBlocksInterval() int { 94 // return b.config.GetInt("create_empty_blocks_interval") 95 //} 96 97 func GetBackend() backend { 98 return backend{} 99 }