Skip to content

Commit 7731061

Browse files
committed
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.
1 parent b9683d3 commit 7731061

36 files changed

+180
-193
lines changed

accounts/abi/argument.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type Argument struct {
3131

3232
func (a *Argument) UnmarshalJSON(data []byte) error {
3333
var extarg struct {
34-
Name string
35-
Type string
34+
Name string
35+
Type string
3636
Indexed bool
3737
}
3838
err := json.Unmarshal(data, &extarg)

cmd/disasm/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
package main
1919

2020
import (
21+
"encoding/hex"
2122
"fmt"
2223
"io/ioutil"
2324
"os"
24-
"encoding/hex"
2525
"strings"
2626

2727
"github.com/ethereum/go-ethereum/core/vm"

core/block_validator_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/ethereum/go-ethereum/common"
2525
"github.com/ethereum/go-ethereum/core/state"
2626
"github.com/ethereum/go-ethereum/core/types"
27-
"github.com/ethereum/go-ethereum/core/vm"
2827
"github.com/ethereum/go-ethereum/ethdb"
2928
"github.com/ethereum/go-ethereum/event"
3029
"github.com/ethereum/go-ethereum/params"
@@ -77,7 +76,7 @@ func TestPutReceipt(t *testing.T) {
7776
hash[0] = 2
7877

7978
receipt := new(types.Receipt)
80-
receipt.Logs = vm.Logs{&vm.Log{
79+
receipt.Logs = []*types.Log{{
8180
Address: addr,
8281
Topics: []common.Hash{hash},
8382
Data: []byte("hi"),

core/blockchain.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
883883
var (
884884
stats = insertStats{startTime: time.Now()}
885885
events = make([]interface{}, 0, len(chain))
886-
coalescedLogs vm.Logs
886+
coalescedLogs []*types.Log
887887
nonceChecked = make([]bool, len(chain))
888888
)
889889

@@ -1094,7 +1094,7 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
10941094
oldStart = oldBlock
10951095
newStart = newBlock
10961096
deletedTxs types.Transactions
1097-
deletedLogs vm.Logs
1097+
deletedLogs []*types.Log
10981098
// collectLogs collects the logs that were generated during the
10991099
// processing of the block that corresponds with the given hash.
11001100
// These logs are later announced as deleted.
@@ -1210,7 +1210,7 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
12101210

12111211
// postChainEvents iterates over the events generated by a chain insertion and
12121212
// posts them into the event mux.
1213-
func (self *BlockChain) postChainEvents(events []interface{}, logs vm.Logs) {
1213+
func (self *BlockChain) postChainEvents(events []interface{}, logs []*types.Log) {
12141214
// post event logs for further processing
12151215
self.eventMux.Post(logs)
12161216
for _, event := range events {

core/blockchain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ func (bproc) ValidateHeader(*types.Header, *types.Header, bool) error { return n
435435
func (bproc) ValidateState(block, parent *types.Block, state *state.StateDB, receipts types.Receipts, usedGas *big.Int) error {
436436
return nil
437437
}
438-
func (bproc) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, vm.Logs, *big.Int, error) {
438+
func (bproc) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, *big.Int, error) {
439439
return nil, nil, new(big.Int), nil
440440
}
441441

core/database_util_test.go

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626

2727
"github.com/ethereum/go-ethereum/common"
2828
"github.com/ethereum/go-ethereum/core/types"
29-
"github.com/ethereum/go-ethereum/core/vm"
3029
"github.com/ethereum/go-ethereum/crypto"
3130
"github.com/ethereum/go-ethereum/crypto/sha3"
3231
"github.com/ethereum/go-ethereum/ethdb"
@@ -393,9 +392,9 @@ func TestReceiptStorage(t *testing.T) {
393392
receipt1 := &types.Receipt{
394393
PostState: []byte{0x01},
395394
CumulativeGasUsed: big.NewInt(1),
396-
Logs: vm.Logs{
397-
&vm.Log{Address: common.BytesToAddress([]byte{0x11})},
398-
&vm.Log{Address: common.BytesToAddress([]byte{0x01, 0x11})},
395+
Logs: []*types.Log{
396+
{Address: common.BytesToAddress([]byte{0x11})},
397+
{Address: common.BytesToAddress([]byte{0x01, 0x11})},
399398
},
400399
TxHash: common.BytesToHash([]byte{0x11, 0x11}),
401400
ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}),
@@ -404,9 +403,9 @@ func TestReceiptStorage(t *testing.T) {
404403
receipt2 := &types.Receipt{
405404
PostState: []byte{0x02},
406405
CumulativeGasUsed: big.NewInt(2),
407-
Logs: vm.Logs{
408-
&vm.Log{Address: common.BytesToAddress([]byte{0x22})},
409-
&vm.Log{Address: common.BytesToAddress([]byte{0x02, 0x22})},
406+
Logs: []*types.Log{
407+
{Address: common.BytesToAddress([]byte{0x22})},
408+
{Address: common.BytesToAddress([]byte{0x02, 0x22})},
410409
},
411410
TxHash: common.BytesToHash([]byte{0x22, 0x22}),
412411
ContractAddress: common.BytesToAddress([]byte{0x02, 0x22, 0x22}),
@@ -452,9 +451,9 @@ func TestBlockReceiptStorage(t *testing.T) {
452451
receipt1 := &types.Receipt{
453452
PostState: []byte{0x01},
454453
CumulativeGasUsed: big.NewInt(1),
455-
Logs: vm.Logs{
456-
&vm.Log{Address: common.BytesToAddress([]byte{0x11})},
457-
&vm.Log{Address: common.BytesToAddress([]byte{0x01, 0x11})},
454+
Logs: []*types.Log{
455+
{Address: common.BytesToAddress([]byte{0x11})},
456+
{Address: common.BytesToAddress([]byte{0x01, 0x11})},
458457
},
459458
TxHash: common.BytesToHash([]byte{0x11, 0x11}),
460459
ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}),
@@ -463,9 +462,9 @@ func TestBlockReceiptStorage(t *testing.T) {
463462
receipt2 := &types.Receipt{
464463
PostState: []byte{0x02},
465464
CumulativeGasUsed: big.NewInt(2),
466-
Logs: vm.Logs{
467-
&vm.Log{Address: common.BytesToAddress([]byte{0x22})},
468-
&vm.Log{Address: common.BytesToAddress([]byte{0x02, 0x22})},
465+
Logs: []*types.Log{
466+
{Address: common.BytesToAddress([]byte{0x22})},
467+
{Address: common.BytesToAddress([]byte{0x02, 0x22})},
469468
},
470469
TxHash: common.BytesToHash([]byte{0x22, 0x22}),
471470
ContractAddress: common.BytesToAddress([]byte{0x02, 0x22, 0x22}),
@@ -505,14 +504,14 @@ func TestMipmapBloom(t *testing.T) {
505504
db, _ := ethdb.NewMemDatabase()
506505

507506
receipt1 := new(types.Receipt)
508-
receipt1.Logs = vm.Logs{
509-
&vm.Log{Address: common.BytesToAddress([]byte("test"))},
510-
&vm.Log{Address: common.BytesToAddress([]byte("address"))},
507+
receipt1.Logs = []*types.Log{
508+
{Address: common.BytesToAddress([]byte("test"))},
509+
{Address: common.BytesToAddress([]byte("address"))},
511510
}
512511
receipt2 := new(types.Receipt)
513-
receipt2.Logs = vm.Logs{
514-
&vm.Log{Address: common.BytesToAddress([]byte("test"))},
515-
&vm.Log{Address: common.BytesToAddress([]byte("address1"))},
512+
receipt2.Logs = []*types.Log{
513+
{Address: common.BytesToAddress([]byte("test"))},
514+
{Address: common.BytesToAddress([]byte("address1"))},
516515
}
517516

518517
WriteMipmapBloom(db, 1, types.Receipts{receipt1})
@@ -528,14 +527,14 @@ func TestMipmapBloom(t *testing.T) {
528527
// reset
529528
db, _ = ethdb.NewMemDatabase()
530529
receipt := new(types.Receipt)
531-
receipt.Logs = vm.Logs{
532-
&vm.Log{Address: common.BytesToAddress([]byte("test"))},
530+
receipt.Logs = []*types.Log{
531+
{Address: common.BytesToAddress([]byte("test"))},
533532
}
534533
WriteMipmapBloom(db, 999, types.Receipts{receipt1})
535534

536535
receipt = new(types.Receipt)
537-
receipt.Logs = vm.Logs{
538-
&vm.Log{Address: common.BytesToAddress([]byte("test 1"))},
536+
receipt.Logs = []*types.Log{
537+
{Address: common.BytesToAddress([]byte("test 1"))},
539538
}
540539
WriteMipmapBloom(db, 1000, types.Receipts{receipt})
541540

@@ -568,17 +567,12 @@ func TestMipmapChain(t *testing.T) {
568567
switch i {
569568
case 1:
570569
receipt := types.NewReceipt(nil, new(big.Int))
571-
receipt.Logs = vm.Logs{
572-
&vm.Log{
573-
Address: addr,
574-
Topics: []common.Hash{hash1},
575-
},
576-
}
570+
receipt.Logs = []*types.Log{{Address: addr, Topics: []common.Hash{hash1}}}
577571
gen.AddUncheckedReceipt(receipt)
578572
receipts = types.Receipts{receipt}
579573
case 1000:
580574
receipt := types.NewReceipt(nil, new(big.Int))
581-
receipt.Logs = vm.Logs{&vm.Log{Address: addr2}}
575+
receipt.Logs = []*types.Log{{Address: addr2}}
582576
gen.AddUncheckedReceipt(receipt)
583577
receipts = types.Receipts{receipt}
584578

core/events.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
"github.com/ethereum/go-ethereum/common"
2323
"github.com/ethereum/go-ethereum/core/types"
24-
"github.com/ethereum/go-ethereum/core/vm"
2524
)
2625

2726
// TxPreEvent is posted when a transaction enters the transaction pool.
@@ -32,7 +31,7 @@ type TxPostEvent struct{ Tx *types.Transaction }
3231

3332
// PendingLogsEvent is posted pre mining and notifies of pending logs.
3433
type PendingLogsEvent struct {
35-
Logs vm.Logs
34+
Logs []*types.Log
3635
}
3736

3837
// PendingStateEvent is posted pre mining and notifies of pending state changes.
@@ -45,18 +44,18 @@ type NewMinedBlockEvent struct{ Block *types.Block }
4544
type RemovedTransactionEvent struct{ Txs types.Transactions }
4645

4746
// RemovedLogEvent is posted when a reorg happens
48-
type RemovedLogsEvent struct{ Logs vm.Logs }
47+
type RemovedLogsEvent struct{ Logs []*types.Log }
4948

5049
// ChainSplit is posted when a new head is detected
5150
type ChainSplitEvent struct {
5251
Block *types.Block
53-
Logs vm.Logs
52+
Logs []*types.Log
5453
}
5554

5655
type ChainEvent struct {
5756
Block *types.Block
5857
Hash common.Hash
59-
Logs vm.Logs
58+
Logs []*types.Log
6059
}
6160

6261
type ChainSideEvent struct {
@@ -65,7 +64,7 @@ type ChainSideEvent struct {
6564

6665
type PendingBlockEvent struct {
6766
Block *types.Block
68-
Logs vm.Logs
67+
Logs []*types.Log
6968
}
7069

7170
type ChainUncleEvent struct {

core/state/statedb.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"sync"
2525

2626
"github.com/ethereum/go-ethereum/common"
27+
"github.com/ethereum/go-ethereum/core/types"
2728
"github.com/ethereum/go-ethereum/core/vm"
2829
"github.com/ethereum/go-ethereum/crypto"
2930
"github.com/ethereum/go-ethereum/ethdb"
@@ -71,7 +72,7 @@ type StateDB struct {
7172

7273
thash, bhash common.Hash
7374
txIndex int
74-
logs map[common.Hash]vm.Logs
75+
logs map[common.Hash][]*types.Log
7576
logSize uint
7677

7778
// Journal of state modifications. This is the backbone of
@@ -97,7 +98,7 @@ func New(root common.Hash, db ethdb.Database) (*StateDB, error) {
9798
stateObjects: make(map[common.Address]*StateObject),
9899
stateObjectsDirty: make(map[common.Address]struct{}),
99100
refund: new(big.Int),
100-
logs: make(map[common.Hash]vm.Logs),
101+
logs: make(map[common.Hash][]*types.Log),
101102
}, nil
102103
}
103104

@@ -118,7 +119,7 @@ func (self *StateDB) New(root common.Hash) (*StateDB, error) {
118119
stateObjects: make(map[common.Address]*StateObject),
119120
stateObjectsDirty: make(map[common.Address]struct{}),
120121
refund: new(big.Int),
121-
logs: make(map[common.Hash]vm.Logs),
122+
logs: make(map[common.Hash][]*types.Log),
122123
}, nil
123124
}
124125

@@ -138,7 +139,7 @@ func (self *StateDB) Reset(root common.Hash) error {
138139
self.thash = common.Hash{}
139140
self.bhash = common.Hash{}
140141
self.txIndex = 0
141-
self.logs = make(map[common.Hash]vm.Logs)
142+
self.logs = make(map[common.Hash][]*types.Log)
142143
self.logSize = 0
143144
self.clearJournalAndRefund()
144145

@@ -175,7 +176,7 @@ func (self *StateDB) StartRecord(thash, bhash common.Hash, ti int) {
175176
self.txIndex = ti
176177
}
177178

178-
func (self *StateDB) AddLog(log *vm.Log) {
179+
func (self *StateDB) AddLog(log *types.Log) {
179180
self.journal = append(self.journal, addLogChange{txhash: self.thash})
180181

181182
log.TxHash = self.thash
@@ -186,12 +187,12 @@ func (self *StateDB) AddLog(log *vm.Log) {
186187
self.logSize++
187188
}
188189

189-
func (self *StateDB) GetLogs(hash common.Hash) vm.Logs {
190+
func (self *StateDB) GetLogs(hash common.Hash) []*types.Log {
190191
return self.logs[hash]
191192
}
192193

193-
func (self *StateDB) Logs() vm.Logs {
194-
var logs vm.Logs
194+
func (self *StateDB) Logs() []*types.Log {
195+
var logs []*types.Log
195196
for _, lgs := range self.logs {
196197
logs = append(logs, lgs...)
197198
}
@@ -474,7 +475,7 @@ func (self *StateDB) Copy() *StateDB {
474475
stateObjects: make(map[common.Address]*StateObject, len(self.stateObjectsDirty)),
475476
stateObjectsDirty: make(map[common.Address]struct{}, len(self.stateObjectsDirty)),
476477
refund: new(big.Int).Set(self.refund),
477-
logs: make(map[common.Hash]vm.Logs, len(self.logs)),
478+
logs: make(map[common.Hash][]*types.Log, len(self.logs)),
478479
logSize: self.logSize,
479480
}
480481
// Copy the dirty states and logs
@@ -483,7 +484,7 @@ func (self *StateDB) Copy() *StateDB {
483484
state.stateObjectsDirty[addr] = struct{}{}
484485
}
485486
for hash, logs := range self.logs {
486-
state.logs[hash] = make(vm.Logs, len(logs))
487+
state.logs[hash] = make([]*types.Log, len(logs))
487488
copy(state.logs[hash], logs)
488489
}
489490
return state

core/state/statedb_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"testing/quick"
3030

3131
"github.com/ethereum/go-ethereum/common"
32-
"github.com/ethereum/go-ethereum/core/vm"
32+
"github.com/ethereum/go-ethereum/core/types"
3333
"github.com/ethereum/go-ethereum/ethdb"
3434
)
3535

@@ -221,7 +221,7 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction {
221221
fn: func(a testAction, s *StateDB) {
222222
data := make([]byte, 2)
223223
binary.BigEndian.PutUint16(data, uint16(a.args[0]))
224-
s.AddLog(&vm.Log{Address: addr, Data: data})
224+
s.AddLog(&types.Log{Address: addr, Data: data})
225225
},
226226
args: make([]int64, 1),
227227
},

core/state_processor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain) *StateProcess
5757
// Process returns the receipts and logs accumulated during the process and
5858
// returns the amount of gas that was used in the process. If any of the
5959
// transactions failed to execute due to insufficient gas it will return an error.
60-
func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, vm.Logs, *big.Int, error) {
60+
func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, *big.Int, error) {
6161
var (
6262
receipts types.Receipts
6363
totalUsedGas = big.NewInt(0)
6464
err error
6565
header = block.Header()
66-
allLogs vm.Logs
66+
allLogs []*types.Log
6767
gp = new(GasPool).AddGas(block.GasLimit())
6868
)
6969
// Mutate the the block and state according to any hard-fork specs

core/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ type HeaderValidator interface {
5858
// of gas used in the process and return an error if any of the internal rules
5959
// failed.
6060
type Processor interface {
61-
Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, vm.Logs, *big.Int, error)
61+
Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, *big.Int, error)
6262
}

core/types/bloom9.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/ethereum/go-ethereum/common"
2424
"github.com/ethereum/go-ethereum/common/hexutil"
25-
"github.com/ethereum/go-ethereum/core/vm"
2625
"github.com/ethereum/go-ethereum/crypto"
2726
)
2827

@@ -95,7 +94,7 @@ func CreateBloom(receipts Receipts) Bloom {
9594
return BytesToBloom(bin.Bytes())
9695
}
9796

98-
func LogsBloom(logs vm.Logs) *big.Int {
97+
func LogsBloom(logs []*Log) *big.Int {
9998
bin := new(big.Int)
10099
for _, log := range logs {
101100
data := make([]common.Hash, len(log.Topics))

0 commit comments

Comments
 (0)