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

bug: anvil_dumpState full block load doesn't work #8213

Closed
1 of 2 tasks
Tracked by #8269
samlaf opened this issue Jun 20, 2024 · 5 comments · Fixed by #8411
Closed
1 of 2 tasks
Tracked by #8269

bug: anvil_dumpState full block load doesn't work #8213

samlaf opened this issue Jun 20, 2024 · 5 comments · Fixed by #8411
Labels
C-anvil Command: anvil T-bug Type: bug

Comments

@samlaf
Copy link
Contributor

samlaf commented Jun 20, 2024

Component

Anvil

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (3abac32 2024-06-20T00:22:07.769597000Z)

What command(s) is the bug in?

anvil --dump/load-state & cast block n --full

Operating System

macOS (Apple Silicon)

Describe the bug

This is a followup to #8160. There was a bug left in that PR, which is now affecting me. It seems like full block are not dumped properly:

$ cast block 1 --full
Error:
block Number(Number(1)) not found

Does anyone know what the difference between cast block n and cast block n --full, and any intuition as to why blocks can be found, but not full blocks?

When querying via geth's BlockByNumber (which queries https://www.quicknode.com/docs/ethereum/eth_getBlockByNumber), I get panics, which seems to indicate that geth sets the transaction_detail_flag to true (equivalent to -full flag in cast?)

@samlaf samlaf added the T-bug Type: bug label Jun 20, 2024
@mattsse
Copy link
Member

mattsse commented Jun 20, 2024

this looks more like an issue with how the state is reinserted

@samlaf
Copy link
Contributor Author

samlaf commented Jul 5, 2024

Another weirdness we just noticed:

Start anvil chain with a loaded state (with block > 0). Then:

cast block-number // prints 200 (or whatever block the loaded state was dumped at)
cast block --rpc-url --field "number" // prints 0... ?!?!?!

and then if you cast rpc anvil_mine to advance the chain by 1 block. Now:

cast block-number // prints 201 (or whatever)
cast block --rpc-url --field "number" // prints 201 ?!?

@tuler
Copy link
Contributor

tuler commented Jul 11, 2024

This is affecting me as well. Any insight about why this happens, and a potential fix?
The dumped json state seems correct, the transactions are there.

@tuler
Copy link
Contributor

tuler commented Jul 11, 2024

/// Deserialize and add all blocks data to the backend storage
pub fn load_blocks(&mut self, serializable_blocks: Vec<SerializableBlock>) {
for serializable_block in serializable_blocks.iter() {
let block: Block = serializable_block.clone().into();
let block_hash = block.header.hash_slow();
let block_number = block.header.number;
self.blocks.insert(block_hash, block);
self.hashes.insert(U64::from(block_number), block_hash);
}
}

state loading above is not hydrating the transactions memory structure below, only the blocks and hashes.

pub struct BlockchainStorage {
/// all stored blocks (block hash -> block)
pub blocks: HashMap<B256, Block>,
/// mapping from block number -> block hash
pub hashes: HashMap<U64, B256>,
/// The current best hash
pub best_hash: B256,
/// The current best block number
pub best_number: U64,
/// genesis hash of the chain
pub genesis_hash: B256,
/// Mapping from the transaction hash to a tuple containing the transaction as well as the
/// transaction receipt
pub transactions: HashMap<TxHash, MinedTransaction>,
/// The total difficulty of the chain until this block
pub total_difficulty: U256,
}

This makes the get below to fail, because transaction is not there.

let info = storage.transactions.get(&hash)?.info.clone();

@KholdStare
Copy link
Contributor

Could this issue be related to #8179 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-anvil Command: anvil T-bug Type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants