Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract execution trace from EVM execution and provide subscription API #19

Merged
merged 43 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
22bd648
Create go.yml
mask-pp Jan 12, 2022
7bb4d77
Merge branch 'scroll-tech:zkrollup' into zkrollup
mask-pp Jan 13, 2022
e958633
Merge from zkrollup and fix conflict
mask-pp Jan 6, 2022
ed1a8a3
go mod tidy
mask-pp Jan 13, 2022
0efcb0a
fix worker_test test case
mask-pp Jan 13, 2022
9925d5f
fix worker_test test case
mask-pp Jan 13, 2022
cae5f4a
Delete go.yml
mask-pp Jan 13, 2022
a7072bc
Merge branch 'zkrollup' of github.com:mask-pp/go-ethereum into zkrollup
mask-pp Jan 13, 2022
65e5539
add log content, enable memory trace
mask-pp Jan 13, 2022
8368dca
add tracer pool handler
mask-pp Jan 13, 2022
3510875
Add comments and format code
mask-pp Jan 13, 2022
fc18a61
add evmTrace subscribe api
mask-pp Jan 17, 2022
7571c53
Move the evmTrace struct.
mask-pp Jan 18, 2022
f5446f3
Fix miner bug.
mask-pp Jan 18, 2022
5da523a
upgrade evmTrace api
mask-pp Jan 18, 2022
9aea333
fix bug about evmTracesByHash api
mask-pp Jan 19, 2022
e591323
Fix the bug about block.timestamp and remove unnecessary copy.
mask-pp Jan 19, 2022
dca013e
Update eth/filters/api.go
mask-pp Jan 20, 2022
a3ee4a6
Upgrade comments.
mask-pp Jan 20, 2022
1e807ae
Merge branch 'zkrollup' of github.com:mask-pp/go-ethereum into zkrollup
mask-pp Jan 20, 2022
5f945a2
Merge branch 'zkrollup' of github.com:mask-pp/go-ethereum into zkrollup
mask-pp Jan 20, 2022
5a309b4
Merge branch 'zkrollup' of github.com:mask-pp/go-ethereum into zkrollup
mask-pp Jan 20, 2022
53496e0
Delete useless code in test file
mask-pp Jan 20, 2022
74085e9
Update miner/worker.go
mask-pp Jan 20, 2022
a111436
Change the return result to BlockResult.
mask-pp Jan 20, 2022
78d8393
Change return type.
mask-pp Jan 20, 2022
e6f8b78
Change blockResult to blockResults.
mask-pp Jan 20, 2022
c3a52b6
Add ReturnValue.
mask-pp Jan 21, 2022
e613a6b
Update core/rawdb/l2trace.go
mask-pp Jan 21, 2022
adcb40d
Update core/rawdb/l2trace.go
mask-pp Jan 21, 2022
a0db670
Update core/types/l2trace.go
mask-pp Jan 21, 2022
3b8e1e1
Add indent to the comment and rm json encoding flag.
mask-pp Jan 21, 2022
db3557c
Rm json encoding flag.
mask-pp Jan 21, 2022
ced2001
Update core/rawdb/l2trace.go
mask-pp Jan 21, 2022
e67813d
Rm json encoding flag.
mask-pp Jan 21, 2022
fd05da5
Merge branch 'zkrollup' of github.com:mask-pp/go-ethereum into zkrollup
mask-pp Jan 21, 2022
36c0f14
Update ethclient/ethclient.go
mask-pp Jan 21, 2022
e187a7f
Update eth/filters/api.go
mask-pp Jan 21, 2022
ed57fe2
Use as the blockResult prefix flag.
mask-pp Jan 21, 2022
fc06df6
Update eth/filters/filter_system.go
mask-pp Jan 22, 2022
19f9e23
Update eth/filters/filter_system.go
mask-pp Jan 22, 2022
e5cacd0
Update ethclient/ethclient.go
mask-pp Jan 22, 2022
719ed61
Update eth/filters/api.go
mask-pp Jan 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ profile.cov
/dashboard/assets/package-lock.json

**/yarn-error.log

0xmountaintop marked this conversation as resolved.
Show resolved Hide resolved
# github
.github
12 changes: 7 additions & 5 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,17 +1182,18 @@ func (bc *BlockChain) writeKnownBlock(block *types.Block) error {
}

// WriteBlockWithState writes the block and all associated state to the database.
func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, evmTraces []*types.ExecutionResult, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
if !bc.chainmu.TryLock() {
return NonStatTy, errInsertionInterrupted
}
defer bc.chainmu.Unlock()
return bc.writeBlockWithState(block, receipts, logs, state, emitHeadEvent)
//rawdb.WriteEvmTraces(bc.db, block.Hash(), evmTraces)
mask-pp marked this conversation as resolved.
Show resolved Hide resolved
return bc.writeBlockWithState(block, receipts, logs, evmTraces, state, emitHeadEvent)
}

// writeBlockWithState writes the block and all associated state to the database,
// but is expects the chain mutex to be held.
func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, evmTraces []*types.ExecutionResult, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
if bc.insertStopped() {
return NonStatTy, errInsertionInterrupted
}
Expand All @@ -1215,6 +1216,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
rawdb.WriteTd(blockBatch, block.Hash(), block.NumberU64(), externTd)
rawdb.WriteBlock(blockBatch, block)
rawdb.WriteReceipts(blockBatch, block.Hash(), block.NumberU64(), receipts)
rawdb.WriteEvmTraces(blockBatch, block.Hash(), evmTraces)
rawdb.WritePreimages(blockBatch, state.Preimages())
if err := blockBatch.Write(); err != nil {
log.Crit("Failed to write block into disk", "err", err)
Expand Down Expand Up @@ -1314,7 +1316,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
bc.futureBlocks.Remove(block.Hash())

if status == CanonStatTy {
bc.chainFeed.Send(ChainEvent{Block: block, Hash: block.Hash(), Logs: logs})
bc.chainFeed.Send(ChainEvent{Block: block, Hash: block.Hash(), Logs: logs, Traces: evmTraces})
if len(logs) > 0 {
bc.logsFeed.Send(logs)
}
Expand Down Expand Up @@ -1644,7 +1646,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er

// Write the block to the chain and get the status.
substart = time.Now()
status, err := bc.writeBlockWithState(block, receipts, logs, statedb, false)
status, err := bc.writeBlockWithState(block, receipts, logs, nil, statedb, false)
jules marked this conversation as resolved.
Show resolved Hide resolved
atomic.StoreUint32(&followupInterrupt, 1)
if err != nil {
return it.index, err
Expand Down
7 changes: 4 additions & 3 deletions core/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ type NewMinedBlockEvent struct{ Block *types.Block }
type RemovedLogsEvent struct{ Logs []*types.Log }

type ChainEvent struct {
Block *types.Block
Hash common.Hash
Logs []*types.Log
Block *types.Block
Hash common.Hash
Logs []*types.Log
Traces []*types.ExecutionResult
}

type ChainSideEvent struct {
Expand Down
39 changes: 39 additions & 0 deletions core/rawdb/l2trace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package rawdb

import (
"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/ethdb"
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/rlp"
)

// ReadEvmTraces retrieves all the evmTraces belonging to a block.
func ReadEvmTraces(db ethdb.Reader, hash common.Hash) []*types.ExecutionResult {
data, _ := db.Get(evmTracesKey(hash))
if len(data) == 0 {
return nil
}
var evmTraces []*types.ExecutionResult
if err := rlp.DecodeBytes(data, &evmTraces); err != nil {
log.Error("Failed to decode evmTraces", "err", err)
mask-pp marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
return evmTraces
}

// WriteEvmTraces stores evmTrace list into leveldb.
func WriteEvmTraces(db ethdb.KeyValueWriter, hash common.Hash, evmTraces []*types.ExecutionResult) {
bytes, err := rlp.EncodeToBytes(evmTraces)
if err != nil {
log.Crit("Failed to RLP encode evmTraces", "err", err)
mask-pp marked this conversation as resolved.
Show resolved Hide resolved
}
db.Put(evmTracesKey(hash), bytes)
}

// DeleteEvmTraces removes all evmTraces with a block hash.
func DeleteEvmTraces(db ethdb.KeyValueWriter, hash common.Hash) {
if err := db.Delete(evmTracesKey(hash)); err != nil {
log.Crit("Failed to delete evmTraces", "err", err)
mask-pp marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading