mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-02 13:23:10 +00:00
fix: error propagation
This commit is contained in:
parent
2f9ce0c5cf
commit
bd8b4b8fa8
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -994,6 +994,19 @@ dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "common"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"reqwest 0.11.27",
|
||||
"risc0-zkvm",
|
||||
"rpc_primitives",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "consensus"
|
||||
version = "0.1.0"
|
||||
@ -2674,6 +2687,7 @@ dependencies = [
|
||||
"actix-rt",
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"common",
|
||||
"elliptic-curve",
|
||||
"env_logger",
|
||||
"hex",
|
||||
@ -2705,6 +2719,7 @@ dependencies = [
|
||||
"actix-cors",
|
||||
"actix-web",
|
||||
"anyhow",
|
||||
"common",
|
||||
"consensus",
|
||||
"env_logger",
|
||||
"futures",
|
||||
@ -5408,6 +5423,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"accounts",
|
||||
"anyhow",
|
||||
"common",
|
||||
"env_logger",
|
||||
"log",
|
||||
"risc0-zkvm",
|
||||
|
||||
@ -16,6 +16,7 @@ members = [
|
||||
"node_core",
|
||||
"sequencer_core",
|
||||
"rpc_primitives",
|
||||
"common",
|
||||
]
|
||||
|
||||
[workspace.dependencies]
|
||||
|
||||
15
common/Cargo.toml
Normal file
15
common/Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "common"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
thiserror.workspace = true
|
||||
serde_json.workspace = true
|
||||
serde.workspace = true
|
||||
reqwest.workspace = true
|
||||
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-1.2" }
|
||||
|
||||
[dependencies.rpc_primitives]
|
||||
path = "../rpc_primitives"
|
||||
67
common/src/lib.rs
Normal file
67
common/src/lib.rs
Normal file
@ -0,0 +1,67 @@
|
||||
use rpc_primitives::errors::RpcError;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct SequencerRpcError {
|
||||
pub jsonrpc: String,
|
||||
pub error: RpcError,
|
||||
pub id: u64,
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum SequencerClientError {
|
||||
#[error("HTTP error")]
|
||||
HTTPError(reqwest::Error),
|
||||
#[error("Serde error")]
|
||||
SerdeError(serde_json::Error),
|
||||
#[error("Internal error")]
|
||||
InternalError(SequencerRpcError),
|
||||
}
|
||||
|
||||
impl From<reqwest::Error> for SequencerClientError {
|
||||
fn from(value: reqwest::Error) -> Self {
|
||||
SequencerClientError::HTTPError(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for SequencerClientError {
|
||||
fn from(value: serde_json::Error) -> Self {
|
||||
SequencerClientError::SerdeError(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SequencerRpcError> for SequencerClientError {
|
||||
fn from(value: SequencerRpcError) -> Self {
|
||||
SequencerClientError::InternalError(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ExecutionFailureKind {
|
||||
#[error("Failed to write into builder err: {0:?}")]
|
||||
WriteError(anyhow::Error),
|
||||
#[error("Failed to build builder err: {0:?}")]
|
||||
BuilderError(anyhow::Error),
|
||||
#[error("Failed prove execution err: {0:?}")]
|
||||
ProveError(anyhow::Error),
|
||||
#[error("Failed to decode data from VM: {0:?}")]
|
||||
DecodeError(#[from] risc0_zkvm::serde::Error),
|
||||
#[error("Inputs amounts does not match outputs")]
|
||||
AmountMismatchError,
|
||||
#[error("Sequencer client error: {0:?}")]
|
||||
SequencerClientError(#[from] SequencerClientError),
|
||||
}
|
||||
|
||||
impl ExecutionFailureKind {
|
||||
pub fn write_error(err: anyhow::Error) -> Self {
|
||||
Self::WriteError(err)
|
||||
}
|
||||
|
||||
pub fn builder_error(err: anyhow::Error) -> Self {
|
||||
Self::BuilderError(err)
|
||||
}
|
||||
|
||||
pub fn prove_error(err: anyhow::Error) -> Self {
|
||||
Self::ProveError(err)
|
||||
}
|
||||
}
|
||||
@ -38,6 +38,9 @@ path = "../zkvm"
|
||||
[dependencies.rpc_primitives]
|
||||
path = "../rpc_primitives"
|
||||
|
||||
[dependencies.common]
|
||||
path = "../common"
|
||||
|
||||
[dependencies.secp256k1-zkp]
|
||||
workspace = true
|
||||
features = ["std", "rand-std", "rand", "serde", "global-context"]
|
||||
|
||||
@ -3,6 +3,7 @@ use std::sync::{
|
||||
Arc,
|
||||
};
|
||||
|
||||
use common::ExecutionFailureKind;
|
||||
use k256::elliptic_curve::group::GroupEncoding;
|
||||
|
||||
use ::storage::transaction::{Transaction, TransactionPayload, TxKind};
|
||||
@ -23,7 +24,7 @@ use tokio::{sync::RwLock, task::JoinHandle};
|
||||
use utxo::utxo_core::UTXO;
|
||||
use zkvm::{
|
||||
prove_mint_utxo, prove_mint_utxo_multiple_assets, prove_send_utxo, prove_send_utxo_deshielded,
|
||||
prove_send_utxo_multiple_assets_one_receiver, prove_send_utxo_shielded, ExecutionFailureKind,
|
||||
prove_send_utxo_multiple_assets_one_receiver, prove_send_utxo_shielded,
|
||||
};
|
||||
|
||||
pub const BLOCK_GEN_DELAY_SECS: u64 = 20;
|
||||
@ -145,11 +146,10 @@ impl NodeCore {
|
||||
|
||||
pub async fn get_roots(&self) -> [[u8; 32]; 3] {
|
||||
let storage = self.storage.read().await;
|
||||
//All roots are non-None after start of node main loop
|
||||
[
|
||||
storage.nullifier_store.curr_root.unwrap(),
|
||||
storage.utxo_commitments_store.get_root().unwrap(),
|
||||
storage.pub_tx_store.get_root().unwrap(),
|
||||
storage.nullifier_store.curr_root.unwrap_or([0; 32]),
|
||||
storage.utxo_commitments_store.get_root().unwrap_or([0; 32]),
|
||||
storage.pub_tx_store.get_root().unwrap_or([0; 32]),
|
||||
]
|
||||
}
|
||||
|
||||
@ -603,7 +603,7 @@ impl NodeCore {
|
||||
&self,
|
||||
acc: AccountAddress,
|
||||
amount: u128,
|
||||
) -> Result<(SendTxResponse, [u8; 32], [u8; 32])> {
|
||||
) -> Result<(SendTxResponse, [u8; 32], [u8; 32]), ExecutionFailureKind> {
|
||||
//Considering proof time, needs to be done before proof
|
||||
let tx_roots = self.get_roots().await;
|
||||
|
||||
@ -629,7 +629,7 @@ impl NodeCore {
|
||||
acc: AccountAddress,
|
||||
amount: u128,
|
||||
number_of_assets: usize,
|
||||
) -> Result<(SendTxResponse, Vec<[u8; 32]>, Vec<[u8; 32]>)> {
|
||||
) -> Result<(SendTxResponse, Vec<[u8; 32]>, Vec<[u8; 32]>), ExecutionFailureKind> {
|
||||
//Considering proof time, needs to be done before proof
|
||||
let tx_roots = self.get_roots().await;
|
||||
|
||||
@ -656,7 +656,7 @@ impl NodeCore {
|
||||
&self,
|
||||
acc: AccountAddress,
|
||||
amount: u128,
|
||||
) -> Result<SendTxResponse> {
|
||||
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||
//Considering proof time, needs to be done before proof
|
||||
let tx_roots = self.get_roots().await;
|
||||
|
||||
@ -671,7 +671,7 @@ impl NodeCore {
|
||||
utxo: UTXO,
|
||||
comm_hash: [u8; 32],
|
||||
receivers: Vec<(u128, AccountAddress)>,
|
||||
) -> Result<(SendTxResponse, Vec<([u8; 32], [u8; 32])>)> {
|
||||
) -> Result<(SendTxResponse, Vec<([u8; 32], [u8; 32])>), ExecutionFailureKind> {
|
||||
//Considering proof time, needs to be done before proof
|
||||
let tx_roots = self.get_roots().await;
|
||||
|
||||
@ -697,7 +697,7 @@ impl NodeCore {
|
||||
comm_hashes: Vec<[u8; 32]>,
|
||||
number_to_send: usize,
|
||||
receiver: AccountAddress,
|
||||
) -> Result<(SendTxResponse, Vec<[u8; 32]>, Vec<[u8; 32]>)> {
|
||||
) -> Result<(SendTxResponse, Vec<[u8; 32]>, Vec<[u8; 32]>), ExecutionFailureKind> {
|
||||
//Considering proof time, needs to be done before proof
|
||||
let tx_roots = self.get_roots().await;
|
||||
|
||||
@ -723,7 +723,7 @@ impl NodeCore {
|
||||
acc: AccountAddress,
|
||||
amount: u64,
|
||||
receivers: Vec<(u128, AccountAddress)>,
|
||||
) -> Result<(SendTxResponse, Vec<([u8; 32], [u8; 32])>)> {
|
||||
) -> Result<(SendTxResponse, Vec<([u8; 32], [u8; 32])>), ExecutionFailureKind> {
|
||||
//Considering proof time, needs to be done before proof
|
||||
let tx_roots = self.get_roots().await;
|
||||
|
||||
@ -748,7 +748,7 @@ impl NodeCore {
|
||||
utxo: UTXO,
|
||||
comm_gen_hash: [u8; 32],
|
||||
receivers: Vec<(u128, AccountAddress)>,
|
||||
) -> Result<SendTxResponse> {
|
||||
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||
//Considering proof time, needs to be done before proof
|
||||
let tx_roots = self.get_roots().await;
|
||||
|
||||
@ -769,7 +769,7 @@ impl NodeCore {
|
||||
&mut self,
|
||||
acc_addr: AccountAddress,
|
||||
amount: u128,
|
||||
) -> Result<(UTXO, [u8; 32])> {
|
||||
) -> Result<(UTXO, [u8; 32]), ExecutionFailureKind> {
|
||||
let (resp, new_utxo_hash, comm_gen_hash) =
|
||||
self.send_private_mint_tx(acc_addr, amount).await?;
|
||||
info!("Response for mint private is {resp:?}");
|
||||
@ -808,7 +808,7 @@ impl NodeCore {
|
||||
acc_addr: AccountAddress,
|
||||
amount: u128,
|
||||
number_of_assets: usize,
|
||||
) -> Result<(Vec<UTXO>, Vec<[u8; 32]>)> {
|
||||
) -> Result<(Vec<UTXO>, Vec<[u8; 32]>), ExecutionFailureKind> {
|
||||
let (resp, new_utxo_hashes, comm_gen_hashes) = self
|
||||
.send_private_mint_multiple_assets_tx(acc_addr, amount, number_of_assets)
|
||||
.await?;
|
||||
@ -858,7 +858,7 @@ impl NodeCore {
|
||||
acc_addr_rec: AccountAddress,
|
||||
utxo: UTXO,
|
||||
comm_gen_hash: [u8; 32],
|
||||
) -> Result<()> {
|
||||
) -> Result<(), ExecutionFailureKind> {
|
||||
let amount = utxo.amount;
|
||||
|
||||
let old_balance = {
|
||||
@ -904,7 +904,7 @@ impl NodeCore {
|
||||
&mut self,
|
||||
acc_addr: AccountAddress,
|
||||
amount: u128,
|
||||
) -> Result<()> {
|
||||
) -> Result<(), ExecutionFailureKind> {
|
||||
let old_balance = {
|
||||
let acc_map_read_guard = self.storage.read().await;
|
||||
|
||||
@ -946,7 +946,7 @@ impl NodeCore {
|
||||
acc_addr_sender: AccountAddress,
|
||||
acc_addr_rec: AccountAddress,
|
||||
amount: u128,
|
||||
) -> Result<UTXO> {
|
||||
) -> Result<UTXO, ExecutionFailureKind> {
|
||||
let (resp, new_utxo_hashes) = self
|
||||
.send_shielded_send_tx(acc_addr_sender, amount as u64, vec![(amount, acc_addr_rec)])
|
||||
.await?;
|
||||
@ -988,7 +988,7 @@ impl NodeCore {
|
||||
acc_addr_rec: AccountAddress,
|
||||
utxo: UTXO,
|
||||
comm_gen_hash: [u8; 32],
|
||||
) -> Result<UTXO> {
|
||||
) -> Result<UTXO, ExecutionFailureKind> {
|
||||
let amount = utxo.amount;
|
||||
|
||||
let (resp, new_utxo_hashes) = self
|
||||
@ -1035,7 +1035,7 @@ impl NodeCore {
|
||||
utxos: Vec<UTXO>,
|
||||
comm_gen_hashes: Vec<[u8; 32]>,
|
||||
number_to_send: usize,
|
||||
) -> Result<()> {
|
||||
) -> Result<(), ExecutionFailureKind> {
|
||||
let (resp, new_utxo_hashes_rec, new_utxo_hashes_not_sp) = self
|
||||
.send_private_multiple_assets_send_tx(
|
||||
utxos,
|
||||
@ -1201,7 +1201,8 @@ impl NodeCore {
|
||||
comm_hash: [u8; 32],
|
||||
receivers: Vec<(u128, AccountAddress)>,
|
||||
visibility_list: [bool; 3],
|
||||
) -> Result<(SendTxResponse, Vec<([u8; 32], [u8; 32])>, Vec<[u8; 32]>)> {
|
||||
) -> Result<(SendTxResponse, Vec<([u8; 32], [u8; 32])>, Vec<[u8; 32]>), ExecutionFailureKind>
|
||||
{
|
||||
//Considering proof time, needs to be done before proof
|
||||
let tx_roots = self.get_roots().await;
|
||||
|
||||
@ -1230,7 +1231,7 @@ impl NodeCore {
|
||||
utxo: UTXO,
|
||||
comm_gen_hash: [u8; 32],
|
||||
visibility_list: [bool; 3],
|
||||
) -> Result<(Vec<UTXO>, Vec<[u8; 32]>)> {
|
||||
) -> Result<(Vec<UTXO>, Vec<[u8; 32]>), ExecutionFailureKind> {
|
||||
let (resp, new_utxo_hashes, commitments_hashes) = self
|
||||
.send_split_tx(
|
||||
utxo.clone(),
|
||||
@ -1283,7 +1284,7 @@ impl NodeCore {
|
||||
}
|
||||
|
||||
///Mint utxo, make it public
|
||||
pub async fn subscenario_1(&mut self) -> Result<()> {
|
||||
pub async fn subscenario_1(&mut self) -> Result<(), ExecutionFailureKind> {
|
||||
let acc_addr = self.create_new_account().await;
|
||||
|
||||
let (new_utxo, comm_gen_hash) = self.operate_account_mint_private(acc_addr, 100).await?;
|
||||
@ -1300,7 +1301,7 @@ impl NodeCore {
|
||||
}
|
||||
|
||||
///Deposit balance, make it private
|
||||
pub async fn subscenario_2(&mut self) -> Result<()> {
|
||||
pub async fn subscenario_2(&mut self) -> Result<(), ExecutionFailureKind> {
|
||||
let acc_addr = self.create_new_account().await;
|
||||
|
||||
self.operate_account_deposit_public(acc_addr, 100).await?;
|
||||
@ -1312,7 +1313,7 @@ impl NodeCore {
|
||||
}
|
||||
|
||||
///Mint utxo, privately send it to another user
|
||||
pub async fn subscenario_3(&mut self) -> Result<()> {
|
||||
pub async fn subscenario_3(&mut self) -> Result<(), ExecutionFailureKind> {
|
||||
let acc_addr = self.create_new_account().await;
|
||||
let acc_addr_rec = self.create_new_account().await;
|
||||
|
||||
@ -1325,7 +1326,7 @@ impl NodeCore {
|
||||
}
|
||||
|
||||
///Deposit balance, shielded send it to another user
|
||||
pub async fn subscenario_4(&mut self) -> Result<()> {
|
||||
pub async fn subscenario_4(&mut self) -> Result<(), ExecutionFailureKind> {
|
||||
let acc_addr = self.create_new_account().await;
|
||||
let acc_addr_rec = self.create_new_account().await;
|
||||
|
||||
@ -1338,7 +1339,7 @@ impl NodeCore {
|
||||
}
|
||||
|
||||
///Mint utxo, deshielded send it to another user
|
||||
pub async fn subscenario_5(&mut self) -> Result<()> {
|
||||
pub async fn subscenario_5(&mut self) -> Result<(), ExecutionFailureKind> {
|
||||
let acc_addr = self.create_new_account().await;
|
||||
let acc_addr_rec = self.create_new_account().await;
|
||||
|
||||
@ -1364,7 +1365,7 @@ impl NodeCore {
|
||||
&mut self,
|
||||
visibility_list: [bool; 3],
|
||||
publication_index: usize,
|
||||
) -> Result<()> {
|
||||
) -> Result<(), ExecutionFailureKind> {
|
||||
let acc_addr_sender = self.create_new_account().await;
|
||||
|
||||
let acc_addr_rec_1 = self.create_new_account().await;
|
||||
@ -1402,7 +1403,7 @@ impl NodeCore {
|
||||
&mut self,
|
||||
number_of_assets: usize,
|
||||
number_to_send: usize,
|
||||
) -> Result<()> {
|
||||
) -> Result<(), ExecutionFailureKind> {
|
||||
let acc_addr_sender = self.create_new_account().await;
|
||||
let acc_addr_receiver = self.create_new_account().await;
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
use rpc_primitives::errors::RpcError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use storage::{block::Block, transaction::Transaction};
|
||||
|
||||
@ -77,10 +76,3 @@ pub struct SequencerRpcResponse {
|
||||
pub result: serde_json::Value,
|
||||
pub id: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct SequencerRpcError {
|
||||
pub jsonrpc: String,
|
||||
pub error: RpcError,
|
||||
pub id: u64,
|
||||
}
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
use accounts::account_core::Account;
|
||||
use anyhow::Result;
|
||||
use common::{SequencerClientError, SequencerRpcError};
|
||||
use json::{
|
||||
GetBlockDataRequest, GetBlockDataResponse, GetGenesisIdRequest, GetGenesisIdResponse,
|
||||
RegisterAccountRequest, RegisterAccountResponse, SendTxRequest, SendTxResponse,
|
||||
SequencerRpcError, SequencerRpcRequest, SequencerRpcResponse,
|
||||
SequencerRpcRequest, SequencerRpcResponse,
|
||||
};
|
||||
use k256::elliptic_curve::group::GroupEncoding;
|
||||
use reqwest::Client;
|
||||
@ -20,34 +21,6 @@ pub struct SequencerClient {
|
||||
pub config: NodeConfig,
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum SequencerClientError {
|
||||
#[error("HTTP error")]
|
||||
HTTPError(reqwest::Error),
|
||||
#[error("Serde error")]
|
||||
SerdeError(serde_json::Error),
|
||||
#[error("Internal error")]
|
||||
InternalError(SequencerRpcError),
|
||||
}
|
||||
|
||||
impl From<reqwest::Error> for SequencerClientError {
|
||||
fn from(value: reqwest::Error) -> Self {
|
||||
SequencerClientError::HTTPError(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for SequencerClientError {
|
||||
fn from(value: serde_json::Error) -> Self {
|
||||
SequencerClientError::SerdeError(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SequencerRpcError> for SequencerClientError {
|
||||
fn from(value: SequencerRpcError) -> Self {
|
||||
SequencerClientError::InternalError(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl SequencerClient {
|
||||
pub fn new(config: NodeConfig) -> Result<Self> {
|
||||
Ok(Self {
|
||||
|
||||
@ -43,3 +43,6 @@ path = "../node_core"
|
||||
|
||||
[dependencies.rpc_primitives]
|
||||
path = "../rpc_primitives"
|
||||
|
||||
[dependencies.common]
|
||||
path = "../common"
|
||||
|
||||
@ -11,19 +11,23 @@ use rpc_primitives::{
|
||||
};
|
||||
use storage::transaction::ActionData;
|
||||
|
||||
use crate::types::rpc_structs::{
|
||||
ExecuteScenarioMultipleSendRequest, ExecuteScenarioMultipleSendResponse,
|
||||
ExecuteScenarioSplitRequest, ExecuteScenarioSplitResponse, ExecuteSubscenarioRequest,
|
||||
ExecuteSubscenarioResponse, GetBlockDataRequest, GetBlockDataResponse, GetLastBlockRequest,
|
||||
GetLastBlockResponse, RegisterAccountRequest, RegisterAccountResponse,
|
||||
ShowAccountPublicBalanceRequest, ShowAccountPublicBalanceResponse, ShowAccountUTXORequest,
|
||||
ShowAccountUTXOResponse, ShowTransactionRequest, ShowTransactionResponse,
|
||||
UTXOShortEssentialStruct, WriteDepositPublicBalanceRequest, WriteDepositPublicBalanceResponse,
|
||||
WriteMintPrivateUTXOMultipleAssetsRequest, WriteMintPrivateUTXOMultipleAssetsResponse,
|
||||
WriteMintPrivateUTXORequest, WriteMintPrivateUTXOResponse, WriteSendDeshieldedBalanceRequest,
|
||||
WriteSendDeshieldedUTXOResponse, WriteSendPrivateUTXORequest, WriteSendPrivateUTXOResponse,
|
||||
WriteSendShieldedUTXORequest, WriteSendShieldedUTXOResponse, WriteSendSplitUTXOResponse,
|
||||
WriteSplitUTXORequest,
|
||||
use crate::types::{
|
||||
err_rpc::cast_common_execution_error_into_rpc_error,
|
||||
rpc_structs::{
|
||||
ExecuteScenarioMultipleSendRequest, ExecuteScenarioMultipleSendResponse,
|
||||
ExecuteScenarioSplitRequest, ExecuteScenarioSplitResponse, ExecuteSubscenarioRequest,
|
||||
ExecuteSubscenarioResponse, GetBlockDataRequest, GetBlockDataResponse, GetLastBlockRequest,
|
||||
GetLastBlockResponse, RegisterAccountRequest, RegisterAccountResponse,
|
||||
ShowAccountPublicBalanceRequest, ShowAccountPublicBalanceResponse, ShowAccountUTXORequest,
|
||||
ShowAccountUTXOResponse, ShowTransactionRequest, ShowTransactionResponse,
|
||||
UTXOShortEssentialStruct, WriteDepositPublicBalanceRequest,
|
||||
WriteDepositPublicBalanceResponse, WriteMintPrivateUTXOMultipleAssetsRequest,
|
||||
WriteMintPrivateUTXOMultipleAssetsResponse, WriteMintPrivateUTXORequest,
|
||||
WriteMintPrivateUTXOResponse, WriteSendDeshieldedBalanceRequest,
|
||||
WriteSendDeshieldedUTXOResponse, WriteSendPrivateUTXORequest, WriteSendPrivateUTXOResponse,
|
||||
WriteSendShieldedUTXORequest, WriteSendShieldedUTXOResponse, WriteSendSplitUTXOResponse,
|
||||
WriteSplitUTXORequest,
|
||||
},
|
||||
};
|
||||
|
||||
use super::{respond, types::err_rpc::RpcErr, JsonHandler};
|
||||
@ -51,11 +55,26 @@ impl JsonHandler {
|
||||
let mut store = self.node_chain_store.lock().await;
|
||||
|
||||
match req.scenario_id {
|
||||
1 => store.subscenario_1().await?,
|
||||
2 => store.subscenario_2().await?,
|
||||
3 => store.subscenario_3().await?,
|
||||
4 => store.subscenario_4().await?,
|
||||
5 => store.subscenario_5().await?,
|
||||
1 => store
|
||||
.subscenario_1()
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?,
|
||||
2 => store
|
||||
.subscenario_2()
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?,
|
||||
3 => store
|
||||
.subscenario_3()
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?,
|
||||
4 => store
|
||||
.subscenario_4()
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?,
|
||||
5 => store
|
||||
.subscenario_5()
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?,
|
||||
_ => return Err(RpcErr(RpcError::invalid_params("Scenario id not found"))),
|
||||
}
|
||||
}
|
||||
@ -78,7 +97,8 @@ impl JsonHandler {
|
||||
|
||||
store
|
||||
.scenario_1(req.visibility_list, req.publication_index)
|
||||
.await?;
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?;
|
||||
}
|
||||
|
||||
let helperstruct = ExecuteScenarioSplitResponse {
|
||||
@ -99,7 +119,8 @@ impl JsonHandler {
|
||||
|
||||
store
|
||||
.scenario_2(req.number_of_assets, req.number_to_send)
|
||||
.await?;
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?;
|
||||
}
|
||||
|
||||
let helperstruct = ExecuteScenarioMultipleSendResponse {
|
||||
@ -331,7 +352,8 @@ impl JsonHandler {
|
||||
|
||||
cover_guard
|
||||
.operate_account_deposit_public(acc_addr, req.amount as u128)
|
||||
.await?;
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?;
|
||||
};
|
||||
|
||||
let helperstruct = WriteDepositPublicBalanceResponse {
|
||||
@ -357,7 +379,8 @@ impl JsonHandler {
|
||||
|
||||
cover_guard
|
||||
.operate_account_mint_private(acc_addr, req.amount as u128)
|
||||
.await?
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?
|
||||
};
|
||||
|
||||
let helperstruct = WriteMintPrivateUTXOResponse {
|
||||
@ -395,7 +418,8 @@ impl JsonHandler {
|
||||
req.amount as u128,
|
||||
req.num_of_assets,
|
||||
)
|
||||
.await?
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?
|
||||
};
|
||||
|
||||
let helperstruct = WriteMintPrivateUTXOMultipleAssetsResponse {
|
||||
@ -477,7 +501,8 @@ impl JsonHandler {
|
||||
|
||||
cover_guard
|
||||
.operate_account_send_private_one_receiver(acc_addr, utxo_to_send, comm_hash)
|
||||
.await?
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?
|
||||
};
|
||||
|
||||
let helperstruct = WriteSendPrivateUTXOResponse {
|
||||
@ -529,7 +554,8 @@ impl JsonHandler {
|
||||
acc_addr_rec,
|
||||
req.amount as u128,
|
||||
)
|
||||
.await?
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?
|
||||
};
|
||||
|
||||
let helperstruct = WriteSendShieldedUTXOResponse {
|
||||
@ -615,7 +641,8 @@ impl JsonHandler {
|
||||
utxo_to_send,
|
||||
comm_hash,
|
||||
)
|
||||
.await?
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?
|
||||
};
|
||||
|
||||
let helperstruct = WriteSendDeshieldedUTXOResponse {
|
||||
@ -707,7 +734,8 @@ impl JsonHandler {
|
||||
comm_hash,
|
||||
req.visibility_list,
|
||||
)
|
||||
.await?
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?
|
||||
};
|
||||
|
||||
let helperstruct = WriteSendSplitUTXOResponse {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use common::{ExecutionFailureKind, SequencerClientError};
|
||||
use log::debug;
|
||||
|
||||
use node_core::sequencer_client::SequencerClientError;
|
||||
use rpc_primitives::errors::{RpcError, RpcParseError};
|
||||
|
||||
pub struct RpcErr(pub RpcError);
|
||||
@ -59,3 +59,20 @@ pub fn cast_seq_client_error_into_rpc_error(seq_cli_err: SequencerClientError) -
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cast_common_execution_error_into_rpc_error(comm_exec_err: ExecutionFailureKind) -> RpcError {
|
||||
let error_string = comm_exec_err.to_string();
|
||||
|
||||
match comm_exec_err {
|
||||
ExecutionFailureKind::BuilderError(_) => RpcError::new_internal_error(None, &error_string),
|
||||
ExecutionFailureKind::WriteError(_) => RpcError::new_internal_error(None, &error_string),
|
||||
ExecutionFailureKind::DecodeError(_) => RpcError::new_internal_error(None, &error_string),
|
||||
ExecutionFailureKind::ProveError(_) => RpcError::new_internal_error(None, &error_string),
|
||||
ExecutionFailureKind::AmountMismatchError => {
|
||||
RpcError::new_internal_error(None, &error_string)
|
||||
}
|
||||
ExecutionFailureKind::SequencerClientError(seq_cli_err) => {
|
||||
cast_seq_client_error_into_rpc_error(seq_cli_err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,11 +60,13 @@ impl SequencerCore {
|
||||
}
|
||||
|
||||
pub fn get_tree_roots(&self) -> [[u8; 32]; 3] {
|
||||
//All roots are non-None after start of sequencer main loop
|
||||
[
|
||||
self.store.nullifier_store.curr_root.unwrap(),
|
||||
self.store.utxo_commitments_store.get_root().unwrap(),
|
||||
self.store.pub_tx_store.get_root().unwrap(),
|
||||
self.store.nullifier_store.curr_root.unwrap_or([0; 32]),
|
||||
self.store
|
||||
.utxo_commitments_store
|
||||
.get_root()
|
||||
.unwrap_or([0; 32]),
|
||||
self.store.pub_tx_store.get_root().unwrap_or([0; 32]),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,9 @@ path = "../storage"
|
||||
[dependencies.utxo]
|
||||
path = "../utxo"
|
||||
|
||||
[dependencies.common]
|
||||
path = "../common"
|
||||
|
||||
[features]
|
||||
cuda = ["risc0-zkvm/cuda"]
|
||||
default = []
|
||||
|
||||
@ -1,35 +1,8 @@
|
||||
use accounts::account_core::AccountAddress;
|
||||
use common::ExecutionFailureKind;
|
||||
use risc0_zkvm::{default_executor, default_prover, sha::Digest, ExecutorEnv, Receipt};
|
||||
use utxo::utxo_core::{UTXOPayload, UTXO};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ExecutionFailureKind {
|
||||
#[error("Failed to write into builder err: {0:?}")]
|
||||
WriteError(anyhow::Error),
|
||||
#[error("Failed to build builder err: {0:?}")]
|
||||
BuilderError(anyhow::Error),
|
||||
#[error("Failed prove execution err: {0:?}")]
|
||||
ProveError(anyhow::Error),
|
||||
#[error("Failed to decode data from VM: {0:?}")]
|
||||
DecodeError(#[from] risc0_zkvm::serde::Error),
|
||||
#[error("Inputs amounts does not match outputs")]
|
||||
AmountMismatchError,
|
||||
}
|
||||
|
||||
impl ExecutionFailureKind {
|
||||
pub fn write_error(err: anyhow::Error) -> Self {
|
||||
Self::WriteError(err)
|
||||
}
|
||||
|
||||
pub fn builder_error(err: anyhow::Error) -> Self {
|
||||
Self::BuilderError(err)
|
||||
}
|
||||
|
||||
pub fn prove_error(err: anyhow::Error) -> Self {
|
||||
Self::ProveError(err)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prove_mint_utxo(
|
||||
amount_to_mint: u128,
|
||||
owner: AccountAddress,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user