-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,530 additions
and
132 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
use { | ||
anyhow::{anyhow, Result}, | ||
ibc_types::{ | ||
core::client::Height, | ||
lightclients::tendermint::{ | ||
consensus_state::ConsensusState, header::Header as TendermintHeader, | ||
}, | ||
}, | ||
}; | ||
|
||
mod relayer; | ||
#[allow(unused_imports)] | ||
pub use relayer::MockRelayer; | ||
|
||
mod node; | ||
pub use node::TestNodeWithIBC; | ||
|
||
// TODO: this needs to move somewhere else | ||
#[allow(dead_code)] | ||
pub fn create_tendermint_header( | ||
pk: &ed25519_consensus::VerificationKey, | ||
prev_counterparty_consensus_state: Option<(Height, ConsensusState)>, | ||
penumbra_proto::util::tendermint_proxy::v1::GetBlockByHeightResponse{block_id: _, block}: penumbra_proto::util::tendermint_proxy::v1::GetBlockByHeightResponse, | ||
) -> Result<TendermintHeader> { | ||
let block = block.ok_or(anyhow!("no block"))?; | ||
let header = block.header.ok_or(anyhow!("no header"))?; | ||
|
||
// the tendermint SignedHeader is non_exhaustive so we | ||
// can't use struct syntax to instantiate it and have to do | ||
// some annoying manual construction of the pb type instead. | ||
let h: tendermint::block::Header = header.clone().try_into().expect("bad header"); | ||
use tendermint_proto::v0_37::types::SignedHeader as RawSignedHeader; | ||
let rsh: RawSignedHeader = RawSignedHeader { | ||
header: Some(tendermint_proto::v0_37::types::Header { | ||
version: Some(tendermint_proto::v0_37::version::Consensus { | ||
block: header.version.as_ref().expect("version").block, | ||
app: header.version.expect("version").app, | ||
}), | ||
chain_id: header.chain_id, | ||
height: header.height.into(), | ||
time: Some(tendermint_proto::google::protobuf::Timestamp { | ||
seconds: header.time.as_ref().expect("time").seconds, | ||
nanos: header.time.expect("time").nanos, | ||
}), | ||
last_block_id: header.last_block_id.clone().map(|a| { | ||
tendermint_proto::v0_37::types::BlockId { | ||
hash: a.hash, | ||
part_set_header: a.part_set_header.map(|b| { | ||
tendermint_proto::v0_37::types::PartSetHeader { | ||
total: b.total, | ||
hash: b.hash, | ||
} | ||
}), | ||
} | ||
}), | ||
last_commit_hash: header.last_commit_hash.into(), | ||
data_hash: header.data_hash.into(), | ||
validators_hash: header.validators_hash.into(), | ||
next_validators_hash: header.next_validators_hash.into(), | ||
consensus_hash: header.consensus_hash.into(), | ||
app_hash: header.app_hash.into(), | ||
last_results_hash: header.last_results_hash.into(), | ||
evidence_hash: header.evidence_hash.into(), | ||
proposer_address: header.proposer_address.into(), | ||
}), | ||
commit: Some(tendermint_proto::v0_37::types::Commit { | ||
// The commit is for the current height | ||
height: header.height.into(), | ||
round: 0.into(), | ||
block_id: Some(tendermint_proto::v0_37::types::BlockId { | ||
hash: h.hash().into(), | ||
part_set_header: Some(tendermint_proto::v0_37::types::PartSetHeader { | ||
total: 0, | ||
hash: vec![], | ||
}), | ||
}), | ||
signatures: block | ||
.last_commit | ||
.map(|lc| { | ||
lc.signatures | ||
.iter() | ||
.map(|a| tendermint_proto::v0_37::types::CommitSig { | ||
block_id_flag: a.block_id_flag, | ||
validator_address: a.validator_address.clone(), | ||
timestamp: Some(tendermint_proto::google::protobuf::Timestamp { | ||
seconds: a.timestamp.as_ref().expect("time").seconds, | ||
nanos: a.timestamp.clone().expect("time").nanos, | ||
}), | ||
signature: a.signature.clone(), | ||
}) | ||
.collect() | ||
}) | ||
.unwrap(), | ||
}), | ||
}; | ||
|
||
let signed_header = rsh.clone().try_into()?; | ||
|
||
// now get a SignedHeader | ||
let pub_key = tendermint::PublicKey::from_raw_ed25519(pk.as_bytes()).expect("pub key present"); | ||
let proposer_address = tendermint::account::Id::new( | ||
<sha2::Sha256 as sha2::Digest>::digest(pk).as_slice()[0..20] | ||
.try_into() | ||
.expect(""), | ||
); | ||
let validator_set = tendermint::validator::Set::new( | ||
vec![tendermint::validator::Info { | ||
address: proposer_address.try_into()?, | ||
pub_key, | ||
power: 1i64.try_into()?, | ||
name: Some("test validator".to_string()), | ||
proposer_priority: 1i64.try_into()?, | ||
}], | ||
// Same validator as proposer? | ||
Some(tendermint::validator::Info { | ||
address: proposer_address.try_into()?, | ||
pub_key, | ||
power: 1i64.try_into()?, | ||
name: Some("test validator".to_string()), | ||
proposer_priority: 1i64.try_into()?, | ||
}), | ||
); | ||
|
||
// now we can make the Header | ||
Ok(TendermintHeader { | ||
signed_header, | ||
validator_set: validator_set.clone(), | ||
trusted_validator_set: validator_set.clone(), | ||
trusted_height: prev_counterparty_consensus_state | ||
.map(|cs| cs.0) | ||
.unwrap_or_else(|| ibc_types::core::client::Height { | ||
revision_number: 0, | ||
revision_height: 1, | ||
}), | ||
}) | ||
} |
Oops, something went wrong.