Merge branch 'Pravdyvy/debug-udpates' into scenario_fix

This commit is contained in:
Rostyslav Tyshko 2024-12-30 06:45:32 +01:00
commit 63926d0d54
4 changed files with 30 additions and 24 deletions

View File

@ -362,7 +362,7 @@ impl NodeCore {
(
TransactionPayload {
tx_kind: TxKind::Private,
tx_kind: TxKind::Shielded,
execution_input: serde_json::to_vec(&ActionData::SendMoneyShieldedTx(
SendMoneyShieldedTx {
acc_sender: acc,
@ -389,21 +389,14 @@ impl NodeCore {
pub async fn transfer_utxo_deshielded(
&self,
utxo: UTXO,
comm_gen_hash: [u8; 32],
receivers: Vec<(u128, AccountAddress)>,
) -> Transaction {
let commitment_in = {
info!("Attempting to get write guard for commitments");
let guard = self.storage.write().await;
info!("Guard got");
let acc_map_read_guard = self.storage.read().await;
guard.utxo_commitments_store.get_tx(utxo.hash).unwrap().hash
};
info!("Commitnment got");
let commitment_in = acc_map_read_guard.utxo_commitments_store.get_tx(comm_gen_hash).unwrap().hash;
let nullifier = {
let acc_map_read_guard = self.storage.read().await;
let accout = acc_map_read_guard.acc_map.get(&utxo.owner).unwrap();
let accout = acc_map_read_guard.acc_map.get(&utxo.owner).unwrap();
generate_nullifiers(
&utxo,
@ -416,11 +409,10 @@ impl NodeCore {
)
};
info!("Starting send proof");
let (resulting_balances, receipt) = prove_send_utxo_deshielded(utxo, receivers);
TransactionPayload {
tx_kind: TxKind::Private,
tx_kind: TxKind::Deshielded,
execution_input: vec![],
execution_output: serde_json::to_vec(&ActionData::SendMoneyDeshieldedTx(
SendMoneyDeshieldedTx {
@ -442,15 +434,17 @@ impl NodeCore {
&self,
acc: AccountAddress,
amount: u128,
) -> Result<(SendTxResponse, [u8; 32])> {
) -> Result<(SendTxResponse, [u8; 32], [u8; 32])> {
let point_before_prove = std::time::Instant::now();
let (tx, utxo_hash) = self.mint_utxo_private(acc, amount).await;
let point_after_prove = std::time::Instant::now();
let commitment_generated_hash = tx.utxo_commitments_created_hashes[0];
let timedelta = (point_after_prove - point_before_prove).as_millis();
info!("Mint utxo proof spent {timedelta:?} milliseconds");
Ok((self.sequencer_client.send_tx(tx).await?, utxo_hash))
Ok((self.sequencer_client.send_tx(tx).await?, utxo_hash, commitment_generated_hash))
}
pub async fn send_public_deposit(
@ -498,11 +492,11 @@ impl NodeCore {
pub async fn send_deshielded_send_tx(
&self,
utxo: UTXO,
comm_gen_hash: [u8; 32],
receivers: Vec<(u128, AccountAddress)>,
) -> Result<SendTxResponse> {
let point_before_prove = std::time::Instant::now();
info!("Starting deshielded transfer");
let tx = self.transfer_utxo_deshielded(utxo, receivers).await;
let tx = self.transfer_utxo_deshielded(utxo, comm_gen_hash, receivers).await;
let point_after_prove = std::time::Instant::now();
let timedelta = (point_after_prove - point_before_prove).as_millis();
@ -516,7 +510,7 @@ impl NodeCore {
let acc_addr = self.create_new_account().await;
info!("Account created {acc_addr:?}");
let (resp, new_utxo_hash) = self.send_private_mint_tx(acc_addr, 100).await.unwrap();
let (resp, new_utxo_hash, comm_gen_hash) = self.send_private_mint_tx(acc_addr, 100).await.unwrap();
info!("Response for mint private is {resp:?}");
info!("Awaiting new blocks");
@ -535,7 +529,7 @@ impl NodeCore {
};
let resp = self
.send_deshielded_send_tx(new_utxo, vec![(100, acc_addr)])
.send_deshielded_send_tx(new_utxo, comm_gen_hash, vec![(100, acc_addr)])
.await
.unwrap();
info!("Response for send deshielded is {resp:?}");
@ -602,7 +596,7 @@ impl NodeCore {
let acc_addr = self.create_new_account().await;
let acc_addr_rec = self.create_new_account().await;
let (resp, new_utxo_hash) = self.send_private_mint_tx(acc_addr, 100).await.unwrap();
let (resp, _, new_utxo_hash) = self.send_private_mint_tx(acc_addr, 100).await.unwrap();
info!("Response for mint private is {resp:?}");
info!("Awaiting new blocks");
@ -695,7 +689,7 @@ impl NodeCore {
let acc_addr = self.create_new_account().await;
let acc_addr_rec = self.create_new_account().await;
let (resp, new_utxo_hash) = self.send_private_mint_tx(acc_addr, 100).await.unwrap();
let (resp, comm_gen_hash, new_utxo_hash) = self.send_private_mint_tx(acc_addr, 100).await.unwrap();
info!("Response for mint private is {resp:?}");
info!("Awaiting new blocks");
@ -714,7 +708,7 @@ impl NodeCore {
};
let resp = self
.send_deshielded_send_tx(new_utxo, vec![(100, acc_addr_rec)])
.send_deshielded_send_tx(new_utxo, comm_gen_hash, vec![(100, acc_addr_rec)])
.await
.unwrap();
info!("Response for send deshielded is {resp:?}");

View File

@ -54,6 +54,8 @@ impl NodeChainStore {
pub fn dissect_insert_block(&mut self, block: Block) -> Result<()> {
for tx in &block.transactions {
// let public_action = serde_json::from_slice(tx.execution_output);
self.utxo_commitments_store.add_tx_multiple(
tx.utxo_commitments_created_hashes
.clone()

View File

@ -60,6 +60,15 @@ impl UTXO {
pub fn interpret_asset<'de, ToInterpret: Deserialize<'de>>(&'de self) -> Result<ToInterpret> {
Ok(serde_json::from_slice(&self.asset)?)
}
pub fn into_payload(&self) -> UTXOPayload {
UTXOPayload {
owner: self.owner,
asset: self.asset.clone(),
amount: self.amount,
privacy_flag: self.privacy_flag,
}
}
}
#[cfg(test)]

View File

@ -93,8 +93,9 @@ pub fn prove_send_utxo_deshielded(
owners_parts: Vec<(u128, AccountAddress)>,
) -> (Vec<(u128, AccountAddress)>, Receipt) {
let mut builder = ExecutorEnv::builder();
let utxo_payload = spent_utxo.into_payload();
builder.write(&spent_utxo).unwrap();
builder.write(&utxo_payload).unwrap();
builder.write(&owners_parts).unwrap();
let env = builder.build().unwrap();