Skip to content

Commit

Permalink
Merge pull request #46 from jbcaron/feat/up_blockifier
Browse files Browse the repository at this point in the history
fix get_tx_receipt(), l1_da_mode, CI
  • Loading branch information
antiyro authored Apr 10, 2024
2 parents 625ced7 + 6df5c58 commit 70444fc
Show file tree
Hide file tree
Showing 24 changed files with 148 additions and 205 deletions.
4 changes: 1 addition & 3 deletions crates/client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ mp-hashers = { workspace = true }
mp-types = { workspace = true }

# Starknet crates
blockifier = { workspace = true, features = [
"testing",
] }
blockifier = { workspace = true, features = ["testing"] }
bonsai-trie = { workspace = true }
starknet-core = { workspace = true }
starknet-ff = { workspace = true, default-features = false, features = [
Expand Down
14 changes: 9 additions & 5 deletions crates/client/rpc/src/methods/get_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::utils::{
get_block_by_block_hash, l1_data_gas_price, l1_gas_price, new_root, parent_hash, sequencer_address,
starknet_version, status, timestamp, tx_conv, tx_hash_compute, tx_hash_retrieve,
};
use crate::{Felt, Starknet};
use crate::{l1_da_mode, Felt, Starknet};

pub(crate) fn get_block_with_tx_hashes_finalized<A, BE, G, C, P, H>(
server: &Starknet<A, BE, G, C, P, H>,
Expand Down Expand Up @@ -55,6 +55,7 @@ where
let l1_gas_price = l1_gas_price(&starknet_block);
let l1_data_gas_price = l1_data_gas_price(&starknet_block);
let starknet_version = starknet_version(&starknet_block);
let l1_da_mode = l1_da_mode(&starknet_block);

let block_with_tx_hashes = BlockWithTxHashes {
transactions,
Expand All @@ -68,7 +69,7 @@ where
l1_gas_price,
l1_data_gas_price,
starknet_version,
l1_da_mode: todo!(),
l1_da_mode,
};

Ok(MaybePendingBlockWithTxHashes::Block(block_with_tx_hashes))
Expand All @@ -88,6 +89,7 @@ where
let l1_gas_price = l1_gas_price(&starknet_block);
let l1_data_gas_price = l1_data_gas_price(&starknet_block);
let starknet_version = starknet_version(&starknet_block);
let l1_da_mode = l1_da_mode(&starknet_block);

let block_with_tx_hashes = PendingBlockWithTxHashes {
transactions,
Expand All @@ -97,7 +99,7 @@ where
l1_gas_price,
l1_data_gas_price,
starknet_version,
l1_da_mode: todo!(),
l1_da_mode,
};

Ok(MaybePendingBlockWithTxHashes::PendingBlock(block_with_tx_hashes))
Expand Down Expand Up @@ -137,6 +139,7 @@ where
let l1_gas_price = l1_gas_price(&starknet_block);
let l1_data_gas_price = l1_data_gas_price(&starknet_block);
let starknet_version = starknet_version(&starknet_block);
let l1_da_mode = l1_da_mode(&starknet_block);

let block_with_txs = BlockWithTxs {
status,
Expand All @@ -150,7 +153,7 @@ where
l1_gas_price,
l1_data_gas_price,
starknet_version,
l1_da_mode: todo!(),
l1_da_mode,
};

Ok(MaybePendingBlockWithTxs::Block(block_with_txs))
Expand All @@ -172,6 +175,7 @@ where
let l1_gas_price = l1_gas_price(&starknet_block);
let l1_data_gas_price = l1_data_gas_price(&starknet_block);
let starknet_version = starknet_version(&starknet_block);
let l1_da_mode = l1_da_mode(&starknet_block);

let block_with_txs = PendingBlockWithTxs {
transactions,
Expand All @@ -181,7 +185,7 @@ where
l1_gas_price,
l1_data_gas_price,
starknet_version,
l1_da_mode: todo!(),
l1_da_mode,
};

Ok(MaybePendingBlockWithTxs::PendingBlock(block_with_txs))
Expand Down
27 changes: 12 additions & 15 deletions crates/client/rpc/src/methods/read/estimate_message_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,17 @@ pub fn convert_message_into_tx<H: HasherT + Send + Sync + 'static>(
chain_id: Felt252Wrapper,
block_number: Option<u64>,
) -> L1HandlerTransaction {
let transaction = {
let calldata = std::iter::once(Felt252Wrapper::from(message.from_address).into())
.chain(message.payload.into_iter().map(|felt| Felt252Wrapper::from(felt).into()))
.collect();
let tx = starknet_api::transaction::L1HandlerTransaction {
version: TransactionVersion::ZERO,
nonce: Nonce(StarkFelt::ZERO),
contract_address: Felt252Wrapper::from(message.to_address).into(),
entry_point_selector: Felt252Wrapper::from(message.entry_point_selector).into(),
calldata: Calldata(Arc::new(calldata)),
};
let tx_hash = tx.compute_hash::<H>(chain_id, true, block_number);

L1HandlerTransaction { tx, tx_hash, paid_fee_on_l1: Fee(10) }
let calldata = std::iter::once(Felt252Wrapper::from(message.from_address).into())
.chain(message.payload.into_iter().map(|felt| Felt252Wrapper::from(felt).into()))
.collect();
let tx = starknet_api::transaction::L1HandlerTransaction {
version: TransactionVersion::ZERO,
nonce: Nonce(StarkFelt::ZERO),
contract_address: Felt252Wrapper::from(message.to_address).into(),
entry_point_selector: Felt252Wrapper::from(message.entry_point_selector).into(),
calldata: Calldata(Arc::new(calldata)),
};
transaction
let tx_hash = tx.compute_hash::<H>(chain_id, true, block_number);

L1HandlerTransaction { tx, tx_hash, paid_fee_on_l1: Fee(10) }
}
56 changes: 29 additions & 27 deletions crates/client/rpc/src/methods/read/get_transaction_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ use starknet_api::transaction::{
DeclareTransaction, DeployAccountTransaction, InvokeTransaction, L1HandlerTransaction, Transaction, TransactionHash,
};
use starknet_core::types::{
BlockId, ComputationResources, DataResources, DeclareTransactionReceipt, DeployAccountTransactionReceipt,
ExecutionResources, ExecutionResult, FieldElement, Hash256, InvokeTransactionReceipt, L1HandlerTransactionReceipt,
TransactionFinalityStatus, TransactionReceipt, TransactionReceiptWithBlockInfo,
BlockId, ComputationResources, DataAvailabilityResources, DataResources, DeclareTransactionReceipt,
DeployAccountTransactionReceipt, ExecutionResources, ExecutionResult, FieldElement, Hash256,
InvokeTransactionReceipt, L1HandlerTransactionReceipt, TransactionFinalityStatus, TransactionReceipt,
TransactionReceiptWithBlockInfo,
};

use crate::errors::StarknetRpcApiError;
Expand Down Expand Up @@ -109,22 +110,25 @@ where
None => ExecutionResult::Succeeded,
};

// no execution resources for declare transactions
let execution_resources = match execution_infos.execute_call_info {
Some(ref call_info) => blockifier_call_info_to_starknet_resources(call_info),
None => ExecutionResources {
computation_resources: ComputationResources {
steps: todo!(),
memory_holes: todo!(),
range_check_builtin_applications: todo!(),
pedersen_builtin_applications: todo!(),
poseidon_builtin_applications: todo!(),
ec_op_builtin_applications: todo!(),
ecdsa_builtin_applications: todo!(),
bitwise_builtin_applications: todo!(),
keccak_builtin_applications: todo!(),
segment_arena_builtin: todo!(),
steps: 0,
memory_holes: None,
range_check_builtin_applications: None,
pedersen_builtin_applications: None,
poseidon_builtin_applications: None,
ec_op_builtin_applications: None,
ecdsa_builtin_applications: None,
bitwise_builtin_applications: None,
keccak_builtin_applications: None,
segment_arena_builtin: None,
},
data_resources: DataResources {
data_availability: DataAvailabilityResources { l1_gas: 0, l1_data_gas: 0 },
},
data_resources: DataResources { data_availability: todo!() },
},
};

Expand All @@ -148,7 +152,7 @@ where
execution_resources,
execution_result,
}),
Transaction::DeployAccount(tx) => TransactionReceipt::DeployAccount(DeployAccountTransactionReceipt {
Transaction::DeployAccount(_) => TransactionReceipt::DeployAccount(DeployAccountTransactionReceipt {
transaction_hash,
actual_fee,
finality_status,
Expand Down Expand Up @@ -181,7 +185,9 @@ where
_ => unreachable!("Deploy transactions are not supported"),
};

Ok(TransactionReceiptWithBlockInfo { receipt, block: todo!() })
let block_info = starknet_core::types::ReceiptBlock::Block { block_hash: block_hash.0, block_number };

Ok(TransactionReceiptWithBlockInfo { receipt, block: block_info })
}

fn previous_block_hash<A, BE, G, C, P, H>(client: &Starknet<A, BE, G, C, P, H>, block_number: u64) -> RpcResult<DHashT>
Expand Down Expand Up @@ -229,11 +235,11 @@ where
.filter(|tx| !matches!(tx, Transaction::Deploy(_))) // deploy transaction was not supported by blockifier
.map(|tx| match tx {
Transaction::Invoke(invoke_tx) => {
tx_invoke_transaction(invoke_tx.clone(), invoke_tx.compute_hash::<H>(Felt252Wrapper::from(chain_id.0).into(), false, Some(block_number)))
tx_invoke_transaction(invoke_tx.clone(), invoke_tx.compute_hash::<H>(Felt252Wrapper::from(chain_id.0), false, Some(block_number)))
}
// TODO: add real contract address param here
Transaction::DeployAccount(deploy_account_tx) => {
tx_deploy_account(deploy_account_tx.clone(), deploy_account_tx.compute_hash::<H>(Felt252Wrapper::from(chain_id.0).into(), false, Some(block_number)), ContractAddress::default())
tx_deploy_account(deploy_account_tx.clone(), deploy_account_tx.compute_hash::<H>(Felt252Wrapper::from(chain_id.0), false, Some(block_number)), ContractAddress::default())
}
Transaction::Declare(declare_tx) => {
tx_declare(client, substrate_block_hash, declare_tx.clone())
Expand Down Expand Up @@ -313,7 +319,7 @@ where
G: GenesisProvider + Send + Sync + 'static,
H: HasherT + Send + Sync + 'static,
{
let contract_class = client
let _contract_class = client
.overrides
.for_block_hash(client.client.as_ref(), substrate_block_hash)
.contract_class_by_class_hash(substrate_block_hash, class_hash)
Expand Down Expand Up @@ -347,7 +353,7 @@ where
}
}

fn tx_declare_v2(declare_tx: DeclareTransaction, class_hash: ClassHash) -> RpcResult<btx::Transaction> {
fn tx_declare_v2(declare_tx: DeclareTransaction, _class_hash: ClassHash) -> RpcResult<btx::Transaction> {
// Welcome to type hell! This 3-part conversion will take you through the extenses
// of a codebase so thick it might as well be pasta -yum!
// Also should no be a problem as a declare transaction *should* not be able to
Expand All @@ -361,7 +367,7 @@ fn tx_declare_v2(declare_tx: DeclareTransaction, class_hash: ClassHash) -> RpcRe
StarknetRpcApiError::InternalServerError
})?;

let contract_class = ContractClassBf::V1(ContractClassV1Bf::try_from(contract_class).map_err(|e| {
let _contract_class = ContractClassBf::V1(ContractClassV1Bf::try_from(contract_class).map_err(|e| {
log::error!("Failed to convert the compiler CasmContractClass to blockifier CasmContractClass: {e}");
StarknetRpcApiError::InternalServerError
})?);
Expand All @@ -378,7 +384,7 @@ fn tx_declare_v2(declare_tx: DeclareTransaction, class_hash: ClassHash) -> RpcRe
match declare_tx {
DeclareTransaction::V0(_) => todo!(),
DeclareTransaction::V1(_) => todo!(),
DeclareTransaction::V2(_) => tx_declare_v2(declare_tx, class_hash),
DeclareTransaction::V2(_) => tx_declare_v2(declare_tx, _class_hash),
DeclareTransaction::V3(_) => todo!("implement DeclareTransaction::V3"),
}
}
Expand All @@ -390,7 +396,7 @@ where
let chain_id = chain_id.0.into();
let tx_hash = l1_handler.compute_hash::<H>(chain_id, false, Some(block_number));
let paid_fee =
DeoxysBackend::l1_handler_paid_fee().get_fee_paid_for_l1_handler_tx(tx_hash.0.into()).map_err(|e| {
DeoxysBackend::l1_handler_paid_fee().get_fee_paid_for_l1_handler_tx(tx_hash.0).map_err(|e| {
log::error!("Failed to retrieve fee paid on l1 for tx with hash `{tx_hash:?}`: {e}");
StarknetRpcApiError::InternalServerError
})?;
Expand Down Expand Up @@ -435,10 +441,6 @@ where
log::error!("Failed to reexecute the transactions: {e:?}");
StarknetRpcApiError::InternalServerError
})?
.map_err(|e| {
log::error!("One of the transaction failed during it's reexecution: {e:?}");
StarknetRpcApiError::InternalServerError
})?
.pop()
.ok_or_else(|| {
log::error!("No execution info returned for the last transaction");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ where
.map_err(|e| {
log::error!("Failed to reexecute the block transactions: {e:?}");
StarknetRpcApiError::InternalServerError
})?
.map_err(|_| {
log::error!(
"One of the transaction failed during it's reexecution. This should not happen, as the block has \
already been executed successfully in the past. There is a bug somewhere."
);
StarknetRpcApiError::InternalServerError
})?;

let storage_override = starknet.overrides.for_block_hash(starknet.client.as_ref(), substrate_block_hash);
Expand Down
7 changes: 0 additions & 7 deletions crates/client/rpc/src/methods/trace/trace_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ where
.map_err(|e| {
log::error!("Failed to reexecute the block transactions: {e:?}");
StarknetRpcApiError::InternalServerError
})?
.map_err(|_| {
log::error!(
"One of the transaction failed during it's reexecution. This should not happen, as the block has \
already been executed successfully in the past. There is a bug somewhere."
);
StarknetRpcApiError::InternalServerError
})?;

let storage_override = starknet.overrides.for_block_hash(starknet.client.as_ref(), substrate_block_hash);
Expand Down
55 changes: 26 additions & 29 deletions crates/client/rpc/src/methods/trace/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use sp_runtime::traits::Block as BlockT;
use starknet_api::core::{ClassHash, ContractAddress};
use starknet_api::transaction as stx;
use starknet_core::types::{
BlockId, ComputationResources, DataResources, DeclareTransactionTrace, DeployAccountTransactionTrace,
ExecuteInvocation, ExecutionResources, InvokeTransactionTrace, L1HandlerTransactionTrace, RevertedInvocation,
TransactionTrace,
BlockId, ComputationResources, DataAvailabilityResources, DataResources, DeclareTransactionTrace,
DeployAccountTransactionTrace, ExecuteInvocation, ExecutionResources, InvokeTransactionTrace,
L1HandlerTransactionTrace, RevertedInvocation, TransactionTrace,
};
use starknet_ff::FieldElement;

Expand Down Expand Up @@ -139,20 +139,17 @@ pub fn try_get_funtion_invocation_from_call_info<B: BlockT>(
};

// TODO: Replace this with non default exec resources
let execution_resources = ExecutionResources {
computation_resources: ComputationResources {
steps: todo!(),
memory_holes: todo!(),
range_check_builtin_applications: todo!(),
pedersen_builtin_applications: todo!(),
poseidon_builtin_applications: todo!(),
ec_op_builtin_applications: todo!(),
ecdsa_builtin_applications: todo!(),
bitwise_builtin_applications: todo!(),
keccak_builtin_applications: todo!(),
segment_arena_builtin: todo!(),
},
data_resources: DataResources { data_availability: todo!() },
let computation_resources = ComputationResources {
steps: 0,
memory_holes: None,
range_check_builtin_applications: None,
pedersen_builtin_applications: None,
poseidon_builtin_applications: None,
ec_op_builtin_applications: None,
ecdsa_builtin_applications: None,
bitwise_builtin_applications: None,
keccak_builtin_applications: None,
segment_arena_builtin: None,
};

Ok(starknet_core::types::FunctionInvocation {
Expand All @@ -167,7 +164,7 @@ pub fn try_get_funtion_invocation_from_call_info<B: BlockT>(
calls: inner_calls,
events,
messages,
execution_resources: execution_resources.computation_resources,
execution_resources: computation_resources,
})
}

Expand All @@ -182,18 +179,18 @@ pub fn tx_execution_infos_to_tx_trace<B: BlockT>(
// TODO: Replace this with non default exec resources
let execution_resources = ExecutionResources {
computation_resources: ComputationResources {
steps: todo!(),
memory_holes: todo!(),
range_check_builtin_applications: todo!(),
pedersen_builtin_applications: todo!(),
poseidon_builtin_applications: todo!(),
ec_op_builtin_applications: todo!(),
ecdsa_builtin_applications: todo!(),
bitwise_builtin_applications: todo!(),
keccak_builtin_applications: todo!(),
segment_arena_builtin: todo!(),
steps: 0,
memory_holes: None,
range_check_builtin_applications: None,
pedersen_builtin_applications: None,
poseidon_builtin_applications: None,
ec_op_builtin_applications: None,
ecdsa_builtin_applications: None,
bitwise_builtin_applications: None,
keccak_builtin_applications: None,
segment_arena_builtin: None,
},
data_resources: DataResources { data_availability: todo!() },
data_resources: DataResources { data_availability: DataAvailabilityResources { l1_gas: 0, l1_data_gas: 0 } },
};

// If simulated with `SimulationFlag::SkipValidate` this will be `None`
Expand Down
Loading

0 comments on commit 70444fc

Please sign in to comment.