Skip to content

Commit

Permalink
allow governance to change ibc storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed May 29, 2024
1 parent 5a5838a commit c4d3075
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
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));
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

0 comments on commit c4d3075

Please sign in to comment.