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

Commit

Permalink
Merge branch 'main' into bug/genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
hhamud committed Mar 29, 2024
2 parents ae3f9ae + 943f323 commit 317a1bd
Show file tree
Hide file tree
Showing 25 changed files with 691 additions and 307 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/madara-commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ jobs:
target/production/madara key inspect --scheme Ed25519 "${{ steps.key-gen.outputs.SEED_PHRASE }}"
- name: Add keys to the node keystore
run: |
target/production/madara key insert --scheme Sr25519 --suri "${{ steps.key-gen.outputs.SEED_PHRASE }}" --key-type aura
target/production/madara key insert --scheme Ed25519 --suri "${{ steps.key-gen.outputs.SEED_PHRASE }}" --key-type gran
target/production/madara key insert --chain=chain-raw.json --scheme Sr25519 --suri "${{ steps.key-gen.outputs.SEED_PHRASE }}" --key-type aura
target/production/madara key insert --chain=chain-raw.json --scheme Ed25519 --suri "${{ steps.key-gen.outputs.SEED_PHRASE }}" --key-type gran
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
## Next release

- fix: Genesis hash is only consistent upon using the raw chainspec file
- Fix(node): Fix creating a local testnet with multiple nodes fails using only
cli flags
- dev: change `Vec::new` to `Vec::with_capacity` where possible.
- chore(rpc): clean trace api
- feat(rpc): added state diff real value in trace api
- chore: update cairo-vm commit and update gas per op
- refactor(rpc): use single arc instance of starknet rpc
- build: remove patch on `ring-vrf` dependecy
Expand All @@ -24,6 +29,10 @@

## v0.7.0

- fix: fix# Madara Changelog

## Next release

- chore: release v0.7.0
- refacto: remove abusive `TryInto` impl
- dev: optimize tx trace creation
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ starknet-signers = { git = "https://github.com/xJonathanLEI/starknet-rs.git", re
starknet-accounts = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }
starknet-contract = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }

blockifier = { git = "https://github.com/massalabs/blockifier", branch = "no_std-support-7578442-std", default-features = false, features = [
blockifier = { git = "https://github.com/keep-starknet-strange/blockifier", branch = "no_std-support-7578442", default-features = false, features = [
"std",
"parity-scale-codec",
] }
Expand Down
11 changes: 7 additions & 4 deletions crates/client/data-availability/src/avail/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::fs::File;
use std::path::PathBuf;

use serde::Deserialize;

use crate::{DaError, DaLayer, DaMode};
use crate::{DaError, DaMode};

const DEFAULT_AVAIL_WS: &str = "ws://127.0.0.1:9945";
const DEFAULT_APP_ID: u32 = 0;
Expand All @@ -22,10 +25,10 @@ pub struct AvailConfig {
}

impl TryFrom<&PathBuf> for AvailConfig {
type Error = DaErr;
type Error = DaError;
fn try_from(path: &PathBuf) -> Result<Self, Self::Error> {
let file = File::open(path).map_err(|e| DaError::FailedOpeningConfig(e))?;
serde_json::from_reader(file).map_err(|e| DaError::FailedParsingConfig(e))
let file = File::open(path).map_err(DaError::FailedOpeningConfig)?;
serde_json::from_reader(file).map_err(DaError::FailedParsingConfig)
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/client/data-availability/src/avail/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use subxt::ext::sp_core::sr25519::Pair;
use subxt::OnlineClient;

use crate::utils::get_bytes_from_state_diff;
use crate::{DaClient, DaError, DaLayer, DaMode};
use crate::{DaClient, DaError, DaMode};

type AvailPairSigner = subxt::tx::PairSigner<AvailConfig, Pair>;

Expand Down Expand Up @@ -44,7 +44,7 @@ impl SubxtClient {
pub async fn restart(&mut self) -> Result<(), DaError> {
self.client = match build_client(self.config.ws_provider.as_str(), self.config.validate_codegen).await {
Ok(i) => i,
Err(e) => return DaError::FailedBuildingClient(e.into()),
Err(e) => return Err(DaError::FailedBuildingClient(e.into())),
};

Ok(())
Expand All @@ -65,7 +65,7 @@ impl TryFrom<config::AvailConfig> for SubxtClient {

#[async_trait]
impl DaClient for AvailClient {
async fn publish_state_diff(&self, state_diff: Vec<U256>) -> Result<(), DaError> {
async fn publish_state_diff(&self, state_diff: Vec<U256>) -> Result<(), anyhow::Error> {
let bytes = get_bytes_from_state_diff(&state_diff);
let bytes = BoundedVec(bytes);
self.publish_data(&bytes).await?;
Expand All @@ -75,7 +75,7 @@ impl DaClient for AvailClient {

// state diff can be published w/o verification of last state for the time being
// may change in subsequent DaMode implementations
async fn last_published_state(&self) -> Result<I256> {
async fn last_published_state(&self) -> Result<I256, anyhow::Error> {
Ok(I256::from(1))
}

Expand All @@ -102,7 +102,7 @@ impl AvailClient {
let _ = ws_client.restart().await;
}

return DaError::FailedBuildingClient(e.into());
return Err(DaError::FailedBuildingClient(e.into()));
}
};

Expand Down
3 changes: 3 additions & 0 deletions crates/client/data-availability/src/celestia/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::fs::File;
use std::path::PathBuf;

use serde::Deserialize;

use crate::{DaError, DaMode};
Expand Down
9 changes: 6 additions & 3 deletions crates/client/data-availability/src/celestia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct CelestiaClient {

#[async_trait]
impl DaClient for CelestiaClient {
async fn publish_state_diff(&self, state_diff: Vec<U256>) -> Result<(), DaError> {
async fn publish_state_diff(&self, state_diff: Vec<U256>) -> Result<(), anyhow::Error> {
let blob = self.get_blob_from_state_diff(state_diff).map_err(|e| DaError::FailedDataFetching(e.into()))?;

let submitted_height = self.publish_data(&blob).await.map_err(|e| DaError::FailedDataSubmission(e.into()))?;
Expand All @@ -39,7 +39,7 @@ impl DaClient for CelestiaClient {
Ok(())
}

async fn last_published_state(&self) -> Result<I256> {
async fn last_published_state(&self) -> Result<I256, anyhow::Error> {
Ok(I256::from(1))
}

Expand Down Expand Up @@ -93,7 +93,10 @@ impl TryFrom<config::CelestiaConfig> for CelestiaClient {
// we only need to initiate the http provider and not the ws provider, we don't need async
let mut headers = HeaderMap::new();
if let Some(auth_token) = conf.auth_token {
let val = HeaderValue::from_str(&format!("Bearer {}", auth_token))?;
let val = match HeaderValue::from_str(&format!("Bearer {}", auth_token)) {
Ok(value) => value,
Err(e) => return Err(DaError::FailedConversion(e.into())),
};
headers.insert(header::AUTHORIZATION, val);
}

Expand Down
51 changes: 50 additions & 1 deletion crates/client/rpc-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::Arc;

use anyhow::{anyhow, Result};
use blockifier::execution::contract_class::ContractClass as BlockifierContractClass;
use blockifier::state::cached_state::CommitmentStateDiff;
use cairo_lang_casm_contract_class::{CasmContractClass, CasmContractEntryPoint, CasmContractEntryPoints};
use cairo_lang_starknet::contract_class::{
ContractClass as SierraContractClass, ContractEntryPoint, ContractEntryPoints,
Expand All @@ -27,7 +28,7 @@ use starknet_core::types::{
};

/// Returns a [`ContractClass`] from a [`BlockifierContractClass`]
pub fn to_rpc_contract_class(contract_class: BlockifierContractClass) -> Result<ContractClass> {
pub fn blockifier_to_rpc_contract_class_types(contract_class: BlockifierContractClass) -> Result<ContractClass> {
match contract_class {
BlockifierContractClass::V0(contract_class) => {
let entry_points_by_type = to_legacy_entry_points_by_type(&contract_class.entry_points_by_type)?;
Expand All @@ -48,6 +49,54 @@ pub fn to_rpc_contract_class(contract_class: BlockifierContractClass) -> Result<
}
}

/// Returns a [`StateDiff`] from a [`CommitmentStateDiff`]
pub fn blockifier_to_rpc_state_diff_types(commitment_state_diff: CommitmentStateDiff) -> Result<StateDiff> {
let storage_diffs: Vec<ContractStorageDiffItem> = commitment_state_diff
.storage_updates
.into_iter()
.map(|(address, storage_map)| {
let storage_entries = storage_map
.into_iter()
.map(|(key, value)| StorageEntry { key: key.0.0.into(), value: value.into() })
.collect();
ContractStorageDiffItem { address: address.0.0.into(), storage_entries }
})
.collect();

let declared_classes = commitment_state_diff
.class_hash_to_compiled_class_hash
.into_iter()
.map(|(class_hash, compiled_class_hash)| DeclaredClassItem {
class_hash: class_hash.0.into(),
compiled_class_hash: compiled_class_hash.0.into(),
})
.collect();

let deployed_contracts = commitment_state_diff
.address_to_class_hash
.into_iter()
.map(|(address, class_hash)| DeployedContractItem {
address: address.0.0.into(),
class_hash: class_hash.0.into(),
})
.collect();

let nonces = commitment_state_diff
.address_to_nonce
.into_iter()
.map(|(address, nonce)| NonceUpdate { contract_address: address.0.0.into(), nonce: nonce.0.into() })
.collect();

Ok(StateDiff {
storage_diffs,
deprecated_declared_classes: vec![],
declared_classes,
deployed_contracts,
replaced_classes: vec![],
nonces,
})
}

/// Returns a [`StateDiff`] from a [`ThinStateDiff`]
pub fn to_rpc_state_diff(thin_state_diff: ThinStateDiff) -> StateDiff {
let nonces = thin_state_diff
Expand Down
4 changes: 2 additions & 2 deletions crates/client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ where
StarknetRpcApiError::ContractNotFound
})?;

Ok(to_rpc_contract_class(contract_class).map_err(|e| {
Ok(blockifier_to_rpc_contract_class_types(contract_class).map_err(|e| {
error!("Failed to convert contract class at '{contract_address}' to RPC contract class: {e}");
StarknetRpcApiError::InvalidContractClass
})?)
Expand Down Expand Up @@ -861,7 +861,7 @@ where
StarknetRpcApiError::ClassHashNotFound
})?;

Ok(to_rpc_contract_class(contract_class).map_err(|e| {
Ok(blockifier_to_rpc_contract_class_types(contract_class).map_err(|e| {
error!("Failed to convert contract class from hash '{class_hash}' to RPC contract class: {e}");
StarknetRpcApiError::InternalServerError
})?)
Expand Down
1 change: 1 addition & 0 deletions crates/client/rpc/src/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ where
StarknetRpcApiError::ContractError
})?
.swap_remove(0)
.1
.map_err(|e| {
error!("Failed to simulate User Transaction: {:?}", e);
StarknetRpcApiError::InternalServerError
Expand Down
Loading

0 comments on commit 317a1bd

Please sign in to comment.