Skip to content

Commit

Permalink
fix: docker compose (#690)
Browse files Browse the repository at this point in the history
* fix docker compose

* update docker and makefile

* add eth api tracing + fix receipt

* fix order manifest

* add missing tracing
  • Loading branch information
greged93 authored Jan 9, 2024
1 parent b7491c6 commit 8be8b25
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ cairo-felt = { git = "https://github.com/dojoengine/cairo-rs.git", rev = "262b7e
cairo-vm = { git = "https://github.com/dojoengine/cairo-rs.git", rev = "262b7eb4b11ab165a2a936a5f914e78aa732d4a2" }

[dev-dependencies]
toml = "0.7.5"
cargo-husky = { version = "1.5.0", default-features = false, features = [
"precommit-hook",
"run-for-all",
"run-cargo-clippy",
"run-cargo-fmt",
] }
dojo-test-utils = { git = 'https://github.com/dojoengine/dojo', rev = "be16762" }
toml = "0.7.5"
rstest = "0.18.1"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ deploy-kakarot:
cd lib/kakarot && STARKNET_NETWORK=$(STARKNET_NETWORK) poetry run python ./scripts/deploy_kakarot.py && cd ..

run-dev:
PROXY_ACCOUNT_CLASS_HASH=$(shell jq -r '.proxy' ./lib/kakarot/deployments/$(STARKNET_NETWORK)/declarations.json) CONTRACT_ACCOUNT_CLASS_HASH=$(shell jq -r '.contract_account' ./lib/kakarot/deployments/$(STARKNET_NETWORK)/declarations.json) EXTERNALLY_OWNED_ACCOUNT_CLASS_HASH=$(shell jq -r '.externally_owned_account' ./lib/kakarot/deployments/$(STARKNET_NETWORK)/declarations.json) KAKAROT_ADDRESS=$(shell jq -r '.kakarot.address' ./lib/kakarot/deployments/$(STARKNET_NETWORK)/deployments.json) RUST_LOG=trace cargo run
PROXY_ACCOUNT_CLASS_HASH=$(shell jq -r '.proxy' ./lib/kakarot/deployments/$(STARKNET_NETWORK)/declarations.json) CONTRACT_ACCOUNT_CLASS_HASH=$(shell jq -r '.contract_account' ./lib/kakarot/deployments/$(STARKNET_NETWORK)/declarations.json) EXTERNALLY_OWNED_ACCOUNT_CLASS_HASH=$(shell jq -r '.externally_owned_account' ./lib/kakarot/deployments/$(STARKNET_NETWORK)/declarations.json) KAKAROT_ADDRESS=$(shell jq -r '.kakarot.address' ./lib/kakarot/deployments/$(STARKNET_NETWORK)/deployments.json) RUST_LOG=trace cargo run --bin kakarot-rpc

# Run Katana, Deploy Kakarot, Run Kakarot RPC
katana-rpc-up:
Expand Down
37 changes: 19 additions & 18 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
version: '3.2'
version: "3.2"

services:
starknet:
image: ghcr.io/keep-starknet-strange/madara:v0.1.0.experimental.3
image: greged93/madara:latest
ports:
- '9615:9615'
- '9944:9944'
- '30333:30333'
command:
- '--rpc-external'
- '--rpc-methods=unsafe'
- '--rpc-cors=all'
- '--dev'
- "9615:9615"
- "9944:9944"
- "30333:30333"
entrypoint: [/bin/bash, -c]
command: >
"/madara-bin setup --from-remote --base-path=/home/madara --chain=dev && /madara-bin --rpc-external --rpc-methods=unsafe --rpc-cors=all --chain=dev --base-path=/home/madara --alice --force-authoring"
volumes:
- madara:/home/madara
networks:
- internal

Expand All @@ -37,16 +37,16 @@ services:
image: apteno/alpine-jq:2023-07-24
# Parse deployments and save the result to .env file
entrypoint:
- '/bin/sh'
- '-c'
- "/bin/sh"
- "-c"
# First line overrides an existing .env, if any.
# This is to make sure that it is clean even though docker volume was not cleaned.
- |
echo "KAKAROT_ADDRESS=$(jq -r '.kakarot.address' /deployments/custom-rpc/deployments.json)" > /deployments/.env;
echo "DEPLOYER_ACCOUNT_ADDRESS=$(jq -r '.deployer_account.address' /deployments/custom-rpc/deployments.json)" >> /deployments/.env;
echo "PROXY_ACCOUNT_CLASS_HASH=$(jq -r '.proxy' /deployments/custom-rpc/declarations.json)" >> /deployments/.env
echo "EXTERNALLY_OWNED_ACCOUNT_CLASS_HASH=$(jq -r '.externally_owned_account' /deployments/custom-rpc/declarations.json)" >> /deployments/.env
echo "CONTRACT_ACCOUNT_CLASS_HASH=$(jq -r '.contract_account' /deployments/custom-rpc/declarations.json)" >> /deployments/.env
echo "KAKAROT_ADDRESS=$$(jq -r '.kakarot.address' /deployments/custom-rpc/deployments.json)" > /deployments/.env;
echo "DEPLOYER_ACCOUNT_ADDRESS=$$(jq -r '.deployer_account.address' /deployments/custom-rpc/deployments.json)" >> /deployments/.env;
echo "PROXY_ACCOUNT_CLASS_HASH=$$(jq -r '.proxy' /deployments/custom-rpc/declarations.json)" >> /deployments/.env
echo "EXTERNALLY_OWNED_ACCOUNT_CLASS_HASH=$$(jq -r '.externally_owned_account' /deployments/custom-rpc/declarations.json)" >> /deployments/.env
echo "CONTRACT_ACCOUNT_CLASS_HASH=$$(jq -r '.contract_account' /deployments/custom-rpc/declarations.json)" >> /deployments/.env
volumes:
- deployments:/deployments
depends_on:
Expand All @@ -60,7 +60,7 @@ services:
environment:
- KAKAROT_HTTP_RPC_ADDRESS=0.0.0.0:3030
- STARKNET_NETWORK=http://starknet:9944
- RUST_LOG=trace
- RUST_LOG=kakarot_rpc=info
- DEPLOYER_ACCOUNT_PRIVATE_KEY=0x0288a51c164874bb6a1ca7bd1cb71823c234a86d0f7b150d70fa8f06de645396
volumes:
# Mount the volume on workdir and use .env stored in root of the volume
Expand All @@ -77,3 +77,4 @@ networks:

volumes:
deployments:
madara:
23 changes: 23 additions & 0 deletions src/eth_rpc/servers/eth_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ impl<P: Provider + Send + Sync + 'static> KakarotEthRpc<P> {

#[async_trait]
impl<P: Provider + Send + Sync + 'static> EthApiServer for KakarotEthRpc<P> {
#[tracing::instrument(skip_all, ret)]
async fn block_number(&self) -> Result<U64> {
let block_number = self.kakarot_client.starknet_provider().block_number().await.map_err(EthApiError::from)?;
Ok(block_number.into())
}

#[tracing::instrument(skip_all, ret)]
async fn syncing(&self) -> Result<SyncStatus> {
let status = self.kakarot_client.starknet_provider().syncing().await.map_err(EthApiError::from)?;

Expand Down Expand Up @@ -72,34 +74,40 @@ impl<P: Provider + Send + Sync + 'static> EthApiServer for KakarotEthRpc<P> {
Err(EthApiError::MethodNotSupported("eth_coinbase".to_string()).into())
}

#[tracing::instrument(skip_all, ret)]
async fn accounts(&self) -> Result<Vec<Address>> {
Ok(Vec::new())
}

#[tracing::instrument(skip_all, ret)]
async fn chain_id(&self) -> Result<Option<U64>> {
Ok(Some(CHAIN_ID.into()))
}

#[tracing::instrument(skip_all, ret, fields(hash = %hash))]
async fn block_by_hash(&self, hash: H256, full: bool) -> Result<Option<RichBlock>> {
let block_id = EthBlockId::new(BlockId::Hash(hash.into()));
let starknet_block_id: StarknetBlockId = block_id.try_into().map_err(EthApiError::from)?;
let block = self.kakarot_client.get_eth_block_from_starknet_block(starknet_block_id, full).await?;
Ok(Some(block))
}

#[tracing::instrument(skip_all, ret, fields(number = %number, full = full))]
async fn block_by_number(&self, number: BlockNumberOrTag, full: bool) -> Result<Option<RichBlock>> {
let block_id = EthBlockId::new(BlockId::Number(number));
let starknet_block_id: StarknetBlockId = block_id.try_into().map_err(EthApiError::from)?;
let block = self.kakarot_client.get_eth_block_from_starknet_block(starknet_block_id, full).await?;
Ok(Some(block))
}

#[tracing::instrument(skip_all, ret, fields(hash = %hash))]
async fn block_transaction_count_by_hash(&self, hash: H256) -> Result<U64> {
let block_id = BlockId::Hash(hash.into());
let count = self.kakarot_client.get_transaction_count_by_block(block_id).await.map_err(EthApiError::from)?;
Ok(count)
}

#[tracing::instrument(skip_all, ret, fields(number = %number))]
async fn block_transaction_count_by_number(&self, number: BlockNumberOrTag) -> Result<U64> {
let block_id = BlockId::Number(number);
let count = self.kakarot_client.get_transaction_count_by_block(block_id).await.map_err(EthApiError::from)?;
Expand All @@ -126,6 +134,7 @@ impl<P: Provider + Send + Sync + 'static> EthApiServer for KakarotEthRpc<P> {
Err(EthApiError::MethodNotSupported("eth_getUncleByBlockNumberAndIndex".to_string()).into())
}

#[tracing::instrument(skip_all, ret, fields(hash = %hash))]
async fn transaction_by_hash(&self, hash: H256) -> Result<Option<EtherTransaction>> {
let hash: Felt252Wrapper = hash.try_into().map_err(EthApiError::from)?;
let hash: FieldElement = hash.into();
Expand All @@ -152,12 +161,14 @@ impl<P: Provider + Send + Sync + 'static> EthApiServer for KakarotEthRpc<P> {
Ok(Some(eth_transaction))
}

#[tracing::instrument(skip_all, ret, fields(hash = %hash, index = ?index))]
async fn transaction_by_block_hash_and_index(&self, hash: H256, index: Index) -> Result<Option<EtherTransaction>> {
let block_id = BlockId::Hash(hash.into());
let tx = self.kakarot_client.transaction_by_block_id_and_index(block_id, index).await?;
Ok(Some(tx))
}

#[tracing::instrument(skip_all, ret, fields(number = %number, index = ?index))]
async fn transaction_by_block_number_and_index(
&self,
number: BlockNumberOrTag,
Expand All @@ -168,6 +179,7 @@ impl<P: Provider + Send + Sync + 'static> EthApiServer for KakarotEthRpc<P> {
Ok(Some(tx))
}

#[tracing::instrument(skip_all, ret, fields(hash = %hash))]
async fn transaction_receipt(&self, hash: H256) -> Result<Option<TransactionReceipt>> {
// TODO: Error when trying to transform 32 bytes hash to FieldElement
let transaction_hash: Felt252Wrapper = hash.try_into().map_err(EthApiError::from)?;
Expand All @@ -186,18 +198,21 @@ impl<P: Provider + Send + Sync + 'static> EthApiServer for KakarotEthRpc<P> {
Ok(res_receipt)
}

#[tracing::instrument(skip_all, ret, fields(address = %address, block_id = ?block_id))]
async fn balance(&self, address: Address, block_id: Option<BlockId>) -> Result<U256> {
let block_id = block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));
let balance = self.kakarot_client.balance(address, block_id).await?;
Ok(balance)
}

#[tracing::instrument(skip_all, ret, fields(address = %address, index = ?index, block_id = ?block_id))]
async fn storage_at(&self, address: Address, index: U256, block_id: Option<BlockId>) -> Result<U256> {
let block_id = block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));
let value = self.kakarot_client.storage_at(address, index, block_id).await?;
Ok(value)
}

#[tracing::instrument(skip_all, ret, fields(address = %address, block_id = ?block_id))]
async fn transaction_count(&self, address: Address, block_id: Option<BlockId>) -> Result<U256> {
let block_id = block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));

Expand All @@ -206,6 +221,7 @@ impl<P: Provider + Send + Sync + 'static> EthApiServer for KakarotEthRpc<P> {
Ok(transaction_count)
}

#[tracing::instrument(skip_all, ret, fields(address = %address, block_id = ?block_id))]
async fn get_code(&self, address: Address, block_id: Option<BlockId>) -> Result<Bytes> {
let block_id = block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));
let starknet_block_id: StarknetBlockId = EthBlockId::new(block_id).try_into().map_err(EthApiError::from)?;
Expand All @@ -221,6 +237,7 @@ impl<P: Provider + Send + Sync + 'static> EthApiServer for KakarotEthRpc<P> {
Ok(Bytes::from(bytecode.0.into_iter().filter_map(|x: FieldElement| u8::try_from(x).ok()).collect::<Vec<_>>()))
}

#[tracing::instrument(skip_all, ret, fields(filter = ?filter))]
async fn get_logs(&self, filter: Filter) -> Result<FilterChanges> {
// Check the block range
let current_block: u64 =
Expand Down Expand Up @@ -277,6 +294,7 @@ impl<P: Provider + Send + Sync + 'static> EthApiServer for KakarotEthRpc<P> {
Ok(FilterChanges::Logs(logs))
}

#[tracing::instrument(skip_all, ret, fields(request = ?request, block_id = ?block_id))]
async fn call(&self, request: CallRequest, block_id: Option<BlockId>) -> Result<Bytes> {
let block_id = block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));
let result = self.kakarot_client.call(request, block_id).await?;
Expand All @@ -292,17 +310,20 @@ impl<P: Provider + Send + Sync + 'static> EthApiServer for KakarotEthRpc<P> {
Err(EthApiError::MethodNotSupported("eth_createAccessList".to_string()).into())
}

#[tracing::instrument(skip_all, ret, fields(request = ?request, block_id = ?block_id))]
async fn estimate_gas(&self, request: CallRequest, block_id: Option<BlockId>) -> Result<U256> {
let block_id = block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));

Ok(self.kakarot_client.estimate_gas(request, block_id).await?)
}

#[tracing::instrument(skip_all, ret)]
async fn gas_price(&self) -> Result<U256> {
let gas_price = self.kakarot_client.base_fee_per_gas();
Ok(gas_price)
}

#[tracing::instrument(skip_all, ret, fields(block_count = %block_count, newest_block = %newest_block, reward_percentiles = ?reward_percentiles))]
async fn fee_history(
&self,
block_count: U256,
Expand All @@ -314,6 +335,7 @@ impl<P: Provider + Send + Sync + 'static> EthApiServer for KakarotEthRpc<P> {
Ok(fee_history)
}

#[tracing::instrument(skip_all, ret)]
async fn max_priority_fee_per_gas(&self) -> Result<U128> {
let max_priority_fee = self.kakarot_client.max_priority_fee_per_gas();
Ok(max_priority_fee)
Expand Down Expand Up @@ -343,6 +365,7 @@ impl<P: Provider + Send + Sync + 'static> EthApiServer for KakarotEthRpc<P> {
Err(EthApiError::MethodNotSupported("eth_sendTransaction".to_string()).into())
}

#[tracing::instrument(skip_all, ret, fields(bytes = %bytes))]
async fn send_raw_transaction(&self, bytes: Bytes) -> Result<H256> {
let transaction_hash = self.kakarot_client.send_transaction(bytes).await?;
Ok(transaction_hash)
Expand Down
44 changes: 26 additions & 18 deletions src/models/transaction_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,35 @@ impl StarknetTransactionReceipt {
let eth_tx = starknet_tx.to_eth_transaction(client, block_hash, block_number, None).await?;
let from = eth_tx.from;
let to = eth_tx.to;
let contract_address = match to {
// If to is Some, means contract_address should be None as it is a normal transaction
Some(_) => None,
// If to is None, is a contract creation transaction so contract_address should be Some
None => {
let event = events
.iter()
.find(|event| event.keys.iter().any(|key| *key == EVM_CONTRACT_DEPLOYED))
.ok_or(EthApiError::Other(anyhow::anyhow!(
let contract_address = match execution_result {
ExecutionResult::Succeeded => {
match to {
// If to is Some, means contract_address should be None as it is a normal transaction
Some(_) => None,
// If to is None, is a contract creation transaction so contract_address should be Some
None => {
let event = events
.iter()
.find(|event| event.keys.iter().any(|key| *key == EVM_CONTRACT_DEPLOYED))
.ok_or(EthApiError::Other(anyhow::anyhow!(
"Kakarot Core: No contract deployment event found in Kakarot transaction receipt"
)))?;

let evm_address =
event.data.first().ok_or(DataDecodingError::InvalidReturnArrayLength {
entrypoint: "deployment".into(),
expected: 1,
actual: 0,
})?;

let evm_address = Felt252Wrapper::from(*evm_address);
Some(evm_address.try_into()?)
let evm_address =
event.data.first().ok_or(DataDecodingError::InvalidReturnArrayLength {
entrypoint: "deployment".into(),
expected: 1,
actual: 0,
})?;

let evm_address = Felt252Wrapper::from(*evm_address);
Some(evm_address.try_into()?)
}
}
}
ExecutionResult::Reverted { ref reason } => {
tracing::error!("Transaction reverted with {reason}");
None
}
};

Expand Down

0 comments on commit 8be8b25

Please sign in to comment.