Skip to content

Commit

Permalink
Merge pull request #2179 from CortexFoundation/dev
Browse files Browse the repository at this point in the history
head event lit
  • Loading branch information
ucwong authored Oct 24, 2024
2 parents cf17465 + 4ae4d98 commit ae222f3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func (bc *BlockChain) SetHead(head uint64) error {
return err
}
// Send chain head event to update the transaction pool
bc.chainHeadFeed.Send(ChainHeadEvent{Block: bc.CurrentBlock()})
bc.chainHeadFeed.Send(ChainHeadEvent{Header: bc.CurrentHeader()})
return nil
}

Expand All @@ -544,7 +544,7 @@ func (bc *BlockChain) SetHeadWithTimestamp(timestamp uint64) error {
return err
}
// Send chain head event to update the transaction pool
bc.chainHeadFeed.Send(ChainHeadEvent{Block: bc.CurrentBlock()})
bc.chainHeadFeed.Send(ChainHeadEvent{Header: bc.CurrentHeader()})
return nil
}

Expand Down Expand Up @@ -1465,7 +1465,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
// we will fire an accumulated ChainHeadEvent and disable fire
// event here.
if emitHeadEvent {
bc.chainHeadFeed.Send(ChainHeadEvent{Block: block})
bc.chainHeadFeed.Send(ChainHeadEvent{Header: block.Header()})
}
} else {
bc.chainSideFeed.Send(ChainSideEvent{Header: block.Header()})
Expand Down Expand Up @@ -1565,7 +1565,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
// Fire a single chain head event if we've progressed the chain
defer func() {
if lastCanon != nil && bc.CurrentBlock().Hash() == lastCanon.Hash() {
bc.chainHeadFeed.Send(ChainHeadEvent{lastCanon})
bc.chainHeadFeed.Send(ChainHeadEvent{lastCanon.Header()})
}
}()
// Start the parallel header verifier
Expand Down Expand Up @@ -2355,7 +2355,7 @@ func (bc *BlockChain) maintainTxIndex() {
case head := <-headCh:
if done == nil {
done = make(chan struct{})
go bc.indexBlocks(rawdb.ReadTxIndexTail(bc.db), head.Block.NumberU64(), done)
go bc.indexBlocks(rawdb.ReadTxIndexTail(bc.db), head.Header.Number.Uint64(), done)
}
case <-done:
done = nil
Expand Down
2 changes: 1 addition & 1 deletion core/chain_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (c *ChainIndexer) eventLoop(currentHeader *types.Header, events chan ChainH
errc <- nil
return
}
header := ev.Block.Header()
header := ev.Header
if header.ParentHash != prevHash {
// Reorg to the common ancestor if needed (might not exist in light sync mode, skip reorg then)

Expand Down
2 changes: 1 addition & 1 deletion core/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ type ChainSideEvent struct {
Header *types.Header
}

type ChainHeadEvent struct{ Block *types.Block }
type ChainHeadEvent struct{ Header *types.Header }
10 changes: 5 additions & 5 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func NewTxPool(config Config, chainconfig *params.ChainConfig, chain blockChain)
// Subscribe events from blockchain and start the main event loop.
pool.chainHeadSub = pool.chain.SubscribeChainHeadEvent(pool.chainHeadCh)

head := chain.CurrentBlock()
head := chain.CurrentBlock().Header()
pool.wg.Add(1)
go pool.loop(head)

Expand All @@ -342,7 +342,7 @@ func NewTxPool(config Config, chainconfig *params.ChainConfig, chain blockChain)
// loop is the transaction pool's main event loop, waiting for and reacting to
// outside blockchain events as well as for various reporting and transaction
// eviction events.
func (pool *TxPool) loop(head *types.Block) {
func (pool *TxPool) loop(head *types.Header) {
defer pool.wg.Done()

var (
Expand All @@ -362,9 +362,9 @@ func (pool *TxPool) loop(head *types.Block) {
select {
// Handle ChainHeadEvent
case ev := <-pool.chainHeadCh:
if ev.Block != nil {
pool.requestReset(head.Header(), ev.Block.Header())
head = ev.Block
if ev.Header != nil {
pool.requestReset(head, ev.Header)
head = ev.Header
}

// System shutdown.
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
commit(false, commitInterruptNewHead)

case head := <-w.chainHeadCh:
clearPending(head.Block.NumberU64())
clearPending(head.Header.Number.Uint64())
timestamp = time.Now().Unix()
commit(false, commitInterruptNewHead)

Expand Down

0 comments on commit ae222f3

Please sign in to comment.