diff options
author | zelig <viktor.tron@gmail.com> | 2014-07-31 00:03:20 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2014-07-31 00:03:20 +0800 |
commit | 9831619881c5264c2449ce1b906108d892b6e1e1 (patch) | |
tree | f8775b1196fe6b31081a553945377f40bdc8d550 /ethchain/transaction_pool.go | |
parent | 194c58858cd230a9a08b0eb14650720341a5580e (diff) | |
parent | 42d47ecfb09ac0b419db5722602d9b02e21f2457 (diff) | |
download | go-tangerine-9831619881c5264c2449ce1b906108d892b6e1e1.tar go-tangerine-9831619881c5264c2449ce1b906108d892b6e1e1.tar.gz go-tangerine-9831619881c5264c2449ce1b906108d892b6e1e1.tar.bz2 go-tangerine-9831619881c5264c2449ce1b906108d892b6e1e1.tar.lz go-tangerine-9831619881c5264c2449ce1b906108d892b6e1e1.tar.xz go-tangerine-9831619881c5264c2449ce1b906108d892b6e1e1.tar.zst go-tangerine-9831619881c5264c2449ce1b906108d892b6e1e1.zip |
merge upstream
Diffstat (limited to 'ethchain/transaction_pool.go')
-rw-r--r-- | ethchain/transaction_pool.go | 82 |
1 files changed, 6 insertions, 76 deletions
diff --git a/ethchain/transaction_pool.go b/ethchain/transaction_pool.go index 6ab8d83d9..b0d62fd91 100644 --- a/ethchain/transaction_pool.go +++ b/ethchain/transaction_pool.go @@ -4,10 +4,12 @@ import ( "bytes" "container/list" "fmt" - "github.com/ethereum/eth-go/ethlog" - "github.com/ethereum/eth-go/ethwire" "math/big" "sync" + + "github.com/ethereum/eth-go/ethlog" + "github.com/ethereum/eth-go/ethstate" + "github.com/ethereum/eth-go/ethwire" ) var txplogger = ethlog.NewLogger("TXP") @@ -90,78 +92,6 @@ func (pool *TxPool) addTransaction(tx *Transaction) { pool.Ethereum.Broadcast(ethwire.MsgTxTy, []interface{}{tx.RlpData()}) } -/* -// Process transaction validates the Tx and processes funds from the -// sender to the recipient. -func (pool *TxPool) ProcessTransaction(tx *Transaction, state *State, toContract bool) (gas *big.Int, err error) { - fmt.Printf("state root before update %x\n", state.Root()) - defer func() { - if r := recover(); r != nil { - txplogger.Infoln(r) - err = fmt.Errorf("%v", r) - } - }() - - gas = new(big.Int) - addGas := func(g *big.Int) { gas.Add(gas, g) } - addGas(GasTx) - - // Get the sender - sender := state.GetAccount(tx.Sender()) - - if sender.Nonce != tx.Nonce { - err = NonceError(tx.Nonce, sender.Nonce) - return - } - - sender.Nonce += 1 - defer func() { - //state.UpdateStateObject(sender) - // Notify all subscribers - pool.Ethereum.Reactor().Post("newTx:post", tx) - }() - - txTotalBytes := big.NewInt(int64(len(tx.Data))) - txTotalBytes.Div(txTotalBytes, ethutil.Big32) - addGas(new(big.Int).Mul(txTotalBytes, GasSStore)) - - rGas := new(big.Int).Set(gas) - rGas.Mul(gas, tx.GasPrice) - - // Make sure there's enough in the sender's account. Having insufficient - // funds won't invalidate this transaction but simple ignores it. - totAmount := new(big.Int).Add(tx.Value, rGas) - if sender.Amount.Cmp(totAmount) < 0 { - err = fmt.Errorf("[TXPL] Insufficient amount in sender's (%x) account", tx.Sender()) - return - } - state.UpdateStateObject(sender) - fmt.Printf("state root after sender update %x\n", state.Root()) - - // Get the receiver - receiver := state.GetAccount(tx.Recipient) - - // Send Tx to self - if bytes.Compare(tx.Recipient, tx.Sender()) == 0 { - // Subtract the fee - sender.SubAmount(rGas) - } else { - // Subtract the amount from the senders account - sender.SubAmount(totAmount) - - // Add the amount to receivers account which should conclude this transaction - receiver.AddAmount(tx.Value) - - state.UpdateStateObject(receiver) - fmt.Printf("state root after receiver update %x\n", state.Root()) - } - - txplogger.Infof("[TXPL] Processed Tx %x\n", tx.Hash()) - - return -} -*/ - func (pool *TxPool) ValidateTransaction(tx *Transaction) error { // Get the last block so we can retrieve the sender and receiver from // the merkle trie @@ -182,7 +112,7 @@ func (pool *TxPool) ValidateTransaction(tx *Transaction) error { totAmount := new(big.Int).Set(tx.Value) // 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(totAmount) < 0 { + if sender.Balance.Cmp(totAmount) < 0 { return fmt.Errorf("[TXPL] Insufficient amount in sender's (%x) account", tx.Sender()) } @@ -252,7 +182,7 @@ func (pool *TxPool) CurrentTransactions() []*Transaction { return txList } -func (pool *TxPool) RemoveInvalid(state *State) { +func (pool *TxPool) RemoveInvalid(state *ethstate.State) { for e := pool.pool.Front(); e != nil; e = e.Next() { tx := e.Value.(*Transaction) sender := state.GetAccount(tx.Sender()) |