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

feat: add serde to mempool messages #277

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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.

1 change: 1 addition & 0 deletions crates/mempool_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ workspace = true

[dependencies]
async-trait.workspace = true
serde.workspace = true
starknet_api.workspace = true
starknet_mempool_infra = { path = "../mempool_infra" }
thiserror.workspace = true
5 changes: 3 additions & 2 deletions crates/mempool_types/src/communication.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use starknet_mempool_infra::component_client::{ClientError, ComponentClient};
use starknet_mempool_infra::component_definitions::ComponentRequestAndResponseSender;
use thiserror::Error;
Expand All @@ -23,13 +24,13 @@ pub trait MempoolClient: Send + Sync {
async fn get_txs(&self, n_txs: usize) -> MempoolClientResult<Vec<ThinTransaction>>;
}

#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub enum MempoolRequest {
AddTransaction(MempoolInput),
GetTransactions(usize),
}

#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub enum MempoolResponse {
AddTransaction(MempoolResult<()>),
GetTransactions(MempoolResult<Vec<ThinTransaction>>),
Expand Down
3 changes: 2 additions & 1 deletion crates/mempool_types/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use serde::{Deserialize, Serialize};
use starknet_api::transaction::TransactionHash;
use thiserror::Error;

#[derive(Clone, Debug, Error)]
#[derive(Clone, Debug, Error, Serialize, Deserialize)]
pub enum MempoolError {
#[error("Duplicate transaction, with hash: {tx_hash}")]
DuplicateTransaction { tx_hash: TransactionHash },
Expand Down
9 changes: 5 additions & 4 deletions crates/mempool_types/src/mempool_types.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
use serde::{Deserialize, Serialize};
use starknet_api::core::{ContractAddress, Nonce};
use starknet_api::transaction::{Tip, TransactionHash};

use crate::errors::MempoolError;

#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct ThinTransaction {
pub sender_address: ContractAddress,
pub tx_hash: TransactionHash,
pub tip: Tip,
pub nonce: Nonce,
}

#[derive(Clone, Copy, Debug, Default)]
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
pub struct AccountState {
pub nonce: Nonce,
// TODO: add balance field when needed.
}

#[derive(Clone, Copy, Debug, Default)]
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
pub struct Account {
// TODO(Ayelet): Consider removing this field as it is duplicated in ThinTransaction.
pub sender_address: ContractAddress,
pub state: AccountState,
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct MempoolInput {
pub tx: ThinTransaction,
pub account: Account,
Expand Down
Loading