Skip to content
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

Add RFQ event decoder #1909

Merged
merged 3 commits into from
Feb 9, 2024
Merged

Add RFQ event decoder #1909

merged 3 commits into from
Feb 9, 2024

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Jan 22, 2024

Description
Adds a lightweight CLI for decoding RFQ events.

Pass the -d flag to provide the raw event data to the script:

go run main.go -d 0x00000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000a4b10000000000000000000000000b2c639c533813f4aa9d7837caf62653d097ff85000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000000000000000000000000000000000000105117f0000000000000000000000000000000000000000000000000000000001050b39c200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000a4b1000000000000000000000000a4f60bb657367bb05f93a95f5b1d1ae8a469f5ab000000000000000000000000a4f60bb657367bb05f93a95f5b1d1ae8a469f5ab0000000000000000000000000b2c639c533813f4aa9d7837caf62653d097ff85000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000000000000000000000000000000000000105117f0000000000000000000000000000000000000000000000000000000001050b39c2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000065a268a90000000000000000000000000000000000000000000000000000000000000004

Will return:

BridgeRequested:
TransactionID: 0xb7439e36b5527ac6298c2fd035a286d9df33c5352d96f08c48d4bf06f9df4afd
Sender: 0x5Cf2CC2C71231C23cd5C5A008b9339Da33F0FA57
OriginAmount: 4380000000
DestAmount: 4379589058
OriginToken: 0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85
DestToken: 0xaf88d065e77c8cC2239327C5EDb3A432268e5831
SendChainGas: false

Metadata

Summary by CodeRabbit

  • New Features
    • Introduced a command-line tool for decoding Ethereum log events for a fast bridge contract.

@dwasse dwasse requested a review from trajan0x as a code owner January 22, 2024 21:54
@github-actions github-actions bot added go Pull requests that update Go code size/s labels Jan 22, 2024
Copy link
Contributor

coderabbitai bot commented Jan 22, 2024

Walkthrough

The new main.go file is a command-line tool designed to decode raw data from Ethereum logs, specifically targeting events from a fast bridge contract. This tool streamlines the process of understanding blockchain events, a need highlighted by the team member @aureliusbtc.

Changes

File Change Summary
tools/rfqdecoder/main.go Added a new file main.go providing a command-line tool for decoding and handling specific events from Ethereum logs related to a fast bridge contract.

Assessment against linked issues

Objective Addressed Explanation
[RFQ] CLI for Decoding (#1754)
Quick way to decode raw data from Ethereum logs

Poem

"In streams of blockchain's deep, a tool's been cast,
To parse the logs, a CLI at last.
🐇 CodeRabbit hopped through lines of code,
Decoding secrets from the Ethereum abode."

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ed02e79 and 98b138e.
Files selected for processing (1)
  • tools/rfqdecoder/main.go (1 hunks)
Additional comments: 1
tools/rfqdecoder/main.go (1)
  • 29-32: The parser is initialized with an empty Ethereum address. Confirm that this is intentional and correct.

Please verify that initializing fastbridge.NewParser with an empty address is the intended behavior.

Comment on lines 15 to 20
var rawRequest string
flag.StringVar(&rawRequest, "r", "", "raw request")
flag.Parse()
if rawRequest == "" {
panic("must provide raw request (use -r)")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The program panics if the raw request is not provided. Consider providing a user-friendly error message instead of panicking.

- panic("must provide raw request (use -r)")
+ fmt.Println("Error: Must provide raw request (use -r)")
+ os.Exit(1)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
var rawRequest string
flag.StringVar(&rawRequest, "r", "", "raw request")
flag.Parse()
if rawRequest == "" {
panic("must provide raw request (use -r)")
}
var rawRequest string
flag.StringVar(&rawRequest, "r", "", "raw request")
flag.Parse()
if rawRequest == "" {
fmt.Println("Error: Must provide raw request (use -r)")
os.Exit(1)
}

Comment on lines 21 to 23
if rawRequest[:2] == "0x" {
rawRequest = rawRequest[2:]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stripping the "0x" prefix is done without checking the length of rawRequest. Ensure rawRequest is long enough before slicing.

+ if len(rawRequest) >= 2 && rawRequest[:2] == "0x" {

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if rawRequest[:2] == "0x" {
rawRequest = rawRequest[2:]
}
if len(rawRequest) >= 2 && rawRequest[:2] == "0x" {
rawRequest = rawRequest[2:]
}

Comment on lines 34 to 45
log := types.Log{
Topics: []common.Hash{
common.HexToHash("0x120ea0364f36cdac7983bcfdd55270ca09d7f9b314a2ebc425a3b01ab1d6403a"),
common.HexToHash("0xb7439e36b5527ac6298c2fd035a286d9df33c5352d96f08c48d4bf06f9df4afd"),
common.HexToHash("0x0000000000000000000000005cf2cc2c71231c23cd5c5a008b9339da33f0fa57"),
},
Data: requestBytes,
}
_, parsedEvent, ok := parser.ParseEvent(log)
if !ok {
panic("could not parse event")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded hashes in Topics may not be flexible for different environments or contracts. Consider making these configurable.

Suggest refactoring to allow dynamic topic hashes based on the environment or contract address.

Comment on lines +47 to +52
switch event := parsedEvent.(type) {
case *fastbridge.FastBridgeBridgeRequested:
handleBridgeRequested(event)
default:
panic("unknown event")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The switch statement only handles one event type and panics otherwise. This is not scalable for additional event types.

Refactor to support additional event types gracefully without panicking.

Comment on lines +55 to +63
func handleBridgeRequested(event *fastbridge.FastBridgeBridgeRequested) {
fmt.Println("BridgeRequested:")
fmt.Printf("TransactionID: %s\n", hexutil.Encode(event.TransactionId[:]))
fmt.Printf("Sender: %s\n", event.Sender.String())
fmt.Printf("OriginAmount: %s\n", event.OriginAmount.String())
fmt.Printf("DestAmount: %s\n", event.DestAmount.String())
fmt.Printf("OriginToken: %s\n", event.OriginToken.String())
fmt.Printf("DestToken: %s\n", event.DestToken.String())
fmt.Printf("SendChainGas: %v\n", event.SendChainGas)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handleBridgeRequested function prints directly to stdout. Consider returning a structured object for better testability and flexibility.

Refactor to return a structured object instead of printing directly, allowing for easier testing and alternative output formats.

Copy link

codecov bot commented Jan 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6790100) 51.22931% compared to head (c7fa8fd) 51.65117%.
Report is 7 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #1909         +/-   ##
===================================================
+ Coverage   51.22931%   51.65117%   +0.42186%     
===================================================
  Files            397         409         +12     
  Lines          27129       28071        +942     
  Branches         307         307                 
===================================================
+ Hits           13898       14499        +601     
- Misses         11881       12154        +273     
- Partials        1350        1418         +68     
Flag Coverage Δ
agents 47.46662% <ø> (-0.03425%) ⬇️
cctp-relayer 63.00863% <ø> (?)
explorer 24.80881% <ø> (ø)
promexporter 74.80916% <ø> (?)
rfq 40.56067% <ø> (-0.35041%) ⬇️
scribe 52.21130% <ø> (+0.18426%) ⬆️
sinner 64.60481% <ø> (ø)
tools 21.98661% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 98b138e and afba376.
Files selected for processing (1)
  • tools/rfqdecoder/main.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tools/rfqdecoder/main.go

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between afba376 and c7fa8fd.
Files selected for processing (1)
  • tools/rfqdecoder/main.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tools/rfqdecoder/main.go

@aureliusbtc
Copy link
Contributor

LGTM @dwasse

@dwasse dwasse merged commit 04f5cc5 into master Feb 9, 2024
50 checks passed
@dwasse dwasse deleted the feat/rfq-cli branch February 9, 2024 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFQ] CLI For Decoding
2 participants