Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check header and update state #1120

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
20c5ccf
bla
cezarad Jun 8, 2021
b5b9dcf
on going
cezarad Jun 15, 2021
dae68b1
ongoing
cezarad Jun 17, 2021
1b4ac9f
on going
cezarad Jun 18, 2021
58b5618
on going
cezarad Jun 19, 2021
4fb5a0d
timestamp default changed from none to now
cezarad Jun 19, 2021
1deda2a
failed ping pong - signs
cezarad Jun 20, 2021
cc5780a
Update context.rs
cezarad Jun 21, 2021
e63e5b3
bla
cezarad Jun 22, 2021
2c91fe6
blabla
cezarad Jun 22, 2021
8d4ca79
fixed test client_update_ping_pong
cezarad Jun 22, 2021
87f538a
fmt + clippy
cezarad Jun 22, 2021
3b470cc
Update context.rs
cezarad Jun 22, 2021
0bed49f
Update context.rs
cezarad Jun 22, 2021
437d345
remove comments
cezarad Jun 22, 2021
2d76e27
Update host.rs
cezarad Jun 24, 2021
3417872
Update to tendermint-rs v0.20.0
romac Jun 24, 2021
33fe434
Update changelog
romac Jun 24, 2021
4b3e46c
Fix tendermint-rs version in changelog
romac Jun 24, 2021
315dfc4
Merge branch 'master' into Check-Header-And-Update-State
cezarad Jun 24, 2021
a225b75
merged with #1126 Update to tendermint-rs v0.20.0
cezarad Jun 24, 2021
cff89a8
Update predicates.rs
cezarad Jun 30, 2021
be51b51
Merge branch 'master' into Check-Header-And-Update-State
cezarad Jun 30, 2021
4f47dcf
Update context.rs
cezarad Jul 5, 2021
bc72d52
tests
cezarad Jul 5, 2021
06e44e9
Merge branch 'Check-Header-And-Update-State' of https://github.com/in…
cezarad Jul 5, 2021
cdebb03
Merge branch 'Check-Header-And-Update-State' of https://github.com/in…
cezarad Jul 5, 2021
98f5cb0
tendermint stuff in
cezarad Jul 5, 2021
e1a0f1b
Update Cargo.toml
cezarad Jul 5, 2021
fd7bc2e
clippy + fmt
cezarad Jul 6, 2021
9b59b29
moved predicates into ics07 header.rs
cezarad Jul 13, 2021
08a3027
Merge branch 'master' into Check-Header-And-Update-State
adizere Jul 21, 2021
0c797c8
Adapted to latest TM changes
adizere Jul 21, 2021
f94b42d
Fixed MockHeader test
adizere Jul 21, 2021
de1af84
Fmt & clippy
adizere Jul 21, 2021
d48b185
Removed irrelevant file
adizere Jul 21, 2021
e6ec46f
Bit more cleanup
adizere Jul 21, 2021
b5d14b6
Merge branch 'master' into Check-Header-And-Update-State
adizere Jul 23, 2021
0e59f0c
Update header.rs
cezarad Jul 30, 2021
8c190fc
Update Cargo.toml
cezarad Jul 30, 2021
44c139b
Merge branch 'master' into Check-Header-And-Update-State
cezarad Jul 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions Cargo.lock

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

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ exclude = [
"proto-compiler"
]

# [patch.crates-io]
# tendermint = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
# tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
# tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
# tendermint-light-client = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
# tendermint-testgen = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
[patch.crates-io]
tendermint = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
tendermint-light-client = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
tendermint-testgen = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,17 @@ impl From<MsgTransfer> for RawMsgTransfer {

#[cfg(test)]
pub mod test_util {
use std::ops::Add;
use std::time::Duration;

use crate::{
ics24_host::identifier::{ChannelId, PortId},
test_utils::get_dummy_account_id,
timestamp::Timestamp,
Height,
};

use super::MsgTransfer;
use crate::timestamp::Timestamp;

// Returns a dummy `RawMsgTransfer`, for testing only!
pub fn get_dummy_msg_transfer(height: u64) -> MsgTransfer {
Expand All @@ -120,7 +123,7 @@ pub mod test_util {
token: None,
sender: id.clone(),
receiver: id,
timeout_timestamp: Timestamp::from_nanoseconds(1).unwrap(),
timeout_timestamp: Timestamp::now().add(Duration::from_secs(10)).unwrap(),
timeout_height: Height {
revision_number: 0,
revision_height: height,
Expand Down
9 changes: 7 additions & 2 deletions modules/src/ics02_client/client_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::downcast;
use crate::ics02_client::client_consensus::{AnyConsensusState, ConsensusState};
use crate::ics02_client::client_state::{AnyClientState, ClientState};
use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::context::ClientReader;
use crate::ics02_client::error::Kind;
use crate::ics02_client::header::{AnyHeader, Header};
use crate::ics03_connection::connection::ConnectionEnd;
Expand All @@ -25,6 +26,8 @@ pub trait ClientDef: Clone {
/// TODO
fn check_header_and_update_state(
&self,
ctx: &dyn ClientReader,
client_id: ClientId,
client_state: Self::ClientState,
header: Self::Header,
) -> Result<(Self::ClientState, Self::ConsensusState), Box<dyn std::error::Error>>;
Expand Down Expand Up @@ -172,6 +175,8 @@ impl ClientDef for AnyClient {
/// Validates an incoming `header` against the latest consensus state of this client.
fn check_header_and_update_state(
&self,
ctx: &dyn ClientReader,
client_id: ClientId,
client_state: AnyClientState,
header: AnyHeader,
) -> Result<(AnyClientState, AnyConsensusState), Box<dyn std::error::Error>> {
Expand All @@ -184,7 +189,7 @@ impl ClientDef for AnyClient {
.ok_or_else(|| Kind::ClientArgsTypeMismatch(ClientType::Tendermint))?;

let (new_state, new_consensus) =
client.check_header_and_update_state(client_state, header)?;
client.check_header_and_update_state(ctx, client_id, client_state, header)?;

Ok((
AnyClientState::Tendermint(new_state),
Expand All @@ -201,7 +206,7 @@ impl ClientDef for AnyClient {
.ok_or_else(|| Kind::ClientArgsTypeMismatch(ClientType::Mock))?;

let (new_state, new_consensus) =
client.check_header_and_update_state(client_state, header)?;
client.check_header_and_update_state(ctx, client_id, client_state, header)?;

Ok((
AnyClientState::Mock(new_state),
Expand Down
26 changes: 26 additions & 0 deletions modules/src/ics02_client/error.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::num::ParseIntError;

use anomaly::{BoxError, Context};
use tendermint::hash::Hash;
use thiserror::Error;

use crate::ics02_client::client_type::ClientType;
use crate::ics23_commitment::error::Error as Ics23Error;
use crate::ics24_host::error::ValidationKind;
use crate::ics24_host::identifier::ClientId;
use crate::timestamp::Timestamp;
use crate::Height;

pub type Error = anomaly::Error<Kind>;
Expand Down Expand Up @@ -111,6 +113,30 @@ pub enum Kind {

#[error("upgraded client height {0} must be at greater than current client height {1}")]
LowUpgradeHeight(Height, Height),

/// Insufficient voting power in the commit
#[error("insufficient overlap {0}")]
InsufficientVotingPower(String),

#[error("Timestamp none or {0} and now {1}")]
InvalidConsensusStateTimestamp(Timestamp, Timestamp),

/// Not enough trust because insufficient validators overlap
#[error("not enough trust because insufficient validators overlap: {0}")]
NotEnoughTrustedValsSigned(String),

/// Hash mismatch for the validator set
#[error("invalid validator set: header_validators_hash={0} validators_hash={1}")]
InvalidValidatorSet(Hash, Hash),

#[error("not withing trusting period: expires_at={0} now={1}")]
ClientStateNotWithinTrustPeriod(Timestamp, Timestamp),

#[error("header not withing trusting period: expires_at={0} now={1}")]
HeaderNotWithinTrustPeriod(Timestamp, Timestamp),

#[error("Header revision {0} and client state revision {1} should coincide")]
MismatchedRevisions(u64, u64),
}

impl Kind {
Expand Down
5 changes: 1 addition & 4 deletions modules/src/ics02_client/handler/create_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@ mod tests {

let tm_client_state = AnyClientState::Tendermint(ClientState {
chain_id: tm_header.chain_id.clone().into(),
trust_level: TrustThreshold {
numerator: 1,
denominator: 3,
},
trust_level: TrustThreshold::ONE_THIRD,
trusting_period: Duration::from_secs(64000),
unbonding_period: Duration::from_secs(128000),
max_clock_drift: Duration::from_millis(3000),
Expand Down
Loading