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

add litedebug mode #124

Merged
merged 3 commits into from
Aug 8, 2023
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
5 changes: 4 additions & 1 deletion .github/workflows/hive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ jobs:
run: |
cd $GITHUB_WORKSPACE/hive && ./hive --panic --client kcc --sim 'kcc/ishikari-(distri|multinode|singlenode)' \
${{ inputs.hive_extra_flags }}

- name: "[hive] litedebug mode"
run: |
cd $GITHUB_WORKSPACE/hive && ./hive --panic --client kcc --sim 'kcc/litedebug' \
${{ inputs.hive_extra_flags }}
48 changes: 48 additions & 0 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,5 +921,53 @@ func APIs(backend Backend) []rpc.API {
Namespace: "debug",
Service: NewAPI(backend),
},
{
Namespace: "litedebug",
Service: NewLightAPI(backend),
},
}
}

// The Light API is a very simple wrapper around "API"
// Rather than expose a lot of tracing API,
// LightAPI only exposes the following methods:
//
// - TraceTransaction
// - TraceBlockByNumber
// - TraceBlockByHash
// - TraceCall
//
// And also note that all the methods in "litedebug" module will be exposed
// in the "debug" module. Which means you will not call "litedebug_traceTransaction" but
// "debug_traceTransaction" instead.
//
// See node/rpcstack.go:mapNamespace
type LightAPI struct {
internal *API
}

// TraceTransaction
func (api *LightAPI) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig) (interface{}, error) {
return api.internal.TraceTransaction(ctx, hash, config)
}

// TraceBlockByNumber
func (api *LightAPI) TraceBlockByNumber(ctx context.Context, number rpc.BlockNumber, config *TraceConfig) ([]*txTraceResult, error) {
return api.internal.TraceBlockByNumber(ctx, number, config)
}

// TraceBlockByHash
func (api *LightAPI) TraceBlockByHash(ctx context.Context, hash common.Hash, config *TraceConfig) ([]*txTraceResult, error) {
return api.internal.TraceBlockByHash(ctx, hash, config)
}

// TraceCall
func (api *LightAPI) TraceCall(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig) (interface{}, error) {
return api.internal.TraceCall(ctx, args, blockNrOrHash, config)
}

func NewLightAPI(b Backend) *LightAPI {
return &LightAPI{
internal: NewAPI(b),
}
}
14 changes: 13 additions & 1 deletion node/rpcstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,22 @@ func RegisterApis(apis []rpc.API, modules []string, srv *rpc.Server) error {
// Register all the APIs exposed by the services
for _, api := range apis {
if allowList[api.Namespace] || len(allowList) == 0 {
if err := srv.RegisterName(api.Namespace, api.Service); err != nil {
ns := mapNamespace(api.Namespace)
if err := srv.RegisterName(ns, api.Service); err != nil {
return err
}
}
}
return nil
}

// module to namespace mapping
// - methods in "litedebug" module are exposed in "debug" namespace
func mapNamespace(module string) string {
switch module {
case "litedebug":
return "debug"
default:
return module
}
}