Merge pull request #167 from fjl/feature/split-tx-event

Split TxEvent type for tx pre/post
This commit is contained in:
Jeffrey Wilcke 2014-10-29 21:10:04 +01:00
commit fa890c8c01
5 changed files with 53 additions and 61 deletions

@ -408,7 +408,8 @@ func (gui *Gui) update() {
eth.ChainSyncEvent{}, eth.ChainSyncEvent{},
eth.PeerListEvent{}, eth.PeerListEvent{},
ethchain.NewBlockEvent{}, ethchain.NewBlockEvent{},
ethchain.TxEvent{}, ethchain.TxPreEvent{},
ethchain.TxPostEvent{},
ethminer.Event{}, ethminer.Event{},
) )
@ -430,9 +431,8 @@ func (gui *Gui) update() {
gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Balance(), nil) gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Balance(), nil)
} }
case ethchain.TxEvent: case ethchain.TxPreEvent:
tx := ev.Tx tx := ev.Tx
if ev.Type == ethchain.TxPre {
object := state.GetAccount(gui.address()) object := state.GetAccount(gui.address())
if bytes.Compare(tx.Sender(), gui.address()) == 0 { if bytes.Compare(tx.Sender(), gui.address()) == 0 {
@ -442,11 +442,12 @@ func (gui *Gui) update() {
} }
gui.setWalletValue(object.Balance(), unconfirmedFunds) gui.setWalletValue(object.Balance(), unconfirmedFunds)
gui.insertTransaction("pre", tx) gui.insertTransaction("pre", tx)
} else if ev.Type == ethchain.TxPost { case ethchain.TxPostEvent:
tx := ev.Tx
object := state.GetAccount(gui.address()) object := state.GetAccount(gui.address())
if bytes.Compare(tx.Sender(), gui.address()) == 0 { if bytes.Compare(tx.Sender(), gui.address()) == 0 {
object.SubAmount(tx.Value) object.SubAmount(tx.Value)
@ -460,9 +461,7 @@ func (gui *Gui) update() {
} }
gui.setWalletValue(object.Balance(), nil) gui.setWalletValue(object.Balance(), nil)
state.UpdateStateObject(object) state.UpdateStateObject(object)
}
// case object: // case object:
// gui.loadAddressBook() // gui.loadAddressBook()

@ -1,10 +1,10 @@
package ethchain package ethchain
type TxEvent struct { // TxPreEvent is posted when a transaction enters the transaction pool.
Type int // TxPre || TxPost type TxPreEvent struct{ Tx *Transaction }
Tx *Transaction
}
type NewBlockEvent struct { // TxPostEvent is posted when a transaction has been processed.
Block *Block type TxPostEvent struct{ Tx *Transaction }
}
// NewBlockEvent is posted when a block has been imported.
type NewBlockEvent struct{ Block *Block }

@ -191,7 +191,7 @@ done:
} }
// Notify all subscribers // Notify all subscribers
self.eth.EventMux().Post(TxEvent{TxPost, tx}) self.eth.EventMux().Post(TxPostEvent{tx})
receipts = append(receipts, receipt) receipts = append(receipts, receipt)
handled = append(handled, tx) handled = append(handled, tx)

@ -14,17 +14,12 @@ import (
var txplogger = ethlog.NewLogger("TXP") var txplogger = ethlog.NewLogger("TXP")
const ( const txPoolQueueSize = 50
txPoolQueueSize = 50
)
type TxPoolHook chan *Transaction type TxPoolHook chan *Transaction
type TxMsgTy byte type TxMsgTy byte
const ( const (
TxPre = iota
TxPost
minGasPrice = 1000000 minGasPrice = 1000000
) )
@ -169,7 +164,7 @@ out:
txplogger.Debugf("(t) %x => %x (%v) %x\n", tx.Sender()[:4], tmp, tx.Value, tx.Hash()) txplogger.Debugf("(t) %x => %x (%v) %x\n", tx.Sender()[:4], tmp, tx.Value, tx.Hash())
// Notify the subscribers // Notify the subscribers
pool.Ethereum.EventMux().Post(TxEvent{TxPre, tx}) pool.Ethereum.EventMux().Post(TxPreEvent{tx})
} }
case <-pool.quit: case <-pool.quit:
break out break out

@ -64,7 +64,7 @@ func (miner *Miner) Start() {
miner.block = miner.ethereum.ChainManager().NewBlock(miner.coinbase) miner.block = miner.ethereum.ChainManager().NewBlock(miner.coinbase)
mux := miner.ethereum.EventMux() mux := miner.ethereum.EventMux()
miner.events = mux.Subscribe(ethchain.NewBlockEvent{}, ethchain.TxEvent{}) miner.events = mux.Subscribe(ethchain.NewBlockEvent{}, ethchain.TxPreEvent{})
// Prepare inital block // Prepare inital block
//miner.ethereum.StateManager().Prepare(miner.block.State(), miner.block.State()) //miner.ethereum.StateManager().Prepare(miner.block.State(), miner.block.State())
@ -118,8 +118,7 @@ func (miner *Miner) listener() {
} }
miner.startMining() miner.startMining()
case ethchain.TxEvent: case ethchain.TxPreEvent:
if event.Type == ethchain.TxPre {
miner.stopMining() miner.stopMining()
found := false found := false
@ -127,6 +126,8 @@ func (miner *Miner) listener() {
if found = bytes.Compare(ctx.Hash(), event.Tx.Hash()) == 0; found { if found = bytes.Compare(ctx.Hash(), event.Tx.Hash()) == 0; found {
break break
} }
miner.startMining()
} }
if found == false { if found == false {
// Undo all previous commits // Undo all previous commits
@ -134,9 +135,6 @@ func (miner *Miner) listener() {
// Apply new transactions // Apply new transactions
miner.txs = append(miner.txs, event.Tx) miner.txs = append(miner.txs, event.Tx)
} }
miner.startMining()
}
} }
case <-miner.powDone: case <-miner.powDone: