fix: comments fix 1

This commit is contained in:
Oleksandr Pravdyvyi 2025-07-24 16:05:27 +03:00
parent 95fec47897
commit 41b65521f9
No known key found for this signature in database
GPG Key ID: 9F8955C63C443871
6 changed files with 42 additions and 39 deletions

View File

@ -6,5 +6,5 @@ use crate::merkle_tree_public::TreeHashType;
pub struct PublicNativeTokenSend {
pub from: TreeHashType,
pub to: TreeHashType,
pub moved_balance: u64,
pub balance_to_move: u64,
}

View File

@ -3,9 +3,9 @@ use serde::Deserialize;
pub mod block;
pub mod commitment;
pub mod execution_input;
pub mod merkle_tree_public;
pub mod nullifier;
pub mod public_transfer_receipts;
pub mod rpc_primitives;
pub mod transaction;
pub mod utxo_commitment;

View File

@ -5,9 +5,9 @@ use anyhow::Result;
use block_store::NodeBlockStore;
use common::{
block::Block,
execution_input::PublicNativeTokenSend,
merkle_tree_public::merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree},
nullifier::UTXONullifier,
public_transfer_receipts::PublicNativeTokenSend,
utxo_commitment::UTXOCommitment,
};
use k256::AffinePoint;
@ -166,10 +166,10 @@ impl NodeChainStore {
if let Ok(transfer) = native_transfer {
if let Some(acc_sender) = self.acc_map.get_mut(&transfer.from) {
//Can panic, we depend on sequencer maintaining chain consistency here
acc_sender.balance -= transfer.moved_balance;
acc_sender.balance -= transfer.balance_to_move;
if let Some(acc_rec) = self.acc_map.get_mut(&transfer.to) {
acc_rec.balance += transfer.moved_balance;
acc_rec.balance += transfer.balance_to_move;
}
}
}

View File

@ -4,7 +4,7 @@ use std::sync::{
};
use common::{
public_transfer_receipts::PublicNativeTokenSend, transaction::Transaction, ExecutionFailureKind,
execution_input::PublicNativeTokenSend, transaction::Transaction, ExecutionFailureKind,
};
use accounts::{
@ -955,7 +955,7 @@ impl NodeCore {
&self,
from: AccountAddress,
to: AccountAddress,
moved_balance: u64,
balance_to_move: u64,
) -> Result<SendTxResponse, ExecutionFailureKind> {
let tx_roots = self.get_roots().await;
@ -982,7 +982,7 @@ impl NodeCore {
serde_json::to_vec(&PublicNativeTokenSend {
from,
to,
moved_balance,
balance_to_move,
})
.unwrap(),
commitment,

View File

@ -4,9 +4,9 @@ use accounts::account_core::AccountAddress;
use anyhow::Result;
use common::{
block::{Block, HashableBlockData},
execution_input::PublicNativeTokenSend,
merkle_tree_public::TreeHashType,
nullifier::UTXONullifier,
public_transfer_receipts::PublicNativeTokenSend,
transaction::{AuthenticatedTransaction, Transaction, TransactionBody, TxKind},
utxo_commitment::UTXOCommitment,
};
@ -177,33 +177,6 @@ impl SequencerCore {
);
}
//Balance check
if let Ok(native_transfer_action) =
serde_json::from_slice::<PublicNativeTokenSend>(execution_input)
{
let from_balance = self
.store
.acc_store
.get_account_balance(&native_transfer_action.from);
let to_balance = self
.store
.acc_store
.get_account_balance(&native_transfer_action.to);
if from_balance >= native_transfer_action.moved_balance {
self.store.acc_store.set_account_balance(
&native_transfer_action.from,
from_balance - native_transfer_action.moved_balance,
);
self.store.acc_store.set_account_balance(
&native_transfer_action.to,
to_balance + native_transfer_action.moved_balance,
);
} else {
return Err(TransactionMalformationErrorKind::BalanceMismatch { tx: tx_hash });
}
}
Ok(tx)
}
@ -233,9 +206,12 @@ impl SequencerCore {
let TransactionBody {
ref utxo_commitments_created_hashes,
ref nullifier_created_hashes,
execution_input,
..
} = mempool_tx.auth_tx.transaction().body();
let tx_hash = *mempool_tx.auth_tx.hash();
for utxo_comm in utxo_commitments_created_hashes {
self.store
.utxo_commitments_store
@ -252,6 +228,33 @@ impl SequencerCore {
.pub_tx_store
.add_tx(mempool_tx.auth_tx.transaction());
//Balance check
if let Ok(native_transfer_action) =
serde_json::from_slice::<PublicNativeTokenSend>(execution_input)
{
let from_balance = self
.store
.acc_store
.get_account_balance(&native_transfer_action.from);
let to_balance = self
.store
.acc_store
.get_account_balance(&native_transfer_action.to);
if from_balance >= native_transfer_action.balance_to_move {
self.store.acc_store.set_account_balance(
&native_transfer_action.from,
from_balance - native_transfer_action.balance_to_move,
);
self.store.acc_store.set_account_balance(
&native_transfer_action.to,
to_balance + native_transfer_action.balance_to_move,
);
} else {
return Err(TransactionMalformationErrorKind::BalanceMismatch { tx: tx_hash });
}
}
Ok(())
}

View File

@ -66,17 +66,17 @@ impl SequencerAccountsStore {
///Update `account_addr` balance,
///
/// returns 0, if account address not found, othervise returns previous balance
/// returns 0, if account address not found, otherwise returns previous balance
pub fn set_account_balance(&mut self, account_addr: &AccountAddress, new_balance: u64) -> u64 {
let acc_data = self.accounts.get_mut(account_addr);
acc_data
.map(|data| {
let old_bal = data.balance;
let old_balance = data.balance;
data.balance = new_balance;
old_bal
old_balance
})
.unwrap_or(0)
}