Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
add tracing and fix sepolia bug (#864)
Browse files Browse the repository at this point in the history
* add tracing and fix sepolia bug

* fix hive tests

* fix comments
  • Loading branch information
Eikix authored Mar 15, 2024
1 parent 62ae0a5 commit 981db0f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/bin/hive_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn main() -> eyre::Result<()> {
for transaction in body.transactions {
let signer = transaction.recover_signer().ok_or(eyre!("Failed to recover signer"))?;
let chain_id = transaction.chain_id().ok_or(eyre!("Failed to recover chain id"))?;
let starknet_tx = to_starknet_transaction(&transaction, chain_id, signer)?;
let starknet_tx = to_starknet_transaction(&transaction, chain_id, signer, u64::MAX)?;

// Stop if the nonce is incorrect
assert_eq!(starknet_tx.nonce, current_nonce);
Expand Down
31 changes: 29 additions & 2 deletions src/eth_provider/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,28 @@ where
let signer = transaction_signed
.recover_signer()
.ok_or_else(|| ConversionError::ToStarknetTransactionError("Failed to recover signer".to_string()))?;
let transaction = to_starknet_transaction(&transaction_signed, chain_id, signer)?;

let max_fee: u64;
#[cfg(not(feature = "hive"))]
{
// TODO(Kakarot Fee Mechanism): When we no longer need to use the Starknet fees, remove this line.
// We need to get the balance (in Kakarot/Starknet native Token) of the signer to compute the Starknet maximum `max_fee`.
// We used to set max_fee = u64::MAX, but it'll fail if the signer doesn't have enough balance to pay the fees.
let eth_fees_per_gas =
transaction_signed.effective_gas_price(Some(transaction_signed.max_fee_per_gas() as u64)) as u64;
let eth_fees = eth_fees_per_gas.saturating_mul(transaction_signed.gas_limit());
let balance = self.balance(signer, None).await?;
max_fee = {
let max_fee: u64 = balance.try_into().unwrap_or(u64::MAX);
max_fee.saturating_sub(eth_fees)
};
}
#[cfg(feature = "hive")]
{
max_fee = u64::MAX;
}

let transaction = to_starknet_transaction(&transaction_signed, chain_id, signer, max_fee)?;

// If the contract is not found, we need to deploy it.
#[cfg(feature = "hive")]
Expand Down Expand Up @@ -526,7 +547,13 @@ where
#[cfg(not(feature = "testing"))]
{
let hash = transaction_signed.hash();
self.starknet_provider.add_invoke_transaction(BroadcastedInvokeTransaction::V1(transaction)).await?;
let tx =
self.starknet_provider.add_invoke_transaction(BroadcastedInvokeTransaction::V1(transaction)).await?;
tracing::info!(
"Fired a transaction: Starknet Hash: {:?} --- Ethereum Hash: {:?}",
tx.transaction_hash,
hash
);
Ok(hash)
}
// If we are currently testing, we need to return the starknet hash in order
Expand Down
4 changes: 2 additions & 2 deletions src/eth_provider/starknet/kakarot_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub fn to_starknet_transaction(
transaction: &TransactionSigned,
chain_id: u64,
signer: Address,
max_fee: u64,
) -> EthProviderResult<BroadcastedInvokeTransactionV1> {
let starknet_address = starknet_address(signer);

Expand Down Expand Up @@ -111,9 +112,8 @@ pub fn to_starknet_transaction(
]);
execute_calldata.append(&mut signed_data.into_iter().map(FieldElement::from).collect());

let max_fee = (u64::MAX).into();
Ok(BroadcastedInvokeTransactionV1 {
max_fee,
max_fee: max_fee.into(),
signature,
nonce,
sender_address: starknet_address,
Expand Down

0 comments on commit 981db0f

Please sign in to comment.