Added a secondary processor

poc8
obscuren 11 years ago
parent c66cf95b40
commit f5737b929a
  1. 12
      ethchain/transaction_pool.go

@ -34,6 +34,10 @@ type PublicSpeaker interface {
Broadcast(msgType ethwire.MsgType, data []interface{}) Broadcast(msgType ethwire.MsgType, data []interface{})
} }
type TxProcessor interface {
ProcessTransaction(tx *Transaction)
}
// The tx pool a thread safe transaction pool handler. In order to // The tx pool a thread safe transaction pool handler. In order to
// guarantee a non blocking pool we use a queue channel which can be // guarantee a non blocking pool we use a queue channel which can be
// independently read without needing access to the actual pool. If the // independently read without needing access to the actual pool. If the
@ -54,7 +58,7 @@ type TxPool struct {
BlockManager *BlockManager BlockManager *BlockManager
Hook TxPoolHook SecondaryProcessor TxProcessor
} }
func NewTxPool() *TxPool { func NewTxPool() *TxPool {
@ -69,12 +73,14 @@ func NewTxPool() *TxPool {
// Blocking function. Don't use directly. Use QueueTransaction instead // Blocking function. Don't use directly. Use QueueTransaction instead
func (pool *TxPool) addTransaction(tx *Transaction) { func (pool *TxPool) addTransaction(tx *Transaction) {
log.Println("Adding tx to pool")
pool.mutex.Lock() pool.mutex.Lock()
pool.pool.PushBack(tx) pool.pool.PushBack(tx)
pool.mutex.Unlock() pool.mutex.Unlock()
// Broadcast the transaction to the rest of the peers // Broadcast the transaction to the rest of the peers
pool.Speaker.Broadcast(ethwire.MsgTxTy, []interface{}{tx.RlpData()}) pool.Speaker.Broadcast(ethwire.MsgTxTy, []interface{}{tx.RlpData()})
log.Println("broadcasting it")
} }
// Process transaction validates the Tx and processes funds from the // Process transaction validates the Tx and processes funds from the
@ -179,8 +185,8 @@ out:
// doesn't matter since this is a goroutine // doesn't matter since this is a goroutine
pool.addTransaction(tx) pool.addTransaction(tx)
if pool.Hook != nil { if pool.SecondaryProcessor != nil {
pool.Hook <- tx pool.SecondaryProcessor.ProcessTransaction(tx)
} }
} }
case <-pool.quit: case <-pool.quit:

Loading…
Cancel
Save