Skip to content

Commit 17c5ba2

Browse files
committed
core: actually convert transaction pool
1 parent ee7202f commit 17c5ba2

3 files changed

Lines changed: 19 additions & 17 deletions

File tree

‎core/state_transition.go‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"math/big"
66

77
"github.com/ethereum/go-ethereum/common"
8-
"github.com/ethereum/go-ethereum/crypto"
98
"github.com/ethereum/go-ethereum/state"
109
"github.com/ethereum/go-ethereum/vm"
1110
)
@@ -57,13 +56,8 @@ type Message interface {
5756
Data() []byte
5857
}
5958

60-
func AddressFromMessage(msg Message) []byte {
61-
// Generate a new address
62-
return crypto.Sha3(common.NewValue([]interface{}{msg.From(), msg.Nonce()}).Encode())[12:]
63-
}
64-
6559
func MessageCreatesContract(msg Message) bool {
66-
return len(msg.To()) == 0
60+
return msg.To() == nil
6761
}
6862

6963
func MessageGasValue(msg Message) *big.Int {
@@ -93,13 +87,18 @@ func (self *StateTransition) Coinbase() *state.StateObject {
9387
return self.state.GetOrNewStateObject(self.coinbase)
9488
}
9589
func (self *StateTransition) From() *state.StateObject {
96-
return self.state.GetOrNewStateObject(self.msg.From())
90+
f, _ := self.msg.From()
91+
return self.state.GetOrNewStateObject(f)
9792
}
9893
func (self *StateTransition) To() *state.StateObject {
99-
if self.msg != nil && MessageCreatesContract(self.msg) {
94+
if self.msg == nil {
10095
return nil
10196
}
102-
return self.state.GetOrNewStateObject(self.msg.To())
97+
to := self.msg.To()
98+
if to == nil {
99+
return nil // contract creation
100+
}
101+
return self.state.GetOrNewStateObject(*to)
103102
}
104103

105104
func (self *StateTransition) UseGas(amount *big.Int) error {

‎core/transaction_pool.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ func (self *TxPool) addTx(tx *types.Transaction) {
9191
}
9292

9393
func (self *TxPool) add(tx *types.Transaction) error {
94-
if self.txs[tx.Hash()] != nil {
95-
return fmt.Errorf("Known transaction (%x)", tx.Hash()[0:4])
94+
hash := tx.Hash()
95+
if self.txs[hash] != nil {
96+
return fmt.Errorf("Known transaction (%x)", hash[0:4])
9697
}
9798
err := self.ValidateTransaction(tx)
9899
if err != nil {
@@ -102,7 +103,7 @@ func (self *TxPool) add(tx *types.Transaction) error {
102103
self.addTx(tx)
103104

104105
var toname string
105-
if to, valid := tx.To(); valid {
106+
if to := tx.To(); to != nil {
106107
toname = common.Bytes2Hex(to[:4])
107108
} else {
108109
toname = "[NEW_CONTRACT]"
@@ -111,7 +112,7 @@ func (self *TxPool) add(tx *types.Transaction) error {
111112
// verified in ValidateTransaction.
112113
f, _ := tx.From()
113114
from := common.Bytes2Hex(f[:4])
114-
txplogger.Debugf("(t) %x => %s (%v) %x\n", from, to, tx.Value, tx.Hash())
115+
txplogger.Debugf("(t) %x => %s (%v) %x\n", from, toname, tx.Value, tx.Hash())
115116

116117
// Notify the subscribers
117118
go self.eventMux.Post(TxPreEvent{tx})
@@ -137,7 +138,8 @@ func (self *TxPool) AddTransactions(txs []*types.Transaction) {
137138
if err := self.add(tx); err != nil {
138139
txplogger.Debugln(err)
139140
} else {
140-
txplogger.Debugf("tx %x\n", tx.Hash()[0:4])
141+
h := tx.Hash()
142+
txplogger.Debugf("tx %x\n", h[:4])
141143
}
142144
}
143145
}
@@ -161,7 +163,8 @@ func (pool *TxPool) RemoveInvalid(query StateQuery) {
161163

162164
var removedTxs types.Transactions
163165
for _, tx := range pool.txs {
164-
sender := query.GetAccount(tx.From())
166+
from, _ := tx.From()
167+
sender := query.GetAccount(from[:])
165168
err := pool.ValidateTransaction(tx)
166169
if err != nil || sender.Nonce() >= tx.Nonce() {
167170
removedTxs = append(removedTxs, tx)

‎core/vm_env.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func NewEnv(state *state.StateDB, chain *ChainManager, msg Message, block *types
2828
}
2929
}
3030

31-
func (self *VMEnv) Origin() common.Address { return self.msg.From() }
31+
func (self *VMEnv) Origin() common.Address { f, _ := self.msg.From(); return f }
3232
func (self *VMEnv) BlockNumber() *big.Int { return self.block.Number() }
3333
func (self *VMEnv) Coinbase() common.Address { return self.block.Coinbase() }
3434
func (self *VMEnv) Time() int64 { return self.block.Time() }

0 commit comments

Comments
 (0)