Skip to content

Commit

Permalink
Merge branch 'fraccaman/allow-http-url-cli' (#2658)
Browse files Browse the repository at this point in the history
* origin/fraccaman/allow-http-url-cli:
  added changelog
  refactor addresses with protocol
  use tendermint_rpc::Url instead of TendermintAddress
  • Loading branch information
Gianmarco Fraccaroli authored and tzemanovic committed Feb 22, 2024
2 parents 96fcafc + eaf56c7 commit f4b0caf
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/2658-allow-http-url-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Allow users to input http/https url as ledger urls.
([\#2658](https://github.com/anoma/namada/pull/2658))
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ sysinfo.workspace = true
tar.workspace = true
tempfile.workspace = true
tendermint-config.workspace = true
tendermint-rpc.workspace = true
thiserror.workspace = true
tokio = {workspace = true, features = ["full"]}
toml.workspace = true
Expand Down
12 changes: 6 additions & 6 deletions crates/apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2965,7 +2965,7 @@ pub mod args {
use crate::config::genesis::GenesisAddress;
use crate::config::{self, Action, ActionAtHeight};
use crate::facade::tendermint::Timeout;
use crate::facade::tendermint_config::net::Address as TendermintAddress;
use crate::facade::tendermint_rpc::Url;

pub const ADDRESS: Arg<WalletAddress> = arg("address");
pub const ALIAS_OPT: ArgOpt<String> = ALIAS.opt();
Expand Down Expand Up @@ -3097,10 +3097,10 @@ pub mod args {
scheme is not supplied, it is assumed to be TCP.";
pub const CONFIG_RPC_LEDGER_ADDRESS: ArgDefaultFromCtx<ConfigRpcAddress> =
arg_default_from_ctx("node", DefaultFn(|| "".to_string()));
pub const LEDGER_ADDRESS: ArgDefault<TendermintAddress> = arg("node")
.default(DefaultFn(|| {
let raw = "127.0.0.1:26657";
TendermintAddress::from_str(raw).unwrap()
pub const LEDGER_ADDRESS: ArgDefault<Url> =
arg("node").default(DefaultFn(|| {
let raw = "http://127.0.0.1:26657";
Url::from_str(raw).unwrap()
}));
pub const LIST_FIND_ADDRESSES_ONLY: ArgFlag = flag("addr");
pub const LIST_FIND_KEYS_ONLY: ArgFlag = flag("keys");
Expand Down Expand Up @@ -6058,7 +6058,7 @@ pub mod args {
type Keypair = WalletKeypair;
type PublicKey = WalletPublicKey;
type SpendingKey = WalletSpendingKey;
type TendermintAddress = tendermint_config::net::Address;
type TendermintAddress = tendermint_rpc::Url;
type TransferSource = WalletTransferSource;
type TransferTarget = WalletTransferTarget;
type ViewingKey = WalletViewingKey;
Expand Down
6 changes: 3 additions & 3 deletions crates/apps/src/lib/cli/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use namada::types::io::Io;
use namada_sdk::error::Error;
use namada_sdk::queries::Client;
use namada_sdk::rpc::wait_until_node_is_synched;
use tendermint_config::net::Address as TendermintAddress;
use tendermint_rpc::Url as TendermintUrl;

/// Trait for clients that can be used with the CLI.
#[async_trait::async_trait(?Send)]
pub trait CliClient: Client + Sync {
fn from_tendermint_address(address: &TendermintAddress) -> Self;
fn from_tendermint_address(address: &TendermintUrl) -> Self;
async fn wait_until_node_is_synced(
&self,
io: &impl Io,
Expand All @@ -17,7 +17,7 @@ pub trait CliClient: Client + Sync {

#[async_trait::async_trait(?Send)]
impl CliClient for HttpClient {
fn from_tendermint_address(address: &TendermintAddress) -> Self {
fn from_tendermint_address(address: &TendermintUrl) -> Self {
HttpClient::new(address.clone()).unwrap()
}

Expand Down
20 changes: 14 additions & 6 deletions crates/apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use namada_sdk::masp::fs::FsShieldedUtils;
use namada_sdk::masp::ShieldedContext;
use namada_sdk::wallet::Wallet;
use namada_sdk::{Namada, NamadaImpl};
use tendermint_config::net::Address as TendermintAddress;

use super::args;
use crate::cli::utils;
Expand Down Expand Up @@ -74,7 +73,7 @@ pub type WalletPublicKey = FromContext<common::PublicKey>;
pub type WalletBalanceOwner = FromContext<BalanceOwner>;

/// RPC address of a locally configured node
pub type ConfigRpcAddress = FromContext<TendermintAddress>;
pub type ConfigRpcAddress = FromContext<tendermint_rpc::Url>;

/// Address that defaults to the native token address.
#[derive(Clone, Debug)]
Expand All @@ -95,8 +94,8 @@ impl FromStr for AddrOrNativeToken {
}
}

impl From<TendermintAddress> for ConfigRpcAddress {
fn from(value: TendermintAddress) -> Self {
impl From<tendermint_rpc::Url> for ConfigRpcAddress {
fn from(value: tendermint_rpc::Url) -> Self {
FromContext::new(value.to_string())
}
}
Expand Down Expand Up @@ -464,13 +463,22 @@ impl ArgFromContext for AddrOrNativeToken {
}
}

impl ArgFromContext for TendermintAddress {
impl ArgFromContext for tendermint_rpc::Url {
fn arg_from_ctx(
ctx: &ChainContext,
raw: impl AsRef<str>,
) -> Result<Self, String> {
if raw.as_ref().is_empty() {
return Ok(ctx.config.ledger.cometbft.rpc.laddr.clone());
return Self::from_str(
&ctx.config
.ledger
.cometbft
.rpc
.laddr
.to_string()
.replace("tpc", "http"),
)
.map_err(|err| format!("Invalid Tendermint address: {err}"));
}
Self::from_str(raw.as_ref())
.map_err(|err| format!("Invalid Tendermint address: {err}"))
Expand Down
6 changes: 2 additions & 4 deletions crates/apps/src/lib/config/genesis/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ fn get_tx_args(use_device: bool) -> TxArgs {
output_folder: None,
force: false,
broadcast_only: false,
ledger_address: tendermint_config::net::Address::from_str(
"127.0.0.1:26657",
)
.unwrap(),
ledger_address: tendermint_rpc::Url::from_str("http://127.0.0.1:26657")
.unwrap(),
initialized_account_alias: None,
wallet_alias_force: false,
fee_amount: None,
Expand Down
3 changes: 1 addition & 2 deletions crates/apps/src/lib/node/ledger/shell/testing/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use clap::Command as App;
use eyre::Report;
use namada::types::io::Io;
use namada_sdk::error::Error as SdkError;
use tendermint_config::net::Address as TendermintAddress;

use super::node::MockNode;
use crate::cli::api::{CliApi, CliClient};
Expand Down Expand Up @@ -93,7 +92,7 @@ pub fn run(

#[async_trait::async_trait(?Send)]
impl<'a> CliClient for &'a MockNode {
fn from_tendermint_address(_: &TendermintAddress) -> Self {
fn from_tendermint_address(_: &tendermint_rpc::Url) -> Self {
unreachable!("MockNode should always be instantiated at test start.")
}

Expand Down
4 changes: 2 additions & 2 deletions crates/sdk/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ impl NamadaTypes for SdkTypes {
type Address = Address;
type BalanceOwner = namada_core::types::masp::BalanceOwner;
type BpConversionTable = HashMap<Address, BpConversionTableEntry>;
type ConfigRpcTendermintAddress = tendermint_config::net::Address;
type ConfigRpcTendermintAddress = tendermint_rpc::Url;
type Data = Vec<u8>;
type EthereumAddress = ();
type Keypair = namada_core::types::key::common::SecretKey;
type PublicKey = namada_core::types::key::common::PublicKey;
type SpendingKey = namada_core::types::masp::ExtendedSpendingKey;
type TendermintAddress = tendermint_config::net::Address;
type TendermintAddress = tendermint_rpc::Url;
type TransferSource = namada_core::types::masp::TransferSource;
type TransferTarget = namada_core::types::masp::TransferTarget;
type ViewingKey = namada_core::types::masp::ExtendedViewingKey;
Expand Down
8 changes: 4 additions & 4 deletions crates/sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ pub trait Namada: Sized + MaybeSync + MaybeSend {
output_folder: None,
force: false,
broadcast_only: false,
ledger_address: tendermint_config::net::Address::from_str(
"127.0.0.1:26657",
ledger_address: tendermint_rpc::Url::from_str(
"http://127.0.0.1:26657",
)
.unwrap(),
initialized_account_alias: None,
Expand Down Expand Up @@ -642,8 +642,8 @@ where
output_folder: None,
force: false,
broadcast_only: false,
ledger_address: tendermint_config::net::Address::from_str(
"127.0.0.1:26657",
ledger_address: tendermint_rpc::Url::from_str(
"http://127.0.0.1:26657",
)
.unwrap(),
initialized_account_alias: None,
Expand Down
3 changes: 2 additions & 1 deletion crates/tests/src/e2e/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub fn get_actor_rpc(test: &Test, who: Who) -> String {
Config::load(base_dir, &test.net.chain_id, Some(tendermint_mode));
let socket_addr =
convert_tm_addr_to_socket_addr(&config.ledger.cometbft.rpc.laddr);
format!("{}:{}", socket_addr.ip(), socket_addr.port())
format!("http://{}:{}", socket_addr.ip(), socket_addr.port())
}

/// Get some nodes's wallet.
Expand Down Expand Up @@ -578,6 +578,7 @@ pub fn make_hermes_config(test_a: &Test, test_b: &Test) -> Result<()> {
fn make_hermes_chain_config(test: &Test) -> Value {
let chain_id = test.net.chain_id.as_str();
let rpc_addr = get_actor_rpc(test, Who::Validator(0));
let rpc_addr = rpc_addr.strip_prefix("http://").unwrap();

let mut table = toml::map::Map::new();
table.insert("mode".to_owned(), Value::String("push".to_owned()));
Expand Down
33 changes: 16 additions & 17 deletions crates/tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ use namada_apps::config::utils::set_port;
use namada_apps::config::{ethereum_bridge, TendermintMode};
use namada_apps::facade::tendermint::block::Header as TmHeader;
use namada_apps::facade::tendermint::merkle::proof::ProofOps as TmProof;
use namada_apps::facade::tendermint_config::net::Address as TendermintAddress;
use namada_apps::facade::tendermint_rpc::{Client, HttpClient, Url};
use namada_core::types::string_encoding::StringEncoded;
use namada_sdk::masp::fs::FsShieldedUtils;
Expand Down Expand Up @@ -594,8 +593,8 @@ fn create_client(test_a: &Test, test_b: &Test) -> Result<(ClientId, ClientId)> {

fn make_client_state(test: &Test, height: Height) -> TmClientState {
let rpc = get_actor_rpc(test, Who::Validator(0));
let ledger_address = TendermintAddress::from_str(&rpc).unwrap();
let client = HttpClient::new(ledger_address).unwrap();
let tendermint_url = Url::from_str(&rpc).unwrap();
let client = HttpClient::new(tendermint_url).unwrap();

let pos_params =
test.async_runtime().block_on(query_pos_parameters(&client));
Expand Down Expand Up @@ -717,8 +716,8 @@ fn update_client(
}

fn make_light_client_io(test: &Test) -> TmLightClientIo {
let addr = format!("http://{}", get_actor_rpc(test, Who::Validator(0)));
let rpc_addr = Url::from_str(&addr).unwrap();
let rpc = get_actor_rpc(test, Who::Validator(0));
let rpc_addr = Url::from_str(&rpc).unwrap();
let rpc_client = HttpClient::new(rpc_addr).unwrap();
let rpc_timeout = Duration::new(10, 0);

Expand Down Expand Up @@ -1680,8 +1679,8 @@ fn make_ibc_data(message: impl Msg) -> Vec<u8> {

fn query_height(test: &Test) -> Result<Height> {
let rpc = get_actor_rpc(test, Who::Validator(0));
let ledger_address = TendermintAddress::from_str(&rpc).unwrap();
let client = HttpClient::new(ledger_address).unwrap();
let tendermint_url = Url::from_str(&rpc).unwrap();
let client = HttpClient::new(tendermint_url).unwrap();

let status = test
.async_runtime()
Expand All @@ -1693,8 +1692,8 @@ fn query_height(test: &Test) -> Result<Height> {

fn query_header(test: &Test, height: Height) -> Result<TmHeader> {
let rpc = get_actor_rpc(test, Who::Validator(0));
let ledger_address = TendermintAddress::from_str(&rpc).unwrap();
let client = HttpClient::new(ledger_address).unwrap();
let tendermint_url = Url::from_str(&rpc).unwrap();
let client = HttpClient::new(tendermint_url).unwrap();
let height = height.revision_height() as u32;
let result = test
.async_runtime()
Expand All @@ -1714,8 +1713,8 @@ fn check_ibc_update_query(
consensus_height: BlockHeight,
) -> Result<()> {
let rpc = get_actor_rpc(test, Who::Validator(0));
let ledger_address = TendermintAddress::from_str(&rpc).unwrap();
let client = HttpClient::new(ledger_address).unwrap();
let tendermint_url = Url::from_str(&rpc).unwrap();
let client = HttpClient::new(tendermint_url).unwrap();
match test.async_runtime().block_on(RPC.shell().ibc_client_update(
&client,
client_id,
Expand All @@ -1733,8 +1732,8 @@ fn check_ibc_packet_query(
packet: &Packet,
) -> Result<()> {
let rpc = get_actor_rpc(test, Who::Validator(0));
let ledger_address = TendermintAddress::from_str(&rpc).unwrap();
let client = HttpClient::new(ledger_address).unwrap();
let tendermint_url = Url::from_str(&rpc).unwrap();
let client = HttpClient::new(tendermint_url).unwrap();
match test.async_runtime().block_on(RPC.shell().ibc_packet(
&client,
event_type,
Expand All @@ -1756,8 +1755,8 @@ fn query_value_with_proof(
height: Option<Height>,
) -> Result<(Option<Vec<u8>>, TmProof)> {
let rpc = get_actor_rpc(test, Who::Validator(0));
let ledger_address = TendermintAddress::from_str(&rpc).unwrap();
let client = HttpClient::new(ledger_address).unwrap();
let tendermint_url = Url::from_str(&rpc).unwrap();
let client = HttpClient::new(tendermint_url).unwrap();
let result = test.async_runtime().block_on(query_storage_value_bytes(
&client,
key,
Expand Down Expand Up @@ -2058,8 +2057,8 @@ fn get_attributes_from_event(event: &AbciEvent) -> HashMap<String, String> {

fn get_events(test: &Test, height: u32) -> Result<Vec<AbciEvent>> {
let rpc = get_actor_rpc(test, Who::Validator(0));
let ledger_address = TendermintAddress::from_str(&rpc).unwrap();
let client = HttpClient::new(ledger_address).unwrap();
let tendermint_url = Url::from_str(&rpc).unwrap();
let client = HttpClient::new(tendermint_url).unwrap();

let response = test
.async_runtime()
Expand Down
3 changes: 3 additions & 0 deletions crates/tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,9 @@ fn pos_bonds() -> Result<()> {
start_namada_ledger_node_wait_wasm(&test, Some(0), Some(40))?
.background();

let rpc = get_actor_rpc(&test, Who::Validator(0));
wait_for_block_height(&test, &rpc, 2, 30)?;

let validator_0_rpc = get_actor_rpc(&test, Who::Validator(0));

// 2. Submit a self-bond for the first genesis validator
Expand Down
16 changes: 8 additions & 8 deletions crates/tests/src/integration/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::strings::TX_APPLIED_SUCCESS;
#[test]
fn masp_incentives() -> Result<()> {
// This address doesn't matter for tests. But an argument is required.
let validator_one_rpc = "127.0.0.1:26567";
let validator_one_rpc = "http://127.0.0.1:26567";
// Download the shielded pool parameters before starting node
let _ = FsShieldedUtils::new(PathBuf::new());
// Lengthen epoch to ensure that a transaction can be constructed and
Expand Down Expand Up @@ -809,7 +809,7 @@ fn masp_incentives() -> Result<()> {
#[test]
fn spend_unconverted_asset_type() -> Result<()> {
// This address doesn't matter for tests. But an argument is required.
let validator_one_rpc = "127.0.0.1:26567";
let validator_one_rpc = "http://127.0.0.1:26567";
// Download the shielded pool parameters before starting node
let _ = FsShieldedUtils::new(PathBuf::new());

Expand Down Expand Up @@ -929,7 +929,7 @@ fn spend_unconverted_asset_type() -> Result<()> {
#[test]
fn masp_pinned_txs() -> Result<()> {
// This address doesn't matter for tests. But an argument is required.
let validator_one_rpc = "127.0.0.1:26567";
let validator_one_rpc = "http://127.0.0.1:26567";
// Download the shielded pool parameters before starting node
let _ = FsShieldedUtils::new(PathBuf::new());

Expand Down Expand Up @@ -1122,7 +1122,7 @@ fn masp_txs_and_queries() -> Result<()> {
// tracing::level_filters::LevelFilter::INFO,
// )?;
// This address doesn't matter for tests. But an argument is required.
let validator_one_rpc = "127.0.0.1:26567";
let validator_one_rpc = "http://127.0.0.1:26567";
// Download the shielded pool parameters before starting node
let _ = FsShieldedUtils::new(PathBuf::new());

Expand Down Expand Up @@ -1457,7 +1457,7 @@ fn masp_txs_and_queries() -> Result<()> {
#[test]
fn wrapper_fee_unshielding() -> Result<()> {
// This address doesn't matter for tests. But an argument is required.
let validator_one_rpc = "127.0.0.1:26567";
let validator_one_rpc = "http://127.0.0.1:26567";
// Download the shielded pool parameters before starting node
let _ = FsShieldedUtils::new(PathBuf::new());
let (mut node, _services) = setup::setup()?;
Expand Down Expand Up @@ -1748,7 +1748,7 @@ fn wrapper_fee_unshielding() -> Result<()> {
#[test]
fn multiple_unfetched_txs_same_block() -> Result<()> {
// This address doesn't matter for tests. But an argument is required.
let validator_one_rpc = "127.0.0.1:26567";
let validator_one_rpc = "http://127.0.0.1:26567";
// Download the shielded pool parameters before starting node
let _ = FsShieldedUtils::new(PathBuf::new());
let (mut node, _services) = setup::setup()?;
Expand Down Expand Up @@ -2014,7 +2014,7 @@ fn multiple_unfetched_txs_same_block() -> Result<()> {
#[test]
fn cross_epoch_unshield() -> Result<()> {
// This address doesn't matter for tests. But an argument is required.
let validator_one_rpc = "127.0.0.1:26567";
let validator_one_rpc = "http://127.0.0.1:26567";
// Download the shielded pool parameters before starting node
let _ = FsShieldedUtils::new(PathBuf::new());
let (mut node, _services) = setup::setup()?;
Expand Down Expand Up @@ -2115,7 +2115,7 @@ fn cross_epoch_unshield() -> Result<()> {
#[test]
fn dynamic_assets() -> Result<()> {
// This address doesn't matter for tests. But an argument is required.
let validator_one_rpc = "127.0.0.1:26567";
let validator_one_rpc = "http://127.0.0.1:26567";
// Download the shielded pool parameters before starting node
let _ = FsShieldedUtils::new(PathBuf::new());
// Lengthen epoch to ensure that a transaction can be constructed and
Expand Down

0 comments on commit f4b0caf

Please sign in to comment.