mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-07 15:53:14 +00:00
Merge pull request #47 from vacp2p/Pravdyvy/fixed-error-propagation
Fixed error propagation
This commit is contained in:
commit
c3b5921d14
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -994,6 +994,20 @@ dependencies = [
|
|||||||
"os_str_bytes",
|
"os_str_bytes",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "common"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"monotree",
|
||||||
|
"reqwest 0.11.27",
|
||||||
|
"risc0-zkvm",
|
||||||
|
"rpc_primitives",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "consensus"
|
name = "consensus"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -2674,6 +2688,7 @@ dependencies = [
|
|||||||
"actix-rt",
|
"actix-rt",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bincode",
|
"bincode",
|
||||||
|
"common",
|
||||||
"elliptic-curve",
|
"elliptic-curve",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"hex",
|
"hex",
|
||||||
@ -2705,6 +2720,7 @@ dependencies = [
|
|||||||
"actix-cors",
|
"actix-cors",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"common",
|
||||||
"consensus",
|
"consensus",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
"futures",
|
||||||
@ -5410,6 +5426,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"accounts",
|
"accounts",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"common",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"log",
|
"log",
|
||||||
"risc0-zkvm",
|
"risc0-zkvm",
|
||||||
|
|||||||
@ -16,6 +16,7 @@ members = [
|
|||||||
"node_core",
|
"node_core",
|
||||||
"sequencer_core",
|
"sequencer_core",
|
||||||
"rpc_primitives",
|
"rpc_primitives",
|
||||||
|
"common",
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
|
|||||||
16
common/Cargo.toml
Normal file
16
common/Cargo.toml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[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
|
||||||
|
monotree.workspace = true
|
||||||
|
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-1.2" }
|
||||||
|
|
||||||
|
[dependencies.rpc_primitives]
|
||||||
|
path = "../rpc_primitives"
|
||||||
69
common/src/lib.rs
Normal file
69
common/src/lib.rs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
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),
|
||||||
|
#[error("Datebase returned error : {0:?}")]
|
||||||
|
MonoTreeError(#[from] monotree::Errors),
|
||||||
|
}
|
||||||
|
|
||||||
|
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]
|
[dependencies.rpc_primitives]
|
||||||
path = "../rpc_primitives"
|
path = "../rpc_primitives"
|
||||||
|
|
||||||
|
[dependencies.common]
|
||||||
|
path = "../common"
|
||||||
|
|
||||||
[dependencies.secp256k1-zkp]
|
[dependencies.secp256k1-zkp]
|
||||||
workspace = true
|
workspace = true
|
||||||
features = ["std", "rand-std", "rand", "serde", "global-context"]
|
features = ["std", "rand-std", "rand", "serde", "global-context"]
|
||||||
|
|||||||
@ -3,6 +3,7 @@ use std::sync::{
|
|||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use common::ExecutionFailureKind;
|
||||||
use k256::elliptic_curve::group::GroupEncoding;
|
use k256::elliptic_curve::group::GroupEncoding;
|
||||||
|
|
||||||
use ::storage::transaction::{Transaction, TransactionPayload, TxKind};
|
use ::storage::transaction::{Transaction, TransactionPayload, TxKind};
|
||||||
@ -23,7 +24,7 @@ use tokio::{sync::RwLock, task::JoinHandle};
|
|||||||
use utxo::utxo_core::UTXO;
|
use utxo::utxo_core::UTXO;
|
||||||
use zkvm::{
|
use zkvm::{
|
||||||
prove_mint_utxo, prove_mint_utxo_multiple_assets, prove_send_utxo, prove_send_utxo_deshielded,
|
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;
|
pub const BLOCK_GEN_DELAY_SECS: u64 = 20;
|
||||||
@ -603,7 +604,7 @@ impl NodeCore {
|
|||||||
&self,
|
&self,
|
||||||
acc: AccountAddress,
|
acc: AccountAddress,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
) -> Result<(SendTxResponse, [u8; 32], [u8; 32])> {
|
) -> Result<(SendTxResponse, [u8; 32], [u8; 32]), ExecutionFailureKind> {
|
||||||
//Considering proof time, needs to be done before proof
|
//Considering proof time, needs to be done before proof
|
||||||
let tx_roots = self.get_roots().await;
|
let tx_roots = self.get_roots().await;
|
||||||
|
|
||||||
@ -629,7 +630,7 @@ impl NodeCore {
|
|||||||
acc: AccountAddress,
|
acc: AccountAddress,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
number_of_assets: usize,
|
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
|
//Considering proof time, needs to be done before proof
|
||||||
let tx_roots = self.get_roots().await;
|
let tx_roots = self.get_roots().await;
|
||||||
|
|
||||||
@ -656,7 +657,7 @@ impl NodeCore {
|
|||||||
&self,
|
&self,
|
||||||
acc: AccountAddress,
|
acc: AccountAddress,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
) -> Result<SendTxResponse> {
|
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||||
//Considering proof time, needs to be done before proof
|
//Considering proof time, needs to be done before proof
|
||||||
let tx_roots = self.get_roots().await;
|
let tx_roots = self.get_roots().await;
|
||||||
|
|
||||||
@ -671,7 +672,7 @@ impl NodeCore {
|
|||||||
utxo: UTXO,
|
utxo: UTXO,
|
||||||
comm_hash: [u8; 32],
|
comm_hash: [u8; 32],
|
||||||
receivers: Vec<(u128, AccountAddress)>,
|
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
|
//Considering proof time, needs to be done before proof
|
||||||
let tx_roots = self.get_roots().await;
|
let tx_roots = self.get_roots().await;
|
||||||
|
|
||||||
@ -697,7 +698,7 @@ impl NodeCore {
|
|||||||
comm_hashes: Vec<[u8; 32]>,
|
comm_hashes: Vec<[u8; 32]>,
|
||||||
number_to_send: usize,
|
number_to_send: usize,
|
||||||
receiver: AccountAddress,
|
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
|
//Considering proof time, needs to be done before proof
|
||||||
let tx_roots = self.get_roots().await;
|
let tx_roots = self.get_roots().await;
|
||||||
|
|
||||||
@ -723,7 +724,7 @@ impl NodeCore {
|
|||||||
acc: AccountAddress,
|
acc: AccountAddress,
|
||||||
amount: u64,
|
amount: u64,
|
||||||
receivers: Vec<(u128, AccountAddress)>,
|
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
|
//Considering proof time, needs to be done before proof
|
||||||
let tx_roots = self.get_roots().await;
|
let tx_roots = self.get_roots().await;
|
||||||
|
|
||||||
@ -748,7 +749,7 @@ impl NodeCore {
|
|||||||
utxo: UTXO,
|
utxo: UTXO,
|
||||||
comm_gen_hash: [u8; 32],
|
comm_gen_hash: [u8; 32],
|
||||||
receivers: Vec<(u128, AccountAddress)>,
|
receivers: Vec<(u128, AccountAddress)>,
|
||||||
) -> Result<SendTxResponse> {
|
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||||
//Considering proof time, needs to be done before proof
|
//Considering proof time, needs to be done before proof
|
||||||
let tx_roots = self.get_roots().await;
|
let tx_roots = self.get_roots().await;
|
||||||
|
|
||||||
@ -769,7 +770,7 @@ impl NodeCore {
|
|||||||
&mut self,
|
&mut self,
|
||||||
acc_addr: AccountAddress,
|
acc_addr: AccountAddress,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
) -> Result<(UTXO, [u8; 32])> {
|
) -> Result<(UTXO, [u8; 32]), ExecutionFailureKind> {
|
||||||
let (resp, new_utxo_hash, comm_gen_hash) =
|
let (resp, new_utxo_hash, comm_gen_hash) =
|
||||||
self.send_private_mint_tx(acc_addr, amount).await?;
|
self.send_private_mint_tx(acc_addr, amount).await?;
|
||||||
info!("Response for mint private is {resp:?}");
|
info!("Response for mint private is {resp:?}");
|
||||||
@ -804,7 +805,7 @@ impl NodeCore {
|
|||||||
acc_addr: AccountAddress,
|
acc_addr: AccountAddress,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
number_of_assets: usize,
|
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
|
let (resp, new_utxo_hashes, comm_gen_hashes) = self
|
||||||
.send_private_mint_multiple_assets_tx(acc_addr, amount, number_of_assets)
|
.send_private_mint_multiple_assets_tx(acc_addr, amount, number_of_assets)
|
||||||
.await?;
|
.await?;
|
||||||
@ -854,7 +855,7 @@ impl NodeCore {
|
|||||||
acc_addr_rec: AccountAddress,
|
acc_addr_rec: AccountAddress,
|
||||||
utxo: UTXO,
|
utxo: UTXO,
|
||||||
comm_gen_hash: [u8; 32],
|
comm_gen_hash: [u8; 32],
|
||||||
) -> Result<()> {
|
) -> Result<(), ExecutionFailureKind> {
|
||||||
let amount = utxo.amount;
|
let amount = utxo.amount;
|
||||||
|
|
||||||
let old_balance = {
|
let old_balance = {
|
||||||
@ -900,7 +901,7 @@ impl NodeCore {
|
|||||||
&mut self,
|
&mut self,
|
||||||
acc_addr: AccountAddress,
|
acc_addr: AccountAddress,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
) -> Result<()> {
|
) -> Result<(), ExecutionFailureKind> {
|
||||||
let old_balance = {
|
let old_balance = {
|
||||||
let acc_map_read_guard = self.storage.read().await;
|
let acc_map_read_guard = self.storage.read().await;
|
||||||
|
|
||||||
@ -942,7 +943,7 @@ impl NodeCore {
|
|||||||
acc_addr_sender: AccountAddress,
|
acc_addr_sender: AccountAddress,
|
||||||
acc_addr_rec: AccountAddress,
|
acc_addr_rec: AccountAddress,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
) -> Result<UTXO> {
|
) -> Result<UTXO, ExecutionFailureKind> {
|
||||||
let (resp, new_utxo_hashes) = self
|
let (resp, new_utxo_hashes) = self
|
||||||
.send_shielded_send_tx(acc_addr_sender, amount as u64, vec![(amount, acc_addr_rec)])
|
.send_shielded_send_tx(acc_addr_sender, amount as u64, vec![(amount, acc_addr_rec)])
|
||||||
.await?;
|
.await?;
|
||||||
@ -980,7 +981,7 @@ impl NodeCore {
|
|||||||
acc_addr_rec: AccountAddress,
|
acc_addr_rec: AccountAddress,
|
||||||
utxo: UTXO,
|
utxo: UTXO,
|
||||||
comm_gen_hash: [u8; 32],
|
comm_gen_hash: [u8; 32],
|
||||||
) -> Result<UTXO> {
|
) -> Result<UTXO, ExecutionFailureKind> {
|
||||||
let amount = utxo.amount;
|
let amount = utxo.amount;
|
||||||
|
|
||||||
let (resp, new_utxo_hashes) = self
|
let (resp, new_utxo_hashes) = self
|
||||||
@ -1023,7 +1024,7 @@ impl NodeCore {
|
|||||||
utxos: Vec<UTXO>,
|
utxos: Vec<UTXO>,
|
||||||
comm_gen_hashes: Vec<[u8; 32]>,
|
comm_gen_hashes: Vec<[u8; 32]>,
|
||||||
number_to_send: usize,
|
number_to_send: usize,
|
||||||
) -> Result<()> {
|
) -> Result<(), ExecutionFailureKind> {
|
||||||
let (resp, new_utxo_hashes_rec, new_utxo_hashes_not_sp) = self
|
let (resp, new_utxo_hashes_rec, new_utxo_hashes_not_sp) = self
|
||||||
.send_private_multiple_assets_send_tx(
|
.send_private_multiple_assets_send_tx(
|
||||||
utxos,
|
utxos,
|
||||||
@ -1179,7 +1180,8 @@ impl NodeCore {
|
|||||||
comm_hash: [u8; 32],
|
comm_hash: [u8; 32],
|
||||||
receivers: Vec<(u128, AccountAddress)>,
|
receivers: Vec<(u128, AccountAddress)>,
|
||||||
visibility_list: [bool; 3],
|
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
|
//Considering proof time, needs to be done before proof
|
||||||
let tx_roots = self.get_roots().await;
|
let tx_roots = self.get_roots().await;
|
||||||
|
|
||||||
@ -1208,7 +1210,7 @@ impl NodeCore {
|
|||||||
utxo: UTXO,
|
utxo: UTXO,
|
||||||
comm_gen_hash: [u8; 32],
|
comm_gen_hash: [u8; 32],
|
||||||
visibility_list: [bool; 3],
|
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
|
let (resp, new_utxo_hashes, commitments_hashes) = self
|
||||||
.send_split_tx(
|
.send_split_tx(
|
||||||
utxo.clone(),
|
utxo.clone(),
|
||||||
@ -1261,7 +1263,7 @@ impl NodeCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///Mint utxo, make it public
|
///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 acc_addr = self.create_new_account().await;
|
||||||
|
|
||||||
let (new_utxo, comm_gen_hash) = self.operate_account_mint_private(acc_addr, 100).await?;
|
let (new_utxo, comm_gen_hash) = self.operate_account_mint_private(acc_addr, 100).await?;
|
||||||
@ -1278,7 +1280,7 @@ impl NodeCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///Deposit balance, make it private
|
///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;
|
let acc_addr = self.create_new_account().await;
|
||||||
|
|
||||||
self.operate_account_deposit_public(acc_addr, 100).await?;
|
self.operate_account_deposit_public(acc_addr, 100).await?;
|
||||||
@ -1290,7 +1292,7 @@ impl NodeCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///Mint utxo, privately send it to another user
|
///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 = self.create_new_account().await;
|
||||||
let acc_addr_rec = self.create_new_account().await;
|
let acc_addr_rec = self.create_new_account().await;
|
||||||
|
|
||||||
@ -1303,7 +1305,7 @@ impl NodeCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///Deposit balance, shielded send it to another user
|
///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 = self.create_new_account().await;
|
||||||
let acc_addr_rec = self.create_new_account().await;
|
let acc_addr_rec = self.create_new_account().await;
|
||||||
|
|
||||||
@ -1316,7 +1318,7 @@ impl NodeCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///Mint utxo, deshielded send it to another user
|
///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 = self.create_new_account().await;
|
||||||
let acc_addr_rec = self.create_new_account().await;
|
let acc_addr_rec = self.create_new_account().await;
|
||||||
|
|
||||||
@ -1342,7 +1344,7 @@ impl NodeCore {
|
|||||||
&mut self,
|
&mut self,
|
||||||
visibility_list: [bool; 3],
|
visibility_list: [bool; 3],
|
||||||
publication_index: usize,
|
publication_index: usize,
|
||||||
) -> Result<()> {
|
) -> Result<(), ExecutionFailureKind> {
|
||||||
let acc_addr_sender = self.create_new_account().await;
|
let acc_addr_sender = self.create_new_account().await;
|
||||||
|
|
||||||
let acc_addr_rec_1 = self.create_new_account().await;
|
let acc_addr_rec_1 = self.create_new_account().await;
|
||||||
@ -1380,7 +1382,7 @@ impl NodeCore {
|
|||||||
&mut self,
|
&mut self,
|
||||||
number_of_assets: usize,
|
number_of_assets: usize,
|
||||||
number_to_send: usize,
|
number_to_send: usize,
|
||||||
) -> Result<()> {
|
) -> Result<(), ExecutionFailureKind> {
|
||||||
let acc_addr_sender = self.create_new_account().await;
|
let acc_addr_sender = self.create_new_account().await;
|
||||||
let acc_addr_receiver = 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 serde::{Deserialize, Serialize};
|
||||||
use storage::transaction::Transaction;
|
use storage::transaction::Transaction;
|
||||||
|
|
||||||
@ -47,10 +46,3 @@ pub struct SequencerRpcResponse {
|
|||||||
pub result: serde_json::Value,
|
pub result: serde_json::Value,
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
pub struct SequencerRpcError {
|
|
||||||
pub jsonrpc: String,
|
|
||||||
pub error: RpcError,
|
|
||||||
pub id: u64,
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
use accounts::account_core::Account;
|
use accounts::account_core::Account;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use json::{
|
use common::{SequencerClientError, SequencerRpcError};
|
||||||
SendTxRequest, SendTxResponse, SequencerRpcError, SequencerRpcRequest, SequencerRpcResponse,
|
use json::{SendTxRequest, SendTxResponse, SequencerRpcRequest, SequencerRpcResponse};
|
||||||
};
|
|
||||||
use k256::elliptic_curve::group::GroupEncoding;
|
use k256::elliptic_curve::group::GroupEncoding;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use rpc_primitives::requests::{
|
use rpc_primitives::requests::{
|
||||||
@ -22,34 +21,6 @@ pub struct SequencerClient {
|
|||||||
pub config: NodeConfig,
|
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 {
|
impl SequencerClient {
|
||||||
pub fn new(config: NodeConfig) -> Result<Self> {
|
pub fn new(config: NodeConfig) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|||||||
@ -43,3 +43,6 @@ path = "../node_core"
|
|||||||
|
|
||||||
[dependencies.rpc_primitives]
|
[dependencies.rpc_primitives]
|
||||||
path = "../rpc_primitives"
|
path = "../rpc_primitives"
|
||||||
|
|
||||||
|
[dependencies.common]
|
||||||
|
path = "../common"
|
||||||
|
|||||||
@ -16,18 +16,21 @@ use rpc_primitives::requests::{
|
|||||||
RegisterAccountRequest, RegisterAccountResponse,
|
RegisterAccountRequest, RegisterAccountResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::types::rpc_structs::{
|
use crate::types::{
|
||||||
ExecuteScenarioMultipleSendRequest, ExecuteScenarioMultipleSendResponse,
|
err_rpc::cast_common_execution_error_into_rpc_error,
|
||||||
ExecuteScenarioSplitRequest, ExecuteScenarioSplitResponse, ExecuteSubscenarioRequest,
|
rpc_structs::{
|
||||||
ExecuteSubscenarioResponse, ShowAccountPublicBalanceRequest, ShowAccountPublicBalanceResponse,
|
ExecuteScenarioMultipleSendRequest, ExecuteScenarioMultipleSendResponse,
|
||||||
ShowAccountUTXORequest, ShowAccountUTXOResponse, ShowTransactionRequest,
|
ExecuteScenarioSplitRequest, ExecuteScenarioSplitResponse, ExecuteSubscenarioRequest,
|
||||||
ShowTransactionResponse, UTXOShortEssentialStruct, WriteDepositPublicBalanceRequest,
|
ExecuteSubscenarioResponse, ShowAccountPublicBalanceRequest,
|
||||||
WriteDepositPublicBalanceResponse, WriteMintPrivateUTXOMultipleAssetsRequest,
|
ShowAccountPublicBalanceResponse, ShowAccountUTXORequest, ShowAccountUTXOResponse,
|
||||||
WriteMintPrivateUTXOMultipleAssetsResponse, WriteMintPrivateUTXORequest,
|
ShowTransactionRequest, ShowTransactionResponse, UTXOShortEssentialStruct,
|
||||||
WriteMintPrivateUTXOResponse, WriteSendDeshieldedBalanceRequest,
|
WriteDepositPublicBalanceRequest, WriteDepositPublicBalanceResponse,
|
||||||
WriteSendDeshieldedUTXOResponse, WriteSendPrivateUTXORequest, WriteSendPrivateUTXOResponse,
|
WriteMintPrivateUTXOMultipleAssetsRequest, WriteMintPrivateUTXOMultipleAssetsResponse,
|
||||||
WriteSendShieldedUTXORequest, WriteSendShieldedUTXOResponse, WriteSendSplitUTXOResponse,
|
WriteMintPrivateUTXORequest, WriteMintPrivateUTXOResponse,
|
||||||
WriteSplitUTXORequest,
|
WriteSendDeshieldedBalanceRequest, WriteSendDeshieldedUTXOResponse,
|
||||||
|
WriteSendPrivateUTXORequest, WriteSendPrivateUTXOResponse, WriteSendShieldedUTXORequest,
|
||||||
|
WriteSendShieldedUTXOResponse, WriteSendSplitUTXOResponse, WriteSplitUTXORequest,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{respond, types::err_rpc::RpcErr, JsonHandler};
|
use super::{respond, types::err_rpc::RpcErr, JsonHandler};
|
||||||
@ -55,11 +58,26 @@ impl JsonHandler {
|
|||||||
let mut store = self.node_chain_store.lock().await;
|
let mut store = self.node_chain_store.lock().await;
|
||||||
|
|
||||||
match req.scenario_id {
|
match req.scenario_id {
|
||||||
1 => store.subscenario_1().await?,
|
1 => store
|
||||||
2 => store.subscenario_2().await?,
|
.subscenario_1()
|
||||||
3 => store.subscenario_3().await?,
|
.await
|
||||||
4 => store.subscenario_4().await?,
|
.map_err(cast_common_execution_error_into_rpc_error)?,
|
||||||
5 => store.subscenario_5().await?,
|
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"))),
|
_ => return Err(RpcErr(RpcError::invalid_params("Scenario id not found"))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,7 +100,8 @@ impl JsonHandler {
|
|||||||
|
|
||||||
store
|
store
|
||||||
.scenario_1(req.visibility_list, req.publication_index)
|
.scenario_1(req.visibility_list, req.publication_index)
|
||||||
.await?;
|
.await
|
||||||
|
.map_err(cast_common_execution_error_into_rpc_error)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let helperstruct = ExecuteScenarioSplitResponse {
|
let helperstruct = ExecuteScenarioSplitResponse {
|
||||||
@ -103,7 +122,8 @@ impl JsonHandler {
|
|||||||
|
|
||||||
store
|
store
|
||||||
.scenario_2(req.number_of_assets, req.number_to_send)
|
.scenario_2(req.number_of_assets, req.number_to_send)
|
||||||
.await?;
|
.await
|
||||||
|
.map_err(cast_common_execution_error_into_rpc_error)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let helperstruct = ExecuteScenarioMultipleSendResponse {
|
let helperstruct = ExecuteScenarioMultipleSendResponse {
|
||||||
@ -335,7 +355,8 @@ impl JsonHandler {
|
|||||||
|
|
||||||
cover_guard
|
cover_guard
|
||||||
.operate_account_deposit_public(acc_addr, req.amount as u128)
|
.operate_account_deposit_public(acc_addr, req.amount as u128)
|
||||||
.await?;
|
.await
|
||||||
|
.map_err(cast_common_execution_error_into_rpc_error)?;
|
||||||
};
|
};
|
||||||
|
|
||||||
let helperstruct = WriteDepositPublicBalanceResponse {
|
let helperstruct = WriteDepositPublicBalanceResponse {
|
||||||
@ -361,7 +382,8 @@ impl JsonHandler {
|
|||||||
|
|
||||||
cover_guard
|
cover_guard
|
||||||
.operate_account_mint_private(acc_addr, req.amount as u128)
|
.operate_account_mint_private(acc_addr, req.amount as u128)
|
||||||
.await?
|
.await
|
||||||
|
.map_err(cast_common_execution_error_into_rpc_error)?
|
||||||
};
|
};
|
||||||
|
|
||||||
let helperstruct = WriteMintPrivateUTXOResponse {
|
let helperstruct = WriteMintPrivateUTXOResponse {
|
||||||
@ -399,7 +421,8 @@ impl JsonHandler {
|
|||||||
req.amount as u128,
|
req.amount as u128,
|
||||||
req.num_of_assets,
|
req.num_of_assets,
|
||||||
)
|
)
|
||||||
.await?
|
.await
|
||||||
|
.map_err(cast_common_execution_error_into_rpc_error)?
|
||||||
};
|
};
|
||||||
|
|
||||||
let helperstruct = WriteMintPrivateUTXOMultipleAssetsResponse {
|
let helperstruct = WriteMintPrivateUTXOMultipleAssetsResponse {
|
||||||
@ -481,7 +504,8 @@ impl JsonHandler {
|
|||||||
|
|
||||||
cover_guard
|
cover_guard
|
||||||
.operate_account_send_private_one_receiver(acc_addr, utxo_to_send, comm_hash)
|
.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 {
|
let helperstruct = WriteSendPrivateUTXOResponse {
|
||||||
@ -533,7 +557,8 @@ impl JsonHandler {
|
|||||||
acc_addr_rec,
|
acc_addr_rec,
|
||||||
req.amount as u128,
|
req.amount as u128,
|
||||||
)
|
)
|
||||||
.await?
|
.await
|
||||||
|
.map_err(cast_common_execution_error_into_rpc_error)?
|
||||||
};
|
};
|
||||||
|
|
||||||
let helperstruct = WriteSendShieldedUTXOResponse {
|
let helperstruct = WriteSendShieldedUTXOResponse {
|
||||||
@ -619,7 +644,8 @@ impl JsonHandler {
|
|||||||
utxo_to_send,
|
utxo_to_send,
|
||||||
comm_hash,
|
comm_hash,
|
||||||
)
|
)
|
||||||
.await?
|
.await
|
||||||
|
.map_err(cast_common_execution_error_into_rpc_error)?
|
||||||
};
|
};
|
||||||
|
|
||||||
let helperstruct = WriteSendDeshieldedUTXOResponse {
|
let helperstruct = WriteSendDeshieldedUTXOResponse {
|
||||||
@ -711,7 +737,8 @@ impl JsonHandler {
|
|||||||
comm_hash,
|
comm_hash,
|
||||||
req.visibility_list,
|
req.visibility_list,
|
||||||
)
|
)
|
||||||
.await?
|
.await
|
||||||
|
.map_err(cast_common_execution_error_into_rpc_error)?
|
||||||
};
|
};
|
||||||
|
|
||||||
let helperstruct = WriteSendSplitUTXOResponse {
|
let helperstruct = WriteSendSplitUTXOResponse {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
|
use common::{ExecutionFailureKind, SequencerClientError};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
use node_core::sequencer_client::SequencerClientError;
|
|
||||||
use rpc_primitives::errors::{RpcError, RpcParseError};
|
use rpc_primitives::errors::{RpcError, RpcParseError};
|
||||||
|
|
||||||
pub struct RpcErr(pub RpcError);
|
pub struct RpcErr(pub RpcError);
|
||||||
@ -59,3 +59,21 @@ 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)
|
||||||
|
}
|
||||||
|
ExecutionFailureKind::MonoTreeError(_) => RpcError::new_internal_error(None, &error_string),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -23,6 +23,9 @@ path = "../storage"
|
|||||||
[dependencies.utxo]
|
[dependencies.utxo]
|
||||||
path = "../utxo"
|
path = "../utxo"
|
||||||
|
|
||||||
|
[dependencies.common]
|
||||||
|
path = "../common"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
cuda = ["risc0-zkvm/cuda"]
|
cuda = ["risc0-zkvm/cuda"]
|
||||||
default = []
|
default = []
|
||||||
|
|||||||
@ -1,35 +1,8 @@
|
|||||||
use accounts::account_core::AccountAddress;
|
use accounts::account_core::AccountAddress;
|
||||||
|
use common::ExecutionFailureKind;
|
||||||
use risc0_zkvm::{default_executor, default_prover, sha::Digest, ExecutorEnv, Receipt};
|
use risc0_zkvm::{default_executor, default_prover, sha::Digest, ExecutorEnv, Receipt};
|
||||||
use utxo::utxo_core::{UTXOPayload, UTXO};
|
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(
|
pub fn prove_mint_utxo(
|
||||||
amount_to_mint: u128,
|
amount_to_mint: u128,
|
||||||
owner: AccountAddress,
|
owner: AccountAddress,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user