Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Apr 3, 2024
1 parent 149f51c commit b2e912c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion crates/astria-sequencer/src/service/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl Consensus {
response::DeliverTx {
code: code.into(),
info: code.to_string(),
log: format!("{e:?}"),
log: e.to_string(),
..Default::default()
}
}
Expand Down
22 changes: 11 additions & 11 deletions crates/astria-sequencer/src/service/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ impl Service<MempoolRequest> for Mempool {
}
}

// Handles a [`request::CheckTx`] request.
//
// Performs stateless checks (decoding and signature check),
// as well as stateful checks (nonce and balance checks).
//
// If the tx passes all checks, status code 0 is returned.
/// Handles a [`request::CheckTx`] request.
///
/// Performs stateless checks (decoding and signature check),
/// as well as stateful checks (nonce and balance checks).
///
/// If the tx passes all checks, status code 0 is returned.
async fn handle_check_tx<S: StateReadExt + 'static>(
req: request::CheckTx,
state: S,
Expand All @@ -109,7 +109,7 @@ async fn handle_check_tx<S: StateReadExt + 'static>(
Err(e) => {
return response::CheckTx {
code: AbciErrorCode::INVALID_PARAMETER.into(),
log: format!("{e:?}"),
log: e.to_string(),
info: "failed decoding bytes as a protobuf SignedTransaction".into(),
..response::CheckTx::default()
};
Expand All @@ -123,7 +123,7 @@ async fn handle_check_tx<S: StateReadExt + 'static>(
info: "the provided bytes was not a valid protobuf-encoded SignedTransaction, or \
the signature was invalid"
.into(),
log: format!("{e:?}"),
log: e.to_string(),
..response::CheckTx::default()
};
}
Expand All @@ -133,7 +133,7 @@ async fn handle_check_tx<S: StateReadExt + 'static>(
return response::CheckTx {
code: AbciErrorCode::INVALID_PARAMETER.into(),
info: "transaction failed stateless check".into(),
log: format!("{e:?}"),
log: e.to_string(),
..response::CheckTx::default()
};
};
Expand All @@ -142,7 +142,7 @@ async fn handle_check_tx<S: StateReadExt + 'static>(
return response::CheckTx {
code: AbciErrorCode::INVALID_NONCE.into(),
info: "failed verifying transaction nonce".into(),
log: format!("{e:?}"),
log: e.to_string(),
..response::CheckTx::default()
};
};
Expand All @@ -151,7 +151,7 @@ async fn handle_check_tx<S: StateReadExt + 'static>(
return response::CheckTx {
code: AbciErrorCode::INSUFFICIENT_FUNDS.into(),
info: "failed verifying account balance".into(),
log: format!("{e:?}"),
log: e.to_string(),
..response::CheckTx::default()
};
};
Expand Down
14 changes: 10 additions & 4 deletions crates/astria-sequencer/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ pub(crate) async fn check_balance_mempool<S: StateReadExt + 'static>(
.and_modify(|amt| *amt += TRANSFER_FEE)
.or_insert(TRANSFER_FEE);
}
_ => {
Action::ValidatorUpdate(_)
| Action::SudoAddressChange(_)
| Action::Ibc(_)
| Action::IbcRelayerChange(_)
| Action::FeeAssetChange(_)
| Action::Mint(_) => {
continue;
}
}
Expand Down Expand Up @@ -460,7 +465,7 @@ mod test {
}

#[tokio::test]
async fn check_balance_mempool_insuffient_other_asset_balance() {
async fn check_balance_mempool_insufficient_other_asset_balance() {
let storage = cnidarium::TempStorage::new().await.unwrap();
let snapshot = storage.latest_snapshot();
let mut state_tx = StateDelta::new(snapshot);
Expand Down Expand Up @@ -501,8 +506,9 @@ mod test {
};

let signed_tx = tx.into_signed(&alice_signing_key);
check_balance_mempool(&signed_tx, &state_tx)
let err = check_balance_mempool(&signed_tx, &state_tx)
.await
.expect_err("insuffient funds for `other` asset");
.expect_err("insufficient funds for `other` asset");
assert!(err.to_string().contains(&other_asset.to_string()));
}
}

0 comments on commit b2e912c

Please sign in to comment.