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

wasm: update wasm consensus state to be compatible with sdk50 #363

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 5 additions & 13 deletions common/wasm/src/consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ use crate::proto;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ConsensusState {
pub data: Vec<u8>,
pub timestamp_ns: u64,
}

impl ConsensusState {
pub fn new(data: Vec<u8>, timestamp_ns: u64) -> Self {
Self { data, timestamp_ns }
}
pub fn new(data: Vec<u8>) -> Self { Self { data } }
}

impl ibc_core_client_context::consensus_state::ConsensusState
Expand All @@ -23,7 +20,7 @@ impl ibc_core_client_context::consensus_state::ConsensusState
}

fn timestamp(&self) -> ibc_primitives::Timestamp {
ibc_primitives::Timestamp::from_nanoseconds(self.timestamp_ns).unwrap()
ibc_primitives::Timestamp::none()
}

fn encode_vec(self) -> alloc::vec::Vec<u8> {
Expand All @@ -34,9 +31,7 @@ impl ibc_core_client_context::consensus_state::ConsensusState
impl Protobuf<Any> for ConsensusState {}

impl From<ConsensusState> for proto::ConsensusState {
fn from(state: ConsensusState) -> Self {
Self { data: state.data, timestamp_ns: state.timestamp_ns }
}
fn from(state: ConsensusState) -> Self { Self { data: state.data } }
}

impl From<&ConsensusState> for proto::ConsensusState {
Expand All @@ -46,17 +41,14 @@ impl From<&ConsensusState> for proto::ConsensusState {
impl TryFrom<proto::ConsensusState> for ConsensusState {
type Error = proto::BadMessage;
fn try_from(msg: proto::ConsensusState) -> Result<Self, Self::Error> {
Ok(ConsensusState { data: msg.data, timestamp_ns: msg.timestamp_ns })
Ok(ConsensusState { data: msg.data })
}
}

impl TryFrom<&proto::ConsensusState> for ConsensusState {
type Error = proto::BadMessage;
fn try_from(msg: &proto::ConsensusState) -> Result<Self, Self::Error> {
Ok(ConsensusState {
data: <Vec<u8> as Clone>::clone(&msg.data),
timestamp_ns: msg.timestamp_ns,
})
Ok(ConsensusState { data: <Vec<u8> as Clone>::clone(&msg.data) })
}
}

Expand Down
5 changes: 1 addition & 4 deletions common/wasm/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ pub struct ConsensusState {
/// protobuf encoded data of consensus state
#[prost(bytes = "vec", tag = "1")]
pub data: alloc::vec::Vec<u8>,
/// Timestamp in nanoseconds.
#[prost(uint64, tag = "2")]
pub timestamp_ns: u64,
}

impl prost::Name for ConsensusState {
Expand Down Expand Up @@ -37,6 +34,6 @@ impl prost::Name for ConsensusState {
proto_utils::define_message! {
ConsensusState; test_consensus_state {
let data = lib::hash::CryptoHash::test(42).to_vec();
Self { data, timestamp_ns: 1 }
Self { data }
}
}
2 changes: 0 additions & 2 deletions common/wasm/src/snapshots/wasm__proto__consensus_state.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@ expression: any.value
0,
0,
42,
16,
1,
]
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ impl From<cf_guest::ConsensusState> for AnyConsensusState {
data: prost::Message::encode_to_vec(&cf_guest::proto::Any::from(
&state,
)),
timestamp_ns: state.timestamp_ns.get(),
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ impl ibc::ValidationContext for IbcStorage<'_, '_> {
};
let wasm_consensus_state = wasm::consensus_state::ConsensusState::new(
guest_consensus_state.encode_vec(),
state.1.into(),
);
Ok(AnyConsensusState::Wasm(wasm_consensus_state))
// Ok(Self::AnyConsensusState::from(cf_guest::ConsensusState {
Expand Down
Loading