aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2014-12-15 02:15:48 +0800
committerzelig <viktor.tron@gmail.com>2014-12-15 04:27:06 +0800
commitc2af10d256f9fb29f86fc0c33abafeb62ebbe570 (patch)
treeb152a52eae2533fd26c4a66cc0afd6b6b0c4f1f4
parentb89ed8eb7bc9ced4a7daa33cc81e1579a6d2ddfc (diff)
downloadgo-tangerine-c2af10d256f9fb29f86fc0c33abafeb62ebbe570.tar.gz
go-tangerine-c2af10d256f9fb29f86fc0c33abafeb62ebbe570.tar.zst
go-tangerine-c2af10d256f9fb29f86fc0c33abafeb62ebbe570.zip
transaction pool changes
- use eventer events to broadcast transactions - CurrentTransactions -> GetTransactions - add AddTransactions
-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..2eb0b55df 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -10,7 +10,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
- "github.com/ethereum/go-ethereum/wire"
)
var txplogger = logger.NewLogger("TXP")
@@ -18,7 +17,9 @@ var txplogger = logger.NewLogger("TXP")
const txPoolQueueSize = 50
type TxPoolHook chan *types.Transaction
-type TxMsgTy byte
+type TxMsg struct {
+ Tx *types.Transaction
+}
const (
minGasPrice = 1000000
@@ -26,11 +27,6 @@ const (
var MinGasPrice = big.NewInt(10000000000000)
-type TxMsg struct {
- Tx *types.Transaction
- Type TxMsgTy
-}
-
func EachTx(pool *list.List, it func(*types.Transaction, *list.Element) bool) {
for e := pool.Front(); e != nil; e = e.Next() {
if it(e.Value.(*types.Transaction), e) {
@@ -94,7 +90,7 @@ 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.Ethereum.EventMux().Post(TxPreEvent{tx})
}
func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
@@ -169,7 +165,17 @@ func (self *TxPool) Size() int {
return self.pool.Len()
}
-func (pool *TxPool) CurrentTransactions() []*types.Transaction {
+func (self *TxPool) AddTransactions(txs []*types.Transaction) {
+ for _, tx := range txs {
+ if err := self.Add(tx); err != nil {
+ txplogger.Infoln(err)
+ } else {
+ txplogger.Infof("tx %x\n", tx.Hash()[0:4])
+ }
+ }
+}
+
+func (pool *TxPool) GetTransactions() []*types.Transaction {
pool.mutex.Lock()
defer pool.mutex.Unlock()
@@ -216,7 +222,7 @@ func (self *TxPool) RemoveSet(txs types.Transactions) {
}
func (pool *TxPool) Flush() []*types.Transaction {
- txList := pool.CurrentTransactions()
+ txList := pool.GetTransactions()
// Recreate a new list all together
// XXX Is this the fastest way?