aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/transaction_pool.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-03-05 17:42:51 +0800
committerobscuren <geffobscura@gmail.com>2014-03-05 17:42:51 +0800
commit92f2abdf769f52ea8e5e6d02bf326744e926f5b4 (patch)
tree234bcf5278e6804736f7392095733ef133e7fe03 /ethchain/transaction_pool.go
parent5b1613d65b0c3471b80990120022b5a745ecab86 (diff)
downloadgo-tangerine-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar.gz
go-tangerine-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar.zst
go-tangerine-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.zip
Partially refactored server/txpool/block manager/block chain
The Ethereum structure now complies to a EthManager interface which is being used by the tx pool, block manager and block chain in order to gain access to each other. It's become simpeler. TODO: BlockManager => StateManager
Diffstat (limited to 'ethchain/transaction_pool.go')
-rw-r--r--ethchain/transaction_pool.go18
1 files changed, 6 insertions, 12 deletions
diff --git a/ethchain/transaction_pool.go b/ethchain/transaction_pool.go
index 763560570..2c9a26936 100644
--- a/ethchain/transaction_pool.go
+++ b/ethchain/transaction_pool.go
@@ -41,10 +41,6 @@ func FindTx(pool *list.List, finder func(*Transaction, *list.Element) bool) *Tra
return nil
}
-type PublicSpeaker interface {
- Broadcast(msgType ethwire.MsgType, data []interface{})
-}
-
type TxProcessor interface {
ProcessTransaction(tx *Transaction)
}
@@ -55,8 +51,7 @@ 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 {
- //server *Server
- Speaker PublicSpeaker
+ Ethereum EthManager
// The mutex for accessing the Tx pool.
mutex sync.Mutex
// Queueing channel for reading and writing incoming
@@ -67,20 +62,19 @@ type TxPool struct {
// The actual pool
pool *list.List
- BlockManager *BlockManager
-
SecondaryProcessor TxProcessor
subscribers []chan TxMsg
}
-func NewTxPool() *TxPool {
+func NewTxPool(ethereum EthManager) *TxPool {
return &TxPool{
//server: s,
mutex: sync.Mutex{},
pool: list.New(),
queueChan: make(chan *Transaction, txPoolQueueSize),
quit: make(chan bool),
+ Ethereum: ethereum,
}
}
@@ -91,7 +85,7 @@ func (pool *TxPool) addTransaction(tx *Transaction) {
pool.mutex.Unlock()
// Broadcast the transaction to the rest of the peers
- pool.Speaker.Broadcast(ethwire.MsgTxTy, []interface{}{tx.RlpData()})
+ pool.Ethereum.Broadcast(ethwire.MsgTxTy, []interface{}{tx.RlpData()})
}
// Process transaction validates the Tx and processes funds from the
@@ -152,14 +146,14 @@ func (pool *TxPool) ProcessTransaction(tx *Transaction, block *Block) (err error
func (pool *TxPool) ValidateTransaction(tx *Transaction) error {
// Get the last block so we can retrieve the sender and receiver from
// the merkle trie
- block := pool.BlockManager.BlockChain().CurrentBlock
+ block := pool.Ethereum.BlockChain().CurrentBlock
// Something has gone horribly wrong if this happens
if block == nil {
return errors.New("No last block on the block chain")
}
// Get the sender
- accountState := pool.BlockManager.GetAddrState(tx.Sender())
+ accountState := pool.Ethereum.StateManager().GetAddrState(tx.Sender())
sender := accountState.Account
totAmount := new(big.Int).Add(tx.Value, new(big.Int).Mul(TxFee, TxFeeRat))