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

fix: allow governance to change ibc storage #3328

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 22 additions & 0 deletions crates/ibc/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,28 @@ pub fn is_ibc_trace_key(key: &Key) -> Option<(String, String)> {
}
}

/// Check if a key is an IBC parameter Key
pub fn is_params_key(key: &Key) -> bool {
match &key.segments[..] {
[
DbKeySeg::AddressSeg(addr),
DbKeySeg::StringSeg(prefix),
DbKeySeg::StringSeg(_),
] => {
if addr == &Address::Internal(InternalAddress::Ibc)
&& (prefix == MINT_LIMIT
|| prefix == THROUGHPUT_LIMIT
|| prefix == PARAMS)
{
true
} else {
false
}
}
_ => false,
}
}

/// Returns true if the given key is for an IBC counter for clients,
/// connections, or channelEnds
pub fn is_ibc_counter_key(key: &Key) -> bool {
Expand Down
25 changes: 25 additions & 0 deletions crates/namada/src/ledger/native_vp/ibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use namada_core::arith::{self, checked};
use namada_core::collections::HashSet;
use namada_core::storage::Key;
use namada_gas::{IBC_ACTION_EXECUTE_GAS, IBC_ACTION_VALIDATE_GAS};
use namada_governance::is_proposal_accepted;
use namada_ibc::event::IbcEvent;
use namada_ibc::storage::{is_params_key, params_key};
use namada_ibc::{
Error as ActionError, IbcActions, NftTransferModule, TransferModule,
ValidationParams,
Expand Down Expand Up @@ -43,6 +45,8 @@ pub enum Error {
NativeVpError(#[from] native_vp::Error),
#[error("IBC VP error: Decoding error: {0}")]
Decoding(#[from] std::io::Error),
#[error("IBC VP error: governance proposal change is invalid")]
InvalidGovernanceChange,
#[error("IBC VP error: IBC message is required as transaction data")]
NoTxData,
#[error("IBC VP error: IBC action error: {0}")]
Expand Down Expand Up @@ -83,6 +87,27 @@ where
keys_changed: &BTreeSet<Key>,
_verifiers: &BTreeSet<Address>,
) -> VpResult<()> {
// Is VP triggered by a governance proposal?
let is_governance_proposal = is_proposal_accepted(
&self.ctx.pre(),
batched_tx
.tx
.data(batched_tx.cmt)
.unwrap_or_default()
.as_ref(),
)
.unwrap_or_default();

if is_governance_proposal {
let changed_keys_are_params =
keys_changed.iter().any(|key| is_ibc_key(key));
Copy link
Member

Choose a reason for hiding this comment

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

is_params_key?

if changed_keys_are_params {
return Ok(());
} else {
return Err(Error::InvalidGovernanceChange);
}
}

let tx_data =
batched_tx.tx.data(batched_tx.cmt).ok_or(Error::NoTxData)?;

Expand Down
Loading