core/types, params: EIP#155

This commit is contained in:
Jeffrey Wilcke
2016-11-02 13:44:13 +01:00
parent 5cd86443ee
commit 4dca5d4db7
46 changed files with 1074 additions and 470 deletions

View File

@ -92,6 +92,7 @@ type TxPool struct {
eventMux *event.TypeMux
events event.Subscription
localTx *txSet
signer types.Signer
mu sync.RWMutex
pending map[common.Address]*txList // All currently processable transactions
@ -108,6 +109,7 @@ type TxPool struct {
func NewTxPool(config *params.ChainConfig, eventMux *event.TypeMux, currentStateFn stateFn, gasLimitFn func() *big.Int) *TxPool {
pool := &TxPool{
config: config,
signer: types.NewEIP155Signer(config.ChainId),
pending: make(map[common.Address]*txList),
queue: make(map[common.Address]*txList),
all: make(map[common.Hash]*types.Transaction),
@ -139,8 +141,10 @@ func (pool *TxPool) eventLoop() {
switch ev := ev.Data.(type) {
case ChainHeadEvent:
pool.mu.Lock()
if ev.Block != nil && pool.config.IsHomestead(ev.Block.Number()) {
pool.homestead = true
if ev.Block != nil {
if pool.config.IsHomestead(ev.Block.Number()) {
pool.homestead = true
}
}
pool.resetState()
@ -272,7 +276,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction) error {
return err
}
from, err := tx.From()
from, err := types.Sender(pool.signer, tx)
if err != nil {
return ErrInvalidSender
}
@ -307,7 +311,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction) error {
return ErrInsufficientFunds
}
intrGas := IntrinsicGas(tx.Data(), MessageCreatesContract(tx), pool.homestead)
intrGas := IntrinsicGas(tx.Data(), tx.To() == nil, pool.homestead)
if tx.Gas().Cmp(intrGas) < 0 {
return ErrIntrinsicGas
}
@ -336,7 +340,7 @@ func (pool *TxPool) add(tx *types.Transaction) error {
if to := tx.To(); to != nil {
rcpt = common.Bytes2Hex(to[:4])
}
from, _ := tx.From() // from already verified during tx validation
from, _ := types.Sender(pool.signer, tx) // from already verified during tx validation
glog.Infof("(t) 0x%x => %s (%v) %x\n", from[:4], rcpt, tx.Value, hash)
}
return nil
@ -347,7 +351,7 @@ func (pool *TxPool) add(tx *types.Transaction) error {
// Note, this method assumes the pool lock is held!
func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction) {
// Try to insert the transaction into the future queue
from, _ := tx.From() // already validated
from, _ := types.Sender(pool.signer, tx) // already validated
if pool.queue[from] == nil {
pool.queue[from] = newTxList(false)
}
@ -459,7 +463,7 @@ func (pool *TxPool) removeTx(hash common.Hash) {
if !ok {
return
}
addr, _ := tx.From() // already validated during insertion
addr, _ := types.Sender(pool.signer, tx) // already validated during insertion
// Remove it from the list of known transactions
delete(pool.all, hash)