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

[Coinbase Go/No-Go] Bond balances in genesis block #2308

Merged
merged 48 commits into from
Feb 13, 2024

Conversation

vicsn
Copy link
Contributor

@vicsn vicsn commented Jan 18, 2024

Motivation

We want to be able to bond balances in the genesis block.

This PR modifies Genesis::Ratify, such that it contains the desired state of the committee, account, and bonded mappings in credits.aleo. This initial state is checked for consistency before it is directly injected into the FinalizeStore.

Related PRs

https://github.com/AleoHQ/snarkOS/pull/3016

d0cd
d0cd previously requested changes Jan 18, 2024
ledger/block/src/ratify/mod.rs Outdated Show resolved Hide resolved

#[allow(clippy::large_enum_variant)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this has a non-trivial impact on object/storage size?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might have some impact, but the jump from (Committee<N>, PublicBalances<N>) to (Committee<N>, PublicBalances<N>, BondedBalances<N>) won't be that big.

Copy link
Contributor

Choose a reason for hiding this comment

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

Considering every block contains this enum, and we will always pay the worst-case memory footprint, I don't understand why one chose to ignore this clippy warning.

You should follow the advise of clippy to resolve it (I assume its to use Box). Otherwise, every enum variant will always pay the worst case bound.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why one chose to ignore this clippy warning
By being too much in a get shit done mood, my bad.

@d0cd since you've been finishing off the PR, want to wrap the contents in Box? I also just recently noticed we're already using this pattern in snarkVM.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done! By boxing the elements of Genesis::Ratify the size reduces from 240 to 32 bytes.

// Update the bonded balance in finalize storage.
let operation = store.update_key_value(program_id, bonded_mapping, key, next_value)?;
finalize_operations.push(operation);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't looked into this in depth, but outside of the bonded mapping, we need to update the committee_state in the committee mapping and also the number of delegators if/when this PR gets merged in - https://github.com/AleoHQ/snarkVM/pull/2213.

In addition, we need checks that the delegated bonding amount meets all the requirements (for example, delegation must be more than X credits)

@vicsn vicsn force-pushed the bond_balances_in_genesis branch from 960a41b to 74d29bf Compare January 18, 2024 23:01
Copy link
Contributor

@d0cd d0cd left a comment

Choose a reason for hiding this comment

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

Updated to address feedback.

@d0cd d0cd requested a review from raychu86 January 19, 2024 15:55
@d0cd d0cd dismissed their stale review January 19, 2024 17:32

Feedback has been addressed

@d0cd d0cd marked this pull request as ready for review January 22, 2024 22:15
@raychu86
Copy link
Contributor

Would be nice to have some tests that ensures the bond balances is equivalent to actual bond_public transactions.

// Check that the amount meets the minimum requirement, depending on whether the address is a validator.
if *address == *validator_address {
ensure!(
*amount >= 1_000_000_000_000_u64,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to ensure that these values match the credits.aleo minimum requirements? Might be good to write some comments and maybe add some tests for enforcement to catch any changes down the line.

@d0cd d0cd requested a review from raychu86 January 26, 2024 20:13
@d0cd d0cd requested a review from raychu86 February 11, 2024 05:43
})
.collect_vec();
assert_eq!(actual_account.len(), expected_account.len());
// Check that all entries except for the one for the first validator are the same.
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix comment. Also why is the first validator entry different?

Suggested change
// Check that all entries except for the one for the first validator are the same.
// Check that all entries except for the first validator are the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is because the first validator also executes a number of additional transactions in the genesis_quorum method.
Consequently, its balance after adding the genesis block is not the same as the public balance provided in Genesis::Ratify.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you maybe clarify that in the comment? Otherwise, we won't know why down the line.

.collect_vec();
assert_eq!(actual_bonded.len(), expected_bonded.len());
for entry in actual_bonded.iter() {
assert!(expected_bonded.contains(entry));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we check the amounts in the bonded and account mappings?

Copy link
Contributor

Choose a reason for hiding this comment

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

NVM, i see now that the actual_bonded and expected_bonded variables are Vectors, so the contains call will check that the balance is correct.

d0cd and others added 4 commits February 12, 2024 16:15
Co-authored-by: Raymond Chu <14917648+raychu86@users.noreply.github.com>
Signed-off-by: d0cd <23022326+d0cd@users.noreply.github.com>
@howardwu howardwu changed the title Bond balances in genesis block [Coinbase Go/No-Go] Bond balances in genesis block Feb 13, 2024
@howardwu howardwu merged commit 88347f3 into mainnet Feb 13, 2024
78 checks passed
@howardwu howardwu deleted the bond_balances_in_genesis branch February 13, 2024 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants