aboutsummaryrefslogtreecommitdiffstats
path: root/core/transaction_pool.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-18 20:12:54 +0800
committerobscuren <geffobscura@gmail.com>2014-12-18 20:12:54 +0800
commit49e0267fe76cfd13eaf3e5e26caa637b93dbdd29 (patch)
treeaec7d379e9a981af2c72f194acc594d658b8e7cf /core/transaction_pool.go
parent590aace88dce9922d40fca71e87905383a71d12b (diff)
downloaddexon-49e0267fe76cfd13eaf3e5e26caa637b93dbdd29.tar.gz
dexon-49e0267fe76cfd13eaf3e5e26caa637b93dbdd29.tar.zst
dexon-49e0267fe76cfd13eaf3e5e26caa637b93dbdd29.zip
Locks, refactor, tests
* Added additional chain tests * Added proper mutex' on chain * Removed ethereum dependencies
Diffstat (limited to 'core/transaction_pool.go')
-rw-r--r--core/transaction_pool.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/core/transaction_pool.go b/core/transaction_pool.go
index 7166d35e8..36b0beb28 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -8,6 +8,7 @@ import (
"sync"
"github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/wire"
@@ -61,7 +62,6 @@ type TxProcessor interface {
// pool is being drained or synced for whatever reason the transactions
// will simple queue up and handled when the mutex is freed.
type TxPool struct {
- Ethereum EthManager
// The mutex for accessing the Tx pool.
mutex sync.Mutex
// Queueing channel for reading and writing incoming
@@ -75,14 +75,20 @@ type TxPool struct {
SecondaryProcessor TxProcessor
subscribers []chan TxMsg
+
+ broadcaster types.Broadcaster
+ chainManager *ChainManager
+ eventMux *event.TypeMux
}
-func NewTxPool(ethereum EthManager) *TxPool {
+func NewTxPool(chainManager *ChainManager, broadcaster types.Broadcaster, eventMux *event.TypeMux) *TxPool {
return &TxPool{
- pool: list.New(),
- queueChan: make(chan *types.Transaction, txPoolQueueSize),
- quit: make(chan bool),
- Ethereum: ethereum,
+ pool: list.New(),
+ queueChan: make(chan *types.Transaction, txPoolQueueSize),
+ quit: make(chan bool),
+ chainManager: chainManager,
+ eventMux: eventMux,
+ broadcaster: broadcaster,
}
}
@@ -94,13 +100,13 @@ func (pool *TxPool) addTransaction(tx *types.Transaction) {
pool.pool.PushBack(tx)
// Broadcast the transaction to the rest of the peers
- pool.Ethereum.Broadcast(wire.MsgTxTy, []interface{}{tx.RlpData()})
+ pool.broadcaster.Broadcast(wire.MsgTxTy, []interface{}{tx.RlpData()})
}
func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
// Get the last block so we can retrieve the sender and receiver from
// the merkle trie
- block := pool.Ethereum.ChainManager().CurrentBlock
+ block := pool.chainManager.CurrentBlock
// Something has gone horribly wrong if this happens
if block == nil {
return fmt.Errorf("No last block on the block chain")
@@ -116,7 +122,7 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
}
// Get the sender
- sender := pool.Ethereum.ChainManager().State().GetAccount(tx.Sender())
+ sender := pool.chainManager.State().GetAccount(tx.Sender())
totAmount := new(big.Int).Set(tx.Value)
// Make sure there's enough in the sender's account. Having insufficient
@@ -160,7 +166,7 @@ func (self *TxPool) Add(tx *types.Transaction) error {
txplogger.Debugf("(t) %x => %x (%v) %x\n", tx.Sender()[:4], tmp, tx.Value, tx.Hash())
// Notify the subscribers
- go self.Ethereum.EventMux().Post(TxPreEvent{tx})
+ go self.eventMux.Post(TxPreEvent{tx})
return nil
}