Skip to content

Commit

Permalink
Implement block header generation with signing
Browse files Browse the repository at this point in the history
  • Loading branch information
zbuc committed Aug 20, 2024
1 parent 9a12043 commit e95eeca
Show file tree
Hide file tree
Showing 21 changed files with 16 additions and 3,134 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request:
# Don't run Rust tests if only docs changed.
paths-ignore:
- "docs/**"
- 'docs/**'

jobs:
test:
Expand Down Expand Up @@ -48,9 +48,7 @@ jobs:
fi
- name: Run tests with nextest
# run: cargo nextest run --release --features migration
# only run ibc_handshake test for debugging
run: cargo nextest run --release --features migration ibc_handshake
run: cargo nextest run --release --features migration
env:
CARGO_TERM_COLOR: always

Expand Down
44 changes: 1 addition & 43 deletions crates/bin/pd/src/network/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,48 +175,6 @@ 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 @@ -240,7 +198,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::from(seed.0);
let node_key_sk = ed25519_consensus::SigningKey::new(OsRng);
let signing_key_bytes = node_key_sk.as_bytes().as_slice();

// generate consensus key for tendermint.
Expand Down
7 changes: 0 additions & 7 deletions crates/cnidarium/src/store/substore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,6 @@ 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: 0 additions & 1 deletion crates/core/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ 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: 0 additions & 1 deletion crates/core/app/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ 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: 2 additions & 37 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, proposal_hash = %proposal.hash, "processing proposal");
// We process the proposal in an isolated state fork. Eventually, we should cache this work and
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
// 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,26 +187,7 @@ 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 @@ -259,25 +240,9 @@ 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 e95eeca

Please sign in to comment.