-
Notifications
You must be signed in to change notification settings - Fork 193
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
refactor(evm): converted untyped event to typed and cleaned up #2053
Changes from 6 commits
19e8815
1919734
ae1dac6
91a1674
5957c08
7acd795
2cc64b8
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 | ||||
---|---|---|---|---|---|---|
|
@@ -195,7 +195,7 @@ func generateStorageKey(key gethcommon.Address, slot uint64) string { | |||||
// Concatenate key and slot | ||||||
data := append(keyBytes, slotBytes...) | ||||||
|
||||||
// Hash the data using Keccak256 | ||||||
// EthHash the data using Keccak256 | ||||||
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.
Suggested change
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. Fixed |
||||||
hash := sha3.NewLegacyKeccak256() | ||||||
hash.Write(data) | ||||||
return gethcommon.BytesToHash(hash.Sum(nil)).Hex() | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,7 +6,6 @@ | |||||
"math" | ||||||
"math/big" | ||||||
"strconv" | ||||||
"strings" | ||||||
|
||||||
tmrpcclient "github.com/cometbft/cometbft/rpc/client" | ||||||
tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" | ||||||
|
@@ -334,16 +333,11 @@ | |||||
if event.Type != msgType { | ||||||
continue | ||||||
} | ||||||
|
||||||
for _, attr := range event.Attributes { | ||||||
if attr.Key == evm.AttributeKeyEthereumBloom { | ||||||
return gethcore.BytesToBloom( | ||||||
hexutils.HexToBytes( // Bloom stores hex bytes | ||||||
strings.ReplaceAll(attr.Value, `"`, ""), // Unquote typed event | ||||||
), | ||||||
), nil | ||||||
} | ||||||
blockBloomEvent, err := evm.EventBlockBloomFromABCIEvent(event) | ||||||
if err != nil { | ||||||
continue | ||||||
} | ||||||
return gethcore.BytesToBloom(hexutils.HexToBytes(blockBloomEvent.Bloom)), nil | ||||||
} | ||||||
return gethcore.Bloom{}, errors.New("block bloom event is not found") | ||||||
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.
Suggested change
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. Fixed |
||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,7 +7,6 @@ | |||||||||||||
"math/big" | ||||||||||||||
|
||||||||||||||
errorsmod "cosmossdk.io/errors" | ||||||||||||||
|
||||||||||||||
tmrpcclient "github.com/cometbft/cometbft/rpc/client" | ||||||||||||||
tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" | ||||||||||||||
sdk "github.com/cosmos/cosmos-sdk/types" | ||||||||||||||
|
@@ -307,7 +306,8 @@ | |||||||||||||
} | ||||||||||||||
|
||||||||||||||
// fallback to tendermint tx evmTxIndexer | ||||||||||||||
query := fmt.Sprintf("%s.%s='%s'", evm.TypeMsgEthereumTx, evm.AttributeKeyEthereumTxHash, hash.Hex()) | ||||||||||||||
query := fmt.Sprintf("%s.%s='%s'", evm.PendingEthereumTxEvent, evm.PendingEthereumTxEventAttrEthHash, hash.Hex()) | ||||||||||||||
|
||||||||||||||
txResult, err := b.queryTendermintTxIndexer(query, func(txs *rpc.ParsedTxs) *rpc.ParsedTx { | ||||||||||||||
return txs.GetTxByHash(hash) | ||||||||||||||
}) | ||||||||||||||
|
@@ -326,8 +326,9 @@ | |||||||||||||
|
||||||||||||||
// fallback to tendermint tx evmTxIndexer | ||||||||||||||
query := fmt.Sprintf("tx.height=%d AND %s.%s=%d", | ||||||||||||||
height, evm.TypeMsgEthereumTx, | ||||||||||||||
evm.AttributeKeyTxIndex, index, | ||||||||||||||
height, evm.PendingEthereumTxEventTxAttrIndex, | ||||||||||||||
evm.PendingEthereumTxEventTxAttrIndex, | ||||||||||||||
index, | ||||||||||||||
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. Incorrect query construction due to misuse of attribute key There is an issue with the query construction where Apply this diff to correct the query: query := fmt.Sprintf("tx.height=%d AND %s.%s=%d",
- height, evm.PendingEthereumTxEventTxAttrIndex,
+ height, evm.PendingEthereumTxEvent,
evm.PendingEthereumTxEventTxAttrIndex,
index,
) This correction ensures that the event type 📝 Committable suggestion
Suggested change
|
||||||||||||||
) | ||||||||||||||
txResult, err := b.queryTendermintTxIndexer(query, func(txs *rpc.ParsedTxs) *rpc.ParsedTx { | ||||||||||||||
return txs.GetTxByTxIndex(int(index)) // #nosec G701 -- checked for int overflow already | ||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,8 +8,10 @@ | |||||
"sort" | ||||||
"strings" | ||||||
|
||||||
"cosmossdk.io/errors" | ||||||
sdk "github.com/cosmos/cosmos-sdk/types" | ||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||||||
"github.com/cosmos/gogoproto/proto" | ||||||
"google.golang.org/grpc/codes" | ||||||
"google.golang.org/grpc/status" | ||||||
|
||||||
|
@@ -212,7 +214,7 @@ | |||||
func AllTxLogsFromEvents(events []abci.Event) ([][]*gethcore.Log, error) { | ||||||
allLogs := make([][]*gethcore.Log, 0, 4) | ||||||
for _, event := range events { | ||||||
if event.Type != evm.EventTypeTxLog { | ||||||
if event.Type != proto.MessageName((*evm.EventTxLog)(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.
Suggested change
Technically equivalent, but nil pointers look a bit concerning 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. Fixed |
||||||
continue | ||||||
} | ||||||
|
||||||
|
@@ -229,7 +231,7 @@ | |||||
// TxLogsFromEvents parses ethereum logs from cosmos events for specific msg index | ||||||
func TxLogsFromEvents(events []abci.Event, msgIndex int) ([]*gethcore.Log, error) { | ||||||
for _, event := range events { | ||||||
if event.Type != evm.EventTypeTxLog { | ||||||
if event.Type != proto.MessageName((*evm.EventTxLog)(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.
Suggested change
Technically equivalent, but nil pointers look a bit concerning 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. Fixed |
||||||
continue | ||||||
} | ||||||
|
||||||
|
@@ -246,20 +248,19 @@ | |||||
|
||||||
// ParseTxLogsFromEvent parse tx logs from one event | ||||||
func ParseTxLogsFromEvent(event abci.Event) ([]*gethcore.Log, error) { | ||||||
logs := make([]*evm.Log, 0, len(event.Attributes)) | ||||||
for _, attr := range event.Attributes { | ||||||
if attr.Key != evm.AttributeKeyTxLog { | ||||||
continue | ||||||
} | ||||||
|
||||||
var log evm.Log | ||||||
if err := json.Unmarshal([]byte(attr.Value), &log); err != nil { | ||||||
return nil, err | ||||||
eventTxLog, err := evm.EventTxLogFromABCIEvent(event) | ||||||
if err != nil { | ||||||
return nil, errors.Wrapf(err, "failed to parse event tx log") | ||||||
} | ||||||
var evmLogs []*evm.Log | ||||||
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. 🛠️ Refactor suggestion Preallocate slice capacity for efficiency To enhance performance by reducing allocations, preallocate the evmLogs := make([]*evm.Log, 0, len(eventTxLog.TxLogs)) |
||||||
for _, logString := range eventTxLog.TxLogs { | ||||||
var evmLog evm.Log | ||||||
if err = json.Unmarshal([]byte(logString), &evmLog); err != nil { | ||||||
return nil, errors.Wrapf(err, "failed unmarshal event tx log") | ||||||
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. Correct error message grammar Adjust the error message for grammatical clarity. Change: return nil, errors.Wrapf(err, "failed unmarshal event tx log") to: return nil, errors.Wrapf(err, "failed to unmarshal event tx log") |
||||||
} | ||||||
|
||||||
logs = append(logs, &log) | ||||||
evmLogs = append(evmLogs, &evmLog) | ||||||
} | ||||||
return evm.LogsToEthereum(logs), nil | ||||||
return evm.LogsToEthereum(evmLogs), nil | ||||||
} | ||||||
|
||||||
// ShouldIgnoreGasUsed returns true if the gasUsed in result should be ignored | ||||||
|
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.
Can you expand on what this comment means?
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.
Wrote a better comment