mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-02 13:23:10 +00:00
fix: updated block structure + added block fetching method
This commit is contained in:
parent
2ac149d162
commit
f23e29ddfb
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3775,6 +3775,7 @@ dependencies = [
|
||||
"sequencer_core",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"storage",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
||||
@ -68,6 +68,7 @@ impl SequencerCore {
|
||||
ref execution_output,
|
||||
ref utxo_commitments_created_hashes,
|
||||
ref nullifier_created_hashes,
|
||||
..
|
||||
} = tx.tx;
|
||||
|
||||
//Sanity check
|
||||
@ -176,10 +177,18 @@ impl SequencerCore {
|
||||
self.execute_check_transaction_on_state(tx)?;
|
||||
}
|
||||
|
||||
let prev_block_hash = self
|
||||
.store
|
||||
.block_store
|
||||
.get_block_at_id(self.chain_height)?
|
||||
.prev_block_hash;
|
||||
|
||||
let hashable_data = HashableBlockData {
|
||||
block_id: self.chain_height + 1,
|
||||
prev_block_id: self.chain_height,
|
||||
transactions: transactions.into_iter().map(|tx_mem| tx_mem.tx).collect(),
|
||||
data: vec![],
|
||||
prev_block_hash,
|
||||
};
|
||||
|
||||
let block = Block::produce_block_from_hashable_data(hashable_data);
|
||||
|
||||
@ -28,15 +28,19 @@ impl SequecerChainStore {
|
||||
let pub_tx_store = PublicTransactionMerkleTree::new(vec![]);
|
||||
|
||||
let mut data = [0; 32];
|
||||
let mut prev_block_hash = [0; 32];
|
||||
|
||||
if is_genesis_random {
|
||||
OsRng.fill_bytes(&mut data);
|
||||
OsRng.fill_bytes(&mut prev_block_hash);
|
||||
}
|
||||
|
||||
let hashable_data = HashableBlockData {
|
||||
block_id: genesis_id,
|
||||
prev_block_id: genesis_id.saturating_sub(1),
|
||||
transactions: vec![],
|
||||
data: data.to_vec(),
|
||||
prev_block_hash,
|
||||
};
|
||||
|
||||
let genesis_block = Block::produce_block_from_hashable_data(hashable_data);
|
||||
|
||||
@ -28,5 +28,8 @@ path = "../networking"
|
||||
[dependencies.sequencer_core]
|
||||
path = "../sequencer_core"
|
||||
|
||||
[dependencies.storage]
|
||||
path = "../storage"
|
||||
|
||||
[dependencies.rpc_primitives]
|
||||
path = "../rpc_primitives"
|
||||
|
||||
@ -11,8 +11,8 @@ use rpc_primitives::{
|
||||
use crate::{
|
||||
rpc_error_responce_inverter,
|
||||
types::rpc_structs::{
|
||||
HelloRequest, HelloResponse, RegisterAccountRequest, RegisterAccountResponse,
|
||||
SendTxRequest, SendTxResponse,
|
||||
GetBlockDataRequest, GetBlockDataResponse, HelloRequest, HelloResponse,
|
||||
RegisterAccountRequest, RegisterAccountResponse, SendTxRequest, SendTxResponse,
|
||||
},
|
||||
};
|
||||
|
||||
@ -83,11 +83,29 @@ impl JsonHandler {
|
||||
respond(helperstruct)
|
||||
}
|
||||
|
||||
async fn process_get_block_data(&self, request: Request) -> Result<Value, RpcErr> {
|
||||
let get_block_req = GetBlockDataRequest::parse(Some(request.params))?;
|
||||
|
||||
let block = {
|
||||
let state = self.sequencer_state.lock().await;
|
||||
|
||||
state
|
||||
.store
|
||||
.block_store
|
||||
.get_block_at_id(get_block_req.block_id)?
|
||||
};
|
||||
|
||||
let helperstruct = GetBlockDataResponse { block };
|
||||
|
||||
respond(helperstruct)
|
||||
}
|
||||
|
||||
pub async fn process_request_internal(&self, request: Request) -> Result<Value, RpcErr> {
|
||||
match request.method.as_ref() {
|
||||
"hello" => self.process_temp_hello(request).await,
|
||||
"register_account" => self.process_register_account_request(request).await,
|
||||
"send_tx" => self.process_send_tx(request).await,
|
||||
"get_block" => self.process_get_block_data(request).await,
|
||||
_ => Err(RpcErr(RpcError::method_not_found(request.method))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ use rpc_primitives::parser::RpcRequest;
|
||||
use sequencer_core::transaction_mempool::TransactionMempool;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use storage::block::Block;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct HelloRequest {}
|
||||
@ -21,9 +22,15 @@ pub struct SendTxRequest {
|
||||
pub transaction: TransactionMempool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetBlockDataRequest {
|
||||
pub block_id: u64,
|
||||
}
|
||||
|
||||
parse_request!(HelloRequest);
|
||||
parse_request!(RegisterAccountRequest);
|
||||
parse_request!(SendTxRequest);
|
||||
parse_request!(GetBlockDataRequest);
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct HelloResponse {
|
||||
@ -39,3 +46,8 @@ pub struct RegisterAccountResponse {
|
||||
pub struct SendTxResponse {
|
||||
pub status: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetBlockDataResponse {
|
||||
pub block: Block,
|
||||
}
|
||||
|
||||
@ -7,10 +7,11 @@ pub type BlockHash = [u8; 32];
|
||||
pub type Data = Vec<u8>;
|
||||
pub type BlockId = u64;
|
||||
|
||||
//ToDo: Add fields to block when model is clear
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Block {
|
||||
pub block_id: BlockId,
|
||||
pub prev_block_id: BlockId,
|
||||
pub prev_block_hash: BlockHash,
|
||||
pub hash: BlockHash,
|
||||
pub transactions: Vec<Transaction>,
|
||||
pub data: Data,
|
||||
@ -19,6 +20,8 @@ pub struct Block {
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct HashableBlockData {
|
||||
pub block_id: BlockId,
|
||||
pub prev_block_id: BlockId,
|
||||
pub prev_block_hash: BlockHash,
|
||||
pub transactions: Vec<Transaction>,
|
||||
pub data: Data,
|
||||
}
|
||||
@ -31,9 +34,11 @@ impl Block {
|
||||
|
||||
Self {
|
||||
block_id: hashable_data.block_id,
|
||||
prev_block_id: hashable_data.prev_block_id,
|
||||
hash,
|
||||
transactions: hashable_data.transactions,
|
||||
data: hashable_data.data,
|
||||
prev_block_hash: hashable_data.prev_block_hash,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,4 +23,6 @@ pub struct Transaction {
|
||||
pub utxo_commitments_created_hashes: Vec<TreeHashType>,
|
||||
///Tx output nullifiers
|
||||
pub nullifier_created_hashes: Vec<TreeHashType>,
|
||||
///Execution proof (private part)
|
||||
pub execution_proof_private: String,
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user