Skip to content

Commit

Permalink
use actual type for txIndex and clauseIndex in tracer.Context
Browse files Browse the repository at this point in the history
  • Loading branch information
libotony committed Jan 18, 2024
1 parent b4244dc commit 38fe09b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions api/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func New(repo *chain.Repository, stater *state.Stater, forkConfig thor.ForkConfi
}
}

func (d *Debug) prepareClauseEnv(ctx context.Context, blockID thor.Bytes32, txIndex uint64, clauseIndex uint64) (*runtime.Runtime, *runtime.TransactionExecutor, thor.Bytes32, error) {
func (d *Debug) prepareClauseEnv(ctx context.Context, blockID thor.Bytes32, txIndex uint64, clauseIndex uint32) (*runtime.Runtime, *runtime.TransactionExecutor, thor.Bytes32, error) {

Check failure on line 56 in api/debug/debug.go

View workflow job for this annotation

GitHub Actions / golangci-lint

line is 183 characters (lll)
block, err := d.repo.GetBlock(blockID)
if err != nil {
if d.repo.IsNotFound(err) {
Expand All @@ -66,7 +66,7 @@ func (d *Debug) prepareClauseEnv(ctx context.Context, blockID thor.Bytes32, txIn
return nil, nil, thor.Bytes32{}, utils.Forbidden(errors.New("tx index out of range"))
}
txID := txs[txIndex].ID()
if clauseIndex >= uint64(len(txs[txIndex].Clauses())) {
if clauseIndex >= uint32(len(txs[txIndex].Clauses())) {

Check failure on line 69 in api/debug/debug.go

View workflow job for this annotation

GitHub Actions / golangci-lint

only one cuddle assignment allowed before if statement (wsl)
return nil, nil, thor.Bytes32{}, utils.Forbidden(errors.New("clause index out of range"))
}
skipPoA := d.repo.GenesisBlock().Header().ID() == devNetGenesisID
Expand All @@ -86,7 +86,7 @@ func (d *Debug) prepareClauseEnv(ctx context.Context, blockID thor.Bytes32, txIn
if err != nil {
return nil, nil, thor.Bytes32{}, err
}
clauseCounter := uint64(0)
clauseCounter := uint32(0)

Check failure on line 89 in api/debug/debug.go

View workflow job for this annotation

GitHub Actions / golangci-lint

assignments should only be cuddled with other assignments (wsl)
for txExec.HasNextClause() {
if txIndex == uint64(i) && clauseIndex == clauseCounter {
return rt, txExec, txID, nil
Expand All @@ -110,7 +110,7 @@ func (d *Debug) prepareClauseEnv(ctx context.Context, blockID thor.Bytes32, txIn
}

// trace an existed clause
func (d *Debug) traceClause(ctx context.Context, tracer tracers.Tracer, blockID thor.Bytes32, txIndex uint64, clauseIndex uint64) (interface{}, error) {
func (d *Debug) traceClause(ctx context.Context, tracer tracers.Tracer, blockID thor.Bytes32, txIndex uint64, clauseIndex uint32) (interface{}, error) {

Check failure on line 113 in api/debug/debug.go

View workflow job for this annotation

GitHub Actions / golangci-lint

line is 152 characters (lll)
rt, txExec, txID, err := d.prepareClauseEnv(ctx, blockID, txIndex, clauseIndex)
if err != nil {
return nil, err
Expand All @@ -120,8 +120,8 @@ func (d *Debug) traceClause(ctx context.Context, tracer tracers.Tracer, blockID
BlockID: blockID,
BlockTime: rt.Context().Time,
TxID: txID,
TxIndex: int(txIndex),
ClauseIndex: int(clauseIndex),
TxIndex: txIndex,
ClauseIndex: clauseIndex,
State: rt.State(),
})
rt.SetVMConfig(vm.Config{Tracer: tracer})
Expand Down Expand Up @@ -259,7 +259,7 @@ func (d *Debug) traceCall(ctx context.Context, tracer tracers.Tracer, summary *c
return tracer.GetResult()
}

func (d *Debug) debugStorage(ctx context.Context, contractAddress thor.Address, blockID thor.Bytes32, txIndex uint64, clauseIndex uint64, keyStart []byte, maxResult int) (*StorageRangeResult, error) {
func (d *Debug) debugStorage(ctx context.Context, contractAddress thor.Address, blockID thor.Bytes32, txIndex uint64, clauseIndex uint32, keyStart []byte, maxResult int) (*StorageRangeResult, error) {

Check failure on line 262 in api/debug/debug.go

View workflow job for this annotation

GitHub Actions / golangci-lint

line is 200 characters (lll)
rt, _, _, err := d.prepareClauseEnv(ctx, blockID, txIndex, clauseIndex)
if err != nil {
return nil, err
Expand Down Expand Up @@ -316,7 +316,7 @@ func (d *Debug) handleDebugStorage(w http.ResponseWriter, req *http.Request) err
return utils.WriteJSON(w, res)
}

func (d *Debug) parseTarget(target string) (blockID thor.Bytes32, txIndex uint64, clauseIndex uint64, err error) {
func (d *Debug) parseTarget(target string) (blockID thor.Bytes32, txIndex uint64, clauseIndex uint32, err error) {

Check failure on line 319 in api/debug/debug.go

View workflow job for this annotation

GitHub Actions / golangci-lint

calculated cyclomatic complexity for function parseTarget is 11, max is 10 (cyclop)
parts := strings.Split(target, "/")
if len(parts) != 3 {
return thor.Bytes32{}, 0, 0, utils.BadRequest(errors.New("target:" + target + " unsupported"))
Expand Down Expand Up @@ -346,10 +346,13 @@ func (d *Debug) parseTarget(target string) (blockID thor.Bytes32, txIndex uint64
}
txIndex = i
}
clauseIndex, err = strconv.ParseUint(parts[2], 0, 0)
i, err := strconv.ParseUint(parts[2], 0, 0)

Check failure on line 349 in api/debug/debug.go

View workflow job for this annotation

GitHub Actions / golangci-lint

assignments should only be cuddled with other assignments (wsl)
if err != nil {
return thor.Bytes32{}, 0, 0, utils.BadRequest(errors.WithMessage(err, "target[2]"))
} else if i > math.MaxUint32 {
return thor.Bytes32{}, 0, 0, utils.BadRequest(errors.New("invalid target[2]"))

Check failure on line 353 in api/debug/debug.go

View workflow job for this annotation

GitHub Actions / golangci-lint

error returned from external package is unwrapped: sig: func github.com/vechain/thor/v2/api/utils.BadRequest(cause error) error (wrapcheck)
}
clauseIndex = uint32(i)

Check failure on line 355 in api/debug/debug.go

View workflow job for this annotation

GitHub Actions / golangci-lint

assignments should only be cuddled with other assignments (wsl)
return
}

Expand Down
4 changes: 2 additions & 2 deletions tracers/tracers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
type Context struct {
BlockID thor.Bytes32 // Hash of the block the tx is contained within (zero if dangling tx or call)
BlockTime uint64 // Timestamp of the block the tx is contained within
TxIndex int // Index of the transaction within a block (zero if dangling tx or call)
TxIndex uint64 // Index of the transaction within a block (zero if dangling tx or call)
TxID thor.Bytes32 // ID of the transaction being traced (zero if dangling call)
ClauseIndex int // Index of the clause within a transaction (zero if dangling call)
ClauseIndex uint32 // Index of the clause within a transaction (zero if dangling call)
State *state.State
}

Expand Down

0 comments on commit 38fe09b

Please sign in to comment.