Skip to content

Commit

Permalink
Merge branch 'bengt/minimum-gas-price' (#1882)
Browse files Browse the repository at this point in the history
* origin/bengt/minimum-gas-price:
  changelog: add #1882
  changes gas_cost -> minimum_gas_price in the genesis file
  • Loading branch information
Fraccaman committed Sep 25, 2023
2 parents 7a53e57 + 520f0b5 commit d946b93
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/1882-minimum-gas-price.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Renamed `gas_cost` to `minimum_gas_price` in the genesis file.
([\#1882](https://github.com/anoma/namada/pull/1882))
10 changes: 6 additions & 4 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ pub mod genesis_config {
pub fee_unshielding_descriptions_limit: u64,
/// Map of the cost per gas unit for every token allowed for fee
/// payment
pub gas_cost: BTreeMap<Address, token::Amount>,
pub minimum_gas_price: BTreeMap<Address, token::Amount>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -616,7 +616,7 @@ pub mod genesis_config {
pos_gain_d: parameters.pos_gain_d,
staked_ratio: Dec::zero(),
pos_inflation_amount: token::Amount::zero(),
gas_cost: parameters.gas_cost,
minimum_gas_price: parameters.minimum_gas_price,
fee_unshielding_gas_limit: parameters.fee_unshielding_gas_limit,
fee_unshielding_descriptions_limit: parameters
.fee_unshielding_descriptions_limit,
Expand Down Expand Up @@ -885,7 +885,7 @@ pub struct Parameters {
/// Fee unshielding descriptions limit
pub fee_unshielding_descriptions_limit: u64,
/// Map of the cost per gas unit for every token allowed for fee payment
pub gas_cost: BTreeMap<Address, token::Amount>,
pub minimum_gas_price: BTreeMap<Address, token::Amount>,
}

#[cfg(not(any(test, feature = "dev")))]
Expand Down Expand Up @@ -1007,7 +1007,9 @@ pub fn genesis(num_validators: u64) -> Genesis {
pos_gain_d: Dec::new(1, 1).expect("This can't fail"),
staked_ratio: Dec::zero(),
pos_inflation_amount: token::Amount::zero(),
gas_cost: [(nam(), token::Amount::from(1))].into_iter().collect(),
minimum_gas_price: [(nam(), token::Amount::from(1))]
.into_iter()
.collect(),
fee_unshielding_gas_limit: 20_000,
fee_unshielding_descriptions_limit: 15,
};
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/node/ledger/shell/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ where
pos_gain_d,
staked_ratio,
pos_inflation_amount,
gas_cost,
minimum_gas_price,
fee_unshielding_gas_limit,
fee_unshielding_descriptions_limit,
} = genesis.parameters;
Expand Down Expand Up @@ -181,7 +181,7 @@ where
pos_gain_d,
staked_ratio,
pos_inflation_amount,
gas_cost,
minimum_gas_price,
fee_unshielding_gas_limit,
fee_unshielding_descriptions_limit,
};
Expand Down
8 changes: 5 additions & 3 deletions apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ where
CA: 'static + WasmCacheAccess + Sync,
{
// Check that fee token is an allowed one
let gas_cost = namada::ledger::parameters::read_gas_cost(
let minimum_gas_price = namada::ledger::parameters::read_gas_cost(
&self.wl_storage,
&wrapper.fee.token,
)
Expand All @@ -1368,12 +1368,14 @@ where
wrapper.fee.token
))))?;

if wrapper.fee.amount_per_gas_unit < gas_cost {
if wrapper.fee.amount_per_gas_unit < minimum_gas_price {
// The fees do not match the minimum required
return Err(Error::TxApply(protocol::Error::FeeError(format!(
"Fee amount {:?} do not match the minimum required amount \
{:?} for token {}",
wrapper.fee.amount_per_gas_unit, gas_cost, wrapper.fee.token
wrapper.fee.amount_per_gas_unit,
minimum_gas_price,
wrapper.fee.token
))));
}

Expand Down
10 changes: 5 additions & 5 deletions core/src/ledger/parameters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct Parameters {
/// Fee unshielding descriptions limit
pub fee_unshielding_descriptions_limit: u64,
/// Map of the cost per gas unit for every token allowed for fee payment
pub gas_cost: BTreeMap<Address, token::Amount>,
pub minimum_gas_price: BTreeMap<Address, token::Amount>,
}

/// Epoch duration. A new epoch begins as soon as both the `min_num_of_blocks`
Expand Down Expand Up @@ -130,7 +130,7 @@ impl Parameters {
pos_gain_d,
staked_ratio,
pos_inflation_amount,
gas_cost,
minimum_gas_price,
fee_unshielding_gas_limit,
fee_unshielding_descriptions_limit,
} = self;
Expand Down Expand Up @@ -214,7 +214,7 @@ impl Parameters {
storage.write(&pos_inflation_key, pos_inflation_amount)?;

let gas_cost_key = storage::get_gas_cost_key();
storage.write(&gas_cost_key, gas_cost)?;
storage.write(&gas_cost_key, minimum_gas_price)?;

Ok(())
}
Expand Down Expand Up @@ -538,7 +538,7 @@ where
// read gas cost
let gas_cost_key = storage::get_gas_cost_key();
let value = storage.read(&gas_cost_key)?;
let gas_cost: BTreeMap<Address, token::Amount> = value
let minimum_gas_price: BTreeMap<Address, token::Amount> = value
.ok_or(ReadError::ParametersMissing)
.into_storage_result()?;

Expand All @@ -556,7 +556,7 @@ where
pos_gain_d,
staked_ratio,
pos_inflation_amount,
gas_cost,
minimum_gas_price,
fee_unshielding_gas_limit,
fee_unshielding_descriptions_limit,
})
Expand Down
4 changes: 2 additions & 2 deletions core/src/ledger/parameters/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct Keys {
vp_whitelist: &'static str,
max_proposal_bytes: &'static str,
max_block_gas: &'static str,
gas_cost: &'static str,
minimum_gas_price: &'static str,
fee_unshielding_gas_limit: &'static str,
fee_unshielding_descriptions_limit: &'static str,
max_signatures_per_transaction: &'static str,
Expand Down Expand Up @@ -192,7 +192,7 @@ pub fn get_max_block_gas_key() -> Key {

/// Storage key used for the gas cost table
pub fn get_gas_cost_key() -> Key {
get_gas_cost_key_at_addr(ADDRESS)
get_minimum_gas_price_key_at_addr(ADDRESS)
}

/// Storage key used for the max signatures per transaction key
Expand Down
2 changes: 1 addition & 1 deletion core/src/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ mod tests {
pos_inflation_amount: token::Amount::zero(),
fee_unshielding_gas_limit: 20_000,
fee_unshielding_descriptions_limit: 15,
gas_cost: BTreeMap::default(),
minimum_gas_price: BTreeMap::default(),
};
parameters.init_storage(&mut wl_storage).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion genesis/dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pos_gain_d = "0.1"
# The maximum number of signatures allowed per transaction
max_signatures_per_transaction = 15

[parameters.gas_cost]
[parameters.minimum_gas_price]
"atest1v4ehgw36x3prswzxggunzv6pxqmnvdj9xvcyzvpsggeyvs3cg9qnywf589qnwvfsg5erg3fkl09rg5" = "0.000001"

# Proof of stake parameters.
Expand Down
2 changes: 1 addition & 1 deletion genesis/e2e-tests-single-node.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pos_gain_d = "0.1"
# The maximum number of signatures allowed per transaction
max_signatures_per_transaction = 15

[parameters.gas_cost]
[parameters.minimum_gas_price]
"atest1v4ehgw36x3prswzxggunzv6pxqmnvdj9xvcyzvpsggeyvs3cg9qnywf589qnwvfsg5erg3fkl09rg5" = "0.000001"

# Proof of stake parameters.
Expand Down

0 comments on commit d946b93

Please sign in to comment.