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(devnet): devnet predeployed contracts stable address across systems (re)
- chore: Fixed README table format
- fix(cli): fixed devnet cli arguments
Expand Down
25 changes: 24 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,32 @@ 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)?;

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(prev_block_number),
value: prev_block_hash,
}],
});
}
Ok(None) => {
// this shouldn't happen, ideally should panic
log::error!("No block hash found for block number {}", prev_block_number);
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 panic ig?

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

}
Err(e) => {
log::error!("Error fetching block hash for block {}: {:?}", prev_block_number, e);
}
}
}

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

let parent_block_hash = Felt::ZERO; // temp parent block hash
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/chain_config/src/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ impl ChainConfig {
chain_name: "Madara".into(),
chain_id: ChainId::Other("MADARA_DEVNET".into()),
sequencer_address: Felt::from_hex_unchecked("0x123").try_into().unwrap(),
block_time: Duration::from_secs(4),
pending_block_update_time: Duration::from_secs(1),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
block_time: Duration::from_secs(4),
pending_block_update_time: Duration::from_secs(1),

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

..ChainConfig::starknet_sepolia()
}
}
Expand Down
Loading