From 7731061903bb992f7630ab389863951efb360258 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 5 Jan 2017 14:03:50 +0100 Subject: [PATCH] core/vm: move Log to core/types This significantly reduces the dependency closure of ethclient, which no longer depends on core/vm as of this change. All uses of vm.Logs are replaced by []*types.Log. NewLog is gone too, the constructor simply returned a literal. --- accounts/abi/argument.go | 4 +- cmd/disasm/main.go | 2 +- core/block_validator_test.go | 3 +- core/blockchain.go | 6 +-- core/blockchain_test.go | 2 +- core/database_util_test.go | 54 ++++++++++++------------- core/events.go | 11 +++--- core/state/statedb.go | 21 +++++----- core/state/statedb_test.go | 4 +- core/state_processor.go | 4 +- core/types.go | 2 +- core/types/bloom9.go | 3 +- core/{vm => types}/log.go | 8 +--- core/{vm => types}/log_test.go | 2 +- core/types/receipt.go | 21 +++++----- core/vm/instructions.go | 11 +++++- core/vm/interface.go | 3 +- core/vm/noop.go | 3 +- eth/api_backend.go | 2 +- eth/backend_test.go | 5 +-- eth/filters/api.go | 17 ++++---- eth/filters/filter.go | 17 ++++---- eth/filters/filter_system.go | 23 ++++++----- eth/filters/filter_system_test.go | 65 +++++++++++++++---------------- eth/filters/filter_test.go | 23 ++++++----- ethclient/ethclient.go | 7 ++-- interfaces.go | 5 +-- internal/ethapi/api.go | 2 +- les/api_backend.go | 2 +- light/vm_env.go | 3 +- miner/worker.go | 12 +++--- mobile/ethclient.go | 5 +-- mobile/vm.go | 6 +-- tests/state_test_util.go | 6 +-- tests/util.go | 4 +- tests/vm_test_util.go | 5 ++- 36 files changed, 180 insertions(+), 193 deletions(-) rename core/{vm => types}/log.go (96%) rename core/{vm => types}/log_test.go (99%) diff --git a/accounts/abi/argument.go b/accounts/abi/argument.go index 4faafdd3b1..4691318ce7 100644 --- a/accounts/abi/argument.go +++ b/accounts/abi/argument.go @@ -31,8 +31,8 @@ type Argument struct { func (a *Argument) UnmarshalJSON(data []byte) error { var extarg struct { - Name string - Type string + Name string + Type string Indexed bool } err := json.Unmarshal(data, &extarg) diff --git a/cmd/disasm/main.go b/cmd/disasm/main.go index d792e8ee55..41cad0231b 100644 --- a/cmd/disasm/main.go +++ b/cmd/disasm/main.go @@ -18,10 +18,10 @@ package main import ( + "encoding/hex" "fmt" "io/ioutil" "os" - "encoding/hex" "strings" "github.com/ethereum/go-ethereum/core/vm" diff --git a/core/block_validator_test.go b/core/block_validator_test.go index 6fcab1e5f0..0546866125 100644 --- a/core/block_validator_test.go +++ b/core/block_validator_test.go @@ -24,7 +24,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/params" @@ -77,7 +76,7 @@ func TestPutReceipt(t *testing.T) { hash[0] = 2 receipt := new(types.Receipt) - receipt.Logs = vm.Logs{&vm.Log{ + receipt.Logs = []*types.Log{{ Address: addr, Topics: []common.Hash{hash}, Data: []byte("hi"), diff --git a/core/blockchain.go b/core/blockchain.go index 0de5294800..2081457a9e 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -883,7 +883,7 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) { var ( stats = insertStats{startTime: time.Now()} events = make([]interface{}, 0, len(chain)) - coalescedLogs vm.Logs + coalescedLogs []*types.Log nonceChecked = make([]bool, len(chain)) ) @@ -1094,7 +1094,7 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error { oldStart = oldBlock newStart = newBlock deletedTxs types.Transactions - deletedLogs vm.Logs + deletedLogs []*types.Log // collectLogs collects the logs that were generated during the // processing of the block that corresponds with the given hash. // These logs are later announced as deleted. @@ -1210,7 +1210,7 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error { // postChainEvents iterates over the events generated by a chain insertion and // posts them into the event mux. -func (self *BlockChain) postChainEvents(events []interface{}, logs vm.Logs) { +func (self *BlockChain) postChainEvents(events []interface{}, logs []*types.Log) { // post event logs for further processing self.eventMux.Post(logs) for _, event := range events { diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 62d85e2e54..a2c3504792 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -435,7 +435,7 @@ func (bproc) ValidateHeader(*types.Header, *types.Header, bool) error { return n func (bproc) ValidateState(block, parent *types.Block, state *state.StateDB, receipts types.Receipts, usedGas *big.Int) error { return nil } -func (bproc) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, vm.Logs, *big.Int, error) { +func (bproc) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, *big.Int, error) { return nil, nil, new(big.Int), nil } diff --git a/core/database_util_test.go b/core/database_util_test.go index 83750aa60a..c8fd857eac 100644 --- a/core/database_util_test.go +++ b/core/database_util_test.go @@ -26,7 +26,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/ethdb" @@ -393,9 +392,9 @@ func TestReceiptStorage(t *testing.T) { receipt1 := &types.Receipt{ PostState: []byte{0x01}, CumulativeGasUsed: big.NewInt(1), - Logs: vm.Logs{ - &vm.Log{Address: common.BytesToAddress([]byte{0x11})}, - &vm.Log{Address: common.BytesToAddress([]byte{0x01, 0x11})}, + Logs: []*types.Log{ + {Address: common.BytesToAddress([]byte{0x11})}, + {Address: common.BytesToAddress([]byte{0x01, 0x11})}, }, TxHash: common.BytesToHash([]byte{0x11, 0x11}), ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}), @@ -404,9 +403,9 @@ func TestReceiptStorage(t *testing.T) { receipt2 := &types.Receipt{ PostState: []byte{0x02}, CumulativeGasUsed: big.NewInt(2), - Logs: vm.Logs{ - &vm.Log{Address: common.BytesToAddress([]byte{0x22})}, - &vm.Log{Address: common.BytesToAddress([]byte{0x02, 0x22})}, + Logs: []*types.Log{ + {Address: common.BytesToAddress([]byte{0x22})}, + {Address: common.BytesToAddress([]byte{0x02, 0x22})}, }, TxHash: common.BytesToHash([]byte{0x22, 0x22}), ContractAddress: common.BytesToAddress([]byte{0x02, 0x22, 0x22}), @@ -452,9 +451,9 @@ func TestBlockReceiptStorage(t *testing.T) { receipt1 := &types.Receipt{ PostState: []byte{0x01}, CumulativeGasUsed: big.NewInt(1), - Logs: vm.Logs{ - &vm.Log{Address: common.BytesToAddress([]byte{0x11})}, - &vm.Log{Address: common.BytesToAddress([]byte{0x01, 0x11})}, + Logs: []*types.Log{ + {Address: common.BytesToAddress([]byte{0x11})}, + {Address: common.BytesToAddress([]byte{0x01, 0x11})}, }, TxHash: common.BytesToHash([]byte{0x11, 0x11}), ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}), @@ -463,9 +462,9 @@ func TestBlockReceiptStorage(t *testing.T) { receipt2 := &types.Receipt{ PostState: []byte{0x02}, CumulativeGasUsed: big.NewInt(2), - Logs: vm.Logs{ - &vm.Log{Address: common.BytesToAddress([]byte{0x22})}, - &vm.Log{Address: common.BytesToAddress([]byte{0x02, 0x22})}, + Logs: []*types.Log{ + {Address: common.BytesToAddress([]byte{0x22})}, + {Address: common.BytesToAddress([]byte{0x02, 0x22})}, }, TxHash: common.BytesToHash([]byte{0x22, 0x22}), ContractAddress: common.BytesToAddress([]byte{0x02, 0x22, 0x22}), @@ -505,14 +504,14 @@ func TestMipmapBloom(t *testing.T) { db, _ := ethdb.NewMemDatabase() receipt1 := new(types.Receipt) - receipt1.Logs = vm.Logs{ - &vm.Log{Address: common.BytesToAddress([]byte("test"))}, - &vm.Log{Address: common.BytesToAddress([]byte("address"))}, + receipt1.Logs = []*types.Log{ + {Address: common.BytesToAddress([]byte("test"))}, + {Address: common.BytesToAddress([]byte("address"))}, } receipt2 := new(types.Receipt) - receipt2.Logs = vm.Logs{ - &vm.Log{Address: common.BytesToAddress([]byte("test"))}, - &vm.Log{Address: common.BytesToAddress([]byte("address1"))}, + receipt2.Logs = []*types.Log{ + {Address: common.BytesToAddress([]byte("test"))}, + {Address: common.BytesToAddress([]byte("address1"))}, } WriteMipmapBloom(db, 1, types.Receipts{receipt1}) @@ -528,14 +527,14 @@ func TestMipmapBloom(t *testing.T) { // reset db, _ = ethdb.NewMemDatabase() receipt := new(types.Receipt) - receipt.Logs = vm.Logs{ - &vm.Log{Address: common.BytesToAddress([]byte("test"))}, + receipt.Logs = []*types.Log{ + {Address: common.BytesToAddress([]byte("test"))}, } WriteMipmapBloom(db, 999, types.Receipts{receipt1}) receipt = new(types.Receipt) - receipt.Logs = vm.Logs{ - &vm.Log{Address: common.BytesToAddress([]byte("test 1"))}, + receipt.Logs = []*types.Log{ + {Address: common.BytesToAddress([]byte("test 1"))}, } WriteMipmapBloom(db, 1000, types.Receipts{receipt}) @@ -568,17 +567,12 @@ func TestMipmapChain(t *testing.T) { switch i { case 1: receipt := types.NewReceipt(nil, new(big.Int)) - receipt.Logs = vm.Logs{ - &vm.Log{ - Address: addr, - Topics: []common.Hash{hash1}, - }, - } + receipt.Logs = []*types.Log{{Address: addr, Topics: []common.Hash{hash1}}} gen.AddUncheckedReceipt(receipt) receipts = types.Receipts{receipt} case 1000: receipt := types.NewReceipt(nil, new(big.Int)) - receipt.Logs = vm.Logs{&vm.Log{Address: addr2}} + receipt.Logs = []*types.Log{{Address: addr2}} gen.AddUncheckedReceipt(receipt) receipts = types.Receipts{receipt} diff --git a/core/events.go b/core/events.go index 414493fbf9..31ad8364ba 100644 --- a/core/events.go +++ b/core/events.go @@ -21,7 +21,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" ) // TxPreEvent is posted when a transaction enters the transaction pool. @@ -32,7 +31,7 @@ type TxPostEvent struct{ Tx *types.Transaction } // PendingLogsEvent is posted pre mining and notifies of pending logs. type PendingLogsEvent struct { - Logs vm.Logs + Logs []*types.Log } // PendingStateEvent is posted pre mining and notifies of pending state changes. @@ -45,18 +44,18 @@ type NewMinedBlockEvent struct{ Block *types.Block } type RemovedTransactionEvent struct{ Txs types.Transactions } // RemovedLogEvent is posted when a reorg happens -type RemovedLogsEvent struct{ Logs vm.Logs } +type RemovedLogsEvent struct{ Logs []*types.Log } // ChainSplit is posted when a new head is detected type ChainSplitEvent struct { Block *types.Block - Logs vm.Logs + Logs []*types.Log } type ChainEvent struct { Block *types.Block Hash common.Hash - Logs vm.Logs + Logs []*types.Log } type ChainSideEvent struct { @@ -65,7 +64,7 @@ type ChainSideEvent struct { type PendingBlockEvent struct { Block *types.Block - Logs vm.Logs + Logs []*types.Log } type ChainUncleEvent struct { diff --git a/core/state/statedb.go b/core/state/statedb.go index 82e2ec7c1f..bbcde94433 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -24,6 +24,7 @@ import ( "sync" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" @@ -71,7 +72,7 @@ type StateDB struct { thash, bhash common.Hash txIndex int - logs map[common.Hash]vm.Logs + logs map[common.Hash][]*types.Log logSize uint // Journal of state modifications. This is the backbone of @@ -97,7 +98,7 @@ func New(root common.Hash, db ethdb.Database) (*StateDB, error) { stateObjects: make(map[common.Address]*StateObject), stateObjectsDirty: make(map[common.Address]struct{}), refund: new(big.Int), - logs: make(map[common.Hash]vm.Logs), + logs: make(map[common.Hash][]*types.Log), }, nil } @@ -118,7 +119,7 @@ func (self *StateDB) New(root common.Hash) (*StateDB, error) { stateObjects: make(map[common.Address]*StateObject), stateObjectsDirty: make(map[common.Address]struct{}), refund: new(big.Int), - logs: make(map[common.Hash]vm.Logs), + logs: make(map[common.Hash][]*types.Log), }, nil } @@ -138,7 +139,7 @@ func (self *StateDB) Reset(root common.Hash) error { self.thash = common.Hash{} self.bhash = common.Hash{} self.txIndex = 0 - self.logs = make(map[common.Hash]vm.Logs) + self.logs = make(map[common.Hash][]*types.Log) self.logSize = 0 self.clearJournalAndRefund() @@ -175,7 +176,7 @@ func (self *StateDB) StartRecord(thash, bhash common.Hash, ti int) { self.txIndex = ti } -func (self *StateDB) AddLog(log *vm.Log) { +func (self *StateDB) AddLog(log *types.Log) { self.journal = append(self.journal, addLogChange{txhash: self.thash}) log.TxHash = self.thash @@ -186,12 +187,12 @@ func (self *StateDB) AddLog(log *vm.Log) { self.logSize++ } -func (self *StateDB) GetLogs(hash common.Hash) vm.Logs { +func (self *StateDB) GetLogs(hash common.Hash) []*types.Log { return self.logs[hash] } -func (self *StateDB) Logs() vm.Logs { - var logs vm.Logs +func (self *StateDB) Logs() []*types.Log { + var logs []*types.Log for _, lgs := range self.logs { logs = append(logs, lgs...) } @@ -474,7 +475,7 @@ func (self *StateDB) Copy() *StateDB { stateObjects: make(map[common.Address]*StateObject, len(self.stateObjectsDirty)), stateObjectsDirty: make(map[common.Address]struct{}, len(self.stateObjectsDirty)), refund: new(big.Int).Set(self.refund), - logs: make(map[common.Hash]vm.Logs, len(self.logs)), + logs: make(map[common.Hash][]*types.Log, len(self.logs)), logSize: self.logSize, } // Copy the dirty states and logs @@ -483,7 +484,7 @@ func (self *StateDB) Copy() *StateDB { state.stateObjectsDirty[addr] = struct{}{} } for hash, logs := range self.logs { - state.logs[hash] = make(vm.Logs, len(logs)) + state.logs[hash] = make([]*types.Log, len(logs)) copy(state.logs[hash], logs) } return state diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index f918203780..8743173009 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -29,7 +29,7 @@ import ( "testing/quick" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" ) @@ -221,7 +221,7 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction { fn: func(a testAction, s *StateDB) { data := make([]byte, 2) binary.BigEndian.PutUint16(data, uint16(a.args[0])) - s.AddLog(&vm.Log{Address: addr, Data: data}) + s.AddLog(&types.Log{Address: addr, Data: data}) }, args: make([]int64, 1), }, diff --git a/core/state_processor.go b/core/state_processor.go index 82a371a9e6..4f6ca651e1 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -57,13 +57,13 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain) *StateProcess // Process returns the receipts and logs accumulated during the process and // returns the amount of gas that was used in the process. If any of the // transactions failed to execute due to insufficient gas it will return an error. -func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, vm.Logs, *big.Int, error) { +func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, *big.Int, error) { var ( receipts types.Receipts totalUsedGas = big.NewInt(0) err error header = block.Header() - allLogs vm.Logs + allLogs []*types.Log gp = new(GasPool).AddGas(block.GasLimit()) ) // Mutate the the block and state according to any hard-fork specs diff --git a/core/types.go b/core/types.go index d84d0987f4..7fd658979c 100644 --- a/core/types.go +++ b/core/types.go @@ -58,5 +58,5 @@ type HeaderValidator interface { // of gas used in the process and return an error if any of the internal rules // failed. type Processor interface { - Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, vm.Logs, *big.Int, error) + Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, *big.Int, error) } diff --git a/core/types/bloom9.go b/core/types/bloom9.go index a1d13e2186..bcca59907f 100644 --- a/core/types/bloom9.go +++ b/core/types/bloom9.go @@ -22,7 +22,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" ) @@ -95,7 +94,7 @@ func CreateBloom(receipts Receipts) Bloom { return BytesToBloom(bin.Bytes()) } -func LogsBloom(logs vm.Logs) *big.Int { +func LogsBloom(logs []*Log) *big.Int { bin := new(big.Int) for _, log := range logs { data := make([]common.Hash, len(log.Topics)) diff --git a/core/vm/log.go b/core/types/log.go similarity index 96% rename from core/vm/log.go rename to core/types/log.go index 347bd6e5dc..7efb06b5c1 100644 --- a/core/vm/log.go +++ b/core/types/log.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -package vm +package types import ( "encoding/json" @@ -79,10 +79,6 @@ type jsonLog struct { Removed bool `json:"removed"` } -func NewLog(address common.Address, topics []common.Hash, data []byte, number uint64) *Log { - return &Log{Address: address, Topics: topics, Data: data, BlockNumber: number} -} - // EncodeRLP implements rlp.Encoder. func (l *Log) EncodeRLP(w io.Writer) error { return rlp.Encode(w, rlpLog{Address: l.Address, Topics: l.Topics, Data: l.Data}) @@ -150,8 +146,6 @@ func (l *Log) UnmarshalJSON(input []byte) error { return nil } -type Logs []*Log - // LogForStorage is a wrapper around a Log that flattens and parses the entire content of // a log including non-consensus fields. type LogForStorage Log diff --git a/core/vm/log_test.go b/core/types/log_test.go similarity index 99% rename from core/vm/log_test.go rename to core/types/log_test.go index 994753c622..bf742ccac2 100644 --- a/core/vm/log_test.go +++ b/core/types/log_test.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -package vm +package types import ( "encoding/json" diff --git a/core/types/receipt.go b/core/types/receipt.go index 70c10d4225..0a6a35e334 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -25,7 +25,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/rlp" ) @@ -40,7 +39,7 @@ type Receipt struct { PostState []byte CumulativeGasUsed *big.Int Bloom Bloom - Logs vm.Logs + Logs []*Log // Implementation fields (don't reorder!) TxHash common.Hash @@ -52,7 +51,7 @@ type jsonReceipt struct { PostState *common.Hash `json:"root"` CumulativeGasUsed *hexutil.Big `json:"cumulativeGasUsed"` Bloom *Bloom `json:"logsBloom"` - Logs *vm.Logs `json:"logs"` + Logs []*Log `json:"logs"` TxHash *common.Hash `json:"transactionHash"` ContractAddress *common.Address `json:"contractAddress"` GasUsed *hexutil.Big `json:"gasUsed"` @@ -76,7 +75,7 @@ func (r *Receipt) DecodeRLP(s *rlp.Stream) error { PostState []byte CumulativeGasUsed *big.Int Bloom Bloom - Logs vm.Logs + Logs []*Log } if err := s.Decode(&receipt); err != nil { return err @@ -93,7 +92,7 @@ func (r *Receipt) MarshalJSON() ([]byte, error) { PostState: &root, CumulativeGasUsed: (*hexutil.Big)(r.CumulativeGasUsed), Bloom: &r.Bloom, - Logs: &r.Logs, + Logs: r.Logs, TxHash: &r.TxHash, ContractAddress: &r.ContractAddress, GasUsed: (*hexutil.Big)(r.GasUsed), @@ -120,7 +119,7 @@ func (r *Receipt) UnmarshalJSON(input []byte) error { PostState: (*dec.PostState)[:], CumulativeGasUsed: (*big.Int)(dec.CumulativeGasUsed), Bloom: *dec.Bloom, - Logs: *dec.Logs, + Logs: dec.Logs, TxHash: *dec.TxHash, GasUsed: (*big.Int)(dec.GasUsed), } @@ -142,9 +141,9 @@ type ReceiptForStorage Receipt // EncodeRLP implements rlp.Encoder, and flattens all content fields of a receipt // into an RLP stream. func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error { - logs := make([]*vm.LogForStorage, len(r.Logs)) + logs := make([]*LogForStorage, len(r.Logs)) for i, log := range r.Logs { - logs[i] = (*vm.LogForStorage)(log) + logs[i] = (*LogForStorage)(log) } return rlp.Encode(w, []interface{}{r.PostState, r.CumulativeGasUsed, r.Bloom, r.TxHash, r.ContractAddress, logs, r.GasUsed}) } @@ -158,7 +157,7 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error { Bloom Bloom TxHash common.Hash ContractAddress common.Address - Logs []*vm.LogForStorage + Logs []*LogForStorage GasUsed *big.Int } if err := s.Decode(&receipt); err != nil { @@ -166,9 +165,9 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error { } // Assign the consensus fields r.PostState, r.CumulativeGasUsed, r.Bloom = receipt.PostState, receipt.CumulativeGasUsed, receipt.Bloom - r.Logs = make(vm.Logs, len(receipt.Logs)) + r.Logs = make([]*Log, len(receipt.Logs)) for i, log := range receipt.Logs { - r.Logs[i] = (*vm.Log)(log) + r.Logs[i] = (*Log)(log) } // Assign the implementation fields r.TxHash, r.ContractAddress, r.GasUsed = receipt.TxHash, receipt.ContractAddress, receipt.GasUsed diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 2839b71098..5bfa73a30f 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -22,6 +22,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params" ) @@ -605,8 +606,14 @@ func makeLog(size int) executionFunc { } d := memory.Get(mStart.Int64(), mSize.Int64()) - log := NewLog(contract.Address(), topics, d, env.BlockNumber.Uint64()) - env.StateDB.AddLog(log) + env.StateDB.AddLog(&types.Log{ + Address: contract.Address(), + Topics: topics, + Data: d, + // This is a non-consensus field, but assigned here because + // core/state doesn't know the current block number. + BlockNumber: env.BlockNumber.Uint64(), + }) return nil, nil } } diff --git a/core/vm/interface.go b/core/vm/interface.go index b81f591252..8617b2d0f7 100644 --- a/core/vm/interface.go +++ b/core/vm/interface.go @@ -20,6 +20,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" ) // StateDB is an EVM database for full state querying. @@ -58,7 +59,7 @@ type StateDB interface { RevertToSnapshot(int) Snapshot() int - AddLog(*Log) + AddLog(*types.Log) } // Account represents a contract or basic ethereum account. diff --git a/core/vm/noop.go b/core/vm/noop.go index ca7d1055a8..ef68372730 100644 --- a/core/vm/noop.go +++ b/core/vm/noop.go @@ -20,6 +20,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" ) func NoopCanTransfer(db StateDB, from common.Address, balance *big.Int) bool { @@ -65,4 +66,4 @@ func (NoopStateDB) Exist(common.Address) bool { return f func (NoopStateDB) Empty(common.Address) bool { return false } func (NoopStateDB) RevertToSnapshot(int) {} func (NoopStateDB) Snapshot() int { return 0 } -func (NoopStateDB) AddLog(*Log) {} +func (NoopStateDB) AddLog(*types.Log) {} diff --git a/eth/api_backend.go b/eth/api_backend.go index 801b6a4f61..1174588ea7 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -31,7 +31,7 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/params" - rpc "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/rpc" "golang.org/x/net/context" ) diff --git a/eth/backend_test.go b/eth/backend_test.go index 212c4c4d37..8d55f30b90 100644 --- a/eth/backend_test.go +++ b/eth/backend_test.go @@ -23,7 +23,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/params" ) @@ -38,12 +37,12 @@ func TestMipmapUpgrade(t *testing.T) { switch i { case 1: receipt := types.NewReceipt(nil, new(big.Int)) - receipt.Logs = vm.Logs{&vm.Log{Address: addr}} + receipt.Logs = []*types.Log{&types.Log{Address: addr}} gen.AddUncheckedReceipt(receipt) receipts = types.Receipts{receipt} case 2: receipt := types.NewReceipt(nil, new(big.Int)) - receipt.Logs = vm.Logs{&vm.Log{Address: addr}} + receipt.Logs = []*types.Log{&types.Log{Address: addr}} gen.AddUncheckedReceipt(receipt) receipts = types.Receipts{receipt} } diff --git a/eth/filters/api.go b/eth/filters/api.go index bbb34d3ded..65d7fd17e2 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -29,7 +29,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/rpc" @@ -46,7 +45,7 @@ type filter struct { deadline *time.Timer // filter is inactiv when deadline triggers hashes []common.Hash crit FilterCriteria - logs []*vm.Log + logs []*types.Log s *Subscription // associated subscription in event system } @@ -242,7 +241,7 @@ func (api *PublicFilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc var ( rpcSub = notifier.CreateSubscription() - matchedLogs = make(chan []*vm.Log) + matchedLogs = make(chan []*types.Log) ) logsSub, err := api.events.SubscribeLogs(crit, matchedLogs) @@ -293,14 +292,14 @@ type FilterCriteria struct { // // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter func (api *PublicFilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) { - logs := make(chan []*vm.Log) + logs := make(chan []*types.Log) logsSub, err := api.events.SubscribeLogs(crit, logs) if err != nil { return rpc.ID(""), err } api.filtersMu.Lock() - api.filters[logsSub.ID] = &filter{typ: LogsSubscription, crit: crit, deadline: time.NewTimer(deadline), logs: make([]*vm.Log, 0), s: logsSub} + api.filters[logsSub.ID] = &filter{typ: LogsSubscription, crit: crit, deadline: time.NewTimer(deadline), logs: make([]*types.Log, 0), s: logsSub} api.filtersMu.Unlock() go func() { @@ -327,7 +326,7 @@ func (api *PublicFilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) { // GetLogs returns logs matching the given argument that are stored within the state. // // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs -func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*vm.Log, error) { +func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*types.Log, error) { if crit.FromBlock == nil { crit.FromBlock = big.NewInt(rpc.LatestBlockNumber.Int64()) } @@ -366,7 +365,7 @@ func (api *PublicFilterAPI) UninstallFilter(id rpc.ID) bool { // If the filter could not be found an empty array of logs is returned. // // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterlogs -func (api *PublicFilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*vm.Log, error) { +func (api *PublicFilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*types.Log, error) { api.filtersMu.Lock() f, found := api.filters[id] api.filtersMu.Unlock() @@ -441,9 +440,9 @@ func returnHashes(hashes []common.Hash) []common.Hash { // returnLogs is a helper that will return an empty log array in case the given logs array is nil, // otherwise the given logs array is returned. -func returnLogs(logs []*vm.Log) []*vm.Log { +func returnLogs(logs []*types.Log) []*types.Log { if logs == nil { - return []*vm.Log{} + return []*types.Log{} } return logs } diff --git a/eth/filters/filter.go b/eth/filters/filter.go index 76ca86524d..9a8e2fd70a 100644 --- a/eth/filters/filter.go +++ b/eth/filters/filter.go @@ -25,7 +25,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/rpc" @@ -91,7 +90,7 @@ func (f *Filter) SetTopics(topics [][]common.Hash) { // all matching entries from the first block that contains matches, // updating the start point of the filter accordingly. If no results are // found, a nil slice is returned. -func (f *Filter) FindOnce(ctx context.Context) ([]*vm.Log, error) { +func (f *Filter) FindOnce(ctx context.Context) ([]*types.Log, error) { head, _ := f.backend.HeaderByNumber(ctx, rpc.LatestBlockNumber) if head == nil { return nil, nil @@ -122,7 +121,7 @@ func (f *Filter) FindOnce(ctx context.Context) ([]*vm.Log, error) { } // Run filters logs with the current parameters set -func (f *Filter) Find(ctx context.Context) (logs []*vm.Log, err error) { +func (f *Filter) Find(ctx context.Context) (logs []*types.Log, err error) { for { newLogs, err := f.FindOnce(ctx) if len(newLogs) == 0 || err != nil { @@ -132,7 +131,7 @@ func (f *Filter) Find(ctx context.Context) (logs []*vm.Log, err error) { } } -func (f *Filter) mipFind(start, end uint64, depth int) (logs []*vm.Log, blockNumber uint64) { +func (f *Filter) mipFind(start, end uint64, depth int) (logs []*types.Log, blockNumber uint64) { level := core.MIPMapLevels[depth] // normalise numerator so we can work in level specific batches and // work with the proper range checks @@ -168,7 +167,7 @@ func (f *Filter) mipFind(start, end uint64, depth int) (logs []*vm.Log, blockNum return nil, end } -func (f *Filter) getLogs(ctx context.Context, start, end uint64) (logs []*vm.Log, blockNumber uint64, err error) { +func (f *Filter) getLogs(ctx context.Context, start, end uint64) (logs []*types.Log, blockNumber uint64, err error) { for i := start; i <= end; i++ { blockNumber := rpc.BlockNumber(i) header, err := f.backend.HeaderByNumber(ctx, blockNumber) @@ -184,9 +183,9 @@ func (f *Filter) getLogs(ctx context.Context, start, end uint64) (logs []*vm.Log if err != nil { return nil, end, err } - var unfiltered []*vm.Log + var unfiltered []*types.Log for _, receipt := range receipts { - unfiltered = append(unfiltered, ([]*vm.Log)(receipt.Logs)...) + unfiltered = append(unfiltered, ([]*types.Log)(receipt.Logs)...) } logs = filterLogs(unfiltered, nil, nil, f.addresses, f.topics) if len(logs) > 0 { @@ -209,8 +208,8 @@ func includes(addresses []common.Address, a common.Address) bool { } // filterLogs creates a slice of logs matching the given criteria. -func filterLogs(logs []*vm.Log, fromBlock, toBlock *big.Int, addresses []common.Address, topics [][]common.Hash) []*vm.Log { - var ret []*vm.Log +func filterLogs(logs []*types.Log, fromBlock, toBlock *big.Int, addresses []common.Address, topics [][]common.Hash) []*types.Log { + var ret []*types.Log Logs: for _, log := range logs { if fromBlock != nil && fromBlock.Int64() >= 0 && fromBlock.Uint64() > log.BlockNumber { diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go index 1b360cfdb6..7493dd231e 100644 --- a/eth/filters/filter_system.go +++ b/eth/filters/filter_system.go @@ -27,7 +27,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/rpc" "golang.org/x/net/context" @@ -64,7 +63,7 @@ type subscription struct { typ Type created time.Time logsCrit FilterCriteria - logs chan []*vm.Log + logs chan []*types.Log hashes chan common.Hash headers chan *types.Header installed chan struct{} // closed when the filter is installed @@ -151,7 +150,7 @@ func (es *EventSystem) subscribe(sub *subscription) *Subscription { // SubscribeLogs creates a subscription that will write all logs matching the // given criteria to the given logs channel. Default value for the from and to // block is "latest". If the fromBlock > toBlock an error is returned. -func (es *EventSystem) SubscribeLogs(crit FilterCriteria, logs chan []*vm.Log) (*Subscription, error) { +func (es *EventSystem) SubscribeLogs(crit FilterCriteria, logs chan []*types.Log) (*Subscription, error) { var from, to rpc.BlockNumber if crit.FromBlock == nil { from = rpc.LatestBlockNumber @@ -189,7 +188,7 @@ func (es *EventSystem) SubscribeLogs(crit FilterCriteria, logs chan []*vm.Log) ( // subscribeMinedPendingLogs creates a subscription that returned mined and // pending logs that match the given criteria. -func (es *EventSystem) subscribeMinedPendingLogs(crit FilterCriteria, logs chan []*vm.Log) *Subscription { +func (es *EventSystem) subscribeMinedPendingLogs(crit FilterCriteria, logs chan []*types.Log) *Subscription { sub := &subscription{ id: rpc.NewID(), typ: MinedAndPendingLogsSubscription, @@ -207,7 +206,7 @@ func (es *EventSystem) subscribeMinedPendingLogs(crit FilterCriteria, logs chan // subscribeLogs creates a subscription that will write all logs matching the // given criteria to the given logs channel. -func (es *EventSystem) subscribeLogs(crit FilterCriteria, logs chan []*vm.Log) *Subscription { +func (es *EventSystem) subscribeLogs(crit FilterCriteria, logs chan []*types.Log) *Subscription { sub := &subscription{ id: rpc.NewID(), typ: LogsSubscription, @@ -225,7 +224,7 @@ func (es *EventSystem) subscribeLogs(crit FilterCriteria, logs chan []*vm.Log) * // subscribePendingLogs creates a subscription that writes transaction hashes for // transactions that enter the transaction pool. -func (es *EventSystem) subscribePendingLogs(crit FilterCriteria, logs chan []*vm.Log) *Subscription { +func (es *EventSystem) subscribePendingLogs(crit FilterCriteria, logs chan []*types.Log) *Subscription { sub := &subscription{ id: rpc.NewID(), typ: PendingLogsSubscription, @@ -248,7 +247,7 @@ func (es *EventSystem) SubscribeNewHeads(headers chan *types.Header) *Subscripti id: rpc.NewID(), typ: BlocksSubscription, created: time.Now(), - logs: make(chan []*vm.Log), + logs: make(chan []*types.Log), hashes: make(chan common.Hash), headers: headers, installed: make(chan struct{}), @@ -265,7 +264,7 @@ func (es *EventSystem) SubscribePendingTxEvents(hashes chan common.Hash) *Subscr id: rpc.NewID(), typ: PendingTransactionsSubscription, created: time.Now(), - logs: make(chan []*vm.Log), + logs: make(chan []*types.Log), hashes: hashes, headers: make(chan *types.Header), installed: make(chan struct{}), @@ -284,7 +283,7 @@ func (es *EventSystem) broadcast(filters filterIndex, ev *event.Event) { } switch e := ev.Data.(type) { - case vm.Logs: + case []*types.Log: if len(e) > 0 { for _, f := range filters[LogsSubscription] { if ev.Time.After(f.created) { @@ -370,7 +369,7 @@ func (es *EventSystem) lightFilterNewHead(newHeader *types.Header, callBack func } // filter logs of a single header in light client mode -func (es *EventSystem) lightFilterLogs(header *types.Header, addresses []common.Address, topics [][]common.Hash, remove bool) []*vm.Log { +func (es *EventSystem) lightFilterLogs(header *types.Header, addresses []common.Address, topics [][]common.Hash, remove bool) []*types.Log { if bloomFilter(header.Bloom, addresses, topics) { // Get the logs of the block ctx, _ := context.WithTimeout(context.Background(), time.Second*5) @@ -378,7 +377,7 @@ func (es *EventSystem) lightFilterLogs(header *types.Header, addresses []common. if err != nil { return nil } - var unfiltered []*vm.Log + var unfiltered []*types.Log for _, receipt := range receipts { for _, log := range receipt.Logs { logcopy := *log @@ -396,7 +395,7 @@ func (es *EventSystem) lightFilterLogs(header *types.Header, addresses []common. func (es *EventSystem) eventLoop() { var ( index = make(filterIndex) - sub = es.mux.Subscribe(core.PendingLogsEvent{}, core.RemovedLogsEvent{}, vm.Logs{}, core.TxPreEvent{}, core.ChainEvent{}) + sub = es.mux.Subscribe(core.PendingLogsEvent{}, core.RemovedLogsEvent{}, []*types.Log{}, core.TxPreEvent{}, core.ChainEvent{}) ) for i := UnknownSubscription; i < LastIndexSubscription; i++ { diff --git a/eth/filters/filter_system_test.go b/eth/filters/filter_system_test.go index 3ce0cf6634..5f51c0aa8a 100644 --- a/eth/filters/filter_system_test.go +++ b/eth/filters/filter_system_test.go @@ -27,7 +27,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/params" @@ -263,30 +262,30 @@ func TestLogFilter(t *testing.T) { notUsedTopic = common.HexToHash("0x9999999999999999999999999999999999999999999999999999999999999999") // posted twice, once as vm.Logs and once as core.PendingLogsEvent - allLogs = vm.Logs{ - vm.NewLog(firstAddr, []common.Hash{}, []byte(""), 0), - vm.NewLog(firstAddr, []common.Hash{firstTopic}, []byte(""), 1), - vm.NewLog(secondAddr, []common.Hash{firstTopic}, []byte(""), 1), - vm.NewLog(thirdAddress, []common.Hash{secondTopic}, []byte(""), 2), - vm.NewLog(thirdAddress, []common.Hash{secondTopic}, []byte(""), 3), + allLogs = []*types.Log{ + {Address: firstAddr}, + {Address: firstAddr, Topics: []common.Hash{firstTopic}, BlockNumber: 1}, + {Address: secondAddr, Topics: []common.Hash{firstTopic}, BlockNumber: 1}, + {Address: thirdAddress, Topics: []common.Hash{secondTopic}, BlockNumber: 2}, + {Address: thirdAddress, Topics: []common.Hash{secondTopic}, BlockNumber: 3}, } - expectedCase7 = vm.Logs{allLogs[3], allLogs[4], allLogs[0], allLogs[1], allLogs[2], allLogs[3], allLogs[4]} - expectedCase11 = vm.Logs{allLogs[1], allLogs[2], allLogs[1], allLogs[2]} + expectedCase7 = []*types.Log{allLogs[3], allLogs[4], allLogs[0], allLogs[1], allLogs[2], allLogs[3], allLogs[4]} + expectedCase11 = []*types.Log{allLogs[1], allLogs[2], allLogs[1], allLogs[2]} testCases = []struct { crit FilterCriteria - expected vm.Logs + expected []*types.Log id rpc.ID }{ // match all 0: {FilterCriteria{}, allLogs, ""}, // match none due to no matching addresses - 1: {FilterCriteria{Addresses: []common.Address{common.Address{}, notUsedAddress}, Topics: [][]common.Hash{allLogs[0].Topics}}, vm.Logs{}, ""}, + 1: {FilterCriteria{Addresses: []common.Address{common.Address{}, notUsedAddress}, Topics: [][]common.Hash{allLogs[0].Topics}}, []*types.Log{}, ""}, // match logs based on addresses, ignore topics 2: {FilterCriteria{Addresses: []common.Address{firstAddr}}, allLogs[:2], ""}, // match none due to no matching topics (match with address) - 3: {FilterCriteria{Addresses: []common.Address{secondAddr}, Topics: [][]common.Hash{[]common.Hash{notUsedTopic}}}, vm.Logs{}, ""}, + 3: {FilterCriteria{Addresses: []common.Address{secondAddr}, Topics: [][]common.Hash{[]common.Hash{notUsedTopic}}}, []*types.Log{}, ""}, // match logs based on addresses and topics 4: {FilterCriteria{Addresses: []common.Address{thirdAddress}, Topics: [][]common.Hash{[]common.Hash{firstTopic, secondTopic}}}, allLogs[3:5], ""}, // match logs based on multiple addresses and "or" topics @@ -321,14 +320,14 @@ func TestLogFilter(t *testing.T) { } for i, tt := range testCases { - var fetched []*vm.Log + var fetched []*types.Log for { // fetch all expected logs results, err := api.GetFilterChanges(tt.id) if err != nil { t.Fatalf("Unable to fetch logs: %v", err) } - fetched = append(fetched, results.([]*vm.Log)...) + fetched = append(fetched, results.([]*types.Log)...) if len(fetched) >= len(tt.expected) { break } @@ -373,21 +372,21 @@ func TestPendingLogsSubscription(t *testing.T) { notUsedTopic = common.HexToHash("0x9999999999999999999999999999999999999999999999999999999999999999") allLogs = []core.PendingLogsEvent{ - core.PendingLogsEvent{Logs: vm.Logs{vm.NewLog(firstAddr, []common.Hash{}, []byte(""), 0)}}, - core.PendingLogsEvent{Logs: vm.Logs{vm.NewLog(firstAddr, []common.Hash{firstTopic}, []byte(""), 1)}}, - core.PendingLogsEvent{Logs: vm.Logs{vm.NewLog(secondAddr, []common.Hash{firstTopic}, []byte(""), 2)}}, - core.PendingLogsEvent{Logs: vm.Logs{vm.NewLog(thirdAddress, []common.Hash{secondTopic}, []byte(""), 3)}}, - core.PendingLogsEvent{Logs: vm.Logs{vm.NewLog(thirdAddress, []common.Hash{secondTopic}, []byte(""), 4)}}, - core.PendingLogsEvent{Logs: vm.Logs{ - vm.NewLog(thirdAddress, []common.Hash{firstTopic}, []byte(""), 5), - vm.NewLog(thirdAddress, []common.Hash{thirdTopic}, []byte(""), 5), - vm.NewLog(thirdAddress, []common.Hash{forthTopic}, []byte(""), 5), - vm.NewLog(firstAddr, []common.Hash{firstTopic}, []byte(""), 5), + {Logs: []*types.Log{{Address: firstAddr, Topics: []common.Hash{}, BlockNumber: 0}}}, + {Logs: []*types.Log{{Address: firstAddr, Topics: []common.Hash{firstTopic}, BlockNumber: 1}}}, + {Logs: []*types.Log{{Address: secondAddr, Topics: []common.Hash{firstTopic}, BlockNumber: 2}}}, + {Logs: []*types.Log{{Address: thirdAddress, Topics: []common.Hash{secondTopic}, BlockNumber: 3}}}, + {Logs: []*types.Log{{Address: thirdAddress, Topics: []common.Hash{secondTopic}, BlockNumber: 4}}}, + {Logs: []*types.Log{ + {Address: thirdAddress, Topics: []common.Hash{firstTopic}, BlockNumber: 5}, + {Address: thirdAddress, Topics: []common.Hash{thirdTopic}, BlockNumber: 5}, + {Address: thirdAddress, Topics: []common.Hash{forthTopic}, BlockNumber: 5}, + {Address: firstAddr, Topics: []common.Hash{firstTopic}, BlockNumber: 5}, }}, } - convertLogs = func(pl []core.PendingLogsEvent) vm.Logs { - var logs vm.Logs + convertLogs = func(pl []core.PendingLogsEvent) []*types.Log { + var logs []*types.Log for _, l := range pl { logs = append(logs, l.Logs...) } @@ -396,18 +395,18 @@ func TestPendingLogsSubscription(t *testing.T) { testCases = []struct { crit FilterCriteria - expected vm.Logs - c chan []*vm.Log + expected []*types.Log + c chan []*types.Log sub *Subscription }{ // match all {FilterCriteria{}, convertLogs(allLogs), nil, nil}, // match none due to no matching addresses - {FilterCriteria{Addresses: []common.Address{common.Address{}, notUsedAddress}, Topics: [][]common.Hash{[]common.Hash{}}}, vm.Logs{}, nil, nil}, + {FilterCriteria{Addresses: []common.Address{common.Address{}, notUsedAddress}, Topics: [][]common.Hash{[]common.Hash{}}}, []*types.Log{}, nil, nil}, // match logs based on addresses, ignore topics {FilterCriteria{Addresses: []common.Address{firstAddr}}, append(convertLogs(allLogs[:2]), allLogs[5].Logs[3]), nil, nil}, // match none due to no matching topics (match with address) - {FilterCriteria{Addresses: []common.Address{secondAddr}, Topics: [][]common.Hash{[]common.Hash{notUsedTopic}}}, vm.Logs{}, nil, nil}, + {FilterCriteria{Addresses: []common.Address{secondAddr}, Topics: [][]common.Hash{[]common.Hash{notUsedTopic}}}, []*types.Log{}, nil, nil}, // match logs based on addresses and topics {FilterCriteria{Addresses: []common.Address{thirdAddress}, Topics: [][]common.Hash{[]common.Hash{firstTopic, secondTopic}}}, append(convertLogs(allLogs[3:5]), allLogs[5].Logs[0]), nil, nil}, // match logs based on multiple addresses and "or" topics @@ -415,7 +414,7 @@ func TestPendingLogsSubscription(t *testing.T) { // block numbers are ignored for filters created with New***Filter, these return all logs that match the given criterias when the state changes {FilterCriteria{Addresses: []common.Address{firstAddr}, FromBlock: big.NewInt(2), ToBlock: big.NewInt(3)}, append(convertLogs(allLogs[:2]), allLogs[5].Logs[3]), nil, nil}, // multiple pending logs, should match only 2 topics from the logs in block 5 - {FilterCriteria{Addresses: []common.Address{thirdAddress}, Topics: [][]common.Hash{[]common.Hash{firstTopic, forthTopic}}}, vm.Logs{allLogs[5].Logs[0], allLogs[5].Logs[2]}, nil, nil}, + {FilterCriteria{Addresses: []common.Address{thirdAddress}, Topics: [][]common.Hash{[]common.Hash{firstTopic, forthTopic}}}, []*types.Log{allLogs[5].Logs[0], allLogs[5].Logs[2]}, nil, nil}, } ) @@ -423,7 +422,7 @@ func TestPendingLogsSubscription(t *testing.T) { // on slow machines this could otherwise lead to missing events when the subscription is created after // (some) events are posted. for i := range testCases { - testCases[i].c = make(chan []*vm.Log) + testCases[i].c = make(chan []*types.Log) testCases[i].sub, _ = api.events.SubscribeLogs(testCases[i].crit, testCases[i].c) } @@ -431,7 +430,7 @@ func TestPendingLogsSubscription(t *testing.T) { i := n tt := test go func() { - var fetched []*vm.Log + var fetched []*types.Log fetchLoop: for { logs := <-tt.c diff --git a/eth/filters/filter_test.go b/eth/filters/filter_test.go index ab6a87851f..35495e8af2 100644 --- a/eth/filters/filter_test.go +++ b/eth/filters/filter_test.go @@ -27,17 +27,16 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" - "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/params" ) func makeReceipt(addr common.Address) *types.Receipt { receipt := types.NewReceipt(nil, new(big.Int)) - receipt.Logs = vm.Logs{ - &vm.Log{Address: addr}, + receipt.Logs = []*types.Log{ + {Address: addr}, } receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) return receipt @@ -146,8 +145,8 @@ func TestFilters(t *testing.T) { switch i { case 1: receipt := types.NewReceipt(nil, new(big.Int)) - receipt.Logs = vm.Logs{ - &vm.Log{ + receipt.Logs = []*types.Log{ + { Address: addr, Topics: []common.Hash{hash1}, }, @@ -156,8 +155,8 @@ func TestFilters(t *testing.T) { receipts = types.Receipts{receipt} case 2: receipt := types.NewReceipt(nil, new(big.Int)) - receipt.Logs = vm.Logs{ - &vm.Log{ + receipt.Logs = []*types.Log{ + { Address: addr, Topics: []common.Hash{hash2}, }, @@ -166,8 +165,8 @@ func TestFilters(t *testing.T) { receipts = types.Receipts{receipt} case 998: receipt := types.NewReceipt(nil, new(big.Int)) - receipt.Logs = vm.Logs{ - &vm.Log{ + receipt.Logs = []*types.Log{ + { Address: addr, Topics: []common.Hash{hash3}, }, @@ -176,8 +175,8 @@ func TestFilters(t *testing.T) { receipts = types.Receipts{receipt} case 999: receipt := types.NewReceipt(nil, new(big.Int)) - receipt.Logs = vm.Logs{ - &vm.Log{ + receipt.Logs = []*types.Log{ + { Address: addr, Topics: []common.Hash{hash4}, }, diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 3acaaa0d11..1d04d9e032 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -26,7 +26,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" "golang.org/x/net/context" @@ -294,14 +293,14 @@ func (ec *Client) NonceAt(ctx context.Context, account common.Address, blockNumb // Filters // FilterLogs executes a filter query. -func (ec *Client) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]vm.Log, error) { - var result []vm.Log +func (ec *Client) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) { + var result []types.Log err := ec.c.CallContext(ctx, &result, "eth_getLogs", toFilterArg(q)) return result, err } // SubscribeFilterLogs subscribes to the results of a streaming filter query. -func (ec *Client) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- vm.Log) (ethereum.Subscription, error) { +func (ec *Client) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) { return ec.c.EthSubscribe(ctx, ch, "logs", toFilterArg(q)) } diff --git a/interfaces.go b/interfaces.go index bbb204ff23..f7e71a3173 100644 --- a/interfaces.go +++ b/interfaces.go @@ -23,7 +23,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "golang.org/x/net/context" ) @@ -156,8 +155,8 @@ type FilterQuery struct { // Logs received through a streaming query subscription may have Removed set to true, // indicating that the log was reverted due to a chain reorganisation. type LogFilterer interface { - FilterLogs(ctx context.Context, q FilterQuery) ([]vm.Log, error) - SubscribeFilterLogs(ctx context.Context, q FilterQuery, ch chan<- vm.Log) (Subscription, error) + FilterLogs(ctx context.Context, q FilterQuery) ([]types.Log, error) + SubscribeFilterLogs(ctx context.Context, q FilterQuery, ch chan<- types.Log) (Subscription, error) } // TransactionSender wraps transaction sending. The SendTransaction method injects a diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 561e72b014..7cfcfc8d49 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -963,7 +963,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(txHash common.Hash) (ma "logsBloom": receipt.Bloom, } if receipt.Logs == nil { - fields["logs"] = []vm.Logs{} + fields["logs"] = [][]*types.Log{} } // If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation if receipt.ContractAddress != (common.Address{}) { diff --git a/les/api_backend.go b/les/api_backend.go index e4f7417d61..3a71ac4e02 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -31,7 +31,7 @@ import ( "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/light" "github.com/ethereum/go-ethereum/params" - rpc "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/rpc" "golang.org/x/net/context" ) diff --git a/light/vm_env.go b/light/vm_env.go index cc0c568c96..1b225c8de0 100644 --- a/light/vm_env.go +++ b/light/vm_env.go @@ -20,6 +20,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "golang.org/x/net/context" @@ -42,7 +43,7 @@ func (s *VMState) Error() error { return s.err } -func (s *VMState) AddLog(log *vm.Log) {} +func (s *VMState) AddLog(log *types.Log) {} // errHandler handles and stores any state error that happens during execution. func (s *VMState) errHandler(err error) { diff --git a/miner/worker.go b/miner/worker.go index 3ae51d1208..adb224c474 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -327,7 +327,7 @@ func (self *worker) wait() { } // broadcast before waiting for validation - go func(block *types.Block, logs vm.Logs, receipts []*types.Receipt) { + go func(block *types.Block, logs []*types.Log, receipts []*types.Receipt) { self.mux.Post(core.NewMinedBlockEvent{Block: block}) self.mux.Post(core.ChainEvent{Block: block, Hash: block.Hash(), Logs: logs}) @@ -537,7 +537,7 @@ func (self *worker) commitUncle(work *Work, uncle *types.Header) error { func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsByPriceAndNonce, gasPrice *big.Int, bc *core.BlockChain) { gp := new(core.GasPool).AddGas(env.header.GasLimit) - var coalescedLogs vm.Logs + var coalescedLogs []*types.Log for { // Retrieve the next transaction and abort if all done @@ -597,12 +597,12 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB // make a copy, the state caches the logs and these logs get "upgraded" from pending to mined // logs by filling in the block hash when the block was mined by the local miner. This can // cause a race condition if a log was "upgraded" before the PendingLogsEvent is processed. - cpy := make(vm.Logs, len(coalescedLogs)) + cpy := make([]*types.Log, len(coalescedLogs)) for i, l := range coalescedLogs { - cpy[i] = new(vm.Log) + cpy[i] = new(types.Log) *cpy[i] = *l } - go func(logs vm.Logs, tcount int) { + go func(logs []*types.Log, tcount int) { if len(logs) > 0 { mux.Post(core.PendingLogsEvent{Logs: logs}) } @@ -613,7 +613,7 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB } } -func (env *Work) commitTransaction(tx *types.Transaction, bc *core.BlockChain, gp *core.GasPool) (error, vm.Logs) { +func (env *Work) commitTransaction(tx *types.Transaction, bc *core.BlockChain, gp *core.GasPool) (error, []*types.Log) { snap := env.state.Snapshot() receipt, _, err := core.ApplyTransaction(env.config, bc, gp, env.state, env.header, tx, env.header.GasUsed, vm.Config{}) diff --git a/mobile/ethclient.go b/mobile/ethclient.go index 36a15aa47c..4e83285017 100644 --- a/mobile/ethclient.go +++ b/mobile/ethclient.go @@ -22,7 +22,6 @@ import ( "math/big" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/ethclient" ) @@ -191,7 +190,7 @@ func (ec *EthereumClient) FilterLogs(ctx *Context, query *FilterQuery) (logs *Lo return nil, err } // Temp hack due to vm.Logs being []*vm.Log - res := make(vm.Logs, len(rawLogs)) + res := make([]*types.Log, len(rawLogs)) for i, log := range rawLogs { res[i] = &log } @@ -208,7 +207,7 @@ type FilterLogsHandler interface { // SubscribeFilterLogs subscribes to the results of a streaming filter query. func (ec *EthereumClient) SubscribeFilterLogs(ctx *Context, query *FilterQuery, handler FilterLogsHandler, buffer int) (sub *Subscription, _ error) { // Subscribe to the event internally - ch := make(chan vm.Log, buffer) + ch := make(chan types.Log, buffer) rawSub, err := ec.client.SubscribeFilterLogs(ctx.context, query.query, ch) if err != nil { return nil, err diff --git a/mobile/vm.go b/mobile/vm.go index cb098d3904..72093e3d5b 100644 --- a/mobile/vm.go +++ b/mobile/vm.go @@ -21,13 +21,13 @@ package geth import ( "errors" - "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/core/types" ) // Log represents a contract log event. These events are generated by the LOG // opcode and stored/indexed by the node. type Log struct { - log *vm.Log + log *types.Log } func (l *Log) GetAddress() *Address { return &Address{l.log.Address} } @@ -40,7 +40,7 @@ func (l *Log) GetBlockHash() *Hash { return &Hash{l.log.BlockHash} } func (l *Log) GetIndex() int { return int(l.log.Index) } // Logs represents a slice of VM logs. -type Logs struct{ logs vm.Logs } +type Logs struct{ logs []*types.Log } // Size returns the number of logs in the slice. func (l *Logs) Size() int { diff --git a/tests/state_test_util.go b/tests/state_test_util.go index f47f5f7a1b..8221815a88 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -28,7 +28,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" - "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/params" @@ -146,7 +146,7 @@ func runStateTest(chainConfig *params.ChainConfig, test VmTest) error { ret []byte // gas *big.Int // err error - logs vm.Logs + logs []*types.Log ) ret, logs, _, _ = RunState(chainConfig, statedb, env, test.Transaction) @@ -203,7 +203,7 @@ func runStateTest(chainConfig *params.ChainConfig, test VmTest) error { return nil } -func RunState(chainConfig *params.ChainConfig, statedb *state.StateDB, env, tx map[string]string) ([]byte, vm.Logs, *big.Int, error) { +func RunState(chainConfig *params.ChainConfig, statedb *state.StateDB, env, tx map[string]string) ([]byte, []*types.Log, *big.Int, error) { environment, msg := NewEVMEnvironment(false, chainConfig, statedb, env, tx) gaspool := new(core.GasPool).AddGas(common.Big(env["currentGasLimit"])) diff --git a/tests/util.go b/tests/util.go index a0a6ab3747..134d5b4f80 100644 --- a/tests/util.go +++ b/tests/util.go @@ -47,7 +47,7 @@ func init() { } } -func checkLogs(tlog []Log, logs vm.Logs) error { +func checkLogs(tlog []Log, logs []*types.Log) error { if len(tlog) != len(logs) { return fmt.Errorf("log length mismatch. Expected %d, got %d", len(tlog), len(logs)) @@ -70,7 +70,7 @@ func checkLogs(tlog []Log, logs vm.Logs) error { } } } - genBloom := common.LeftPadBytes(types.LogsBloom(vm.Logs{logs[i]}).Bytes(), 256) + genBloom := common.LeftPadBytes(types.LogsBloom([]*types.Log{logs[i]}).Bytes(), 256) if !bytes.Equal(genBloom, common.Hex2Bytes(log.BloomF)) { return fmt.Errorf("bloom mismatch") diff --git a/tests/vm_test_util.go b/tests/vm_test_util.go index dc9f1d62ce..d6411147fe 100644 --- a/tests/vm_test_util.go +++ b/tests/vm_test_util.go @@ -26,6 +26,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/logger/glog" @@ -164,7 +165,7 @@ func runVmTest(test VmTest) error { ret []byte gas *big.Int err error - logs vm.Logs + logs []*types.Log ) ret, logs, gas, err = RunVm(statedb, env, test.Exec) @@ -211,7 +212,7 @@ func runVmTest(test VmTest) error { return nil } -func RunVm(statedb *state.StateDB, env, exec map[string]string) ([]byte, vm.Logs, *big.Int, error) { +func RunVm(statedb *state.StateDB, env, exec map[string]string) ([]byte, []*types.Log, *big.Int, error) { chainConfig := ¶ms.ChainConfig{ HomesteadBlock: params.MainNetHomesteadBlock, DAOForkBlock: params.MainNetDAOForkBlock,