aboutsummaryrefslogtreecommitdiffstats
path: root/transaction_pool.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-01-22 06:27:08 +0800
committerobscuren <geffobscura@gmail.com>2014-01-22 06:27:08 +0800
commit3616080db46931202003157bacf10748008bebc0 (patch)
treea2004c7c4c8f6c91999b734b75a57ac31b04cb97 /transaction_pool.go
parente47230f82da93ef0110faa76211b9b6f13b1060b (diff)
downloaddexon-3616080db46931202003157bacf10748008bebc0.tar
dexon-3616080db46931202003157bacf10748008bebc0.tar.gz
dexon-3616080db46931202003157bacf10748008bebc0.tar.bz2
dexon-3616080db46931202003157bacf10748008bebc0.tar.lz
dexon-3616080db46931202003157bacf10748008bebc0.tar.xz
dexon-3616080db46931202003157bacf10748008bebc0.tar.zst
dexon-3616080db46931202003157bacf10748008bebc0.zip
Added synchronisation of transactions across remote pools
Diffstat (limited to 'transaction_pool.go')
-rw-r--r--transaction_pool.go26
1 files changed, 21 insertions, 5 deletions
diff --git a/transaction_pool.go b/transaction_pool.go
index f645afd06..b302931de 100644
--- a/transaction_pool.go
+++ b/transaction_pool.go
@@ -1,9 +1,11 @@
package main
import (
+ "bytes"
"container/list"
"errors"
"github.com/ethereum/ethutil-go"
+ "github.com/ethereum/ethwire-go"
"log"
"math/big"
"sync"
@@ -56,9 +58,11 @@ func NewTxPool(s *Server) *TxPool {
// Blocking function. Don't use directly. Use QueueTransaction instead
func (pool *TxPool) addTransaction(tx *ethutil.Transaction) {
pool.mutex.Lock()
- defer pool.mutex.Unlock()
-
pool.pool.PushBack(tx)
+ pool.mutex.Unlock()
+
+ // Broadcast the transaction to the rest of the peers
+ pool.server.Broadcast(ethwire.MsgTxTy, tx.RlpEncode())
}
// Process transaction validates the Tx and processes funds from the
@@ -89,7 +93,12 @@ func (pool *TxPool) processTransaction(tx *ethutil.Transaction) error {
// Make sure there's enough in the sender's account. Having insufficient
// funds won't invalidate this transaction but simple ignores it.
if sender.Amount.Cmp(tx.Value) < 0 {
- return errors.New("Insufficient amount in sender's account")
+ if Debug {
+ log.Println("Insufficient amount in sender's account. Adding 1 ETH for debug")
+ sender.Amount = ethutil.BigPow(10, 18)
+ } else {
+ return errors.New("Insufficient amount in sender's account")
+ }
}
// Subtract the amount from the senders account
@@ -121,6 +130,15 @@ out:
for {
select {
case tx := <-pool.queueChan:
+ hash := tx.Hash()
+ foundTx := FindTx(pool.pool, func(tx *ethutil.Transaction, e *list.Element) bool {
+ return bytes.Compare(tx.Hash(), hash) == 0
+ })
+
+ if foundTx != nil {
+ break
+ }
+
// Process the transaction
err := pool.processTransaction(tx)
if err != nil {
@@ -144,8 +162,6 @@ func (pool *TxPool) Flush() {
pool.mutex.Lock()
defer pool.mutex.Unlock()
-
- pool.mutex.Unlock()
}
func (pool *TxPool) Start() {