Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
first version
Browse files Browse the repository at this point in the history
  • Loading branch information
crypto-facs committed Sep 13, 2021
1 parent bbcbf18 commit 0c4b322
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 8 additions & 2 deletions ethereum/rpc/namespaces/debug/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ func (a *API) TraceBlockByNumber(height rpctypes.BlockNumber, config *evmtypes.T
return res, nil
}

var (
results = make([]*types.TxTraceResult, len(txsLength))
wg = new(sync.WaitGroup)
jobs = make(chan *types.TxTraceTask, len(req.Transactions))
)

transactionsTraceRequest := make([]*evmtypes.TraceBlockTransaction, txsLength)

// Get all tx messages
Expand All @@ -142,8 +148,8 @@ func (a *API) TraceBlockByNumber(height rpctypes.BlockNumber, config *evmtypes.T

ethMessage, ok := tx.GetMsgs()[0].(*evmtypes.MsgEthereumTx)
if !ok {
a.logger.Debug("invalid transaction type", "type", fmt.Sprintf("%T", tx))
return nil, fmt.Errorf("invalid transaction type %T", tx)
// Just considers Ethereum transactions
continue
}

transactionsTraceRequest[i] = &evmtypes.TraceBlockTransaction{
Expand Down
11 changes: 5 additions & 6 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,19 +513,18 @@ func (k Keeper) TraceBlock(c context.Context, req *types.QueryTraceBlockRequest)
// Receive an array of transactions with MSGs and TxIndex
var (
results = make([]*types.TxTraceResult, len(req.Transactions))
pend = new(sync.WaitGroup)
wg = new(sync.WaitGroup)
jobs = make(chan *types.TxTraceTask, len(req.Transactions))
)

threads := runtime.NumCPU()
if threads > len(req.Transactions) {
threads = len(req.Transactions)
}

wg.Add(threads)
for th := 0; th < threads; th++ {
pend.Add(1)
go func() {
defer pend.Done()
defer wg.Done()
// Fetch and execute the next transaction trace tasks
for task := range jobs {
res, err := k.traceTx(coinbase, signer, req.Transactions[task.Index].Index, params, c, ctx, ethCfg, req.Transactions[task.Index].Msg, req.TraceConfig)
Expand All @@ -543,7 +542,7 @@ func (k Keeper) TraceBlock(c context.Context, req *types.QueryTraceBlockRequest)
}

close(jobs)
pend.Wait()
wg.Wait()

resultData, err := json.Marshal(results)
if err != nil {
Expand Down Expand Up @@ -579,7 +578,7 @@ func (k *Keeper) traceTx(coinbase common.Address, signer ethtypes.Signer, txInde
}

txContext := core.NewEVMTxContext(coreMessage)
// Constuct the JavaScript tracer to execute with
// Construct the JavaScript tracer to execute with
if tracer, err = tracers.New(traceConfig.Tracer, txContext); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down

0 comments on commit 0c4b322

Please sign in to comment.