Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(indexer): quorum certificate validation #893

Open
wants to merge 11 commits into
base: development
Choose a base branch
from
Prev Previous commit
Next Next commit
add qc to vn json_rpc
  • Loading branch information
mrnaveira committed Jan 11, 2024
commit 2faf307c0f299a42153bf3cd11c4d72505710bb1
54 changes: 38 additions & 16 deletions applications/tari_validator_node/src/json_rpc/handlers.rs
Original file line number Diff line number Diff line change
@@ -335,32 +335,54 @@ impl JsonRpcHandlers {
pub async fn get_substate(&self, value: JsonRpcExtractor) -> JrpcResult {
let answer_id = value.get_answer_id();
let data: GetSubstateRequest = value.parse_params()?;
let shard_id = ShardId::from_address(&data.address, data.version);

let maybe_substate = self
let mut tx = self
.state_store
.with_read_tx(|tx| {
let shard_id = ShardId::from_address(&data.address, data.version);
SubstateRecord::get(tx, &shard_id).optional()
})
.create_read_tx()
.map_err(internal_error(answer_id))?;

let maybe_substate = SubstateRecord::get(&mut tx, &shard_id)
.optional()
.map_err(internal_error(answer_id))?;

let Some(substate) = maybe_substate else {
return Ok(JsonRpcResponse::success(answer_id, GetSubstateResponse {
status: SubstateStatus::DoesNotExist,
created_by_tx: None,
value: None,
quorum_certificates: vec![],
}));
};

let created_qc = substate
.get_created_quorum_certificate(&mut tx)
.map_err(internal_error(answer_id))?;

match maybe_substate {
Some(substate) if substate.is_destroyed() => Ok(JsonRpcResponse::success(answer_id, GetSubstateResponse {
let resp = if substate.is_destroyed() {
let destroyed_qc = substate
.get_destroyed_quorum_certificate(&mut tx)
.map_err(internal_error(answer_id))?;
GetSubstateResponse {
status: SubstateStatus::Down,
created_by_tx: Some(substate.created_by_transaction),
value: None,
})),
Some(substate) => Ok(JsonRpcResponse::success(answer_id, GetSubstateResponse {
quorum_certificates: Some(created_qc)
.into_iter()
.chain(destroyed_qc)
.map(|qc| qc.into())
.collect()
}
} else {
GetSubstateResponse {
status: SubstateStatus::Up,
created_by_tx: Some(substate.created_by_transaction),
value: Some(substate.into_substate_value()),
})),
None => Ok(JsonRpcResponse::success(answer_id, GetSubstateResponse {
status: SubstateStatus::DoesNotExist,
created_by_tx: None,
value: None,
})),
}
quorum_certificates: vec![created_qc.into()],
}
};

Ok(JsonRpcResponse::success(answer_id, resp))
}

pub async fn get_substates_created_by_transaction(&self, value: JsonRpcExtractor) -> JrpcResult {
3 changes: 2 additions & 1 deletion clients/validator_node_client/src/types.rs
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ use serde::{Deserialize, Serialize};
use tari_common_types::{transaction::TxId, types::PublicKey};
use tari_dan_common_types::{committee::CommitteeShard, shard_bucket::ShardBucket, Epoch, ShardId};
use tari_dan_storage::{
consensus_models::{Block, BlockId, ExecutedTransaction, QuorumDecision, SubstateRecord},
consensus_models::{Block, BlockId, ExecutedTransaction, QuorumDecision, SubstateRecord, QuorumCertificate},
global::models::ValidatorNode,
Ordering,
};
@@ -271,6 +271,7 @@ pub struct GetSubstateResponse {
pub value: Option<SubstateValue>,
pub created_by_tx: Option<TransactionId>,
pub status: SubstateStatus,
pub quorum_certificates: Vec<QuorumCertificate>,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]