8000 tracers: refactor tracer api and avoid OOM while tracing by yoomee1313 · Pull Request #1581 · klaytn/klaytn · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

tracers: refactor tracer api and avoid OOM while tracing #1581

Merged
merged 6 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion build/update-license.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ var (
"node/cn/handler.go": "eth/handler.go",
"node/cn/api_backend.go": "eth/api_backend.go",
"node/cn/api_sc_backend.go": "eth/api_backend.go",
"node/cn/api_tracer.go": "eth/api_tracer.go",
"node/cn/tracers/api.go": "eth/tracers/api.go",
"node/cn/config.go": "eth/config.go",
"node/cn/backend.go": "eth/backend.go",
"node/cn/sc_backend.go": "eth/backend.go",
Expand Down
1 change: 1 addition & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,7 @@ func MakeGenesis(ctx *cli.Context) *blockchain.Genesis {
// RegisterCNService adds a CN client to the stack.
func RegisterCNService(stack *node.Node, cfg *cn.Config) {
// TODO-Klaytn add syncMode.LightSync func and add LesServer

err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
cfg.WsEndpoint = stack.WSEndpoint()
fullNode, err := cn.New(ctx, cfg)
Expand Down
8 changes: 4 additions & 4 deletions datasync/chaindatafetcher/chaindata_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/klaytn/klaytn/networks/p2p"
"github.com/klaytn/klaytn/networks/rpc"
"github.com/klaytn/klaytn/node"
"github.com/klaytn/klaytn/node/cn"
"github.com/klaytn/klaytn/node/cn/tracers"
"github.com/rcrowley/go-metrics"
)

Expand All @@ -63,7 +63,7 @@ type ChainDataFetcher struct {
config *ChainDataFetcherConfig

blockchain BlockChain
debugAPI *cn.PrivateDebugAPI
debugAPI *tracers.API

chainCh chan blockchain.ChainEvent
chainSub event.Subscription
Expand Down Expand Up @@ -281,7 +281,7 @@ func (f *ChainDataFetcher) makeChainEvent(blockNumber uint64) (blockchain.ChainE
if block.Transactions().Len() > 0 {
fct := "fastCallTracer"
timeout := "24h"
results, err := f.debugAPI.TraceBlockByNumber(context.Background(), rpc.BlockNumber(block.Number().Int64()), &cn.TraceConfig{
results, err := f.debugAPI.TraceBlockByNumber(context.Background(), rpc.BlockNumber(block.Number().Int64()), &tracers.TraceConfig{
Tracer: &fct,
Timeout: &timeout,
})
Expand Down Expand Up @@ -317,7 +317,7 @@ func (f *ChainDataFetcher) Components() []interface{} {
func (f *ChainDataFetcher) setDebugAPI(apis []rpc.API) {
for _, a := range apis {
switch s := a.Service.(type) {
case *cn.PrivateDebugAPI:
case *tracers.API:
f.debugAPI = s
}
}
Expand Down
2 changes: 1 addition & 1 deletion log/log_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"time"
)

// statsReportLimit is the time limit during working after which we always print
// StatsReportLimit is the time limit during working after which we always print
// out progress. This avoids the user wondering what's going on.
const StatsReportLimit = 10 * time.Second

Expand Down
7 changes: 6 additions & 1 deletion node/cn/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,12 @@ type storageEntry struct {

// StorageRangeAt returns the storage at the given block height and transaction index.
func (api *PrivateDebugAPI) StorageRangeAt(ctx context.Context, blockHash common.Hash, txIndex int, contractAddress common.Address, keyStart hexutil.Bytes, maxResult int) (StorageRangeResult, error) {
_, _, statedb, err := api.computeTxEnv(blockHash, txIndex, 0)
// Retrieve the block
block := api.cn.blockchain.GetBlockByHash(blockHash)
if block == nil {
return StorageRangeResult{}, fmt.Errorf("block %#x not found", blockHash)
}
_, _, statedb, err := api.cn.stateAtTransaction(block, txIndex, 0)
if err != nil {
return StorageRangeResult{}, err
}
Expand Down
8 changes: 8 additions & 0 deletions node/cn/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ func (b *CNAPIBackend) Engine() consensus.Engine {
return b.cn.engine
}

func (b *CNAPIBackend) StateAtBlock(ctx context.Context, block *types.Block, reexec uint64, base *state.StateDB, checkLive bool, preferDisk bool) (*state.StateDB, error) {
return b.cn.stateAtBlock(block, reexec, base, checkLive, preferDisk)
}

func (b *CNAPIBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (blockchain.Message, vm.Context, *state.StateDB, error) {
return b.cn.stateAtTransaction(block, txIndex, reexec)
}

func (b *CNAPIBackend) FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
}
233 changes: 0 additions & 233 deletions node/cn/api_tracer_test.go

This file was deleted.

7 changes: 7 additions & 0 deletions node/cn/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"github.com/klaytn/klaytn/node"
"github.com/klaytn/klaytn/node/cn/filters"
"github.com/klaytn/klaytn/node/cn/gasprice"
"github.com/klaytn/klaytn/node/cn/tracers"
"github.com/klaytn/klaytn/params"
"github.com/klaytn/klaytn/reward"
"github.com/klaytn/klaytn/rlp"
Expand Down Expand Up @@ -486,6 +487,7 @@ func (s *CN) APIs() []rpc.API {
governanceKlayAPI := governance.NewGovernanceKlayAPI(s.governance, s.blockchain)
publicGovernanceAPI := governance.NewGovernanceAPI(s.governance)
publicDownloaderAPI := downloader.NewPublicDownloaderAPI(s.protocolManager.Downloader(), s.eventMux)
privateTracerAPI := tracers.NewAPI(s.APIBackend)

ethAPI.SetPublicFilterAPI(publicFilterAPI)
ethAPI.SetGovernanceKlayAPI(governanceKlayAPI)
Expand Down Expand Up @@ -526,6 +528,11 @@ func (s *CN) APIs() []rpc.API {
Namespace: "debug",
Version: "1.0",
Service: NewPrivateDebugAPI(s.chainConfig, s),
}, {
Namespace: "debug",
Version: "1.0",
Service: privateTracerAPI,
Public: false,
}, {
Namespace: "net",
Version: "1.0",
Expand Down
1 change: 0 additions & 1 deletion node/cn/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Source Files

- api.go : provides private debug API related to block and state
- api_backend.go : implements CNAPIBackend which is a wrapper of CN to serve API requests
- api_tracer.go : provides private debug API related to trace chain, block and state
- backend.go : implements CN struct used for the Klaytn consensus node service
- bloombits.go : implements BloomIndexer, an indexer built with bloom bits for fast filtering
- channel_manager.go : implements ChannelManager struct, which is used to manage channel for each message
Expand Down
Loading
0