Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Aug 10, 2023
1 parent 7ed5c15 commit d3ec95b
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 132 deletions.
8 changes: 3 additions & 5 deletions src/fixtures/generate_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use serde::{Deserialize, Serialize};
use sha2::Sha256;
use std::{fs::File, io::Write};
use subtle_encoding::hex;
use tendermint::{
merkle::simple_hash_from_byte_vectors,
validator::Set as ValidatorSet,
};
use tendermint::{merkle::simple_hash_from_byte_vectors, validator::Set as ValidatorSet};

#[derive(Debug, Deserialize)]
struct Response {
Expand Down Expand Up @@ -60,7 +57,8 @@ pub async fn get_celestia_consensus_signatures() -> Result<(), Error> {
// Read from https://rpc-t.celestia.nodestake.top/signed_block?height=131950 using
// Serves latest block
let height = 11000;
let mut url = "http://rpc.testnet.celestia.citizencosmos.space/signed_block?height=".to_string();
let mut url =
"http://rpc.testnet.celestia.citizencosmos.space/signed_block?height=".to_string();
url.push_str(height.to_string().as_str());

// Send a GET request and wait for the response
Expand Down
48 changes: 26 additions & 22 deletions src/inputs.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/// Source (tendermint-rs): https://github.com/informalsystems/tendermint-rs/blob/e930691a5639ef805c399743ac0ddbba0e9f53da/tendermint/src/merkle.rs#L32
use crate::merkle::{generate_proofs_from_header, non_absent_vote, SignedBlock, TempSignedBlock};
use tendermint::{
validator::Set as ValidatorSet,
vote::SignedVote,
vote::ValidatorIndex,
};
use subtle_encoding::hex;
use tendermint::crypto::ed25519::VerificationKey;
use tendermint::Signature;
use tendermint::{validator::Set as ValidatorSet, vote::SignedVote, vote::ValidatorIndex};
use tendermint_proto::Protobuf;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -58,10 +54,8 @@ fn get_path_indices(index: u64, total: u64) -> Vec<bool> {
pub fn generate_step_inputs() -> CelestiaBlockProof {
// Generate test cases from Celestia block:
let temp_block = Box::new(TempSignedBlock::from(
serde_json::from_str::<TempSignedBlock>(include_str!(
"./fixtures/11000/signed_block.json"
))
.unwrap(),
serde_json::from_str::<TempSignedBlock>(include_str!("./fixtures/11000/signed_block.json"))
.unwrap(),
));

// Cast to SignedBlock
Expand All @@ -75,7 +69,10 @@ pub fn generate_step_inputs() -> CelestiaBlockProof {
),
});

println!("header hash: {:?}", String::from_utf8(hex::encode(block.header.hash().as_bytes())));
println!(
"header hash: {:?}",
String::from_utf8(hex::encode(block.header.hash().as_bytes()))
);

let mut validators = Vec::new();

Expand All @@ -91,22 +88,24 @@ pub fn generate_step_inputs() -> CelestiaBlockProof {
},
);
if block.commit.signatures[i].is_commit() {
let vote = non_absent_vote(
&block.commit.signatures[i],
val_idx,
&block.commit,
)
.unwrap();

let vote =
non_absent_vote(&block.commit.signatures[i], val_idx, &block.commit).unwrap();

let signed_vote = Box::new(
SignedVote::from_vote(vote.clone(), block.header.chain_id.clone())
.expect("missing signature"),
);
let sig = signed_vote.signature();
let val_bytes = validator.hash_bytes();
println!("pubkey: {:?}", String::from_utf8(hex::encode(validator.pub_key.ed25519().unwrap().as_bytes())));
println!(
"pubkey: {:?}",
String::from_utf8(hex::encode(validator.pub_key.ed25519().unwrap().as_bytes()))
);
println!("voting_power: {:?}", validator.power());
println!("val_bytes: {:?}", String::from_utf8(hex::encode(&val_bytes)));
println!(
"val_bytes: {:?}",
String::from_utf8(hex::encode(&val_bytes))
);
println!("val_bytes len: {:?}", val_bytes.len());

validators.push(Validator {
Expand Down Expand Up @@ -169,7 +168,12 @@ pub fn generate_step_inputs() -> CelestiaBlockProof {
proof: enc_next_validators_hash_proof.aunts,
};

CelestiaBlockProof { validators, header: header_hash.into(), data_hash_proof, validator_hash_proof: validators_hash_proof, next_validators_hash_proof, round_present: false }


CelestiaBlockProof {
validators,
header: header_hash.into(),
data_hash_proof,
validator_hash_proof: validators_hash_proof,
next_validators_hash_proof,
round_present: false,
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod fixtures;
pub mod inputs;
pub mod merkle;
pub mod fixtures;
pub mod utils;
pub mod validator;

Expand Down
Loading

0 comments on commit d3ec95b

Please sign in to comment.