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

Misbehavior monitoring and handling #691

Merged
merged 41 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
feece5a
Split client_def in state, consensus, header. Add sketch for Tx decod…
ancazamfir Feb 15, 2021
1272f19
Added misbehaviour message, structures, relayer submission
ancazamfir Feb 18, 2021
b693bed
tentative try with interim update event from cosmos PR
ancazamfir Feb 18, 2021
2056f24
Merge branch 'master' into anca/misbehavior
ancazamfir Feb 25, 2021
ddfedb6
trying to decode the header from event
ancazamfir Mar 2, 2021
c1cccf8
decode the header in client update event
ancazamfir Mar 2, 2021
edcb1d0
Added restart support, move some of the misbehaviour detection in lig…
ancazamfir Mar 8, 2021
85a0569
Merge branch 'master' into anca/misbehavior
ancazamfir Mar 8, 2021
1fc35b8
fix merge
ancazamfir Mar 8, 2021
0271f1d
add support for potential on-chain state pruning, cleanup
ancazamfir Mar 9, 2021
ea787f2
Update changelog
ancazamfir Mar 9, 2021
bd6eb26
sketch for time travelling lunatic attack check
ancazamfir Mar 9, 2021
396fa07
fmt
ancazamfir Mar 9, 2021
0555dee
Decode misbehaviour events, added comments
ancazamfir Mar 10, 2021
6eb9659
Merge branch 'master' into anca/misbehavior
ancazamfir Mar 15, 2021
bb201c0
Update to reflect bad updates in the middle
ancazamfir Mar 15, 2021
64aa705
Merge branch 'master' into anca/misbehavior
ancazamfir Mar 29, 2021
d7d4479
cargo fmt
ancazamfir Mar 30, 2021
b1f5439
Merge branch 'master' into anca/misbehavior
ancazamfir Mar 31, 2021
03f520c
Merge branch 'master' into anca/misbehavior
ancazamfir Apr 2, 2021
7b53ac5
Cleanup consensus query and allow query for all
ancazamfir Apr 2, 2021
c2129a9
Allow target and trusted heights to be specified in client updates
ancazamfir Apr 2, 2021
372a298
Allow update with any existing trusted height
ancazamfir Apr 2, 2021
cd576de
Disallow create client with same src and dst
ancazamfir Apr 2, 2021
5e26396
Fix tests
ancazamfir Apr 2, 2021
36ed699
Added mock misbehaviour
ancazamfir Apr 6, 2021
373fdb2
Fix CI and reorg code
ancazamfir Apr 7, 2021
48b86a0
Merge branch 'master' into anca/misbehavior
ancazamfir Apr 7, 2021
ea1a083
Cleanup
ancazamfir Apr 7, 2021
f435289
Merge branch 'master' into anca/misbehavior
ancazamfir Apr 8, 2021
e3ccb50
Updates after sitdown review
ancazamfir Apr 8, 2021
2050095
Update comments
ancazamfir Apr 8, 2021
7420aec
Flip back the logic in compatible_headers()
ancazamfir Apr 8, 2021
48b04fb
Rename client_misbehaviour to misbehaviour
ancazamfir Apr 8, 2021
35fcb14
review comments
ancazamfir Apr 9, 2021
cc003de
fmt
ancazamfir Apr 9, 2021
29d67f3
Return UpdateClient::consensus_height by copy instead of reference
romac Apr 9, 2021
a11c3c0
Small cleanup in LightClient::build_misbehaviour
romac Apr 9, 2021
7361934
Small cleanup in chain::cosmos
romac Apr 9, 2021
d7293dd
Set pagination limit to u64::MAX for all queries that support it to e…
romac Apr 9, 2021
3942d74
Addressed review comments
ancazamfir Apr 9, 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
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
- [ibc-relayer]
- Support for relayer restart ([#561])
- Add support for ordered channels ([#599])
- Consistent identifier handling across ICS 02, 03 and 04 ([#622])

- [ibc-relayer]
- Misbehaviour detection and evidence submission ([#632])
- Use a stateless light client without a runtime ([#673])

- [ibc-relayer-cli]
Expand All @@ -35,7 +33,7 @@
- MBT: use modelator crate ([#761])

- [ibc-relayer]
- [nothing yet]
- Consistent identifier handling across ICS 02, 03 and 04 ([#622])

- [ibc-relayer-cli]
- Clarified success path for updating a client that is already up-to-date ([#734])
Expand Down Expand Up @@ -80,6 +78,7 @@
[#550]: https://github.com/informalsystems/ibc-rs/issues/550
[#599]: https://github.com/informalsystems/ibc-rs/issues/599
[#630]: https://github.com/informalsystems/ibc-rs/issues/630
[#632]: https://github.com/informalsystems/ibc-rs/issues/632
[#672]: https://github.com/informalsystems/ibc-rs/issues/672
[#673]: https://github.com/informalsystems/ibc-rs/issues/673
[#675]: https://github.com/informalsystems/ibc-rs/issues/675
Expand Down
11 changes: 5 additions & 6 deletions e2e/e2e/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ class ClientUpdated:
@cmd("tx raw update-client")
class TxUpdateClient(Cmd[ClientUpdated]):
dst_chain_id: ChainId
src_chain_id: ChainId
dst_client_id: ClientId

def args(self) -> List[str]:
return [self.dst_chain_id, self.src_chain_id, self.dst_client_id]
return [self.dst_chain_id, self.dst_client_id]

def process(self, result: Any) -> ClientUpdated:
return from_dict(ClientUpdated, result['UpdateClient'])
return from_dict(ClientUpdated, result['UpdateClient']['common'])


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -102,8 +101,8 @@ def create_client(c: Config, dst: ChainId, src: ChainId) -> ClientCreated:
return client


def update_client(c: Config, dst: ChainId, src: ChainId, client_id: ClientId) -> ClientUpdated:
cmd = TxUpdateClient(dst_chain_id=dst, src_chain_id=src,
def update_client(c: Config, dst: ChainId, client_id: ClientId) -> ClientUpdated:
cmd = TxUpdateClient(dst_chain_id=dst,
dst_client_id=client_id)
res = cmd.run(c).success()
l.info(f'Updated client to: {res.consensus_height}')
Expand All @@ -122,7 +121,7 @@ def create_update_query_client(c: Config, dst: ChainId, src: ChainId) -> ClientI
split()
query_client_state(c, dst, client.client_id)
split()
update_client(c, dst, src, client.client_id)
update_client(c, dst, client.client_id)
split()
query_client_state(c, dst, client.client_id)
split()
Expand Down
1 change: 0 additions & 1 deletion e2e/e2e/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Ordering(Enum):
ClientType = NewType('ClientType', str)
BlockHeight = NewType('BlockHeight', str)


def split():
sleep(0.5)
print()
8 changes: 5 additions & 3 deletions modules/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::Height;
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum IbcEventType {
CreateClient,
UpdateClient,
SendPacket,
WriteAck,
}
Expand All @@ -21,6 +22,7 @@ impl IbcEventType {
pub fn as_str(&self) -> &'static str {
match *self {
IbcEventType::CreateClient => "create_client",
IbcEventType::UpdateClient => "update_client",
IbcEventType::SendPacket => "send_packet",
IbcEventType::WriteAck => "write_acknowledgement",
}
Expand All @@ -35,7 +37,7 @@ pub enum IbcEvent {
CreateClient(ClientEvents::CreateClient),
UpdateClient(ClientEvents::UpdateClient),
UpgradeClient(ClientEvents::UpgradeClient),
ClientMisbehavior(ClientEvents::ClientMisbehavior),
ClientMisbehaviour(ClientEvents::ClientMisbehaviour),

OpenInitConnection(ConnectionEvents::OpenInit),
OpenTryConnection(ConnectionEvents::OpenTry),
Expand Down Expand Up @@ -87,7 +89,7 @@ impl IbcEvent {
IbcEvent::NewBlock(bl) => bl.height(),
IbcEvent::CreateClient(ev) => ev.height(),
IbcEvent::UpdateClient(ev) => ev.height(),
IbcEvent::ClientMisbehavior(ev) => ev.height(),
IbcEvent::ClientMisbehaviour(ev) => ev.height(),
IbcEvent::OpenInitConnection(ev) => ev.height(),
IbcEvent::OpenTryConnection(ev) => ev.height(),
IbcEvent::OpenAckConnection(ev) => ev.height(),
Expand All @@ -113,7 +115,7 @@ impl IbcEvent {
IbcEvent::CreateClient(ev) => ev.set_height(height),
IbcEvent::UpdateClient(ev) => ev.set_height(height),
IbcEvent::UpgradeClient(ev) => ev.set_height(height),
IbcEvent::ClientMisbehavior(ev) => ev.set_height(height),
IbcEvent::ClientMisbehaviour(ev) => ev.set_height(height),
IbcEvent::OpenInitConnection(ev) => ev.set_height(height),
IbcEvent::OpenTryConnection(ev) => ev.set_height(height),
IbcEvent::OpenAckConnection(ev) => ev.set_height(height),
Expand Down
50 changes: 49 additions & 1 deletion modules/src/ics02_client/client_consensus.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use core::marker::{Send, Sync};
use std::convert::TryFrom;
use std::convert::{TryFrom, TryInto};

use chrono::{DateTime, Utc};
use prost_types::Any;
use serde::Serialize;
use tendermint_proto::Protobuf;

use ibc_proto::ibc::core::client::v1::ConsensusStateWithHeight;

use crate::events::IbcEventType;
use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::error::{Error, Kind};
use crate::ics02_client::height::Height;
use crate::ics07_tendermint::consensus_state;
use crate::ics23_commitment::commitment::CommitmentRoot;
use crate::ics24_host::identifier::ClientId;
#[cfg(any(test, feature = "mocks"))]
use crate::mock::client_state::MockConsensusState;

Expand Down Expand Up @@ -108,6 +113,41 @@ impl From<AnyConsensusState> for Any {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
pub struct AnyConsensusStateWithHeight {
pub height: Height,
pub consensus_state: AnyConsensusState,
}

impl Protobuf<ConsensusStateWithHeight> for AnyConsensusStateWithHeight {}

impl TryFrom<ConsensusStateWithHeight> for AnyConsensusStateWithHeight {
type Error = Error;

fn try_from(value: ConsensusStateWithHeight) -> Result<Self, Self::Error> {
let state = value
.consensus_state
.map(AnyConsensusState::try_from)
.transpose()
.map_err(|e| Kind::InvalidRawConsensusState.context(e))?
.ok_or(Kind::EmptyConsensusStateResponse)?;

Ok(AnyConsensusStateWithHeight {
height: value.height.ok_or(Kind::InvalidHeightResult)?.try_into()?,
consensus_state: state,
})
}
}

impl From<AnyConsensusStateWithHeight> for ConsensusStateWithHeight {
fn from(value: AnyConsensusStateWithHeight) -> Self {
ConsensusStateWithHeight {
height: Some(value.height.into()),
consensus_state: Some(value.consensus_state.into()),
}
}
}

impl ConsensusState for AnyConsensusState {
fn client_type(&self) -> ClientType {
self.client_type()
Expand All @@ -125,3 +165,11 @@ impl ConsensusState for AnyConsensusState {
self
}
}

#[derive(Clone, Debug)]
pub struct QueryClientEventRequest {
ancazamfir marked this conversation as resolved.
Show resolved Hide resolved
pub height: crate::Height,
pub event_id: IbcEventType,
pub client_id: ClientId,
pub consensus_height: crate::Height,
}
2 changes: 2 additions & 0 deletions modules/src/ics02_client/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use tendermint_proto::Protobuf;

use crate::ics02_client::client_type::ClientType;
use crate::ics02_client::error::{Error, Kind};

use crate::ics07_tendermint::client_state;
use crate::ics24_host::identifier::ChainId;
#[cfg(any(test, feature = "mocks"))]
Expand Down Expand Up @@ -53,6 +54,7 @@ impl AnyClientState {
Self::Mock(mock_state) => mock_state.latest_height(),
}
}

pub fn client_type(&self) -> ClientType {
match self {
Self::Tendermint(state) => state.client_type(),
Expand Down
6 changes: 6 additions & 0 deletions modules/src/ics02_client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ pub enum Kind {
#[error("unknown header type: {0}")]
UnknownHeaderType(String),

#[error("unknown misbehaviour type: {0}")]
UnknownMisbehaviourType(String),

#[error("invalid raw client state")]
InvalidRawClientState,

Expand All @@ -65,6 +68,9 @@ pub enum Kind {
#[error("invalid raw header")]
InvalidRawHeader,

#[error("invalid raw misbehaviour")]
InvalidRawMisbehaviour,

#[error("invalid height result")]
InvalidHeightResult,

Expand Down
Loading