"github.com/bytom/p2p"
"github.com/bytom/p2p/trust"
"github.com/bytom/protocol"
+ "github.com/bytom/protocol/bc"
protocolTypes "github.com/bytom/protocol/bc/types"
"github.com/bytom/types"
)
const (
// BlockchainChannel is a channel for blocks and status updates
BlockchainChannel = byte(0x40)
+ maxNewBlockChSize = int(1024)
statusUpdateIntervalSeconds = 10
maxBlockchainResponseSize = 22020096 + 2
sw *p2p.Switch
handler http.Handler
evsw types.EventSwitch
+ newBlockCh chan *bc.Hash
miningEnable bool
}
// NewBlockchainReactor returns the reactor of whole blockchain.
func NewBlockchainReactor(chain *protocol.Chain, txPool *protocol.TxPool, accounts *account.Manager, assets *asset.Registry, sw *p2p.Switch, hsm *pseudohsm.HSM, wallet *wallet.Wallet, txfeeds *txfeed.Tracker, accessTokens *accesstoken.CredentialStore, miningEnable bool) *BlockchainReactor {
+ newBlockCh := make(chan *bc.Hash, maxNewBlockChSize)
bcr := &BlockchainReactor{
chain: chain,
wallet: wallet,
assets: assets,
blockKeeper: newBlockKeeper(chain, sw),
txPool: txPool,
- mining: cpuminer.NewCPUMiner(chain, accounts, txPool),
- miningPool: miningpool.NewMiningPool(chain, accounts, txPool),
+ mining: cpuminer.NewCPUMiner(chain, accounts, txPool, newBlockCh),
+ miningPool: miningpool.NewMiningPool(chain, accounts, txPool, newBlockCh),
mux: http.NewServeMux(),
sw: sw,
hsm: hsm,
txFeedTracker: txfeeds,
accessTokens: accessTokens,
miningEnable: miningEnable,
+ newBlockCh: newBlockCh,
}
bcr.BaseReactor = *p2p.NewBaseReactor("BlockchainReactor", bcr)
return bcr
for {
select {
+ case blockHash := <-bcr.newBlockCh:
+ block, err := bcr.chain.GetBlockByHash(blockHash)
+ if err != nil {
+ log.Errorf("Error get block from newBlockCh %v", err)
+ }
+ log.WithFields(log.Fields{"Hash": blockHash, "height": block.Height}).Info("Boardcast my new block")
case newTx := <-newTxCh:
bcr.txFeedTracker.TxFilter(newTx)
go bcr.BroadcastTransaction(newTx)