-
Notifications
You must be signed in to change notification settings - Fork 32
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 airdrop tool #204
base: main
Are you sure you want to change the base?
Add airdrop tool #204
Conversation
…es with actual function calls
WalkthroughThis update introduces changes to the airdrop functionality by incorporating the snapshot process of various Cosmos chains. It enhances existing modules with robust reward calculation logic for different chains while adding new utility functions for efficient data handling and improving configuration management. Changes
Assessment against linked issues
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 30
@coderabbitai review |
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.
Actionable comments posted: 4
…d reimplement exponential backoff
@coderabbitai review |
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.
Actionable comments posted: 1
@coderabbitai review |
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.
Actionable comments posted: 3
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- airdrop/chains/terra.go (1 hunks)
- airdrop/utils/utils.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- airdrop/chains/terra.go
Additional comments not posted (2)
airdrop/utils/utils.go (2)
39-53
: Ensure proper resource management in HTTP requests.The
MakeGetRequest
function creates an HTTP request but does not ensure that the response body is closed in case of errors before returning. This can lead to resource leaks. Consider adding a deferred close after checking the error from theDo
method.+ if res != nil { + defer res.Body.Close() + }
266-281
: Refactor to centralize error handling and retry logic.The previous comment about centralizing error handling and retry logic is still valid here. Consider applying the same refactor to the
RetryableBalanceFunc
.
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- airdrop/config/constant.go (1 hunks)
- airdrop/main.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- airdrop/config/constant.go
- airdrop/main.go
I'm thinking to merge this and then stick it into the CI system. Thank you. |
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
go.sum
is excluded by!**/*.sum
Files selected for processing (1)
- go.mod (8 hunks)
Additional comments not posted (4)
go.mod (4)
31-31
: Verify impact of gRPC update.Ensure that the update to
google.golang.org/grpc v1.64.0
does not introduce any breaking changes or incompatibilities in the project.
78-78
: Verify impact of bitset update.Ensure that the update to
github.com/bits-and-blooms/bitset v1.11.0
does not introduce any breaking changes or incompatibilities in the project.
80-80
: Verify impact of backoff update.Ensure that the update to
github.com/cenkalti/backoff/v4 v4.3.0
does not introduce any breaking changes or incompatibilities in the project.
106-106
: Verify necessity and impact of new dependencies.Ensure that the new dependencies
github.com/ethereum/go-ethereum v1.14.3
,github.com/holiman/uint256 v1.2.4
,github.com/joho/godotenv v1.5.1
, andgithub.com/onsi/gomega v1.30.0
are necessary and do not introduce any security vulnerabilities or significant performance overhead.Also applies to: 147-147, 154-154, 172-172
I think we can still make the codebase more readable and maintainable. A bit of refactoring is necessary, and I'll take care of it. I'll also change this PR to draft before refactoring. |
@coderabbitai review |
Actions performedReview triggered.
|
1 similar comment
Actions performedReview triggered.
|
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.
Actionable comments posted: 22
Outside diff range and nitpick comments (26)
airdrop/chains/terra.go (5)
23-24
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to fetch validators for Terra: %v\n", err) + log.Printf("Failed to fetch validators for Terra using URL %s: %v\n", config.GetTerraConfig().API, err)
36-37
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to fetch delegations for validator %s at Terra: %v\n", validator.OperatorAddress, err) + log.Printf("Failed to fetch delegations for validator %s at Terra using URL %s: %v\n", validator.OperatorAddress, config.GetTerraConfig().API, err)
48-49
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to fetch Terra token price: %v", err) + log.Printf("Failed to fetch Terra token price from CoinID %s: %v", config.GetTerraConfig().CoinID, err)
65-66
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to convert EveAirdrop string to dec: %v", err) + log.Printf("Failed to convert EveAirdrop string %s to dec: %v", config.EveAirdrop, err)
85-86
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to convert Terra bech32 address for delegator %s: %v\n", delegator.Delegation.DelegatorAddress, err) + log.Printf("Failed to convert Terra bech32 address for delegator %s with address %s: %v\n", delegator.Delegation.DelegatorAddress, eveBech32Address, err)airdrop/chains/stargaze.go (8)
20-21
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Error loading Stargaze environment variables: %v", err) + log.Printf("Error loading Stargaze environment variables from .env file: %v", err)
26-27
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to get latest height for Stargaze: %v", err) + log.Printf("Failed to get latest height for Stargaze using URL %s: %v", config.GetStargazeConfig().RPC+"/status", err)
32-33
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to connect to gRPC Stargaze: %v", err) + log.Printf("Failed to connect to gRPC Stargaze using address %s: %v", config.GetStargazeConfig().GRPCAddr, err)
40-41
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to get Stargaze validators: %v", err) + log.Printf("Failed to get Stargaze validators at block height %s: %v", blockHeight, err)
48-49
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to query delegate info for Stagaze validator: %v", err) + log.Printf("Failed to query delegate info for Stagaze validator %s at block height %s: %v", validator.OperatorAddress, blockHeight, err)
58-59
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to fetch Stargaze token price: %v", err) + log.Printf("Failed to fetch Stargaze token price from CoinID %s: %v", config.GetStargazeConfig().CoinID, err)
73-74
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to convert EveAirdrop string to dec: %v", err) + log.Printf("Failed to convert EveAirdrop string %s to dec: %v", config.EveAirdrop, err)
88-89
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to convert Stargaze bech32 address: %v", err) + log.Printf("Failed to convert Stargaze bech32 address for delegator %s: %v", delegator.Delegation.DelegatorAddress, err)airdrop/chains/sentinel.go (8)
21-22
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Error loading Sentinel environment variables: %v", err) + log.Printf("Error loading Sentinel environment variables from .env file: %v", err)
27-28
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to get latest height for Sentinel: %v", err) + log.Printf("Failed to get latest height for Sentinel using URL %s: %v", config.GetSentinelConfig().RPC+"/status", err)
33-34
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to connect to gRPC Sentinel: %v", err) + log.Printf("Failed to connect to gRPC Sentinel using address %s: %v", config.GetSentinelConfig().GRPCAddr, err)
41-42
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to get Sentinel validators: %v", err) + log.Printf("Failed to get Sentinel validators at block height %s: %v", blockHeight, err)
50-51
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to query delegate info for Sentinel validator: %v", err) + log.Printf("Failed to query delegate info for Sentinel validator %s at block height %s: %v", validator.OperatorAddress, blockHeight, err)
61-62
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to fetch Sentinel token price: %v", err) + log.Printf("Failed to fetch Sentinel token price from CoinID %s: %v", config.GetSentinelConfig().CoinID, err)
78-79
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to convert EveAirdrop string to dec: %v", err) + log.Printf("Failed to convert EveAirdrop string %s to dec: %v", config.EveAirdrop, err)
94-95
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to convert Sentinel bech32 address: %v", err) + log.Printf("Failed to convert Sentinel bech32 address for delegator %s: %v", delegator.Delegation.DelegatorAddress, err)airdrop/chains/akash.go (5)
21-22
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Error loading Akash environment variables: %v", err) + log.Printf("Error loading Akash environment variables from .env file: %v", err)
27-28
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to get latest height for Akash: %v", err) + log.Printf("Failed to get latest height for Akash using URL %s: %v", config.GetAkashConfig().RPC+"/status", err)
36-37
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to connect to gRPC Akash: %v", err) + log.Printf("Failed to connect to gRPC Akash using address %s: %v", config.GetAkashConfig().GRPCAddr, err)
47-48
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to get Akash validators: %v", err) + log.Printf("Failed to get Akash validators at block height %s: %v", blockHeight, err)
56-57
: Enhance error logging for better traceability.Consider enhancing the error logging by including more context about the operation being performed. This can help in debugging issues more effectively.
- log.Printf("Failed to query delegate info for Akash validator: %v", err) + log.Printf("Failed to query delegate info for Akash validator %s at block height %s: %v", validator.OperatorAddress, blockHeight </blockquote></details> </blockquote></details> <details> <summary>Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** <details> <summary>Commits</summary> Files that changed from the base of the PR and between 2de323a93bfe78b02dd06eb1e480f9f71ca0313c and 9968d3a3ea60508cc60bca64fbede1fbfa0ceff0. </details> <details> <summary>Files ignored due to path filters (1)</summary> * `airdrop/go.sum` is excluded by `!**/*.sum` </details> <details> <summary>Files selected for processing (18)</summary> * airdrop/.gitignore (1 hunks) * airdrop/Makefile (1 hunks) * airdrop/chains/akash.go (1 hunks) * airdrop/chains/bostrom.go (1 hunks) * airdrop/chains/celestia.go (1 hunks) * airdrop/chains/composable.go (1 hunks) * airdrop/chains/cosmos.go (1 hunks) * airdrop/chains/cosmosnft.go (1 hunks) * airdrop/chains/ethereumnft.go (1 hunks) * airdrop/chains/neutron.go (1 hunks) * airdrop/chains/sentinel.go (1 hunks) * airdrop/chains/stargaze.go (1 hunks) * airdrop/chains/terra.go (1 hunks) * airdrop/chains/terrac.go (1 hunks) * airdrop/cmd/airdrop/main.go (1 hunks) * airdrop/config/constant.go (1 hunks) * airdrop/go.mod (1 hunks) * airdrop/utils/utils.go (1 hunks) </details> <details> <summary>Files skipped from review due to trivial changes (2)</summary> * airdrop/.gitignore * airdrop/config/constant.go </details> <details> <summary>Additional comments not posted (33)</summary><blockquote> <details> <summary>airdrop/Makefile (1)</summary><blockquote> `1-3`: **LGTM! Ensure the build target is correctly defined.** The build target `airdrop-tool` uses the `go build` command to compile the `airdropd` executable from the `cmd/airdrop` directory. Ensure that the directory structure is correct and the `cmd/airdrop` directory contains the main package. </blockquote></details> <details> <summary>airdrop/chains/bostrom.go (1)</summary><blockquote> `63-67`: **Improve error handling.** Instead of logging the error and returning a new error, consider wrapping the original error with additional context using `fmt.Errorf`. ```diff - log.Printf("Failed to convert EveAirdrop string to dec: %v", err) - return nil, nil, 0, fmt.Errorf("failed to convert EveAirdrop string to dec: %w", err) + return nil, nil, 0, fmt.Errorf("failed to convert EveAirdrop string to dec: %w", err)Likely invalid or redundant comment.
airdrop/chains/terrac.go (1)
46-50
: Improve error handling.Instead of logging the error and returning a new error, consider wrapping the original error with additional context using
fmt.Errorf
.- log.Printf("Failed to fetch TerraC token price: %v", err) - return nil, nil, 0, fmt.Errorf("failed to fetch TerraC token price: %w", err) + return nil, nil, 0, fmt.Errorf("failed to fetch TerraC token price: %w", err)Likely invalid or redundant comment.
airdrop/chains/neutron.go (3)
87-90
: Improve error handling.Instead of logging the error and returning a new error, consider wrapping the original error with additional context using
fmt.Errorf
.- return nil, fmt.Errorf("failed to connect to gRPC Neutron: %w", err) + return nil, fmt.Errorf("failed to connect to gRPC Neutron: %w", err)Likely invalid or redundant comment.
112-114
: Improve error handling.Instead of logging the error and returning a new error, consider wrapping the original error with additional context using
fmt.Errorf
.- return nil, fmt.Errorf("failed to query all Neutron's denom owners: %w", err) + return nil, fmt.Errorf("failed to query all Neutron's denom owners: %w", err)Likely invalid or redundant comment.
34-38
: Improve error handling.Instead of logging the error and returning a new error, consider wrapping the original error with additional context using
fmt.Errorf
.- log.Printf("Failed to fetch Neutron token price: %v", err) - return nil, nil, 0, fmt.Errorf("failed to fetch Neutron token price: %w", err) + return nil, nil, 0, fmt.Errorf("failed to fetch Neutron token price: %w", err)Likely invalid or redundant comment.
airdrop/chains/cosmos.go (1)
32-39
: Improve error handling.Instead of logging the error and returning a new error, consider wrapping the original error with additional context using
fmt.Errorf
.- log.Printf("Failed to fetch Delegations for Cosmos: %v", err) - return nil, nil, 0, fmt.Errorf("failed to fetch Delegations for Cosmos: %w", err) + return nil, nil, 0, fmt.Errorf("failed to fetch Delegations for Cosmos: %w", err)Likely invalid or redundant comment.
airdrop/chains/celestia.go (6)
19-23
: LGTM!Environment variables are loaded correctly and errors are handled appropriately.
25-30
: LGTM!Fetching the latest block height is handled correctly and errors are logged appropriately.
32-37
: LGTM!Setting up the gRPC connection is handled correctly and errors are logged appropriately.
41-46
: LGTM!Fetching validators is handled correctly and errors are logged appropriately.
49-63
: LGTM!Fetching delegations for each validator is handled correctly and errors are logged appropriately.
65-70
: LGTM!Calculating the token price and threshold is handled correctly and errors are logged appropriately.
airdrop/chains/composable.go (6)
19-23
: LGTM!Environment variables are loaded correctly and errors are handled appropriately.
25-30
: LGTM!Fetching the latest block height is handled correctly and errors are logged appropriately.
32-37
: LGTM!Setting up the gRPC connection is handled correctly and errors are logged appropriately.
41-46
: LGTM!Fetching validators is handled correctly and errors are logged appropriately.
49-61
: LGTM!Fetching delegations for each validator is handled correctly and errors are logged appropriately.
63-68
: LGTM!Calculating the token price and threshold is handled correctly and errors are logged appropriately.
airdrop/go.mod (4)
1-5
: LGTM!Module declaration and Go version are specified correctly.
7-28
: LGTM!Required dependencies are listed correctly.
30-36
: LGTM!Additional required dependencies are listed correctly.
38-162
: LGTM!Indirect dependencies are listed correctly.
airdrop/utils/utils.go (10)
34-40
: LGTM!The
handleHTTPError
function handles HTTP-related errors correctly.
42-55
: LGTM!The
MakeGetRequest
function handles HTTP GET requests and errors correctly.
57-60
: LGTM!The
GetFunctionName
function correctly returns the name of the given function.
62-70
: LGTM!The
FindValidatorInfo
function correctly finds the index of a validator by its address.
72-104
: LGTM!The
GetLatestHeight
function handles fetching the latest block height correctly and uses exponential backoff for retries.
106-133
: LGTM!The
GetValidators
function handles retrieving the list of validators correctly and uses exponential backoff for retries.
135-160
: LGTM!The
GetValidatorDelegations
function handles retrieving the delegations for a specific validator correctly and uses exponential backoff for retries.
162-173
: LGTM!The
ConvertBech32Address
function handles converting an address to a Bech32 address correctly.
175-183
: LGTM!The
FindValidatorInfoCustomType
function correctly finds the index of a validator by its address in a custom validator type.
185-218
: LGTM!The
FetchValidators
function handles fetching the list of validators correctly and uses exponential backoff for retries.
@faddat sir, have you finalized the percentage weight for the airdrop across the chains? Please ensure that the total percentage is 100% |
Close #113
Notes
Summary by CodeRabbit
New Features
Chores
.gitignore
to include files related to an Airdrop tool.airdropd
executable.go.mod
for theairdrop
module.Documentation