Skip to content

Commit

Permalink
Merge branch 'fred/allow_fee_granters' of github.com:fkneeland-figure…
Browse files Browse the repository at this point in the history
…/ibc-rs into fred/allow_fee_granters
  • Loading branch information
fkneeland-figure committed Dec 7, 2021
2 parents 0263fa1 + ad6adbd commit e3098fe
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 145 deletions.
1 change: 1 addition & 0 deletions ci/hermes.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ ENTRYPOINT ["/usr/bin/hermes"]
COPY --chown=0:0 --from=build-env /usr/lib/x86_64-linux-gnu/libssl.so.1.1 /usr/lib/x86_64-linux-gnu/libssl.so.1.1
COPY --chown=0:0 --from=build-env /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
COPY --chown=0:0 --from=build-env /root/ibc-rs/target/release/hermes /usr/bin/hermes
COPY --chown=0:0 --from=build-env /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
2 changes: 1 addition & 1 deletion e2e/e2e/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AllowUpdate:
@dataclass
class ClientState:
chain_id: ChainId
frozen_height: Height
frozen_height: Optional[Height]
latest_height: Height
max_clock_drift: Duration
trust_level: TrustLevel
Expand Down
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
11 changes: 10 additions & 1 deletion modules/src/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ impl TryFrom<RawClientState> for ClientState {
.clone()
.ok_or_else(Error::missing_trusting_period)?;

let frozen_height = raw.frozen_height.and_then(|raw_height| {
let height = raw_height.into();
if height == Height::zero() {
None
} else {
Some(height)
}
});

Ok(Self {
chain_id: ChainId::from_string(raw.chain_id.as_str()),
trust_level: trust_level
Expand All @@ -224,7 +233,7 @@ impl TryFrom<RawClientState> for ClientState {
.latest_height
.ok_or_else(Error::missing_latest_height)?
.into(),
frozen_height: raw.frozen_height.map(|h| h.into()),
frozen_height,
upgrade_path: raw.upgrade_path,
allow_update: AllowUpdate {
after_expiry: raw.allow_update_after_expiry,
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
4 changes: 2 additions & 2 deletions relayer-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ version = "=0.23.1"
features = ["unstable"]

[dependencies.abscissa_core]
version = "0.6.0-beta.1"
version = "=0.6.0-beta.1"
features = ["options"]

[dev-dependencies]
abscissa_core = { version = "0.6.0-beta.1", features = ["testing"] }
abscissa_core = { version = "=0.6.0-beta.1", features = ["testing"] }
once_cell = "1.8"
regex = "1.5"
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)
.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 @@ -412,9 +406,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 @@ -426,16 +420,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
Loading

0 comments on commit e3098fe

Please sign in to comment.