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

Commit

Permalink
feat(rpc): Support for pending state (#1434)
Browse files Browse the repository at this point in the history
  • Loading branch information
bidzyyys authored Feb 21, 2024
1 parent 66c1d13 commit 194cf75
Show file tree
Hide file tree
Showing 22 changed files with 1,117 additions and 315 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/starknet-rpc-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
./target/release/madara setup --chain=dev --from-local=configs
- name: Compile contracts for rpc-tests
run: |
cd starknet-rpc-test/contracts && ./generate_declare_contracts.sh 8
cd starknet-rpc-test/contracts && ./generate_declare_contracts.sh 10
- name: Run rpc test without cache
run: |-
./target/release/madara --dev --sealing=manual --da-layer=ethereum --da-conf=examples/da-confs/ethereum.json &
Expand Down
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

- feat(rpc): support for pending state
- test(rpc): disable state_diff tests
- feat(rpc): add tests for estimateMessageFee RPC call
- refacto: rename braavos call aggregator contract
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions crates/client/rpc-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use starknet_core::types::{
BlockHashAndNumber, BlockId, BroadcastedDeclareTransaction, BroadcastedDeployAccountTransaction,
BroadcastedInvokeTransaction, BroadcastedTransaction, ContractClass, DeclareTransactionResult,
DeployAccountTransactionResult, EventFilterWithPage, EventsPage, FeeEstimate, FieldElement, FunctionCall,
InvokeTransactionResult, MaybePendingBlockWithTxHashes, MaybePendingBlockWithTxs, MaybePendingTransactionReceipt,
MsgFromL1, SimulatedTransaction, SimulationFlag, StateUpdate, SyncStatusType, Transaction,
InvokeTransactionResult, MaybePendingBlockWithTxHashes, MaybePendingBlockWithTxs, MaybePendingStateUpdate,
MaybePendingTransactionReceipt, MsgFromL1, SimulatedTransaction, SimulationFlag, SyncStatusType, Transaction,
TransactionTraceWithHash,
};

Expand Down Expand Up @@ -150,7 +150,7 @@ pub trait StarknetReadRpcApi {

/// Get the information about the result of executing the requested block
#[method(name = "getStateUpdate")]
fn get_state_update(&self, block_id: BlockId) -> RpcResult<StateUpdate>;
fn get_state_update(&self, block_id: BlockId) -> RpcResult<MaybePendingStateUpdate>;

/// Returns all events matching the given filter
#[method(name = "getEvents")]
Expand Down
2 changes: 2 additions & 0 deletions crates/client/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ sp-arithmetic = { workspace = true, default-features = true }
sp-blockchain = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-runtime = { workspace = true, default-features = true }
sp-timestamp = { workspace = true, default-features = true }

# Substrate client
sc-client-api = { workspace = true, default-features = true }
sc-network-sync = { workspace = true }
Expand Down
22 changes: 5 additions & 17 deletions crates/client/rpc/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ use crate::errors::StarknetRpcApiError;
use crate::types::{ContinuationToken, RpcEventFilter};
use crate::Starknet;

impl<A: ChainApi, B, BE, G, C, P, H> Starknet<A, B, BE, G, C, P, H>
impl<A, B, BE, G, C, P, H> Starknet<A, B, BE, G, C, P, H>
where
A: ChainApi<Block = B> + 'static,
B: BlockT,
C: HeaderBackend<B> + BlockBackend<B> + StorageProvider<B, BE> + 'static,
C: ProvideRuntimeApi<B>,
Expand Down Expand Up @@ -58,33 +59,20 @@ where
})?
.ok_or(StarknetRpcApiError::BlockNotFound)?;

let chain_id = self.client.runtime_api().chain_id(substrate_block_hash).map_err(|_| {
let chain_id = self.get_chain_id(substrate_block_hash).map_err(|_| {
error!("Failed to retrieve chain id");
StarknetRpcApiError::InternalServerError
})?;

let index_and_events =
self.client.runtime_api().get_starknet_events_and_their_associated_tx_index(substrate_block_hash).map_err(
|e| {
error!(
"Failed to retrieve starknet events and their associated transaction index. Substrate block \
hash: {substrate_block_hash}, chain ID: {chain_id:?}, error: {e}"
);
StarknetRpcApiError::InternalServerError
},
)?;
let index_and_events = self.get_starknet_events_and_their_associated_tx_index(substrate_block_hash)?;

let starknet_block = get_block_by_block_hash(self.client.as_ref(), substrate_block_hash).map_err(|e| {
error!("Failed to retrieve starknet block from substrate block hash: error: {e}");
StarknetRpcApiError::InternalServerError
})?;
let txn_hashes = self.get_cached_transaction_hashes(starknet_block.header().hash::<H>().into());
let block_extrinsics_len = block_extrinsics.len();
let starknet_txs =
self.client.runtime_api().extrinsic_filter(substrate_block_hash, block_extrinsics).map_err(|e| {
error!("Failed to filter extrinsics. Substrate block hash: {substrate_block_hash}, error: {e}");
StarknetRpcApiError::InternalServerError
})?;
let starknet_txs = self.filter_extrinsics(substrate_block_hash, block_extrinsics)?;
let inherent_count = block_extrinsics_len - starknet_txs.len();
let mut tx_hash_and_events: Vec<(Felt252Wrapper, starknet_api::transaction::Event)> = vec![];
for (index, event) in index_and_events {
Expand Down
Loading

0 comments on commit 194cf75

Please sign in to comment.