Skip to content

Commit

Permalink
feat(katana): update RPC to v0.5.1 (#1259)
Browse files Browse the repository at this point in the history
* bump `starknet-rs` to `0.8.0`

* wip

* wip

* no error

* update

* update

* wip

* update

* update

* fix hurl test

* fix

* update hurl test

* Update examples/rpc/starknet/starknet_getBlockWithTxs.hurl

Co-authored-by: glihm <[email protected]>

* Update examples/rpc/starknet/starknet_getStorageAt.hurl

Co-authored-by: glihm <[email protected]>

---------

Co-authored-by: glihm <[email protected]>
  • Loading branch information
kariy and glihm authored Dec 13, 2023
1 parent c78fad8 commit b01bf09
Show file tree
Hide file tree
Showing 37 changed files with 589 additions and 222 deletions.
52 changes: 18 additions & 34 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ members = [
"crates/katana/rpc",
"crates/katana/rpc/rpc-types",
"crates/katana/rpc/rpc-types-builder",
"crates/katana/runner",
"crates/katana/storage/db",
"crates/katana/storage/provider",
"crates/katana/runner",
"crates/sozo",
"crates/torii/client",
"crates/torii/server",
Expand Down Expand Up @@ -96,7 +96,7 @@ serde_json = "1.0"
serde_with = "2.3.1"
smol_str = { version = "0.2.0", features = [ "serde" ] }
sqlx = { version = "0.7.2", features = [ "chrono", "macros", "regexp", "runtime-async-std", "runtime-tokio", "sqlite", "uuid" ] }
starknet = "0.7.0"
starknet = "0.8.0"
starknet-crypto = "0.6.1"
starknet_api = "0.6.0-rc3"
strum = "0.25"
Expand Down
11 changes: 4 additions & 7 deletions crates/dojo-world/src/contracts/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use starknet::core::utils::{
ParseCairoShortStringError,
};
use starknet::macros::short_string;
use starknet::providers::{
MaybeUnknownErrorCode, Provider, ProviderError, StarknetErrorWithMessage,
};
use starknet::providers::{Provider, ProviderError};
use starknet_crypto::poseidon_hash_many;

use crate::contracts::world::{ContractReaderError, WorldContractReader};
Expand Down Expand Up @@ -89,10 +87,9 @@ where
.await
.map(|res| res[0])
.map_err(|err| match err {
ProviderError::StarknetError(StarknetErrorWithMessage {
code: MaybeUnknownErrorCode::Known(StarknetError::ContractNotFound),
..
}) => ModelError::ModelNotFound,
ProviderError::StarknetError(StarknetError::ContractNotFound) => {
ModelError::ModelNotFound
}
err => err.into(),
})?;

Expand Down
23 changes: 8 additions & 15 deletions crates/dojo-world/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use starknet::core::utils::{
ParseCairoShortStringError,
};
use starknet::macros::selector;
use starknet::providers::{
MaybeUnknownErrorCode, Provider, ProviderError, StarknetErrorWithMessage,
};
use starknet::providers::{Provider, ProviderError};
use thiserror::Error;

use crate::contracts::model::ModelError;
Expand Down Expand Up @@ -168,10 +166,9 @@ impl Manifest {

let world_class_hash =
provider.get_class_hash_at(BLOCK_ID, world_address).await.map_err(|err| match err {
ProviderError::StarknetError(StarknetErrorWithMessage {
code: MaybeUnknownErrorCode::Known(StarknetError::ContractNotFound),
..
}) => ManifestError::RemoteWorldNotFound,
ProviderError::StarknetError(StarknetError::ContractNotFound) => {
ManifestError::RemoteWorldNotFound
}
err => err.into(),
})?;

Expand All @@ -184,10 +181,9 @@ impl Manifest {
.get_class_hash_at(BLOCK_ID, executor_address)
.await
.map_err(|err| match err {
ProviderError::StarknetError(StarknetErrorWithMessage {
code: MaybeUnknownErrorCode::Known(StarknetError::ContractNotFound),
..
}) => ManifestError::ExecutorNotFound,
ProviderError::StarknetError(StarknetError::ContractNotFound) => {
ManifestError::ExecutorNotFound
}
err => err.into(),
})?;

Expand Down Expand Up @@ -290,10 +286,7 @@ where
{
Ok(res) => parse_cairo_short_string(&res[0])?.into(),

Err(ProviderError::StarknetError(StarknetErrorWithMessage {
code: MaybeUnknownErrorCode::Known(StarknetError::ContractError),
..
})) => SmolStr::from(""),
Err(ProviderError::StarknetError(StarknetError::ContractError(_))) => SmolStr::from(""),

Err(err) => return Err(err.into()),
};
Expand Down
21 changes: 4 additions & 17 deletions crates/dojo-world/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ use starknet::core::utils::{
get_contract_address, get_selector_from_name, CairoShortStringToFeltError,
};
use starknet::macros::{felt, selector};
use starknet::providers::{
MaybeUnknownErrorCode, Provider, ProviderError, StarknetErrorWithMessage,
};
use starknet::providers::{Provider, ProviderError};
use starknet::signers::Signer;
use thiserror::Error;

Expand Down Expand Up @@ -106,11 +104,7 @@ pub trait Declarable {
.get_class(BlockId::Tag(BlockTag::Pending), flattened_class.class_hash())
.await
{
Err(ProviderError::StarknetError(StarknetErrorWithMessage {
code: MaybeUnknownErrorCode::Known(StarknetError::ClassHashNotFound),
..
})) => {}

Err(ProviderError::StarknetError(StarknetError::ClassHashNotFound)) => {}
Ok(_) => return Err(MigrationError::ClassAlreadyDeclared),
Err(e) => return Err(MigrationError::Provider(e)),
}
Expand Down Expand Up @@ -181,10 +175,7 @@ pub trait Deployable: Declarable + Sync {
to: world_address,
},

Err(ProviderError::StarknetError(StarknetErrorWithMessage {
code: MaybeUnknownErrorCode::Known(StarknetError::ContractNotFound),
..
})) => Call {
Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => Call {
calldata: vec![self.salt(), class_hash],
selector: selector!("deploy_contract"),
to: world_address,
Expand Down Expand Up @@ -251,11 +242,7 @@ pub trait Deployable: Declarable + Sync {
.get_class_hash_at(BlockId::Tag(BlockTag::Pending), contract_address)
.await
{
Err(ProviderError::StarknetError(StarknetErrorWithMessage {
code: MaybeUnknownErrorCode::Known(StarknetError::ContractNotFound),
..
})) => {}

Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => {}
Ok(_) => return Err(MigrationError::ContractAlreadyDeployed(contract_address)),
Err(e) => return Err(MigrationError::Provider(e)),
}
Expand Down
13 changes: 4 additions & 9 deletions crates/dojo-world/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use starknet::core::types::{
ExecutionResult, FieldElement, MaybePendingTransactionReceipt, PendingTransactionReceipt,
StarknetError, TransactionFinalityStatus, TransactionReceipt,
};
use starknet::providers::{
MaybeUnknownErrorCode, Provider, ProviderError, StarknetErrorWithMessage,
};
use starknet::providers::{Provider, ProviderError};
use tokio::time::{Instant, Interval};

type GetReceiptResult = Result<MaybePendingTransactionReceipt, ProviderError>;
Expand Down Expand Up @@ -185,11 +183,9 @@ where
}
},

Err(ProviderError::StarknetError(StarknetErrorWithMessage {
code:
MaybeUnknownErrorCode::Known(StarknetError::TransactionHashNotFound),
..
})) => {}
Err(ProviderError::StarknetError(
StarknetError::TransactionHashNotFound,
)) => {}

Err(e) => {
return Poll::Ready(Err(TransactionWaitingError::Provider(e)));
Expand Down Expand Up @@ -230,7 +226,6 @@ fn execution_status_from_receipt(receipt: &TransactionReceipt) -> &ExecutionResu
fn execution_status_from_pending_receipt(receipt: &PendingTransactionReceipt) -> &ExecutionResult {
match receipt {
PendingTransactionReceipt::Invoke(receipt) => &receipt.execution_result,
PendingTransactionReceipt::Deploy(receipt) => &receipt.execution_result,
PendingTransactionReceipt::Declare(receipt) => &receipt.execution_result,
PendingTransactionReceipt::L1Handler(receipt) => &receipt.execution_result,
PendingTransactionReceipt::DeployAccount(receipt) => &receipt.execution_result,
Expand Down
15 changes: 10 additions & 5 deletions crates/katana/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ use std::sync::Arc;

use blockifier::block_context::BlockContext;
use katana_primitives::block::{
Block, FinalityStatus, Header, PartialHeader, SealedBlockWithStatus,
Block, FinalityStatus, GasPrices, Header, PartialHeader, SealedBlockWithStatus,
};
use katana_primitives::contract::ContractAddress;
use katana_primitives::receipt::Receipt;
use katana_primitives::state::StateUpdatesWithDeclaredClasses;
use katana_primitives::transaction::TxWithHash;
use katana_primitives::version::CURRENT_STARKNET_VERSION;
use katana_primitives::FieldElement;
use katana_provider::providers::fork::ForkedProvider;
use katana_provider::providers::in_memory::InMemoryProvider;
Expand Down Expand Up @@ -149,15 +150,19 @@ impl Backend {

let partial_header = PartialHeader {
parent_hash: prev_hash,
gas_price: block_context.gas_prices.eth_l1_gas_price,
number: block_context.block_number.0,
version: CURRENT_STARKNET_VERSION,
timestamp: block_context.block_timestamp.0,
sequencer_address: block_context.sequencer_address.into(),
gas_prices: GasPrices {
eth_gas_price: block_context.gas_prices.eth_l1_gas_price.try_into().unwrap(),
strk_gas_price: block_context.gas_prices.strk_l1_gas_price.try_into().unwrap(),
},
};

let tx_count = txs.len();
let block_number = partial_header.number;
let header = Header::new(partial_header, FieldElement::ZERO);
let block_number = block_context.block_number.0;

let header = Header::new(partial_header, block_number, FieldElement::ZERO);
let block = Block { header, body: txs }.seal();
let block = SealedBlockWithStatus { block, status: FinalityStatus::AcceptedOnL2 };

Expand Down
Loading

0 comments on commit b01bf09

Please sign in to comment.