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

Bump Rust toolchain to 1.57, fix lints #1642

Merged
merged 6 commits into from
Dec 5, 2021
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
10 changes: 1 addition & 9 deletions modules/src/clients/ics07_tendermint/client_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,11 @@ use crate::Height;

use crate::downcast;

#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct TendermintClient {
verifier: ProdVerifier,
}

impl Default for TendermintClient {
fn default() -> Self {
Self {
verifier: ProdVerifier::default(),
}
}
}

impl ClientDef for TendermintClient {
type Header = Header;
type ClientState = ClientState;
Expand Down
12 changes: 1 addition & 11 deletions modules/src/core/ics03_connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,13 @@ impl ConnectionEnd {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Counterparty {
client_id: ClientId,
pub connection_id: Option<ConnectionId>,
prefix: CommitmentPrefix,
}

impl Default for Counterparty {
fn default() -> Self {
Counterparty {
client_id: Default::default(),
connection_id: None,
prefix: Default::default(),
}
}
}

impl Protobuf<RawCounterparty> for Counterparty {}

// Converts from the wire format RawCounterparty. Typically used from the relayer side
Expand Down
14 changes: 1 addition & 13 deletions modules/src/core/ics03_connection/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn extract_attributes_from_tx(event: &tendermint::abci::Event) -> Result<Attribu
Ok(attr)
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Attributes {
pub height: Height,
pub connection_id: Option<ConnectionId>,
Expand All @@ -80,18 +80,6 @@ pub struct Attributes {
pub counterparty_client_id: ClientId,
}

impl Default for Attributes {
fn default() -> Self {
Attributes {
height: Default::default(),
connection_id: Default::default(),
client_id: Default::default(),
counterparty_connection_id: Default::default(),
counterparty_client_id: Default::default(),
}
}
}

/// Convert attributes to Tendermint ABCI tags
///
/// # Note
Expand Down
11 changes: 1 addition & 10 deletions modules/src/core/ics04_channel/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,21 +244,12 @@ impl ChannelEnd {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Counterparty {
pub port_id: PortId,
pub channel_id: Option<ChannelId>,
}

impl Default for Counterparty {
fn default() -> Self {
Counterparty {
port_id: Default::default(),
channel_id: None,
}
}
}

impl Counterparty {
pub fn new(port_id: PortId, channel_id: Option<ChannelId>) -> Self {
Self {
Expand Down
15 changes: 1 addition & 14 deletions modules/src/core/ics04_channel/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn extract_packet_and_write_ack_from_tx(
Ok((packet, write_ack))
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Attributes {
pub height: Height,
pub port_id: PortId,
Expand All @@ -199,19 +199,6 @@ impl Attributes {
}
}

impl Default for Attributes {
fn default() -> Self {
Attributes {
height: Default::default(),
port_id: Default::default(),
channel_id: Default::default(),
connection_id: Default::default(),
counterparty_port_id: Default::default(),
counterparty_channel_id: Default::default(),
}
}
}

/// Convert attributes to Tendermint ABCI tags
///
/// # Note
Expand Down
10 changes: 3 additions & 7 deletions modules/src/core/ics04_channel/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,11 @@ impl core::fmt::Display for PacketMsgType {
}

/// The sequence number of a packet enforces ordering among packets from the same source.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[derive(
Copy, Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize, Serialize,
)]
pub struct Sequence(u64);

impl Default for Sequence {
fn default() -> Self {
Sequence(0)
}
}

impl FromStr for Sequence {
type Err = Error;

Expand Down
8 changes: 1 addition & 7 deletions modules/src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub const ZERO_DURATION: Duration = Duration::from_secs(0);
/// a `u64` value and a raw timestamp. In protocol buffer, the timestamp is
/// represented as a `u64` Unix timestamp in nanoseconds, with 0 representing the absence
/// of timestamp.
#[derive(PartialEq, Eq, Copy, Clone, Debug, Deserialize, Serialize, Hash)]
#[derive(PartialEq, Eq, Copy, Clone, Debug, Default, Deserialize, Serialize, Hash)]
pub struct Timestamp {
time: Option<DateTime<Utc>>,
}
Expand Down Expand Up @@ -241,12 +241,6 @@ impl From<Time> for Timestamp {
}
}

impl Default for Timestamp {
fn default() -> Self {
Timestamp { time: None }
}
}

pub mod util {

const NANOS_PER_SEC: u64 = 1_000_000_000;
Expand Down
47 changes: 9 additions & 38 deletions relayer-cli/src/components.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
use std::io;

use abscissa_core::{Component, FrameworkError, FrameworkErrorKind};
use tracing_subscriber::{
filter::EnvFilter,
fmt::{
format::{DefaultFields, Format, Full, Json, JsonFields},
time::SystemTime,
Formatter as TracingFormatter,
},
reload::Handle,
util::SubscriberInitExt,
FmtSubscriber,
};
use tracing_subscriber::{filter::EnvFilter, util::SubscriberInitExt, FmtSubscriber};

use ibc_relayer::config::GlobalConfig;

use crate::config::Error;

/// Custom types to simplify the `Tracing` definition below
type JsonFormatter = TracingFormatter<JsonFields, Format<Json, SystemTime>, StdWriter>;
type PrettyFormatter = TracingFormatter<DefaultFields, Format<Full, SystemTime>, StdWriter>;
type StdWriter = fn() -> io::Stderr;

/// A custom component for parametrizing `tracing` in the relayer.
/// Primarily used for:
///
/// - Customizing the log output level, for filtering the output produced via tracing macros
/// (`debug!`, `info!`, etc.) or abscissa macros (`status_err`, `status_info`, etc.).
/// - Enabling JSON-formatted output without coloring
#[derive(Component, Debug)]
pub struct JsonTracing {
filter_handle: Handle<EnvFilter, JsonFormatter>,
}
pub struct JsonTracing;

impl JsonTracing {
/// Creates a new [`JsonTracing`] component
#[allow(trivial_casts)]
pub fn new(cfg: GlobalConfig) -> Result<Self, FrameworkError> {
let filter = build_tracing_filter(cfg.log_level.to_string())?;
// Note: JSON formatter is un-affected by ANSI 'color' option. Set to 'false'.
Expand All @@ -45,47 +25,38 @@ impl JsonTracing {
let builder = FmtSubscriber::builder()
.with_target(false)
.with_env_filter(filter)
.with_writer(std::io::stderr as StdWriter)
.with_writer(std::io::stderr)
.with_ansi(use_color)
.with_thread_ids(true)
.json()
.with_filter_reloading();

let filter_handle = builder.reload_handle();
.json();

let subscriber = builder.finish();
subscriber.init();

Ok(Self { filter_handle })
Ok(Self)
}
}

#[derive(Component, Debug)]
pub struct PrettyTracing {
filter_handle: Handle<EnvFilter, PrettyFormatter>,
}
pub struct PrettyTracing;

impl PrettyTracing {
/// Creates a new [`PrettyTracing`] component
#[allow(trivial_casts)]
pub fn new(cfg: GlobalConfig) -> Result<Self, FrameworkError> {
let filter = build_tracing_filter(cfg.log_level.to_string())?;

// Construct a tracing subscriber with the supplied filter and enable reloading.
let builder = FmtSubscriber::builder()
.with_target(false)
.with_env_filter(filter)
.with_writer(std::io::stderr as StdWriter)
.with_writer(std::io::stderr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: This code should be tested at a basic level in the E2E python scripts, which rely on the JSON output. It would still be useful to run some CLI commands with and without --json to make sure we're not changing the structure of the output here.

We can do that, however, in the release PR (which will close #1648): on that occasion, we also would like to update the guide, which requires re-running the CLI anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a stylistic change, the cast did nothing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was required on a previous version of rustc, glad to see it's not needed anymore :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah hm, this means we've implicitly bumped our MSRV.
If we care about such things, it may make sense to add a clippy.toml and maintain the MSRV there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah let's do that!

.with_ansi(enable_ansi())
.with_thread_ids(true)
.with_filter_reloading();

let filter_handle = builder.reload_handle();
.with_thread_ids(true);

let subscriber = builder.finish();
subscriber.init();

Ok(Self { filter_handle })
Ok(Self)
}
}

Expand Down
24 changes: 9 additions & 15 deletions relayer/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Relayer configuration

mod error;
mod proof_specs;
pub mod reload;
pub mod types;
Expand All @@ -18,9 +19,10 @@ use ibc::core::ics24_host::identifier::{ChainId, ChannelId, PortId};
use ibc::timestamp::ZERO_DURATION;

use crate::config::types::{MaxMsgNum, MaxTxSize, Memo};
use crate::error::Error;
use crate::keyring::Store;

pub use error::Error;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GasPrice {
pub price: f64,
Expand Down Expand Up @@ -286,20 +288,12 @@ impl fmt::Display for LogLevel {
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct GlobalConfig {
pub log_level: LogLevel,
}

impl Default for GlobalConfig {
fn default() -> Self {
Self {
log_level: LogLevel::default(),
}
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct TelemetryConfig {
Expand Down Expand Up @@ -411,9 +405,9 @@ pub struct ChainConfig {

/// Attempt to load and parse the TOML config file as a `Config`.
pub fn load(path: impl AsRef<Path>) -> Result<Config, Error> {
let config_toml = std::fs::read_to_string(&path).map_err(Error::config_io)?;
let config_toml = std::fs::read_to_string(&path).map_err(Error::io)?;

let config = toml::from_str::<Config>(&config_toml[..]).map_err(Error::config_decode)?;
let config = toml::from_str::<Config>(&config_toml[..]).map_err(Error::decode)?;

Ok(config)
}
Expand All @@ -425,16 +419,16 @@ pub fn store(config: &Config, path: impl AsRef<Path>) -> Result<(), Error> {
} else {
File::create(path)
}
.map_err(Error::config_io)?;
.map_err(Error::io)?;

store_writer(config, &mut file)
}

/// Serialize the given `Config` as TOML to the given writer.
pub(crate) fn store_writer(config: &Config, mut writer: impl Write) -> Result<(), Error> {
let toml_config = toml::to_string_pretty(&config).map_err(Error::config_encode)?;
let toml_config = toml::to_string_pretty(&config).map_err(Error::encode)?;

writeln!(writer, "{}", toml_config).map_err(Error::config_io)?;
writeln!(writer, "{}", toml_config).map_err(Error::io)?;

Ok(())
}
Expand Down
18 changes: 18 additions & 0 deletions relayer/src/config/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use flex_error::{define_error, TraceError};

define_error! {
Error {
Io
[ TraceError<std::io::Error> ]
|_| { "config I/O error" },

Decode
[ TraceError<toml::de::Error> ]
|_| { "invalid configuration" },

Encode
[ TraceError<toml::ser::Error> ]
|_| { "invalid configuration" },

}
}
4 changes: 2 additions & 2 deletions relayer/src/config/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::{ChainConfig, Config};
#[derive(Debug, Error)]
pub enum Error {
#[error("failed to load configuration from disk")]
LoadFailed(#[source] crate::error::Error),
LoadFailed(#[source] super::error::Error),

#[error("configuration is inconsistent, did not find config for added/updated chain {0}")]
InconsistentConfig(ChainId),
Expand Down Expand Up @@ -80,7 +80,7 @@ impl ConfigReload {
for update in updates {
if self
.tx_cmd
.send(SupervisorCmd::UpdateConfig(update))
.send(SupervisorCmd::UpdateConfig(Box::new(update)))
.is_err()
{
debug!("failed to send config update to supervisor, channel is closed");
Expand Down
12 changes: 0 additions & 12 deletions relayer/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,10 @@ use crate::sdk_error::SdkError;

define_error! {
Error {
ConfigIo
[ TraceError<std::io::Error> ]
|_| { "config I/O error" },

Io
[ TraceError<std::io::Error> ]
|_| { "I/O error" },

ConfigDecode
[ TraceError<toml::de::Error> ]
|_| { "invalid configuration" },

ConfigEncode
[ TraceError<toml::ser::Error> ]
|_| { "invalid configuration" },

Rpc
{ url: tendermint_rpc::Url }
[ TraceClone<TendermintRpcError> ]
Expand Down
Loading