From 0c4b3222e54c5d848342f71c16b8efe38d13e5e4 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Mon, 13 Sep 2021 19:36:46 +0200 Subject: [PATCH] first version --- ethereum/rpc/namespaces/debug/api.go | 10 ++++++++-- x/evm/keeper/grpc_query.go | 11 +++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ethereum/rpc/namespaces/debug/api.go b/ethereum/rpc/namespaces/debug/api.go index c4d53f7725..85b20f627e 100644 --- a/ethereum/rpc/namespaces/debug/api.go +++ b/ethereum/rpc/namespaces/debug/api.go @@ -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 @@ -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{ diff --git a/x/evm/keeper/grpc_query.go b/x/evm/keeper/grpc_query.go index d6e146b73d..85d911a3fe 100644 --- a/x/evm/keeper/grpc_query.go +++ b/x/evm/keeper/grpc_query.go @@ -513,7 +513,7 @@ 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)) ) @@ -521,11 +521,10 @@ func (k Keeper) TraceBlock(c context.Context, req *types.QueryTraceBlockRequest) 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) @@ -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 { @@ -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()) }