Skip to content

Commit

Permalink
Merge pull request #124 from junnmm/junnmm/feat-lightdebug
Browse files Browse the repository at this point in the history
add litedebug mode
  • Loading branch information
viaweb3 committed Aug 8, 2023
2 parents 164ec6c + 7b5a95e commit 0cec1af
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
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
}
}

0 comments on commit 0cec1af

Please sign in to comment.