Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into omri/starknet_syncing_fn
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavGrs committed Jul 19, 2023
2 parents c346403 + 3d812dd commit cb253a3
Show file tree
Hide file tree
Showing 29 changed files with 479 additions and 351 deletions.
277 changes: 139 additions & 138 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ async-trait = "0.1.56"
axum = "0.6.12"
base64 = "0.13.0"
byteorder = "1.4.3"
cairo-lang-starknet = "2.0.0-rc1"
cairo-lang-casm = "2.0.0-rc1"
cairo-lang-utils = "2.0.0-rc1"
cairo-lang-starknet = "2.1.0-rc0"
cairo-lang-casm = "2.1.0-rc0"
cairo-lang-utils = "2.1.0-rc0"
camelpaste = "0.1.0"
clap = "3.2.19"
const_format = "0.2.30"
Expand Down Expand Up @@ -76,7 +76,7 @@ serde = "1.0.130"
serde_json = "1.0.81"
serde_yaml = "0.9.16"
simple_logger = "4.0.0"
starknet_api = "0.2.0"
starknet_api = { git = "https://github.com/starkware-libs/starknet-api", rev = "ecc9b6946ef13003da202838e4124a9ad2efabb0" }
tempfile = "3.3.0"
thiserror = "1.0.31"
tokio = "1.18.2"
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jsonrpsee = { workspace = true, features = ["full"] }
metrics.workspace = true
papyrus_common = { path = "../papyrus_common"}
papyrus_proc_macros = { path = "../papyrus_proc_macros"}
papyrus_storage = { path = "../papyrus_storage" }
papyrus_storage = { path = "../papyrus_storage", version = "0.0.1" }
starknet_writer_client = { path = "../starknet_writer_client" }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
Expand Down
19 changes: 8 additions & 11 deletions crates/papyrus_gateway/src/v0_3_0/api/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,9 @@ impl JsonRpcV0_3_0Server for JsonRpcServerV0_3_0Impl {

let block_number = transaction_index.0;
let status = get_block_status(&txn, block_number)?;
let header: BlockHeader =
get_block_header_by_number(&txn, block_number).map_err(internal_server_error)?;

let transaction = txn
.get_transaction(transaction_index)
let block_hash = get_block_header_by_number::<_, BlockHeader>(&txn, block_number)
.map_err(internal_server_error)?
.ok_or_else(|| ErrorObjectOwned::from(JsonRpcError::TransactionHashNotFound))?;
.block_hash;

let thin_tx_output = txn
.get_transaction_output(transaction_index)
Expand All @@ -228,12 +224,13 @@ impl JsonRpcV0_3_0Server for JsonRpcServerV0_3_0Impl {
let output = TransactionOutput::from_thin_transaction_output(thin_tx_output, events);

Ok(TransactionReceiptWithStatus {
receipt: TransactionReceipt::from_transaction_output(
output,
&transaction,
header.block_hash,
receipt: TransactionReceipt {
transaction_hash,
r#type: output.r#type(),
block_hash,
block_number,
),
output,
},
status: status.into(),
})
}
Expand Down
17 changes: 9 additions & 8 deletions crates/papyrus_gateway/src/v0_3_0/api/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,21 +571,22 @@ async fn get_transaction_receipt() {
.commit()
.unwrap();

let transaction = block.body.transactions.index(0);
let transaction_hash = block.body.transactions.index(0).transaction_hash();
let output = TransactionOutput::from(block.body.transaction_outputs.index(0).clone());
let expected_receipt = TransactionReceiptWithStatus {
receipt: TransactionReceipt::from_transaction_output(
receipt: TransactionReceipt {
transaction_hash,
r#type: output.r#type(),
block_hash: block.header.block_hash,
block_number: block.header.block_number,
output,
transaction,
block.header.block_hash,
block.header.block_number,
),
},
status: TransactionStatus::AcceptedOnL2,
};
let res = module
.call::<_, TransactionReceiptWithStatus>(
"starknet_V0_3_0_getTransactionReceipt",
[transaction.transaction_hash()],
[transaction_hash],
)
.await
.unwrap();
Expand All @@ -608,7 +609,7 @@ async fn get_transaction_receipt() {
let res = module
.call::<_, TransactionReceiptWithStatus>(
"starknet_V0_3_0_getTransactionReceipt",
[transaction.transaction_hash()],
[transaction_hash],
)
.await
.unwrap();
Expand Down
53 changes: 4 additions & 49 deletions crates/papyrus_gateway/src/v0_3_0/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,54 +299,7 @@ pub struct TransactionReceiptWithStatus {
}

#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[serde(untagged)]
pub enum TransactionReceipt {
Deploy(DeployTransactionReceipt),
Common(CommonTransactionReceipt),
}

impl TransactionReceipt {
pub fn from_transaction_output(
output: TransactionOutput,
transaction: &starknet_api::transaction::Transaction,
block_hash: BlockHash,
block_number: BlockNumber,
) -> Self {
let common = CommonTransactionReceipt {
transaction_hash: transaction.transaction_hash(),
r#type: output.r#type(),
block_hash,
block_number,
output,
};

match transaction {
starknet_api::transaction::Transaction::DeployAccount(tx) => {
Self::Deploy(DeployTransactionReceipt {
common,
contract_address: tx.contract_address,
})
}
starknet_api::transaction::Transaction::Deploy(tx) => {
Self::Deploy(DeployTransactionReceipt {
common,
contract_address: tx.contract_address,
})
}
_ => Self::Common(common),
}
}
}

#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
pub struct DeployTransactionReceipt {
#[serde(flatten)]
pub common: CommonTransactionReceipt,
pub contract_address: ContractAddress,
}

#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
pub struct CommonTransactionReceipt {
pub struct TransactionReceipt {
pub transaction_hash: TransactionHash,
pub r#type: TransactionType,
pub block_hash: BlockHash,
Expand All @@ -358,9 +311,9 @@ pub struct CommonTransactionReceipt {
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[serde(untagged)]
pub enum TransactionOutput {
Declare(DeclareTransactionOutput),
Deploy(DeployTransactionOutput),
DeployAccount(DeployAccountTransactionOutput),
Declare(DeclareTransactionOutput),
Invoke(InvokeTransactionOutput),
L1Handler(L1HandlerTransactionOutput),
}
Expand All @@ -383,13 +336,15 @@ impl TransactionOutput {
actual_fee: thin_deploy.actual_fee,
messages_sent: thin_deploy.messages_sent,
events,
contract_address: thin_deploy.contract_address,
})
}
ThinTransactionOutput::DeployAccount(thin_deploy) => {
TransactionOutput::DeployAccount(DeployAccountTransactionOutput {
actual_fee: thin_deploy.actual_fee,
messages_sent: thin_deploy.messages_sent,
events,
contract_address: thin_deploy.contract_address,
})
}
ThinTransactionOutput::Invoke(thin_invoke) => {
Expand Down
37 changes: 2 additions & 35 deletions crates/papyrus_gateway/src/v0_3_0/transaction_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ use papyrus_storage::body::events::{
ThinDeclareTransactionOutput, ThinDeployAccountTransactionOutput, ThinDeployTransactionOutput,
ThinInvokeTransactionOutput, ThinL1HandlerTransactionOutput, ThinTransactionOutput,
};
use starknet_api::block::BlockHeader;
use starknet_api::transaction::{
DeclareTransactionOutput, DeployAccountTransactionOutput, DeployTransactionOutput,
InvokeTransactionOutput, L1HandlerTransactionOutput, Transaction,
};
use starknet_api::transaction::Transaction;
use test_utils::{get_rng, GetTestInstance};

use crate::v0_3_0::transaction::{TransactionOutput, TransactionReceipt};
use crate::v0_3_0::transaction::TransactionOutput;

macro_rules! gen_test_from_thin_transaction_output_macro {
($variant: ident) => {
Expand Down Expand Up @@ -94,32 +90,3 @@ async fn test_gateway_trascation_from_starknet_api_transaction() {
Transaction::DeployAccount(inner_transaction.clone()).try_into().unwrap();
assert_eq!(transaction.transaction_hash(), inner_transaction.transaction_hash);
}

macro_rules! test_recipe_from_transtaction_output {
($variant:ident, $recipe_type:ident) => {
paste! {
#[tokio::test]
async fn [<test_recipe_from_transtaction_output_ $variant:lower>]() {
let mut rng = get_rng();
let block_header = BlockHeader::default();
let transaction = Transaction::$variant(
starknet_api::transaction::[<$variant Transaction>]::get_test_instance(&mut rng),
);
let output = TransactionOutput::$variant([<$variant TransactionOutput>]::default());
let receipt = TransactionReceipt::from_transaction_output(
output,
&transaction,
block_header.block_hash,
block_header.block_number,
);
assert_matches!(receipt, TransactionReceipt::$recipe_type(_));
}
}
}
}

test_recipe_from_transtaction_output!(Declare, Common);
test_recipe_from_transtaction_output!(Invoke, Common);
test_recipe_from_transtaction_output!(L1Handler, Common);
test_recipe_from_transtaction_output!(Deploy, Deploy);
test_recipe_from_transtaction_output!(DeployAccount, Deploy);
2 changes: 1 addition & 1 deletion crates/papyrus_monitoring_gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ futures-util.workspace = true
hyper = { workspace = true, features = ["full"] }
metrics-exporter-prometheus = { version = "0.12.1" }
metrics-process = { version = "1.0.11" }
papyrus_storage = { path = "../papyrus_storage" }
papyrus_storage = { path = "../papyrus_storage", version = "0.0.1" }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
thiserror.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jsonrpsee = { workspace = true, features = ["full"] }
libmdbx = { workspace = true, features = ["lifetimed-bytes"] }
papyrus_gateway = { path = "../papyrus_gateway" }
papyrus_monitoring_gateway = { path = "../papyrus_monitoring_gateway" }
papyrus_storage = { path = "../papyrus_storage" }
papyrus_storage = { path = "../papyrus_storage", version = "0.0.1" }
papyrus_sync = { path = "../papyrus_sync" }
reqwest = { workspace = true, features = ["json", "blocking"] }
serde = { workspace = true, features = ["derive"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async fn main() {
let mut block_marker = initial_block_number;
let block_stream = central_source.stream_new_blocks(block_marker, last_block_number).fuse();
pin_mut!(block_stream);
while let Some(Ok((block_number, _block))) = block_stream.next().await {
while let Some(Ok((block_number, _block, _starknet_version))) = block_stream.next().await {
assert!(
block_marker == block_number,
"Expected block number ({block_marker}) does not match the result ({block_number}).",
Expand Down
6 changes: 6 additions & 0 deletions crates/papyrus_storage/src/body/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ pub struct ThinDeployTransactionOutput {
pub messages_sent: Vec<MessageToL1>,
/// The contract addresses of the events emitted by the transaction.
pub events_contract_addresses: Vec<ContractAddress>,
/// The contract address of the deployed contract.
pub contract_address: ContractAddress,
}

/// A thin version of
Expand All @@ -355,6 +357,8 @@ pub struct ThinDeployAccountTransactionOutput {
pub messages_sent: Vec<MessageToL1>,
/// The contract addresses of the events emitted by the transaction.
pub events_contract_addresses: Vec<ContractAddress>,
/// The contract address of the deployed contract.
pub contract_address: ContractAddress,
}

impl From<TransactionOutput> for ThinTransactionOutput {
Expand All @@ -374,13 +378,15 @@ impl From<TransactionOutput> for ThinTransactionOutput {
actual_fee: tx_output.actual_fee,
messages_sent: tx_output.messages_sent,
events_contract_addresses,
contract_address: tx_output.contract_address,
})
}
TransactionOutput::DeployAccount(tx_output) => {
ThinTransactionOutput::DeployAccount(ThinDeployAccountTransactionOutput {
actual_fee: tx_output.actual_fee,
messages_sent: tx_output.messages_sent,
events_contract_addresses,
contract_address: tx_output.contract_address,
})
}
TransactionOutput::Invoke(tx_output) => {
Expand Down
Loading

0 comments on commit cb253a3

Please sign in to comment.