Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Convert Banks#9033

Merged
carllin merged 11 commits intosolana-labs:v1.0from
carllin:VersionBanks
Mar 26, 2020
Merged

Convert Banks#9033
carllin merged 11 commits intosolana-labs:v1.0from
carllin:VersionBanks

Conversation

@carllin
Copy link
Copy Markdown
Contributor

@carllin carllin commented Mar 23, 2020

Problem

Old bank structure is incompatible with changes to bank implemented here: #8958

Summary of Changes

  1. Add a conversion to the new bank structure when deserializing the bank from 1.0 snapshots
  2. Write out version 1.1 snapshots
  3. Note this change includes changes from: Store and compute node/stake state in EpochStakes struct #8958

With 1 + 2, when validators all upgrade to 1.1, only 1.1 snapshots should be present in the system and we can throw away this code.

Note that with this change, any validators that don't upgrade to this change will be unable to process the new 1.1 snapshots.

Fixes #

@carllin carllin requested review from mvines and sakridge March 23, 2020 23:24
Comment thread ledger/src/snapshot_utils.rs Outdated
BankVersions::Bank1_0(deserialize_from_snapshot(stream.by_ref())?)
}
SNAPSHOT_VERSION_1_1 => {
BankVersions::Bank1_1(deserialize_from_snapshot(stream.by_ref())?)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mvines, @sakridge, I ran ledger-tool verify on an old 1.0 snapshot and this works fine.

At first I was like great, the change works!

But on second thought, isn't this a vulnerability? I fundamentally changed a field in the bank that's used by many parts of the system, and the snapshot hash still verified fine...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't require the Bank struct be immutable. There could exist another Solana implementation written in bash that produces the same snapshot hash as the current mostly-Rust implementation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Seems like critical fields in the bank that should be verified(please check if any are missing!)

  1. parent_hash
  2. hard_forks
  3. transaction_count
  4. tick_height
  5. signature_count
  6. capitalization
  7. max_tick_height
  8. hashes_per_tick
  9. ticks_per_slot
  10. ns_per_slot
  11. genesis_creation_time
  12. slots_per_year
  13. slots_per_segment
  14. slot
  15. epoch
  16. block_height
  17. collector_id
  18. collector_fees
  19. fee_calculator
  20. fee_rate_governor
  21. collected_rent
  22. rent_collector
  23. epoch_schedule
  24. inflation
  25. stakes
  26. storage_accounts
  27. epoch_stakes
  28. is_delta
  29. message_processor

Copy link
Copy Markdown
Contributor Author

@carllin carllin Mar 23, 2020

Choose a reason for hiding this comment

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

@mvines seems like I could just replace a stake account, or a epoch stakes account, or inflation/rent in the bank, and it would affect this node's view of consensus

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That would cause a bank hash mismatch

Copy link
Copy Markdown
Contributor

@sakridge sakridge Mar 24, 2020

Choose a reason for hiding this comment

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

Speed is not a reason to not do it, the whole serialized size of the bank is 200KB, that should take about 500us to hash with sha-2. We are already spending 100s of ms to hash the account states.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can, and we'll probably need one of these painful snapshot/Bank adaption PRs every time we do so.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That, or you re-compute these values from the account state which is hashed. That seems like more work to me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hehe I'm just saying that I'm pretty sure that all of the 29 Bank fields that Carl listed above do not all need be included in the bank hash.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's part of #7167 and on @ryoqun 's radar. Part of why we are using the flags to get verified snapshots from only trusted nodes.

@carllin FYI: As @sakridge said, this is the wip-stale-closed PR for the exact thing of this discussion: #8185. I'm steadily approaching to it. There are still other bunch of security issues in the snapshot to tackle first, though. ;)

Comment thread ledger/src/snapshot_utils.rs Outdated
Comment thread ledger/src/snapshot_utils.rs Outdated

pub enum BankVersions {
Bank1_0(Bank1_0),
Bank1_1(Bank),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bank1_1 we can just call Current, and it only gets a version when it's an older bank that we care about

Comment thread ledger/src/snapshot_utils.rs Outdated

pub const SNAPSHOT_VERSION: &str = "1.0.0";
pub const SNAPSHOT_VERSION_1_0: &str = "1.0.0";
pub const SNAPSHOT_VERSION_1_1: &str = "1.1.0";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can just be SNAPSHOT_VERSION ("Current" is the default, only name the legacy versions)

Comment thread runtime/src/bank.rs Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 24, 2020

Codecov Report

Merging #9033 into v1.0 will decrease coverage by <.1%.
The diff coverage is 54.6%.

@@           Coverage Diff           @@
##            v1.0   #9033     +/-   ##
=======================================
- Coverage   80.4%   80.3%   -0.1%     
=======================================
  Files        263     265      +2     
  Lines      57363   57553    +190     
=======================================
+ Hits       46126   46228    +102     
- Misses     11237   11325     +88

@carllin carllin force-pushed the VersionBanks branch 2 times, most recently from 3fb7776 to 0bbc048 Compare March 24, 2020 01:59
Copy link
Copy Markdown
Contributor

@mvines mvines left a comment

Choose a reason for hiding this comment

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

The runtime/src/bank.rs → runtime/src/bank/mod.rs rename seems unnecessary but I'm not strongly opposed.

Let's wait until 1.0.9 ships before landing this in v1.0 though please. I didn't review runtime/src/epoch_stakes.rs, I assume that's been covered in the other PR for master

Comment thread ledger/src/snapshot_utils.rs
Comment thread ledger/src/snapshot_utils.rs Outdated
@mvines
Copy link
Copy Markdown
Contributor

mvines commented Mar 24, 2020

@carllin - please ping me when this PR and #8958 are green and I'll review again, thanks!

@carllin carllin force-pushed the VersionBanks branch 3 times, most recently from 3900a53 to 225a6d1 Compare March 25, 2020 00:18
@carllin
Copy link
Copy Markdown
Contributor Author

carllin commented Mar 25, 2020

@mvines Green!

Copy link
Copy Markdown
Contributor

@mvines mvines left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good! I'm 👎 this PR until we ship v1.0.10 this evening. I'd like to get this in v1.0.11 instead

Copy link
Copy Markdown
Contributor

@mvines mvines left a comment

Choose a reason for hiding this comment

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

1.0.10 has shipped, all clear

@carllin carllin merged commit d4ddb62 into solana-labs:v1.0 Mar 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants