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 Feb 23, 2024
1 parent 0997c25 commit 7518b78
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) {
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())) {
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)
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) {
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) {
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) {
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)
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]"))
}
clauseIndex = uint32(i)
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 7518b78

Please sign in to comment.