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

feat: added special address with block number and block hash #347

Merged
merged 12 commits into from
Oct 18, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- fix(snos): added special address while closing block for SNOS
- fix(mempool): validator errors were ignored in `mempool/rsc/lib.rs`
- fix(primitives): fixed storage entries not being sorted in state commitment
- fix(devnet): devnet predeployed contracts stable address across systems (re)
Expand Down
27 changes: 26 additions & 1 deletion crates/client/mempool/src/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,34 @@ impl<Mempool: MempoolProvider> BlockProductionTask<Mempool> {

// Complete the block with full bouncer capacity.
let start_time = Instant::now();
let (new_state_diff, _n_executed) =
let (mut new_state_diff, _n_executed) =
self.continue_block(self.backend.chain_config().bouncer_config.block_max_capacity)?;

// SNOS requirement: For blocks >= 10, the hash of the block 10 blocks prior
// at address 0x1 with the block number as the key
if block_n >= 10 {
let prev_block_number = block_n - 10;
match self.backend.get_block_hash(&BlockId::Number(prev_block_number)) {
Copy link
Member

Choose a reason for hiding this comment

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

this match can be simplified to

let prev_block_hash = self.backend.get_block_hash(&BlockId::Number(prev_block_number))
  .map_err(|err| Error::Unexpected(
      format!("Error fetching block hash for block {prev_block_number}: {err:#}").into()
  ))?
  .ok_or_else(|| Error::Unexpected(
      format!("No block hash found for block number {prev_block_number}").into()
  ))?;
let address = Felt::ONE;
new_state_diff.storage_diffs.push(ContractStorageDiffItem {
    address,
    storage_entries: vec![StorageEntry { key: Felt::from(block_n), value: prev_block_hash }],
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved

Ok(Some(prev_block_hash)) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's add a comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

let address = Felt::ONE;
new_state_diff.storage_diffs.push(ContractStorageDiffItem {
address,
storage_entries: vec![StorageEntry { key: Felt::from(block_n), value: prev_block_hash }],
});
}
Ok(None) => {
return Err(Error::Unexpected(
format!("No block hash found for block number {}", prev_block_number).into(),
));
}
Err(e) => {
return Err(Error::Unexpected(
format!("Error fetching block hash for block {}: {:?}", prev_block_number, e).into(),
));
}
}
}

// Convert the pending block to a closed block and save to db.

let parent_block_hash = Felt::ZERO; // temp parent block hash
Expand Down
Loading