Skip to content

Commit

Permalink
Npg 3274 explorer tx initial fragment # revised (#4106)
Browse files Browse the repository at this point in the history
* fix merge conflict issues

* ci fix

* ci fix
  • Loading branch information
cong-or authored Sep 28, 2022
1 parent 5d7f312 commit 2dd35d7
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 47 deletions.
12 changes: 12 additions & 0 deletions explorer/src/api/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,18 @@ impl Transaction {
Ok(blocks.iter().map(|b| Block::from(Arc::clone(b))).collect())
}

/// Initial bootstrap config params (initial fragments), only present in Block0
pub async fn initial_configuration_params(
&self,
context: &Context<'_>,
) -> FieldResult<Option<config_param::ConfigParams>> {
let transaction = self.get_contents(context).await?;
match transaction.config_params {
Some(params) => Ok(Some(config_param::ConfigParams::from(&params))),
None => Ok(None),
}
}

pub async fn inputs(&self, context: &Context<'_>) -> FieldResult<Vec<TransactionInput>> {
let transaction = self.get_contents(context).await?;
Ok(transaction
Expand Down
13 changes: 12 additions & 1 deletion explorer/src/db/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use chain_impl_mockchain::{
certificate::{
Certificate, ExternalProposalId, PoolId, PoolRegistration, PoolRetirement, VotePlanId,
},
fragment::{Fragment, FragmentId},
fragment::{ConfigParams, Fragment, FragmentId},
header::{BlockDate, ChainLength, Epoch, HeaderId as HeaderHash},
key::BftLeaderId,
transaction::{InputEnum, TransactionSlice, Witness},
Expand Down Expand Up @@ -70,6 +70,7 @@ pub struct ExplorerTransaction {
pub outputs: Vec<ExplorerOutput>,
pub certificate: Option<Certificate>,
pub offset_in_block: u32,
pub config_params: Option<ConfigParams>,
}

/// Unified Input representation for utxo and account inputs as used in the graphql API
Expand Down Expand Up @@ -161,6 +162,14 @@ impl ExplorerBlock {
let fragment_id = fragment.id();
let offset: u32 = offset.try_into().unwrap();
let metx = match fragment {
Fragment::Initial(config) => Some(ExplorerTransaction {
id: fragment_id,
inputs: vec![],
outputs: vec![],
certificate: None,
offset_in_block: offset,
config_params: Some(config.clone()),
}),
Fragment::Transaction(tx) => {
let tx = tx.as_slice();
Some(ExplorerTransaction::from(
Expand Down Expand Up @@ -277,6 +286,7 @@ impl ExplorerBlock {
outputs,
certificate: None,
offset_in_block: offset,
config_params: None,
})
}
_ => None,
Expand Down Expand Up @@ -429,6 +439,7 @@ impl ExplorerTransaction {
outputs: new_outputs,
certificate,
offset_in_block,
config_params: None,
}
}

Expand Down
2 changes: 1 addition & 1 deletion explorer/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const DEFAULT_LOG_SETTINGS_ENTRY: LogSettingsEntry = LogSettingsEntry {
};

const DEFAULT_QUERY_DEPTH_LIMIT: usize = 15;
const DEFAULT_QUERY_COMPLEXITY_LIMIT: usize = 40;
const DEFAULT_QUERY_COMPLEXITY_LIMIT: usize = 100;

lazy_static! {
pub static ref LOG_FILTER_LEVEL_POSSIBLE_VALUES: Vec<&'static str> = {
Expand Down
18 changes: 18 additions & 0 deletions explorer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ pub fn get_valid_block(explorer: &Explorer, genesis_block: Hash) {
assert_eq!(block_id, genesis_block.to_string());
}

pub fn verify_config_params_present(explorer: &Explorer, jormungandr: JormungandrProcess) {
let binding = jormungandr.block0_configuration().to_block();

// first fragment txs should contain config params
let block0fragment = binding.fragments().next().unwrap();

let params = explorer
.transaction(Hash::from_str(&block0fragment.hash().to_string()).unwrap())
.unwrap()
.data
.unwrap()
.transaction
.initial_configuration_params;

assert!(params.is_some());
}

#[test]
pub fn explorer_tests() {
let config = ExplorerTestConfig::default();
Expand All @@ -75,4 +92,5 @@ pub fn explorer_tests() {

get_invalid_block(explorer.client());
get_valid_block(explorer.client(), jormungandr.genesis_block_hash());
verify_config_params_present(explorer.client(), jormungandr);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ type BlockConnection {
pageInfo: PageInfo!

"""A list of edges."""
edges: [BlockEdge]
edges: [BlockEdge!]!

"""A list of nodes."""
nodes: [Block!]!
totalCount: Int!
}

Expand All @@ -60,11 +63,11 @@ type BlockDate {

"""An edge in a connection."""
type BlockEdge {
"""The item at the end of the edge"""
node: Block!

"""A cursor for use in pagination"""
cursor: String!

"""The item at the end of the edge"""
node: Block!
}

type Branch {
Expand Down Expand Up @@ -222,17 +225,20 @@ type PoolConnection {
pageInfo: PageInfo!

"""A list of edges."""
edges: [PoolEdge]
edges: [PoolEdge!]!

"""A list of nodes."""
nodes: [Pool!]!
totalCount: Int!
}

"""An edge in a connection."""
type PoolEdge {
"""The item at the end of the edge"""
node: Pool!

"""A cursor for use in pagination"""
cursor: String!

"""The item at the end of the edge"""
node: Pool!
}

scalar PoolId
Expand Down Expand Up @@ -283,7 +289,6 @@ type Proposal {

"""
get the vote options range
this is the available range of choices to make for the given
proposal. all casted votes for this proposals ought to be in
within the given range
Expand Down Expand Up @@ -409,6 +414,11 @@ type Transaction {

"""All the blocks this transaction is included in"""
blocks: [Block!]!

"""
Initial bootstrap config params (initial fragments), only present in Block0
"""
initialConfigurationParams: ConfigParams
inputs: [TransactionInput!]!
outputs: [TransactionOutput!]!
certificate: Certificate
Expand All @@ -419,17 +429,20 @@ type TransactionConnection {
pageInfo: PageInfo!

"""A list of edges."""
edges: [TransactionEdge]
edges: [TransactionEdge!]!

"""A list of nodes."""
nodes: [Transaction!]!
totalCount: Int!
}

"""An edge in a connection."""
type TransactionEdge {
"""The item at the end of the edge"""
node: Transaction!

"""A cursor for use in pagination"""
cursor: String!

"""The item at the end of the edge"""
node: Transaction!
}

type TransactionInput {
Expand Down Expand Up @@ -534,17 +547,20 @@ type VotePlanStatusConnection {
pageInfo: PageInfo!

"""A list of edges."""
edges: [VotePlanStatusEdge]
edges: [VotePlanStatusEdge!]!

"""A list of nodes."""
nodes: [VotePlanStatus!]!
totalCount: Int!
}

"""An edge in a connection."""
type VotePlanStatusEdge {
"""The item at the end of the edge"""
node: VotePlanStatus!

"""A cursor for use in pagination"""
cursor: String!

"""The item at the end of the edge"""
node: VotePlanStatus!
}

type VoteProposalStatus {
Expand All @@ -564,17 +580,20 @@ type VoteStatusConnection {
pageInfo: PageInfo!

"""A list of edges."""
edges: [VoteStatusEdge]
edges: [VoteStatusEdge!]!

"""A list of nodes."""
nodes: [VoteStatus!]!
totalCount: Int!
}

"""An edge in a connection."""
type VoteStatusEdge {
"""The item at the end of the edge"""
node: VoteStatus!

"""A cursor for use in pagination"""
cursor: String!

"""The item at the end of the edge"""
node: VoteStatus!
}

type VoteTally {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
query TransactionById($id: String!){
transaction(id: $id) {
id
__typename
initialConfigurationParams { configParams {...configParam}}
blocks{id date{...blockDate}}
inputs{amount address{id}}
outputs{amount address{id}}}}
Expand All @@ -9,3 +11,83 @@ fragment blockDate on BlockDate{
epoch{id}
slot
}

fragment configParam on ConfigParam
{
__typename
... on Block0Date { block0Date }
... on Discrimination { discrimination }
... on ConsensusType { consensusType }
... on SlotsPerEpoch { slotsPerEpoch }
... on SlotDuration { slotDuration}
... on EpochStabilityDepth { epochStabilityDepth }
... on Milli { milli}
... on BlockContentMaxSize { blockContentMaxSize}
... on AddBftLeader { addBftLeader{ id }}
... on RemoveBftLeader { removeBftLeader { id }}
... on LinearFee {
constant
coefficient
certificate
perCertificateFees {
certificatePoolRegistration
certificateStakeDelegation
certificateOwnerStakeDelegation
}
perVoteCertificateFees {
certificateVotePlan
certificateVoteCast
}}
... on ProposalExpiration{ proposalExpiration }
... on KesUpdateSpeed { kesUpdateSpeed}
... on TreasuryAdd { treasuryAdd }
... on TreasuryParams { treasuryParams {
fixed
ratio {
numerator
denominator
}
maxLimit
}}
... on RewardPot { rewardPot }
... on RewardParams { rewardParams {
__typename
... on LinearRewardParams{
constant
ratio {
numerator
denominator
}
epochStart
epochRate
}
... on HalvingRewardParams {
constant
ratio {
numerator
denominator
}
epochStart
epochRate
}
}}
... on PerCertificateFee{
certificatePoolRegistration
certificateStakeDelegation
certificateOwnerStakeDelegation
}
... on FeesInTreasury { feesInTreasury}
... on RewardLimitNone { rewardLimitNone }
... on RewardLimitByAbsoluteStake { rewardLimitByAbsoluteStake {
numerator
denominator
}}
... on PoolRewardParticipationCapping { min max }
... on AddCommitteeId { addCommitteeId}
... on RemoveCommitteeId { removeCommitteeId }
... on PerVoteCertificateFee {
certificateVotePlan
certificateVoteCast
}
... on TransactionMaxExpiryEpochs { transactionMaxExpiryEpochs }
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ impl ExplorerVerifier {

if !block.contents().is_empty() {
for fragment in block.fragments() {
for edge in explorer_block.transactions.edges.as_ref().unwrap() {
let explorer_transaction = &edge.as_ref().unwrap().node;
for edge in &explorer_block.transactions.edges {
let explorer_transaction = &edge.node;
if fragment.hash().to_string() == explorer_transaction.id {
matching_fragments_count += 1;
match &explorer_transaction.certificate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,10 @@ impl ExplorerVerifier {
);
};

assert!(explorer_transactions.edges.is_some());
assert_eq!(fragment_statuses.len(), explorer_transactions.edges.len());

assert_eq!(
fragment_statuses.len(),
explorer_transactions.edges.as_ref().unwrap().len()
);

for edges in explorer_transactions.edges.unwrap().iter() {
let node = &edges.as_ref().unwrap().node;
for edges in explorer_transactions.edges.iter() {
let node = &edges.node;
assert!(fragment_statuses.get(&node.id.to_string()).is_some());
let fragment_status = fragment_statuses.get(&node.id.to_string()).unwrap().1;
assert!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,17 @@ impl ExplorerVerifier {
explorer_proposal.votes.total_count as usize
);
if vote_proposal_status.votes_cast == 0 {
assert!(explorer_proposal.votes.edges.unwrap().is_empty());
assert!(explorer_proposal.votes.edges.is_empty());
} else {
let explorer_votes = explorer_proposal.votes.edges.unwrap();
let explorer_votes = explorer_proposal.votes.edges;
assert_eq!(explorer_votes.len(), vote_proposal_status.votes_cast);
let votes = proposal_votes
.get(&vote_proposal_status.proposal_id.to_string())
.unwrap();
for vote in votes {
for explorer_vote in &explorer_votes {
if vote.0.public_key().to_string()
== explorer_vote.as_ref().unwrap().node.address.id
{
match &explorer_vote.as_ref().unwrap().node.payload {
if vote.0.public_key().to_string() == explorer_vote.node.address.id {
match &explorer_vote.node.payload {
VotePayloadPublicStatus(choice) => {
assert_eq!(choice.choice as u8, vote.1.as_byte())
}
Expand Down
Loading

0 comments on commit 2dd35d7

Please sign in to comment.