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

Feature: Add config option for fee granters #1634

Merged
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/1633-allow-fee-granters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added support for fee granters through config file
([#1633](https://github.com/informalsystems/ibc-rs/issues/1633))
6 changes: 6 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ memo_prefix = ''
# ['transfer', 'channel-0'],
# ]

# Specify that the transaction fees should be payed from this fee granter's account.
# Optional. If unspecified (the default behavior), then no fee granter is used, and
# the account specified in `key_name` will pay the tx fees for all transactions
# submitted to this chain.
# fee_granter = ''

[[chains]]
id = 'ibc-1'
rpc_addr = 'http://127.0.0.1:26557'
Expand Down
1 change: 1 addition & 0 deletions guide/src/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
max_gas = 2000000
fee_granter = ''
gas_price = { price = 0.001, denom = 'stake' }
gas_adjustment = 0.1
clock_drift = '5s'
Expand Down
14 changes: 12 additions & 2 deletions relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ const DEFAULT_MAX_GAS: u64 = 300_000;
/// Fraction of the estimated gas to add to the estimated gas amount when submitting a transaction.
const DEFAULT_GAS_PRICE_ADJUSTMENT: f64 = 0.1;

const DEFAULT_FEE_GRANTER: &str = "";

/// Upper limit on the size of transactions submitted by Hermes, expressed as a
/// fraction of the maximum block size defined in the Tendermint core consensus parameters.
pub const GENESIS_MAX_BYTES_MAX_FRACTION: f64 = 0.9;
Expand Down Expand Up @@ -440,6 +442,14 @@ impl CosmosSdkChain {
self.config.max_gas.unwrap_or(DEFAULT_MAX_GAS)
}

/// Get the fee granter address
fn fee_granter(&self) -> &str {
self.config
.fee_granter
.as_deref()
.unwrap_or(DEFAULT_FEE_GRANTER)
}

/// The gas price
fn gas_price(&self) -> &GasPrice {
&self.config.gas_price
Expand Down Expand Up @@ -644,7 +654,7 @@ impl CosmosSdkChain {
amount: vec![self.max_fee_in_coins()],
gas_limit: self.max_gas(),
payer: "".to_string(),
granter: "".to_string(),
granter: self.fee_granter().to_string(),
}
}

Expand All @@ -655,7 +665,7 @@ impl CosmosSdkChain {
amount: vec![self.fee_from_gas_in_coins(adjusted_gas_limit)],
gas_limit: adjusted_gas_limit,
payer: "".to_string(),
granter: "".to_string(),
granter: self.fee_granter().to_string(),
}
}

Expand Down
1 change: 1 addition & 0 deletions relayer/src/chain/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ pub mod test_utils {
max_gas: None,
gas_price: GasPrice::new(0.001, "uatom".to_string()),
gas_adjustment: None,
fee_granter: None,
max_msg_num: Default::default(),
max_tx_size: Default::default(),
clock_drift: Duration::from_secs(5),
Expand Down
1 change: 1 addition & 0 deletions relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ pub struct ChainConfig {
pub default_gas: Option<u64>,
pub max_gas: Option<u64>,
pub gas_adjustment: Option<f64>,
pub fee_granter: Option<String>,
#[serde(default)]
pub max_msg_num: MaxMsgNum,
#[serde(default)]
Expand Down
1 change: 1 addition & 0 deletions tools/integration-test/src/types/single/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl FullNode {
default_gas: None,
max_gas: Some(3000000),
gas_adjustment: Some(0.1),
fee_granter: None,
max_msg_num: Default::default(),
max_tx_size: Default::default(),
max_block_time: Default::default(),
Expand Down