Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor error handling in get_transaction_status #3

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: release

on:
workflow_dispatch:
push:
branches:
- "**"
tags:
- "v*"

env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io

jobs:
publish:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: |
linux/amd64
linux/arm64
file: ./Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PATHFINDER_FORCE_VERSION=v0.14.1-cartridge
cache-from: type=gha
cache-to: type=gha,mode=max`

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ github.repository }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
4 changes: 2 additions & 2 deletions 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 @@ -53,7 +53,7 @@ axum = "0.7.5"
base64 = "0.13.1"
bincode = "2.0.0-rc.3"
bitvec = "1.0.1"
blockifier = "=0.8.0-rc.1"
blockifier = { git = "https://github.com/cartridge-gg/blockifier", branch = "nonce-check-flag" }
bloomfilter = "1.0.12"
bytes = "1.4.0"
cached = "0.44.0"
Expand Down
9 changes: 8 additions & 1 deletion crates/executor/src/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub fn estimate(
execution_state: ExecutionState<'_>,
transactions: Vec<Transaction>,
skip_validate: bool,
skip_nonce_check: bool,
) -> Result<Vec<FeeEstimate>, TransactionExecutionError> {
let block_number = execution_state.header.number;

Expand All @@ -32,7 +33,13 @@ pub fn estimate(
let tx_info: Result<
blockifier::transaction::objects::TransactionExecutionInfo,
blockifier::transaction::errors::TransactionExecutionError,
> = transaction.execute(&mut state, &block_context, false, !skip_validate);
> = transaction.execute(
&mut state,
&block_context,
false,
!skip_validate,
!skip_nonce_check,
);

match tx_info {
Ok(tx_info) => {
Expand Down
3 changes: 2 additions & 1 deletion crates/executor/src/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub fn simulate(
&block_context,
!skip_fee_charge,
!skip_validate,
true,
);
let state_diff = to_state_diff(&mut tx_state, transaction_declared_deprecated_class_hash)?;
tx_state.commit();
Expand Down Expand Up @@ -185,7 +186,7 @@ pub fn trace(

let mut tx_state = CachedState::<_>::create_transactional(&mut state);
let tx_info = tx
.execute(&mut tx_state, &block_context, true, true)
.execute(&mut tx_state, &block_context, true, true, true)
.map_err(|e| {
// Update the cache with the error. Lock the cache before sending to avoid
// race conditions between senders and receivers.
Expand Down
37 changes: 36 additions & 1 deletion crates/rpc/src/method/get_transaction_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,42 @@ pub enum Output {
AcceptedOnL2(TxnExecutionStatus),
}

crate::error::generate_rpc_error_subset!(Error: TxnHashNotFound);
#[derive(Debug)]
pub enum Error {
Internal(anyhow::Error),
TxnHashNotFound,
GatewayIssue(starknet_gateway_types::error::StarknetError),
}

impl From<anyhow::Error> for Error {
fn from(e: anyhow::Error) -> Self {
Self::Internal(e)
}
}

impl From<starknet_gateway_types::error::SequencerError> for Error {
fn from(e: starknet_gateway_types::error::SequencerError) -> Self {
use starknet_gateway_types::error::SequencerError::*;

match e {
StarknetError(e) => Error::GatewayIssue(e),
ReqwestError(e) => Error::Internal(e.into()),
InvalidStarknetErrorVariant => Error::Internal(anyhow::anyhow!(
"Invalid error variant received from gateway"
)),
}
}
}

impl From<Error> for crate::error::ApplicationError {
fn from(e: Error) -> Self {
match e {
Error::Internal(internal) => Self::Internal(internal),
Error::TxnHashNotFound => Self::TxnHashNotFound,
Error::GatewayIssue(gateway_error) => Self::GatewayError(gateway_error),
}
}
}

pub async fn get_transaction_status(context: RpcContext, input: Input) -> Result<Output, Error> {
// Check database.
Expand Down
8 changes: 7 additions & 1 deletion crates/rpc/src/v05/method/estimate_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ pub async fn estimate_fee(
.map(|tx| crate::executor::map_broadcasted_transaction(&tx, context.chain_id))
.collect::<Result<Vec<_>, _>>()?;

let result = pathfinder_executor::estimate(state, transactions, false)?;
let result = pathfinder_executor::estimate(
state,
transactions,
false,
// skip nonce check because it is not necessary for fee estimation
true,
)?;

Ok::<_, EstimateFeeError>(result)
})
Expand Down
8 changes: 7 additions & 1 deletion crates/rpc/src/v06/method/estimate_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,13 @@ pub async fn estimate_fee_impl(
.map(|tx| crate::executor::map_broadcasted_transaction(&tx, context.chain_id))
.collect::<Result<Vec<_>, _>>()?;

let result = pathfinder_executor::estimate(state, transactions, skip_validate)?;
let result = pathfinder_executor::estimate(
state,
transactions,
skip_validate,
// skip nonce check because it is not necessary for fee estimation
true,
)?;

Ok::<_, EstimateFeeError>(result)
})
Expand Down
8 changes: 7 additions & 1 deletion crates/rpc/src/v06/method/estimate_message_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@ pub(crate) async fn estimate_message_fee_impl(

let transaction = create_executor_transaction(input, context.chain_id)?;

let result = pathfinder_executor::estimate(state, vec![transaction], false)?;
let result = pathfinder_executor::estimate(
state,
vec![transaction],
false,
// skip nonce check because it is not necessary for fee estimation
true,
)?;

Ok::<_, EstimateMessageFeeError>(result)
})
Expand Down
33 changes: 33 additions & 0 deletions crates/rpc/src/v06/method/simulate_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,39 @@ pub(crate) mod tests {
pretty_assertions_sorted::assert_eq!(result.0, expected);
}

#[tokio::test]
async fn test_simulate_transaction_with_invalid_nonce_will_fail() {
let (context, _, _, _) = crate::test_setup::test_context().await;

// create transaction with invalid nonce
let input_json = serde_json::json!({
"block_id": {"block_number": 1},
"transactions": [
{
"contract_address_salt": "0x46c0d4abf0192a788aca261e58d7031576f7d8ea5229f452b0f23e691dd5971",
"max_fee": "0x0",
"signature": [],
"class_hash": DUMMY_ACCOUNT_CLASS_HASH,
"nonce": "0x1337",
"version": TransactionVersion::ONE_WITH_QUERY_VERSION,
"constructor_calldata": [],
"type": "DEPLOY_ACCOUNT"
}
],
"simulation_flags": ["SKIP_FEE_CHARGE"]
});

// assert that the simulation returns an error due to invalid nonce
let input = SimulateTransactionInput::deserialize(&input_json).unwrap();
let err = simulate_transactions(context, input).await.unwrap_err();

if let SimulateTransactionError::TransactionExecutionError { error, .. } = err {
assert!(error.contains("Invalid transaction nonce"))
} else {
panic!("Unexpected error")
}
}

#[tokio::test]
async fn declare_cairo_v0_class() {
pub const CAIRO0_DEFINITION: &[u8] =
Expand Down
Loading