aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-08 19:07:21 +0800
committerobscuren <geffobscura@gmail.com>2015-04-08 19:07:21 +0800
commita953f3ec971fc6aebd28fed78d44778107ee4033 (patch)
treeafe3217314fc03524bb94faf8c0923854deae042
parent31b086f5111e4bd506a4ae468a9247bff24dd5cb (diff)
downloaddexon-a953f3ec971fc6aebd28fed78d44778107ee4033.tar.gz
dexon-a953f3ec971fc6aebd28fed78d44778107ee4033.tar.zst
dexon-a953f3ec971fc6aebd28fed78d44778107ee4033.zip
Sync managed accounts to the network
-rw-r--r--core/transaction_pool.go5
-rw-r--r--eth/backend.go15
2 files changed, 17 insertions, 3 deletions
diff --git a/core/transaction_pool.go b/core/transaction_pool.go
index d642a1de4..930efdaec 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -90,6 +90,7 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
}
func (self *TxPool) addTx(tx *types.Transaction) {
+ self.txs[tx.Hash()] = tx
}
func (self *TxPool) add(tx *types.Transaction) error {
@@ -107,7 +108,7 @@ func (self *TxPool) add(tx *types.Transaction) error {
return err
}
- self.txs[hash] = tx
+ self.addTx(tx)
var toname string
if to := tx.To(); to != nil {
@@ -122,9 +123,7 @@ func (self *TxPool) add(tx *types.Transaction) error {
txplogger.Debugf("(t) %x => %s (%v) %x\n", from, toname, tx.Value, tx.Hash())
// Notify the subscribers
- //println("post")
go self.eventMux.Post(TxPreEvent{tx})
- //println("done post")
return nil
}
diff --git a/eth/backend.go b/eth/backend.go
index 6b60af1f1..317ee7373 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -436,6 +436,21 @@ func (self *Ethereum) txBroadcastLoop() {
for obj := range self.txSub.Chan() {
event := obj.(core.TxPreEvent)
self.net.Broadcast("eth", TxMsg, []*types.Transaction{event.Tx})
+ self.syncAccounts(event.Tx)
+ }
+}
+
+// keep accounts synced up
+func (self *Ethereum) syncAccounts(tx *types.Transaction) {
+ from, err := tx.From()
+ if err != nil {
+ return
+ }
+
+ if self.accountManager.HasAccount(from.Bytes()) {
+ if self.chainManager.TxState().GetNonce(from) < tx.Nonce() {
+ self.chainManager.TxState().SetNonce(from, tx.Nonce()+1)
+ }
}
}