Skip to content

Commit

Permalink
Debug thor solo with different genesis (#828)
Browse files Browse the repository at this point in the history
* Debug thor solo with different genesis

* remove contract call naming from docs

* pr comments
  • Loading branch information
otherview authored Aug 27, 2024
1 parent f1aa5ae commit 0ee058d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func New(
enableMetrics bool,
logsLimit uint64,
allowedTracers map[string]interface{},
soloMode bool,
) (http.HandlerFunc, func()) {
origins := strings.Split(strings.TrimSpace(allowedOrigins), ",")
for i, o := range origins {
Expand Down Expand Up @@ -83,7 +84,7 @@ func New(
Mount(router, "/blocks")
transactions.New(repo, txPool).
Mount(router, "/transactions")
debug.New(repo, stater, forkConfig, callGasLimit, allowCustomTracer, bft, allowedTracers).
debug.New(repo, stater, forkConfig, callGasLimit, allowCustomTracer, bft, allowedTracers, soloMode).
Mount(router, "/debug")
node.New(nw).
Mount(router, "/node")
Expand Down
18 changes: 12 additions & 6 deletions api/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/vechain/thor/v2/block"
"github.com/vechain/thor/v2/chain"
"github.com/vechain/thor/v2/consensus"
"github.com/vechain/thor/v2/genesis"
"github.com/vechain/thor/v2/muxdb"
"github.com/vechain/thor/v2/runtime"
"github.com/vechain/thor/v2/state"
Expand All @@ -38,8 +37,6 @@ import (

const defaultMaxStorageResult = 1000

var devNetGenesisID = genesis.NewDevnet().ID()

type Debug struct {
repo *chain.Repository
stater *state.Stater
Expand All @@ -48,9 +45,18 @@ type Debug struct {
allowCustomTracer bool
bft bft.Finalizer
allowedTracers map[string]interface{}
skipPoA bool
}

func New(repo *chain.Repository, stater *state.Stater, forkConfig thor.ForkConfig, callGaslimit uint64, allowCustomTracer bool, bft bft.Finalizer, allowedTracers map[string]interface{}) *Debug {
func New(
repo *chain.Repository,
stater *state.Stater,
forkConfig thor.ForkConfig,
callGaslimit uint64,
allowCustomTracer bool,
bft bft.Finalizer,
allowedTracers map[string]interface{},
soloMode bool) *Debug {
return &Debug{
repo,
stater,
Expand All @@ -59,6 +65,7 @@ func New(repo *chain.Repository, stater *state.Stater, forkConfig thor.ForkConfi
allowCustomTracer,
bft,
allowedTracers,
soloMode,
}
}

Expand All @@ -78,12 +85,11 @@ func (d *Debug) prepareClauseEnv(ctx context.Context, blockID thor.Bytes32, txIn
if clauseIndex >= uint32(len(txs[txIndex].Clauses())) {
return nil, nil, thor.Bytes32{}, utils.Forbidden(errors.New("clause index out of range"))
}
skipPoA := d.repo.GenesisBlock().Header().ID() == devNetGenesisID
rt, err := consensus.New(
d.repo,
d.stater,
d.forkConfig,
).NewRuntimeForReplay(block.Header(), skipPoA)
).NewRuntimeForReplay(block.Header(), d.skipPoA)
if err != nil {
return nil, nil, thor.Bytes32{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion api/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func initDebugServer(t *testing.T) {
forkConfig := thor.GetForkConfig(b.Header().ID())
router := mux.NewRouter()
allTracersEnabled := map[string]interface{}{"all": new(interface{})}
debug = New(repo, stater, forkConfig, 21000, true, solo.NewBFTEngine(repo), allTracersEnabled)
debug = New(repo, stater, forkConfig, 21000, true, solo.NewBFTEngine(repo), allTracersEnabled, false)
debug.Mount(router, "/debug")
ts = httptest.NewServer(router)
}
Expand Down
4 changes: 2 additions & 2 deletions api/doc/thor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,9 @@ paths:
post:
tags:
- Debug
summary: Trace a contract call
summary: Trace a call
description: |
This endpoint enables clients to create a tracer for a specific vechain function call.
This endpoint enables clients to create a tracer for a specific vechain clause.
You can customize the tracer using various options to suit your debugging requirements.
Expand Down
2 changes: 2 additions & 0 deletions cmd/thor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func defaultAction(ctx *cli.Context) error {
ctx.Bool(enableMetricsFlag.Name),
ctx.Uint64(apiLogsLimitFlag.Name),
parseTracerList(strings.TrimSpace(ctx.String(allowedTracersFlag.Name))),
false,
)
defer func() { log.Info("closing API..."); apiCloser() }()

Expand Down Expand Up @@ -416,6 +417,7 @@ func soloAction(ctx *cli.Context) error {
ctx.Bool(enableMetricsFlag.Name),
ctx.Uint64(apiLogsLimitFlag.Name),
parseTracerList(strings.TrimSpace(ctx.String(allowedTracersFlag.Name))),
true,
)
defer func() { log.Info("closing API..."); apiCloser() }()

Expand Down

0 comments on commit 0ee058d

Please sign in to comment.