Skip to content

Add more data into the execution trace #20

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

Merged
merged 86 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 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
ccc24f3
Upgrade blockResult
mask-pp Jan 28, 2022
b5d071d
Upgrade blockResult
mask-pp Jan 28, 2022
b42f833
Merge branch 'scroll-tech:zkrollup' into zkrollup
mask-pp Jan 28, 2022
1392d81
Merge branch 'zkrollup' of github.com:mask-pp/go-ethereum into blockR…
mask-pp Jan 28, 2022
22e49f6
Bug fix and merge from zkrollup branch.
mask-pp Jan 28, 2022
f54e163
Rename BlockResultByHash to GetBlockResultByHash
mask-pp Jan 28, 2022
086d7ef
Include SLOAD proof
mask-pp Jan 28, 2022
7d169e2
Rename proof to storageProof
mask-pp Jan 28, 2022
00e26ae
Rename `CaptureStateSpecial` to `CaptureStateAfter`
mask-pp Feb 8, 2022
98baf14
Remove the result of opcode's ReturnData.
mask-pp Feb 8, 2022
5a7e42d
fix side-effect
mask-pp Feb 8, 2022
982f7fa
Marshal block and transaction.
mask-pp Feb 8, 2022
83622ac
Fix bug about rlp encode and decode func
mask-pp Feb 8, 2022
09d1a86
Rename fillBlockResult to writeBlockResult
mask-pp Feb 8, 2022
b1f3a94
Data field converts to hexadecimal format
mask-pp Feb 8, 2022
12c6951
Rename to StorageProof
mask-pp Feb 9, 2022
3a5224a
Delete blockResult db operation interface
mask-pp Feb 9, 2022
35dd23a
Add tx's to address for trace
mask-pp Feb 9, 2022
e1a087c
Record trace for special opcodes.
mask-pp Feb 9, 2022
39f0dfd
fix bug about test
mask-pp Feb 9, 2022
1f57eab
Fix a bug about tx executed status
mask-pp Feb 10, 2022
f4c5365
Restore mistaken change
mask-pp Feb 10, 2022
71912fe
Update eth/api.go
mask-pp Feb 11, 2022
8fa206a
revert StorageProof to Proof
mask-pp Feb 11, 2022
664cd58
Update core/vm/logger_trace.go
mask-pp Feb 11, 2022
0b536a7
Update core/types/l2trace_block.go
mask-pp Feb 11, 2022
22b45dd
Update core/types/l2trace_block.go
mask-pp Feb 11, 2022
d4169bd
Merge branch 'scroll-tech:zkrollup' into blockResult
mask-pp Feb 11, 2022
68e379f
Update core/types/l2trace.go
mask-pp Feb 11, 2022
743bee9
Fix inappropriate code and comment.
mask-pp Feb 11, 2022
1671659
Merge branch 'blockResult' of github.com:mask-pp/go-ethereum into blo…
mask-pp Feb 11, 2022
55b09cc
Rename XXTrace to TraceXX
mask-pp Feb 11, 2022
a459fa0
Update core/types/l2trace.go
mask-pp Feb 11, 2022
713e575
Reduced coding volume
mask-pp Feb 11, 2022
d55d98b
Merge branch 'blockResult' of github.com:mask-pp/go-ethereum into blo…
mask-pp Feb 11, 2022
bc1ea5a
bug fix
mask-pp Feb 11, 2022
56d63dc
add 0x prefix
mask-pp Feb 11, 2022
27494b9
Update core/vm/logger_trace.go
mask-pp Feb 18, 2022
5e86c42
Update core/vm/logger_trace.go
mask-pp Feb 18, 2022
12a7463
Merge branch 'scroll-tech:zkrollup' into blockResult
mask-pp Feb 18, 2022
d282350
Change to use contract caller's proof
mask-pp Feb 20, 2022
e7a1bfa
Add opcode trace func of created contract address proof
mask-pp Feb 21, 2022
ecb4d94
format import order
mask-pp Feb 21, 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
91 changes: 65 additions & 26 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

lru "github.com/hashicorp/golang-lru"
"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/common/hexutil"
"github.com/scroll-tech/go-ethereum/common/mclock"
"github.com/scroll-tech/go-ethereum/common/prque"
"github.com/scroll-tech/go-ethereum/consensus"
Expand Down Expand Up @@ -84,13 +85,14 @@ var (
)

const (
bodyCacheLimit = 256
blockCacheLimit = 256
receiptsCacheLimit = 32
txLookupCacheLimit = 1024
maxFutureBlocks = 256
maxTimeFutureBlocks = 30
TriesInMemory = 128
bodyCacheLimit = 256
blockCacheLimit = 256
receiptsCacheLimit = 32
txLookupCacheLimit = 1024
maxFutureBlocks = 256
maxTimeFutureBlocks = 30
TriesInMemory = 128
blockResultCacheLimit = 128

// BlockChainVersion ensures that an incompatible database forces a resync from scratch.
//
Expand Down Expand Up @@ -191,13 +193,14 @@ type BlockChain struct {
currentBlock atomic.Value // Current head of the block chain
currentFastBlock atomic.Value // Current head of the fast-sync chain (may be above the block chain!)

stateCache state.Database // State database to reuse between imports (contains state cache)
bodyCache *lru.Cache // Cache for the most recent block bodies
bodyRLPCache *lru.Cache // Cache for the most recent block bodies in RLP encoded format
receiptsCache *lru.Cache // Cache for the most recent receipts per block
blockCache *lru.Cache // Cache for the most recent entire blocks
txLookupCache *lru.Cache // Cache for the most recent transaction lookup data.
futureBlocks *lru.Cache // future blocks are blocks added for later processing
stateCache state.Database // State database to reuse between imports (contains state cache)
bodyCache *lru.Cache // Cache for the most recent block bodies
bodyRLPCache *lru.Cache // Cache for the most recent block bodies in RLP encoded format
receiptsCache *lru.Cache // Cache for the most recent receipts per block
blockCache *lru.Cache // Cache for the most recent entire blocks
txLookupCache *lru.Cache // Cache for the most recent transaction lookup data.
futureBlocks *lru.Cache // future blocks are blocks added for later processing
blockResultCache *lru.Cache // Cache for the most recent block results.

wg sync.WaitGroup //
quit chan struct{} // shutdown signal, closed in Stop.
Expand Down Expand Up @@ -226,6 +229,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
blockCache, _ := lru.New(blockCacheLimit)
txLookupCache, _ := lru.New(txLookupCacheLimit)
futureBlocks, _ := lru.New(maxFutureBlocks)
blockResultCache, _ := lru.New(blockResultCacheLimit)

bc := &BlockChain{
chainConfig: chainConfig,
Expand All @@ -237,17 +241,18 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
Journal: cacheConfig.TrieCleanJournal,
Preimages: cacheConfig.Preimages,
}),
quit: make(chan struct{}),
chainmu: syncx.NewClosableMutex(),
shouldPreserve: shouldPreserve,
bodyCache: bodyCache,
bodyRLPCache: bodyRLPCache,
receiptsCache: receiptsCache,
blockCache: blockCache,
txLookupCache: txLookupCache,
futureBlocks: futureBlocks,
engine: engine,
vmConfig: vmConfig,
quit: make(chan struct{}),
chainmu: syncx.NewClosableMutex(),
shouldPreserve: shouldPreserve,
bodyCache: bodyCache,
bodyRLPCache: bodyRLPCache,
receiptsCache: receiptsCache,
blockCache: blockCache,
txLookupCache: txLookupCache,
futureBlocks: futureBlocks,
blockResultCache: blockResultCache,
engine: engine,
vmConfig: vmConfig,
}
bc.validator = NewBlockValidator(chainConfig, bc, engine)
bc.prefetcher = newStatePrefetcher(chainConfig, bc, engine)
Expand Down Expand Up @@ -1215,7 +1220,6 @@ 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.WriteBlockResult(blockBatch, block.Hash(), blockResult)
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,6 +1318,12 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
}
bc.futureBlocks.Remove(block.Hash())

// Fill blockResult content
if blockResult != nil {
bc.writeBlockResult(state, block, blockResult)
bc.blockResultCache.Add(block.Hash(), blockResult)
}

if status == CanonStatTy {
bc.chainFeed.Send(ChainEvent{Block: block, Hash: block.Hash(), Logs: logs, BlockResult: blockResult})
if len(logs) > 0 {
Expand All @@ -1333,6 +1343,35 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
return status, nil
}

// Fill blockResult content
func (bc *BlockChain) writeBlockResult(state *state.StateDB, block *types.Block, blockResult *types.BlockResult) {
blockResult.BlockTrace = types.NewTraceBlock(bc.chainConfig, block)
for i, tx := range block.Transactions() {
evmTrace := blockResult.ExecutionResults[i]
// Get the sender's address.
from, _ := types.Sender(types.MakeSigner(bc.chainConfig, block.Number()), tx)
// Get account's proof.
proof, err := state.GetProof(from)
if err != nil {
log.Error("Failed to get proof", "blockNumber", block.NumberU64(), "address", from.String(), "err", err)
} else {
evmTrace.Proof = make([]string, len(proof))
for i := range proof {
evmTrace.Proof[i] = hexutil.Encode(proof[i])
}
}
// Contract is called
if len(tx.Data()) != 0 && tx.To() != nil {
evmTrace.ByteCode = hexutil.Encode(state.GetCode(*tx.To()))
// Get tx.to address's code hash.
codeHash := state.GetCodeHash(*tx.To())
evmTrace.CodeHash = &codeHash
} else if tx.To() == nil { // Contract is created.
evmTrace.ByteCode = hexutil.Encode(tx.Data())
}
}
}

// addFutureBlock checks if the block is within the max allowed window to get
// accepted for future processing, and returns an error if the block is too far
// ahead and was not added.
Expand Down
7 changes: 7 additions & 0 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block {
return bc.GetBlock(hash, *number)
}

func (bc *BlockChain) GetBlockResultByHash(blockHash common.Hash) *types.BlockResult {
if blockResult, ok := bc.blockResultCache.Get(blockHash); ok {
return blockResult.(*types.BlockResult)
}
return nil
}

// GetBlockByNumber retrieves a block from the database by number, caching it
// (associated with its hash) if found.
func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block {
Expand Down
1 change: 1 addition & 0 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
func NewEVMTxContext(msg Message) vm.TxContext {
return vm.TxContext{
Origin: msg.From(),
To: msg.To(),
GasPrice: new(big.Int).Set(msg.GasPrice()),
}
}
Expand Down
39 changes: 0 additions & 39 deletions core/rawdb/l2trace.go

This file was deleted.

Loading