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

feat: use newly stabilized rust features after upgrade #1832

Merged
merged 3 commits into from
Apr 27, 2024
Merged
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
6 changes: 3 additions & 3 deletions lib/block-message/src/chain_impls/cosmos_sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use unionlabs::{
hash::H256,
ibc::core::client::height::IsHeight,
id::ConnectionId,
option_unwrap, promote,
option_unwrap,
tendermint::abci::{event::Event, event_attribute::EventAttribute},
traits::{ClientIdOf, HeightOf},
};
Expand Down Expand Up @@ -278,7 +278,7 @@ where
Fetch::<C>::specific(FetchTransactions {
height: from_height,
// who needs const blocks
page: promote!(NonZeroU32: option_unwrap!(NonZeroU32::new(1_u32))),
page: const { option_unwrap!(NonZeroU32::new(1_u32)) },
}),
))
} else {
Expand All @@ -291,7 +291,7 @@ where
Fetch::<C>::specific(FetchTransactions {
height: from_height,
// who needs const blocks
page: promote!(NonZeroU32: option_unwrap!(NonZeroU32::new(1_u32))),
page: const { option_unwrap!(NonZeroU32::new(1_u32)) },
}),
))]
.into_iter()
Expand Down
44 changes: 17 additions & 27 deletions lib/block-message/src/chain_impls/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,11 @@ pub(crate) async fn fetch_get_logs<Hc>(
revision_number: u64,
) -> QueueMsg<BlockMessageTypes>
where
Hc: EthereumChainExt<Height = Height>,
// TODO: Replace with associated type bounds once stable
Hc::Aggregate: From<AggregateWithChannel<Hc>>,
Hc::Aggregate: From<AggregateWithConnection<Hc>>,
Hc::Fetch: From<FetchChannel<Hc>>,
Hc::Fetch: From<FetchConnection<Hc>>,
Hc: EthereumChainExt<
Height = Height,
Aggregate: From<AggregateWithChannel<Hc>> + From<AggregateWithConnection<Hc>>,
Fetch: From<FetchChannel<Hc>> + From<FetchConnection<Hc>>,
>,

AnyChainIdentified<AnyAggregate>: From<Identified<Hc, Aggregate<Hc>>>,
AnyChainIdentified<AnyFetch>: From<Identified<Hc, Fetch<Hc>>>,
Expand Down Expand Up @@ -178,12 +177,9 @@ pub(crate) async fn fetch_beacon_block_range<C, Hc>(
) -> QueueMsg<BlockMessageTypes>
where
C: ChainSpec,
Hc: ChainExt + EthereumChain,
Hc: ChainExt<Fetch: From<FetchGetLogs> + From<FetchBeaconBlockRange>> + EthereumChain,

AnyChainIdentified<AnyFetch>: From<Identified<Hc, Fetch<Hc>>>,

// TODO: Replace with associated type bounds
Hc::Fetch: From<FetchGetLogs> + From<FetchBeaconBlockRange>,
{
assert!(from_slot < to_slot);

Expand Down Expand Up @@ -246,8 +242,8 @@ pub(crate) async fn fetch_channel<Hc>(
FetchChannel { height, path }: FetchChannel<Hc>,
) -> QueueMsg<BlockMessageTypes>
where
Hc: EthereumChainExt,
Hc::Data: From<ChannelData<Hc>>,
Hc: EthereumChainExt<Data: From<ChannelData<Hc>>>,

AnyChainIdentified<AnyData>: From<Identified<Hc, Data<Hc>>>,
{
data(id(
Expand Down Expand Up @@ -278,8 +274,7 @@ pub(crate) async fn fetch_connection<Hc>(
FetchConnection { height, path }: FetchConnection<Hc>,
) -> QueueMsg<BlockMessageTypes>
where
Hc: EthereumChainExt,
Hc::Data: From<ConnectionData<Hc>>,
Hc: EthereumChainExt<Data: From<ConnectionData<Hc>>>,
AnyChainIdentified<AnyData>: From<Identified<Hc, Data<Hc>>>,
{
data(id(
Expand Down Expand Up @@ -309,11 +304,10 @@ pub async fn mk_aggregate_event<Hc>(
tx_hash: H256,
) -> QueueMsg<BlockMessageTypes>
where
Hc: ChainExt + EthereumChain,
Hc::Aggregate: From<AggregateWithChannel<Hc>>,
Hc::Aggregate: From<AggregateWithConnection<Hc>>,
Hc::Fetch: From<FetchChannel<Hc>>,
Hc::Fetch: From<FetchConnection<Hc>>,
Hc: ChainExt<
Aggregate: From<AggregateWithChannel<Hc>> + From<AggregateWithConnection<Hc>>,
Fetch: From<FetchChannel<Hc>> + From<FetchConnection<Hc>>,
> + EthereumChain,

AnyChainIdentified<AnyAggregate>: From<Identified<Hc, Aggregate<Hc>>>,
AnyChainIdentified<AnyFetch>: From<Identified<Hc, Fetch<Hc>>>,
Expand Down Expand Up @@ -507,13 +501,11 @@ pub fn with_channel<Hc, T>(
raw_event: T,
) -> QueueMsg<BlockMessageTypes>
where
Hc: ChainExt + EthereumChain,
Hc: ChainExt<Aggregate: From<AggregateWithChannel<Hc>>, Fetch: From<FetchChannel<Hc>>>
+ EthereumChain,

AggregateWithChannel<Hc>: From<EventInfo<Hc, T>>,

Hc::Aggregate: From<AggregateWithChannel<Hc>>,
Hc::Fetch: From<FetchChannel<Hc>>,

AnyChainIdentified<AnyAggregate>: From<Identified<Hc, Aggregate<Hc>>>,
AnyChainIdentified<AnyFetch>: From<Identified<Hc, Fetch<Hc>>>,
{
Expand Down Expand Up @@ -548,13 +540,11 @@ pub fn with_connection<Hc, T>(
raw_event: T,
) -> QueueMsg<BlockMessageTypes>
where
Hc: ChainExt + EthereumChain,
Hc: ChainExt<Aggregate: From<AggregateWithConnection<Hc>>, Fetch: From<FetchConnection<Hc>>>
+ EthereumChain,

AggregateWithConnection<Hc>: From<EventInfo<Hc, T>>,

Hc::Aggregate: From<AggregateWithConnection<Hc>>,
Hc::Fetch: From<FetchConnection<Hc>>,

AnyChainIdentified<AnyAggregate>: From<Identified<Hc, Aggregate<Hc>>>,
AnyChainIdentified<AnyFetch>: From<Identified<Hc, Fetch<Hc>>>,
{
Expand Down
12 changes: 8 additions & 4 deletions lib/chain-utils/src/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use unionlabs::{
lightclients::tendermint::{self, fraction::Fraction},
},
id::ClientId,
option_unwrap, promote,
option_unwrap, result_unwrap,
signer::CosmosSigner,
traits::{Chain, ClientState, FromStrExact},
WasmClientType,
Expand Down Expand Up @@ -176,7 +176,7 @@ impl Chain for Cosmos {
// https://github.com/cometbft/cometbft/blob/da0e55604b075bac9e1d5866cb2e62eaae386dd9/light/verifier.go#L16
trust_level: Fraction {
numerator: 1,
denominator: promote!(NonZeroU64: option_unwrap!(NonZeroU64::new(3))),
denominator: const { option_unwrap!(NonZeroU64::new(3)) },
},
// https://github.com/cosmos/relayer/blob/23d1e5c864b35d133cad6a0ef06970a2b1e1b03f/relayer/chains/cosmos/provider.go#L177
trusting_period: unionlabs::google::protobuf::duration::Duration::new(
Expand All @@ -193,8 +193,12 @@ impl Chain for Cosmos {
)
.unwrap(),
// https://github.com/cosmos/relayer/blob/23d1e5c864b35d133cad6a0ef06970a2b1e1b03f/relayer/chains/cosmos/provider.go#L177
max_clock_drift: unionlabs::google::protobuf::duration::Duration::new(60 * 10, 0)
.unwrap(),
max_clock_drift: const {
result_unwrap!(unionlabs::google::protobuf::duration::Duration::new(
60 * 10,
0
))
},
frozen_height: None,
latest_height: Height {
revision_number: self.chain_revision,
Expand Down
6 changes: 3 additions & 3 deletions lib/chain-utils/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use unionlabs::{
NextConnectionSequencePath, ReceiptPath,
},
id::{ChannelId, ClientId, PortId},
option_unwrap, promote,
option_unwrap,
traits::{Chain, ClientIdOf, ClientState, FromStrExact, HeightOf},
uint::U256,
};
Expand Down Expand Up @@ -216,7 +216,7 @@ impl<C: ChainSpec> FromStrExact for EthereumChainType<C> {
"ChainSpec string value is expected to be 7 bytes"
);

match core::str::from_utf8(&concat(C::EXPECTING.as_bytes())) {
match core::str::from_utf8(const { &concat(C::EXPECTING.as_bytes()) }) {
Ok(ok) => ok,
Err(_) => {
panic!()
Expand Down Expand Up @@ -388,7 +388,7 @@ impl<C: ChainSpec, S: EthereumSignersConfig> Chain for Ethereum<C, S> {
min_sync_committee_participants: 0,
trust_level: Fraction {
numerator: 1,
denominator: promote!(NonZeroU64: option_unwrap!(NonZeroU64::new(3))),
denominator: const { option_unwrap!(NonZeroU64::new(3)) },
},
frozen_height: Height {
revision_number: 0,
Expand Down
26 changes: 17 additions & 9 deletions lib/ics23/src/proof_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use unionlabs::{
length_op::LengthOp,
proof_spec::ProofSpec,
},
promote, result_unwrap,
result_unwrap,
};

pub const IAVL_PROOF_SPEC: ProofSpec = ProofSpec {
Expand All @@ -20,10 +20,14 @@ pub const IAVL_PROOF_SPEC: ProofSpec = ProofSpec {
prefix: Cow::Borrowed(&[0]),
},
inner_spec: InnerSpec {
child_order: Cow::Borrowed(promote!(&[PositiveI32AsUsize]: &[
result_unwrap!(PositiveI32AsUsize::new(0)),
result_unwrap!(PositiveI32AsUsize::new(1)),
])),
child_order: Cow::Borrowed(
const {
&[
result_unwrap!(PositiveI32AsUsize::new(0)),
result_unwrap!(PositiveI32AsUsize::new(1)),
]
},
),
child_size: result_unwrap!(PositiveI32AsUsize::new(33)),
min_prefix_length: result_unwrap!(PositiveI32AsUsize::new(4)),
max_prefix_length: result_unwrap!(PositiveI32AsUsize::new(12)),
Expand All @@ -44,10 +48,14 @@ pub const TENDERMINT_PROOF_SPEC: ProofSpec = ProofSpec {
prefix: Cow::Borrowed(&[0]),
},
inner_spec: InnerSpec {
child_order: Cow::Borrowed(promote!(&[PositiveI32AsUsize]: &[
result_unwrap!(PositiveI32AsUsize::new(0)),
result_unwrap!(PositiveI32AsUsize::new(1)),
])),
child_order: Cow::Borrowed(
const {
&[
result_unwrap!(PositiveI32AsUsize::new(0)),
result_unwrap!(PositiveI32AsUsize::new(1)),
]
},
),
child_size: result_unwrap!(PositiveI32AsUsize::new(32)),
min_prefix_length: result_unwrap!(PositiveI32AsUsize::new(1)),
max_prefix_length: result_unwrap!(PositiveI32AsUsize::new(1)),
Expand Down
22 changes: 11 additions & 11 deletions lib/relay-message/src/chain_impls/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use unionlabs::{
},
ics24::ClientStatePath,
tendermint::types::validator::Validator,
traits::{Chain, ClientStateOf, ConsensusStateOf, HeaderOf},
traits::Chain,
TypeUrl,
};

Expand Down Expand Up @@ -62,14 +62,15 @@ impl ChainExt for Cosmos {

impl CosmosSdkChainSealed for Cosmos {}

impl<Tr: ChainExt> DoMsg<Cosmos, Tr> for Cosmos
impl<Tr> DoMsg<Cosmos, Tr> for Cosmos
where
ConsensusStateOf<Tr>: Encode<Proto> + TypeUrl,
ClientStateOf<Tr>: Encode<Proto> + TypeUrl,
HeaderOf<Tr>: Encode<Proto> + TypeUrl,

Tr::StoredClientState<Cosmos>: IntoAny,
Tr::StateProof: Encode<Proto>,
Tr: ChainExt<
SelfConsensusState: Encode<Proto> + TypeUrl,
SelfClientState: Encode<Proto> + TypeUrl,
Header: Encode<Proto> + TypeUrl,
StoredClientState<Cosmos>: IntoAny,
StateProof: Encode<Proto>,
>,
{
async fn msg(&self, msg: Effect<Cosmos, Tr>) -> Result<(), BroadcastTxCommitError> {
do_msg(
Expand Down Expand Up @@ -176,12 +177,11 @@ where
StateProof = MerkleProof,
Data<Tr> = CosmosDataMsg<Hc, Tr>,
Fetch<Tr> = CosmosFetch<Hc, Tr>,
StoredClientState<Tr>: Decode<Proto>,
StoredConsensusState<Tr>: Decode<Proto>,
>,
Tr: ChainExt,

Hc::StoredClientState<Tr>: Decode<Proto>,
Hc::StoredConsensusState<Tr>: Decode<Proto>,

AnyLightClientIdentified<AnyData>: From<identified!(Data<Hc, Tr>)>,
AnyLightClientIdentified<AnyFetch>: From<identified!(Fetch<Hc, Tr>)>,
AnyLightClientIdentified<AnyWait>: From<identified!(Wait<Hc, Tr>)>,
Expand Down
Loading
Loading