-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debug trace tx changes #2230
Debug trace tx changes #2230
Changes from all commits
4c4b0ca
22ebd86
7e0e446
134036e
2e275f8
f6cb6eb
8f611cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,11 +18,13 @@ | |
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
|
||
tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
ethtypes "github.com/ethereum/go-ethereum/core/types" | ||
evmtypes "github.com/evmos/ethermint/x/evm/types" | ||
"github.com/pkg/errors" | ||
rpctypes "github.com/zeta-chain/zetacore/rpc/types" | ||
|
@@ -49,6 +51,11 @@ | |
return nil, err | ||
} | ||
|
||
blockResult, err := b.TendermintBlockResultByNumber(&blk.Block.Height) | ||
if err != nil { | ||
return nil, fmt.Errorf("block result not found for height %d", blk.Block.Height) | ||
} | ||
|
||
// check tx index is not out of bound | ||
// #nosec G701 txs number in block is always less than MaxUint32 | ||
if uint32(len(blk.Block.Txs)) < transaction.TxIndex { | ||
|
@@ -57,18 +64,24 @@ | |
} | ||
|
||
var predecessors []*evmtypes.MsgEthereumTx | ||
for _, txBz := range blk.Block.Txs[:transaction.TxIndex] { | ||
for i, txBz := range blk.Block.Txs[:transaction.TxIndex] { | ||
tx, err := b.clientCtx.TxConfig.TxDecoder()(txBz) | ||
if err != nil { | ||
b.logger.Debug("failed to decode transaction in block", "height", blk.Block.Height, "error", err.Error()) | ||
continue | ||
} | ||
for _, msg := range tx.GetMsgs() { | ||
ethMsg, ok := msg.(*evmtypes.MsgEthereumTx) | ||
if !ok { | ||
|
||
// get parsed eth txs from events from tx result | ||
parsed, err := rpctypes.ParseTxResult(blockResult.TxsResults[i], tx) | ||
Check failure on line 75 in rpc/backend/tracing.go GitHub Actions / lint
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, parsedTx := range parsed.Txs { | ||
ethMsg := getMsgEthereumTxFromParsedTx(parsedTx, tx) | ||
if ethMsg == nil { | ||
continue | ||
} | ||
|
||
predecessors = append(predecessors, ethMsg) | ||
} | ||
} | ||
|
@@ -79,24 +92,30 @@ | |
return nil, err | ||
} | ||
|
||
// add predecessor messages in current cosmos tx | ||
// #nosec G701 always in range | ||
for i := 0; i < int(transaction.MsgIndex); i++ { | ||
ethMsg, ok := tx.GetMsgs()[i].(*evmtypes.MsgEthereumTx) | ||
if !ok { | ||
// get parsed eth txs from events from tx result | ||
parsed, err := rpctypes.ParseTxResult(blockResult.TxsResults[transaction.TxIndex], tx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// iterate parsed eth txs, if its type 88, recreate it and get MsgEthereumTx, otherwise pull it from sdk.Msgs | ||
// when requested tx is found, break, no more predecessors | ||
var ethMsg *evmtypes.MsgEthereumTx | ||
for _, parsedTx := range parsed.Txs { | ||
ethMsg = getMsgEthereumTxFromParsedTx(parsedTx, tx) | ||
if parsedTx.Hash.Hex() == hash.Hex() { | ||
if ethMsg == nil { | ||
return nil, errors.New("error while parsing tx") | ||
} | ||
break | ||
} | ||
if ethMsg == nil { | ||
continue | ||
} | ||
predecessors = append(predecessors, ethMsg) | ||
} | ||
|
||
ethMessage, ok := tx.GetMsgs()[transaction.MsgIndex].(*evmtypes.MsgEthereumTx) | ||
if !ok { | ||
b.logger.Debug("invalid transaction type", "type", fmt.Sprintf("%T", tx)) | ||
return nil, fmt.Errorf("invalid transaction type %T", tx) | ||
} | ||
|
||
traceTxRequest := evmtypes.QueryTraceTxRequest{ | ||
Msg: ethMessage, | ||
Msg: ethMsg, | ||
Predecessors: predecessors, | ||
BlockNumber: blk.Block.Height, | ||
BlockTime: blk.Block.Time, | ||
|
@@ -131,7 +150,37 @@ | |
return decodedResult, nil | ||
} | ||
|
||
func getMsgEthereumTxFromParsedTx(parsedTx rpctypes.ParsedTx, tx sdk.Tx) *evmtypes.MsgEthereumTx { | ||
if parsedTx.Type == 88 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should precise in comment what does it represent |
||
recipient := parsedTx.Recipient | ||
// TODO: is this ok? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so, we should explain in comment for signature not set |
||
t := ethtypes.NewTx(ðtypes.LegacyTx{ | ||
Nonce: parsedTx.Nonce, | ||
Data: parsedTx.Data, | ||
Gas: parsedTx.GasUsed, | ||
To: &recipient, | ||
GasPrice: nil, | ||
Value: parsedTx.Amount, | ||
V: big.NewInt(0), | ||
R: big.NewInt(0), | ||
S: big.NewInt(0), | ||
}) | ||
ethMsg := &evmtypes.MsgEthereumTx{} | ||
err := ethMsg.FromEthereumTx(t) | ||
if err != nil { | ||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't return an error here? |
||
} | ||
return ethMsg | ||
} else { | ||
ethMsg, ok := tx.GetMsgs()[parsedTx.MsgIndex].(*evmtypes.MsgEthereumTx) | ||
if !ok { | ||
return nil | ||
} | ||
return ethMsg | ||
} | ||
} | ||
|
||
// TraceBlock configures a new tracer according to the provided configuration, and | ||
Check warning on line 183 in rpc/backend/tracing.go GitHub Actions / lint
|
||
// executes all the transactions contained within. The return value will be one item | ||
// per transaction, dependent on the requested tracer. | ||
func (b *Backend) TraceBlock(height rpctypes.BlockNumber, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -688,7 +688,6 @@ | |
if gasLimit != nil { | ||
gasCap = gasLimit.Uint64() | ||
} | ||
|
||
msg := ethtypes.NewMessage( | ||
from, | ||
contract, | ||
|
@@ -756,6 +755,8 @@ | |
} | ||
|
||
if !noEthereumTxEvent { | ||
attrs = append(attrs, sdk.NewAttribute("TxData", hexutil.Encode(msg.Data()))) // adding txData for more info in rpc methods | ||
attrs = append(attrs, sdk.NewAttribute("TxNonce", fmt.Sprint(nonce))) // adding nonce for more info in rpc methods | ||
Comment on lines
+758
to
+759
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments should be above the line. And I think we can make these more descriptive |
||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
evmtypes.EventTypeEthereumTx, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/zeta-chain/ethermint/pull/41/files