Skip to content

Commit

Permalink
Mock IBC Test: Handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
zbuc committed Aug 20, 2024
1 parent 0c5afd9 commit f87d69c
Show file tree
Hide file tree
Showing 18 changed files with 2,806 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 43 additions & 1 deletion crates/bin/pd/src/network/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,48 @@ pub struct ValidatorKeys {
}

impl ValidatorKeys {
/// Use a hard-coded seed to generate a new set of validator keys.
pub fn from_seed(seed: [u8; 32]) -> Self {
// Create the spend key for this node.
let seed = SpendKeyBytes(seed);
let spend_key = SpendKey::from(seed.clone());

// Create signing key and verification key for this node.
let validator_id_sk = spend_key.spend_auth_key();
let validator_id_vk = VerificationKey::from(validator_id_sk);

let validator_cons_sk = ed25519_consensus::SigningKey::new(OsRng);

// generate consensus key for tendermint.
let validator_cons_sk = tendermint::PrivateKey::Ed25519(
validator_cons_sk
.as_bytes()
.as_slice()
.try_into()
.expect("32 bytes"),
);
let validator_cons_pk = validator_cons_sk.public_key();

// generate P2P auth key for tendermint.
let node_key_sk = ed25519_consensus::SigningKey::from(seed.0);
let signing_key_bytes = node_key_sk.as_bytes().as_slice();

// generate consensus key for tendermint.
let node_key_sk =
tendermint::PrivateKey::Ed25519(signing_key_bytes.try_into().expect("32 bytes"));
let node_key_pk = node_key_sk.public_key();

ValidatorKeys {
validator_id_sk: validator_id_sk.clone(),
validator_id_vk,
validator_cons_sk,
validator_cons_pk,
node_key_sk,
node_key_pk,
validator_spend_key: seed,
}
}

pub fn generate() -> Self {
// Create the spend key for this node.
// TODO: change to use seed phrase
Expand All @@ -198,7 +240,7 @@ impl ValidatorKeys {
let validator_cons_pk = validator_cons_sk.public_key();

// generate P2P auth key for tendermint.
let node_key_sk = ed25519_consensus::SigningKey::new(OsRng);
let node_key_sk = ed25519_consensus::SigningKey::from(seed.0);
let signing_key_bytes = node_key_sk.as_bytes().as_slice();

// generate consensus key for tendermint.
Expand Down
7 changes: 7 additions & 0 deletions crates/cnidarium/src/store/substore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ impl SubstoreSnapshot {
) -> Result<(Option<Vec<u8>>, ics23::CommitmentProof)> {
let version = self.version();
let tree = jmt::Sha256Jmt::new(self);
let rh = tree.get_root_hash(version)?;
println!(
"HERE in SubstoreSnapshot get_with_proof, key: {}, version: {}, root hash: {}",
hex::encode(key.clone()),
version,
hex::encode(rh.0)
);
tree.get_with_ics23_proof(key, version)
}

Expand Down
1 change: 1 addition & 0 deletions crates/core/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ rand_chacha = { workspace = true }
rand_core = { workspace = true }
tap = { workspace = true }
tempfile = { workspace = true }
tendermint-config = { workspace = true }
tower-http = { workspace = true }
tracing-subscriber = { workspace = true }
url = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/core/app/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ impl App {
}

tracing::debug!(?jmt_root, "finished committing state");
println!("finished committing state {}", hex::encode(jmt_root));

// Get the latest version of the state, now that we've committed it.
self.state = Arc::new(StateDelta::new(storage.latest_snapshot()));
Expand Down
39 changes: 37 additions & 2 deletions crates/core/app/src/server/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ impl Consensus {
&mut self,
proposal: request::ProcessProposal,
) -> Result<response::ProcessProposal> {
tracing::info!(height = ?proposal.height, proposer = ?proposal.proposer_address, hash = %proposal.hash, "processing proposal");
// We process the propopsal in an isolated state fork. Eventually, we should cache this work and
tracing::info!(height = ?proposal.height, proposer = ?proposal.proposer_address, proposal_hash = %proposal.hash, "processing proposal");
// We process the proposal in an isolated state fork. Eventually, we should cache this work and
// re-use it when processing a `FinalizeBlock` message (starting in `0.38.x`).
let mut tmp_app = App::new(self.storage.latest_snapshot());
Ok(tmp_app.process_proposal(proposal).await)
Expand All @@ -187,7 +187,26 @@ impl Consensus {
// We don't need to print the block height, because it will already be
// included in the span modeling the abci request handling.
tracing::info!(time = ?begin_block.header.time, "beginning block");

let storage_revision_height = self.storage.latest_snapshot().version();
let storage_root = self.storage.latest_snapshot().root_hash().await?;
println!(
"BEFORE begin_block {} storage height is {} and storage root is {}",
begin_block.header.height,
storage_revision_height,
hex::encode(storage_root.0)
);
let events = self.app.begin_block(&begin_block).await;

let storage_revision_height = self.storage.latest_snapshot().version();
let storage_root = self.storage.latest_snapshot().root_hash().await?;
println!(
"AFTER begin_block {} storage height is {} and storage root is {}",
begin_block.header.height,
storage_revision_height,
hex::encode(storage_root.0)
);

Ok(response::BeginBlock { events })
}

Expand Down Expand Up @@ -240,9 +259,25 @@ impl Consensus {
}

async fn commit(&mut self) -> Result<response::Commit> {
let storage_revision_height = self.storage.latest_snapshot().version();
let storage_root = self.storage.latest_snapshot().root_hash().await?;
println!(
"BEFORE commit storage height is {} and storage root is {}",
storage_revision_height,
hex::encode(storage_root.0)
);

let app_hash = self.app.commit(self.storage.clone()).await;
tracing::info!(?app_hash, "committed block");

let storage_revision_height = self.storage.latest_snapshot().version();
let storage_root = self.storage.latest_snapshot().root_hash().await?;
println!(
"AFTER commit storage height is {} and storage root is {}",
storage_revision_height,
hex::encode(storage_root.0)
);

Ok(response::Commit {
data: app_hash.0.to_vec().into(),
retain_height: 0u32.into(),
Expand Down
Loading

0 comments on commit f87d69c

Please sign in to comment.