浏览代码

Sync managed accounts to the network

obscuren 10 年之前
父节点
当前提交
a953f3ec97
共有 2 个文件被更改,包括 17 次插入3 次删除
  1. 2 3
      core/transaction_pool.go
  2. 15 0
      eth/backend.go

+ 2 - 3
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
 }

+ 15 - 0
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)
+		}
 	}
 }