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

modify genesis scripts to take rewards vester account balance as an argument and count it towards total supply #525

Merged
merged 8 commits into from
Oct 23, 2023

Conversation

tqin7
Copy link
Contributor

@tqin7 tqin7 commented Oct 6, 2023

Test Plan

Tested by running localnet and verifying bank total supply, bridge module account balance, and rewards vester account balance

@linear
Copy link

linear bot commented Oct 6, 2023

DEC-2141

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 6, 2023

Walkthrough

The changes primarily involve the addition of a new variable REWARDS_VESTER_ACCOUNT_BALANCE to manage the balance of the rewards vester account. The balance is initialized and deducted from the bridge module account balance. Additionally, several scripts have been updated to call the edit_genesis function with an extra argument.

Changes

File Summary
protocol/testing/genesis.sh Added REWARDS_VESTER_ACCOUNT_BALANCE variable. Initialized and deducted it from the bridge module account balance.
protocol/testing/testnet-*/*.sh Updated create_validators() and create_pregenesis_file() functions to call edit_genesis() with an extra argument.
protocol/scripts/genesis/prod_pregenesis.sh Modified create_pregenesis_file() to call edit_genesis() with an extra argument.
protocol/testing/containertest/containertest.sh Updated create_validators function to call edit_genesis with an extra argument.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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.json

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

Commits Files that changed from the base of the PR and between 3f1cf01 and f4ccb40.
Files selected for processing (5)
  • protocol/testing/genesis.sh (3 hunks)
  • protocol/testing/testnet-dev/dev.sh (1 hunks)
  • protocol/testing/testnet-external/pregenesis.sh (1 hunks)
  • protocol/testing/testnet-local/local.sh (1 hunks)
  • protocol/testing/testnet-staging/staging.sh (1 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/testing/testnet-staging/staging.sh
Additional comments (Suppressed): 6
protocol/testing/testnet-external/pregenesis.sh (1)
  • 188-192: The edit_genesis function call has been updated with an additional empty string argument. Ensure that the function definition of edit_genesis has been updated to handle this new argument and that it doesn't break existing functionality.
protocol/testing/testnet-dev/dev.sh (1)
  • 134-137: The edit_genesis function call has been updated with two additional empty string arguments. Ensure that the function definition of edit_genesis has been updated to handle these new arguments and that all calls to this function throughout the codebase have been updated to match the new signature.
protocol/testing/genesis.sh (3)
  • 58-65: The new REWARDS_VESTER_ACCOUNT_BALANCE variable is introduced and defaults to 1e12 if not provided. Ensure that this default value doesn't cause any unexpected behavior in the system.

  • 976-976: The calculation of bridge_module_account_balance now subtracts REWARDS_VESTER_ACCOUNT_BALANCE from TOTAL_NATIVE_TOKEN_SUPPLY. This change could affect other parts of the system that rely on the bridge module account balance. Verify that these changes are propagated correctly throughout the system.

  • 1008-1011: The rewards vester account balance is now set to the value of REWARDS_VESTER_ACCOUNT_BALANCE instead of a hardcoded value. This change should provide more flexibility, but ensure that it doesn't introduce any inconsistencies in the system.

protocol/testing/testnet-local/local.sh (1)
  • 99-103: The edit_genesis function call has been updated with three additional empty string arguments. Ensure that the function definition of edit_genesis has been updated to handle these new parameters and that they are used correctly within the function. Also, verify that all calls to edit_genesis throughout the codebase have been updated to match the new signature.

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

Commits Files that changed from the base of the PR and between f4ccb40 and 571a00d.
Files selected for processing (1)
  • protocol/testing/genesis.sh (3 hunks)
Additional comments (Suppressed): 3
protocol/testing/genesis.sh (3)
  • 64-68: The new hunk introduces a variable REWARDS_VESTER_ACCOUNT_BALANCE which is set to the 7th argument passed to the script. If this argument is not provided, it defaults to 10 million full coins. Ensure that all calls to this script throughout the codebase have been updated to match the new argument structure.

  • 979-979: The bridge module account balance is now initialized as the total native token supply minus the rewards vester account balance. This is a change from the previous behavior where the bridge module account balance was set to the total native token supply. This change could have implications on the total supply of tokens in the system. Make sure this change is intended and that it doesn't negatively impact the system's token economics.

  • 1014-1014: The rewards vester account balance is now set to the value of REWARDS_VESTER_ACCOUNT_BALANCE instead of a hardcoded value of 10 million full coins. This change allows for more flexibility in setting the rewards vester account balance. Ensure that this change is reflected in all places where the rewards vester account balance is used.

@@ -1004,7 +1011,7 @@ function edit_genesis() {
dasel put -t string -f "$GENESIS" ".app_state.bank.balances.[$next_bank_idx].address" -v "${REWARDS_VESTER_ACCOUNT_ADDR}"
dasel put -t json -f "$GENESIS" ".app_state.bank.balances.[$next_bank_idx].coins.[]" -v "{}"
dasel put -t string -f "$GENESIS" ".app_state.bank.balances.[$next_bank_idx].coins.[0].denom" -v "${REWARD_TOKEN}"
dasel put -t string -f "$GENESIS" ".app_state.bank.balances.[$next_bank_idx].coins.[0].amount" -v "10000000$EIGHTEEN_ZEROS" # 10 million full coins
dasel put -t string -f "$GENESIS" ".app_state.bank.balances.[$next_bank_idx].coins.[0].amount" -v "$REWARDS_VESTER_ACCOUNT_BALANCE"
Copy link
Contributor

@teddyding teddyding Oct 10, 2023

Choose a reason for hiding this comment

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

When REWARDS_VESTER_ACCOUNT_BALANCE is zero, we should skip line 1011 to 1015

@@ -969,7 +975,8 @@ function edit_genesis() {
dydx_exchange_config_json=$(cat "$EXCHANGE_CONFIG_JSON_DIR/dydx_exchange_config.json" | jq -c '.')
dasel put -t string -f "$GENESIS" '.app_state.prices.market_params.[34].exchange_config_json' -v "$dydx_exchange_config_json"

bridge_module_account_balance=$TOTAL_NATIVE_TOKEN_SUPPLY
# Initialize bridge module account balance as total native token supply minus rewards vester account balance.
bridge_module_account_balance=$(echo "$TOTAL_NATIVE_TOKEN_SUPPLY - $REWARDS_VESTER_ACCOUNT_BALANCE" | bc)
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of initializing module account balance = total_supply - vester_balance, can we do decrement bridge_module_account_balance balance around line 1014, similar to how to decrement other type of balances?

@@ -61,6 +61,12 @@ function edit_genesis() {
INITIAL_CLOB_PAIR_STATUS='STATUS_ACTIVE'
fi

REWARDS_VESTER_ACCOUNT_BALANCE="$7"
Copy link
Contributor

@teddyding teddyding Oct 10, 2023

Choose a reason for hiding this comment

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

Besides dev local and staging can you make sure https://github.com/dydxprotocol/v4-chain/blob/f50431e3a43a804fc9d4337d779bc054deffd7d9/protocol/scripts/genesis/prod_pregenesis.sh is also updated, and run this script to make sure the sample pregensis file is up-to-date?

Copy link
Contributor Author

@tqin7 tqin7 Oct 18, 2023

Choose a reason for hiding this comment

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

Updated prod_pregenesis,sh as well. When I run that script to check that sample file is up-to-date, the content is the same except that parameters have a different ordering, for example:

<             "ticker": "ARB-USD",
<             "id": 24,
<             "market_id": 24,
<             "liquidity_tier": 1
---
>             "id": 24,
>             "liquidity_tier": 1,
>             "market_id": 24,
>             "ticker": "ARB-USD"

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rebase from main and try again? We recently made a change that fixes non-deterministic ordering in sample pregenesis

Copy link
Contributor Author

Choose a reason for hiding this comment

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

merged main and ran again

Diffing output against current sample_pregenesis.json...
./scripts/genesis/sample_pregenesis.json is up-to-date

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

Commits Files that changed from the base of the PR and between 571a00d and 8574e24.
Files selected for processing (4)
  • protocol/scripts/genesis/prod_pregenesis.sh (1 hunks)
  • protocol/testing/containertest/containertest.sh (1 hunks)
  • protocol/testing/genesis.sh (3 hunks)
  • protocol/testing/testnet-external/pregenesis.sh (1 hunks)
Files skipped from review due to trivial changes (2)
  • protocol/scripts/genesis/prod_pregenesis.sh
  • protocol/testing/containertest/containertest.sh
Additional comments (Suppressed): 4
protocol/testing/testnet-external/pregenesis.sh (1)
  • 182-182: The edit_genesis function call has been updated with an additional empty string argument. Ensure that the function definition has been updated to handle this additional argument and that all other calls to this function throughout the codebase have been updated to match the new signature.
protocol/testing/genesis.sh (3)
  • 70-74: The new hunk introduces a variable REWARDS_VESTER_ACCOUNT_BALANCE which is set to the 7th argument passed to the script. If this argument is not provided, it defaults to 10 million full coins. This change allows the rewards vester account balance to be taken as an argument, which is a good practice for flexibility and configurability. However, ensure that all calls to this script throughout the codebase have been updated to include this new argument.

  • 992-994: The bridge module account balance is initialized as the total native token supply. This is a logical step as the total supply should be distributed among different accounts. However, it's important to note that this balance will be adjusted later to subtract the REWARDS_VESTER_ACCOUNT_BALANCE if it's greater than 0.

  • 1022-1032: The new hunk introduces logic to initialize the bank balance of the rewards vester account if REWARDS_VESTER_ACCOUNT_BALANCE is greater than 0. It also adjusts the bridge_module_account_balance by subtracting the REWARDS_VESTER_ACCOUNT_BALANCE. This is a good practice to ensure that the total supply remains constant. However, it's important to ensure that the REWARDS_VESTER_ACCOUNT_BALANCE is not greater than the total supply to avoid negative balances.

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

Commits Files that changed from the base of the PR and between 8574e24 and f3cfb71.
Files selected for processing (1)
  • protocol/testing/genesis.sh (3 hunks)
Additional comments (Suppressed): 3
protocol/testing/genesis.sh (3)
  • 70-74: The new hunk introduces a variable REWARDS_VESTER_ACCOUNT_BALANCE which is set to the 7th argument passed to the script. If this argument is not provided, it defaults to 10 million full coins. This is a good practice as it allows for flexibility in setting the rewards vester account balance while providing a sensible default.

  • 991-994: The bridge module account balance is now initialized as the total native token supply. This is a logical change as the bridge module account should hold all the native tokens initially.

  • 1022-1032: The new hunk introduces a condition to check if REWARDS_VESTER_ACCOUNT_BALANCE is greater than 0. If it is, the bank balance of the rewards vester account is initialized and the balance is deducted from the bridge module account balance. This is a sensible change as it ensures that the rewards vester account is only initialized if it has a balance and that the total supply of tokens remains constant.

dasel put -t string -f "$GENESIS" ".app_state.bank.balances.[$next_bank_idx].coins.[0].denom" -v "${REWARD_TOKEN}"
dasel put -t string -f "$GENESIS" ".app_state.bank.balances.[$next_bank_idx].coins.[0].amount" -v "10000000$EIGHTEEN_ZEROS" # 10 million full coins
next_bank_idx=$(($next_bank_idx+1))
if [ $(echo "$REWARDS_VESTER_ACCOUNT_BALANCE > 0" | bc -l) -eq 1 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you run localnet and check that localhost:26657/genesis contains the correct balance for reward vester account?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

confirmed:
{"address":"dydx1ltyc6y4skclzafvpznpt2qjwmfwgsndp458rmp","coins":[{"denom":"adv4tnt","amount":"200000000000000000000000000"}]}

REWARDS_VESTER_ACCOUNT_BALANCE="$7"
if [ -z "$REWARDS_VESTER_ACCOUNT_BALANCE" ]; then
# Default to 10 million full coins.
REWARDS_VESTER_ACCOUNT_BALANCE="10000000$EIGHTEEN_ZEROS"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change this to 200 million full coins from realism?

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 f3cfb71 and 3a90a73.
Files selected for processing (3)
  • protocol/scripts/genesis/prod_pregenesis.sh (1 hunks)
  • protocol/testing/genesis.sh (3 hunks)
  • protocol/testing/testnet-external/pregenesis.sh (1 hunks)
Files skipped from review due to trivial changes (2)
  • protocol/scripts/genesis/prod_pregenesis.sh
  • protocol/testing/testnet-external/pregenesis.sh
Additional comments: 2
protocol/testing/genesis.sh (2)
  • 70-74: The new hunk introduces a variable REWARDS_VESTER_ACCOUNT_BALANCE which is set to the 7th argument passed to the script. If this argument is not provided, it defaults to 200 million full coins. This is a change from the old hunk where the rewards vester account balance was hardcoded to 10 million full coins. Ensure that all calls to this script throughout the codebase have been updated to pass the correct argument for the rewards vester account balance.

  • 1024-1034: The new hunk introduces a condition to check if REWARDS_VESTER_ACCOUNT_BALANCE is greater than 0. If it is, the bank balance of the rewards vester account is initialized and the bridge_module_account_balance is updated by subtracting the REWARDS_VESTER_ACCOUNT_BALANCE. This is a change from the old hunk where the bank balance of the rewards vester account was always initialized, regardless of the REWARDS_VESTER_ACCOUNT_BALANCE. This change seems to be in line with the intention to make the rewards vester account balance configurable.

@tqin7 tqin7 merged commit cba238d into main Oct 23, 2023
15 checks passed
@tqin7 tqin7 deleted the tq/dec-2141 branch October 23, 2023 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants