Skip to content

Commit

Permalink
Async updates to the miner for tx broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Jun 12, 2024
1 parent b00c426 commit 7e5c809
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ func (c *Core) TxPool() *TxPool {
return c.sl.txPool
}

func (c *Core) GetTxsFromBroadcastSet(hash common.Hash) (types.Transactions, error) {
return c.sl.GetTxsFromBroadcastSet(hash)
}

func (c *Core) Stop() {
// Delete the append queue
c.appendQueue.Purge()
Expand Down Expand Up @@ -1192,10 +1196,6 @@ func (c *Core) TxPoolPending(enforceTips bool) (map[common.AddressBytes]types.Tr
return c.sl.txPool.TxPoolPending(enforceTips)
}

func (c *Core) GetTxsFromBroadcastSet(hash common.Hash) (types.Transactions, error) {
return c.sl.txPool.GetTxsFromBroadcastSet(hash)
}

func (c *Core) Get(hash common.Hash) *types.Transaction {
return c.sl.txPool.Get(hash)
}
Expand Down
23 changes: 23 additions & 0 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,29 @@ func (sl *Slice) GetSlicesRunning() []common.Location {
return sl.hc.SlicesRunning()
}

func (sl *Slice) GetTxsFromBroadcastSet(hash common.Hash) (types.Transactions, error) {
// Every time we read the broadcast set, get the next set of transactions and
// update the phcache
// Get the latest transactions to be broadcasted from the pool
sl.txPool.broadcastSetMu.RLock()
if len(sl.txPool.broadcastSet) > 0 {
txs := sl.txPool.broadcastSet
hash := types.DeriveSha(txs, trie.NewStackTrie(nil))
bestPh, exists := sl.readPhCache(sl.bestPhKey)
if exists {
bestPh.WorkObject().WorkObjectHeader().SetLocation(sl.NodeLocation())
bestPh.WorkObject().WorkObjectHeader().SetTxHash(hash)
sl.writePhCache(sl.bestPhKey, bestPh)
sl.miner.worker.pendingHeaderFeed.Send(bestPh.WorkObject())
}
sl.txPool.broadcastSetCache.Add(hash, txs)
sl.txPool.broadcastSet = types.Transactions{}
sl.logger.Error("Adding txs set into the broadcastSetCache", hash, "len txs ", len(txs))
}
sl.txPool.broadcastSetMu.RUnlock()
return sl.txPool.GetTxsFromBroadcastSet(hash)
}

////// Expansion related logic

const (
Expand Down

0 comments on commit 7e5c809

Please sign in to comment.