From 0ee058d753e12df847f1e56ee984c4edc6a54b7b Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Tue, 27 Aug 2024 10:41:20 +0100 Subject: [PATCH] Debug thor solo with different genesis (#828) * Debug thor solo with different genesis * remove contract call naming from docs * pr comments --- api/api.go | 3 ++- api/debug/debug.go | 18 ++++++++++++------ api/debug/debug_test.go | 2 +- api/doc/thor.yaml | 4 ++-- cmd/thor/main.go | 2 ++ 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/api/api.go b/api/api.go index 0ac399295..7e2f915be 100644 --- a/api/api.go +++ b/api/api.go @@ -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 { @@ -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") diff --git a/api/debug/debug.go b/api/debug/debug.go index 7eecd9b8c..ab2724e23 100644 --- a/api/debug/debug.go +++ b/api/debug/debug.go @@ -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" @@ -38,8 +37,6 @@ import ( const defaultMaxStorageResult = 1000 -var devNetGenesisID = genesis.NewDevnet().ID() - type Debug struct { repo *chain.Repository stater *state.Stater @@ -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, @@ -59,6 +65,7 @@ func New(repo *chain.Repository, stater *state.Stater, forkConfig thor.ForkConfi allowCustomTracer, bft, allowedTracers, + soloMode, } } @@ -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 } diff --git a/api/debug/debug_test.go b/api/debug/debug_test.go index 467fc95fb..681433ffb 100644 --- a/api/debug/debug_test.go +++ b/api/debug/debug_test.go @@ -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) } diff --git a/api/doc/thor.yaml b/api/doc/thor.yaml index 2769ca18b..24d62c3da 100644 --- a/api/doc/thor.yaml +++ b/api/doc/thor.yaml @@ -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. diff --git a/cmd/thor/main.go b/cmd/thor/main.go index a66dbc563..31aed525a 100644 --- a/cmd/thor/main.go +++ b/cmd/thor/main.go @@ -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() }() @@ -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() }()