anza-xyz / agave

Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
https://www.anza.xyz/
Apache License 2.0
410 stars 202 forks source link

Capitalization overflow on test cluster (v1.18.2) #19

Open steviez opened 8 months ago

steviez commented 8 months ago

Problem

In setting up a new test cluster, @joeaba encountered a capitalization overflow while taking an accounts hash prior to creating a snapshot. The full backtrace / some relevant discussion here on Discord:

...
thread="solAccountsLo10" one=1i message="panicked at accounts-db/src/accounts_hash.rs:849:26:
    summing capitalization cannot overflow" location="accounts-db/src/accounts_hash.rs:849:26" version="1.18.2 (src:13656e30; feat:3352961542, client:SolanaLabs)"

The cluster was created with the following solana-genesis command:

solana-genesis --hashes-per-tick 12500 --bootstrap-validator genesis-keypair.json vote-pubkey.json stake-pubkey.json \
--ledger /home/sol/ledger --cluster-type development --faucet-pubkey faucet.json --faucet-lamports 100000000000000000 \
--bootstrap-validator-lamports 10000000000000 --bootstrap-validator-stake-lamports 250000000000000 \
--primordial-accounts-file accounts.json

The creation of the above genesis file yielded the following capitalization:

Capitalization: 600000000 SOL in 604 accounts

However, here are the lamports that we explicitly added:

18 446 744 073 709 551 615 <== U64::MAX
   100 000 000 000 000 000 <== --faucet-lamports
       250 000 000 000 000 <== --bootstrap-validator-stake-lamports
        10 000 000 000 000 <== --bootstrap-validator-lamports

Note that 500M of the 600M in capitalization stems from an item discovered in https://github.com/solana-labs/solana/pull/35266. Technically, we don't need/want those accounts in a development cluster, but even with 600M capitalization, I don't think we should have overflowed.

Proposed Solution

Recreate the problem and figure out why the overflow happened. Technically, minting too many lamports could cause an overflow. But, even with those extra accounts that got us up to 600M capitalization, we should still have been operating at about 1/30th of u64::MAX:

600M SOL * (1 billion lamports / 1 SOL) / u64::MAX ~= 1 / 30

Joe mentioned that the bootstrap validator was reproducing this. Steps to reproduce:

ptaffet-jump commented 7 months ago

See #338 for details about why this happens