Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
update blockifier with fix of chain-specs building
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelabro committed Apr 23, 2024
1 parent ebb9405 commit 3e99f89
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 84 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/client/l1-messages/src/worker.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use blockifier::transaction::transactions::L1HandlerTransaction;
use ethers::providers::{Http, Provider, StreamExt};
use ethers::types::U256;
pub use mc_eth_client::config::EthereumClientConfig;
Expand Down Expand Up @@ -146,7 +147,7 @@ where

let chain_id = client.runtime_api().chain_id(best_block_hash).map_err(L1MessagesWorkerError::RuntimeApiError)?;
let tx_hash = tx.compute_hash(chain_id, false);
let transaction = blockifier::transaction::transactions::L1HandlerTransaction { tx, tx_hash, paid_fee_on_l1 };
let transaction = L1HandlerTransaction { tx, tx_hash, paid_fee_on_l1 };

let extrinsic = client.runtime_api().convert_l1_transaction(best_block_hash, transaction).map_err(|e| {
log::error!("⟠ Failed to convert L1 Transaction via Runtime Api: {:?}", e);
Expand Down
8 changes: 4 additions & 4 deletions crates/client/rpc/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ where
})?;
for event in raw_events {
emitted_events.push(EmittedEvent {
from_address: Felt252Wrapper::from(event.from_address).0,
keys: event.content.keys.into_iter().map(|felt| Felt252Wrapper::from(felt).0).collect(),
data: event.content.data.0.into_iter().map(|felt| Felt252Wrapper::from(felt).0).collect(),
from_address: Felt252Wrapper::from(event.from_address).into(),
keys: event.content.keys.into_iter().map(|felt| Felt252Wrapper::from(felt).into()).collect(),
data: event.content.data.0.into_iter().map(|felt| Felt252Wrapper::from(felt).into()).collect(),
block_hash: Some(block_hash.into()),
block_number: Some(block_number),
transaction_hash: Felt252Wrapper::from(*tx_hash).0,
transaction_hash: Felt252Wrapper::from(*tx_hash).into(),
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,8 @@ where
.collect();
let tx = starknet_api::transaction::L1HandlerTransaction {
version: TransactionVersion::ZERO,
// Nonce is not used during the message fee estimation.
// Just put whatever.
nonce: Nonce(StarkFelt::ZERO),
contract_address: Felt252Wrapper::from(message.to_address).into(),
entry_point_selector: Felt252Wrapper::from(message.entry_point_selector).into(),
Expand All @@ -1012,7 +1014,7 @@ where
let tx_hash = tx.compute_hash(chain_id, true);

// Hardcoded `paid_fee_on_l1` value as it is not relevant here
L1HandlerTransaction { tx, tx_hash, paid_fee_on_l1: Fee(10) }
L1HandlerTransaction { tx, tx_hash, paid_fee_on_l1: Fee(1) }
};

let fee_estimate = self.do_estimate_message_fee(substrate_block_hash, transaction)?;
Expand Down
5 changes: 2 additions & 3 deletions crates/pallets/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,13 +743,12 @@ pub mod pallet {
// The first tx validation would fail because the contract is not deployed yet,
// so we skip the entrypoint execution for now
(Nonce(StarkFelt::ONE), Nonce(StarkFelt::ZERO)) => {
// Self::validate_unsigned_tx(&transaction)?;
valid_transaction_builder =
valid_transaction_builder.and_requires((sender_address, Nonce(StarkFelt::ZERO)));
}
// Future transaction, we validate the entrypoing in order to avoid having the mempool flooded
// Future transaction, we validate the entrypoint in order to avoid having the mempool flooded
// There is a possiblility of false negative, where a previous tx execution you make the future
// one possible, atm we are ok with this, the user will just way for the
// one possible, atm we are ok with this, the user will just wait for the
// first one to be executed and then send the next one
// May be removed in the future tho
(transaction_nonce, sender_nonce) if transaction_nonce > sender_nonce => {
Expand Down
22 changes: 2 additions & 20 deletions crates/primitives/block/src/header.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use blockifier::blockifier::block::{BlockInfo, GasPrices};
use blockifier::context::{BlockContext, ChainInfo, FeeTokenAddresses};
use blockifier::versioned_constants::VersionedConstants;
use blockifier::blockifier::block::GasPrices;
use mp_felt::Felt252Wrapper;
use mp_hashers::HasherT;
use sp_core::U256;
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::core::{ChainId, ContractAddress};
use starknet_api::core::ContractAddress;
use starknet_api::hash::StarkHash;

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -62,21 +59,6 @@ impl Header {
}
}

/// Converts to a blockifier BlockContext
pub fn into_block_context(self, fee_token_addresses: FeeTokenAddresses, chain_id: ChainId) -> BlockContext {
BlockContext::new_unchecked(
&BlockInfo {
block_number: BlockNumber(self.block_number),
block_timestamp: BlockTimestamp(self.block_timestamp),
sequencer_address: self.sequencer_address,
gas_prices: self.l1_gas_price,
use_kzg_da: true,
},
&ChainInfo { chain_id, fee_token_addresses },
VersionedConstants::latest_constants(),
)
}

/// Compute the hash of the header.
pub fn hash<H: HasherT>(&self) -> Felt252Wrapper {
let data: &[Felt252Wrapper] = &[
Expand Down
53 changes: 1 addition & 52 deletions crates/primitives/block/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
use core::convert::TryFrom;
use std::num::NonZeroU128;

use blockifier::blockifier::block::GasPrices;
use blockifier::context::FeeTokenAddresses;
use mp_felt::Felt252Wrapper;
use mp_hashers::pedersen::PedersenHasher;
use mp_hashers::HasherT;
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::core::{ChainId, ContractAddress, PatriciaKey};
use starknet_api::core::{ContractAddress, PatriciaKey};
use starknet_api::hash::{StarkFelt, StarkHash};

use crate::Header;

fn generate_dummy_header() -> Vec<Felt252Wrapper> {
vec![
Felt252Wrapper::ONE, // block_number
Expand Down Expand Up @@ -78,48 +72,3 @@ fn test_real_header_hash() {

assert_eq!(hash, expected_hash);
}

#[test]
fn test_to_block_context() {
let sequencer_address = ContractAddress(PatriciaKey(StarkFelt::try_from("0xFF").unwrap()));
// Create a block header.
let block_header = Header {
block_number: 1,
block_timestamp: 1,
sequencer_address,
parent_block_hash: Default::default(),
transaction_count: Default::default(),
event_count: Default::default(),
protocol_version: Default::default(),
l1_gas_price: unsafe {
GasPrices {
eth_l1_gas_price: NonZeroU128::new_unchecked(10),
strk_l1_gas_price: NonZeroU128::new_unchecked(10),
eth_l1_data_gas_price: NonZeroU128::new_unchecked(10),
strk_l1_data_gas_price: NonZeroU128::new_unchecked(10),
}
},
extra_data: Default::default(),
};
// Create a fee token address.
let fee_token_addresses = FeeTokenAddresses {
eth_fee_token_address: ContractAddress(PatriciaKey(StarkFelt::try_from("AA").unwrap())),
strk_fee_token_address: ContractAddress(PatriciaKey(StarkFelt::try_from("BB").unwrap())),
};
// Create a chain id.
let chain_id = ChainId("0x1".to_string());
// Try to serialize the block header.
let block_context = block_header.into_block_context(fee_token_addresses.clone(), chain_id);
// Check that the block context was serialized correctly.
assert_eq!(block_context.block_info().block_number, BlockNumber(1));
assert_eq!(block_context.block_info().block_timestamp, BlockTimestamp(1));
assert_eq!(block_context.block_info().sequencer_address, sequencer_address);
assert_eq!(
&block_context.chain_info().fee_token_addresses.eth_fee_token_address,
&fee_token_addresses.eth_fee_token_address
);
assert_eq!(
&block_context.chain_info().fee_token_addresses.strk_fee_token_address,
&fee_token_addresses.strk_fee_token_address
);
}

0 comments on commit 3e99f89

Please sign in to comment.