From 445feaeef58bd89a113743dccf6fd5df55cde6fa Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Thu, 20 Oct 2016 13:36:29 +0200 Subject: core, core/state, trie: EIP158, reprice & skip empty account write This commit implements EIP158 part 1, 2, 3 & 4 1. If an account is empty it's no longer written to the trie. An empty account is defined as (balance=0, nonce=0, storage=0, code=0). 2. Delete an empty account if it's touched 3. An empty account is redefined as either non-existent or empty. 4. Zero value calls and zero value suicides no longer consume the 25k reation costs. params: moved core/config to params Signed-off-by: Jeffrey Wilcke --- light/txpool.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'light/txpool.go') diff --git a/light/txpool.go b/light/txpool.go index 825a0f909..c046cac25 100644 --- a/light/txpool.go +++ b/light/txpool.go @@ -28,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "golang.org/x/net/context" ) @@ -42,7 +43,7 @@ var txPermanent = uint64(500) // always receive all locally signed transactions in the same order as they are // created. type TxPool struct { - config *core.ChainConfig + config *params.ChainConfig quit chan bool eventMux *event.TypeMux events event.Subscription @@ -76,7 +77,7 @@ type TxRelayBackend interface { } // NewTxPool creates a new light transaction pool -func NewTxPool(config *core.ChainConfig, eventMux *event.TypeMux, chain *LightChain, relay TxRelayBackend) *TxPool { +func NewTxPool(config *params.ChainConfig, eventMux *event.TypeMux, chain *LightChain, relay TxRelayBackend) *TxPool { pool := &TxPool{ config: config, nonce: make(map[common.Address]uint64), -- cgit v1.2.3 From 4dca5d4db7fc2c1fac5a2e24dcc99b15573f0188 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Wed, 2 Nov 2016 13:44:13 +0100 Subject: core/types, params: EIP#155 --- light/txpool.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'light/txpool.go') diff --git a/light/txpool.go b/light/txpool.go index c046cac25..309bc3a32 100644 --- a/light/txpool.go +++ b/light/txpool.go @@ -44,6 +44,7 @@ var txPermanent = uint64(500) // created. type TxPool struct { config *params.ChainConfig + signer types.Signer quit chan bool eventMux *event.TypeMux events event.Subscription @@ -80,6 +81,7 @@ type TxRelayBackend interface { func NewTxPool(config *params.ChainConfig, eventMux *event.TypeMux, chain *LightChain, relay TxRelayBackend) *TxPool { pool := &TxPool{ config: config, + signer: types.HomesteadSigner{}, nonce: make(map[common.Address]uint64), pending: make(map[common.Hash]*types.Transaction), mined: make(map[common.Hash][]*types.Transaction), @@ -198,7 +200,7 @@ func (pool *TxPool) checkMinedTxs(ctx context.Context, hash common.Hash, idx uin if len(receipts) != len(block.Transactions()) { panic(nil) // should never happen if hashes did match } - core.SetReceiptsData(block, receipts) + core.SetReceiptsData(pool.config, block, receipts) } //fmt.Println("WriteReceipt", receipts[i].TxHash) core.WriteReceipt(pool.chainDb, receipts[i]) @@ -309,6 +311,7 @@ func (pool *TxPool) eventLoop() { m, r := txc.getLists() pool.relay.NewHead(pool.head, m, r) pool.homestead = pool.config.IsHomestead(head.Number) + pool.signer = types.MakeSigner(pool.config, head.Number) pool.mu.Unlock() } } @@ -340,7 +343,7 @@ func (pool *TxPool) validateTx(ctx context.Context, tx *types.Transaction) error // Validate the transaction sender and it's sig. Throw // if the from fields is invalid. - if from, err = tx.From(); err != nil { + if from, err = types.Sender(pool.signer, tx); err != nil { return core.ErrInvalidSender } @@ -389,7 +392,7 @@ func (pool *TxPool) validateTx(ctx context.Context, tx *types.Transaction) error } // Should supply enough intrinsic gas - if tx.Gas().Cmp(core.IntrinsicGas(tx.Data(), core.MessageCreatesContract(tx), pool.homestead)) < 0 { + if tx.Gas().Cmp(core.IntrinsicGas(tx.Data(), tx.To() == nil, pool.homestead)) < 0 { return core.ErrIntrinsicGas } @@ -413,7 +416,8 @@ func (self *TxPool) add(ctx context.Context, tx *types.Transaction) error { self.pending[hash] = tx nonce := tx.Nonce() + 1 - addr, _ := tx.From() + + addr, _ := types.Sender(self.signer, tx) if nonce > self.nonce[addr] { self.nonce[addr] = nonce } @@ -433,7 +437,7 @@ func (self *TxPool) add(ctx context.Context, tx *types.Transaction) error { } // we can ignore the error here because From is // verified in ValidateTransaction. - f, _ := tx.From() + f, _ := types.Sender(self.signer, tx) from := common.Bytes2Hex(f[:4]) glog.Infof("(t) %x => %s (%v) %x\n", from, toname, tx.Value, hash) } @@ -518,7 +522,7 @@ func (self *TxPool) Content() (map[common.Address]types.Transactions, map[common // Retrieve all the pending transactions and sort by account and by nonce pending := make(map[common.Address]types.Transactions) for _, tx := range self.pending { - account, _ := tx.From() + account, _ := types.Sender(self.signer, tx) pending[account] = append(pending[account], tx) } // There are no queued transactions in a light pool, just return an empty map -- cgit v1.2.3