Skip to content

Commit

Permalink
Control unsigned ismp with a storage item
Browse files Browse the repository at this point in the history
This PR adds a storage item, genesis setting and runtime api to control the activation of unsigned transactions for the ISMP pallet.

The unsigned feature flag is removed, and the development testnet configs have the enableUnsignedTransactions flag turned on by default.
  • Loading branch information
blakebyrnes committed Nov 14, 2024
1 parent 6da0092 commit 4c91a85
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "evm/lib/forge-std"]
path = evm/lib/forge-std
url = git@github.com:foundry-rs/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "evm/lib/solidity-stringutils"]
path = evm/lib/solidity-stringutils
url = https://github.com/Arachnid/solidity-stringutils
Expand Down
2 changes: 1 addition & 1 deletion modules/ismp/pallets/call-decompressor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sp-api = { workspace = true }

# polytope labs
ismp = { workspace = true }
pallet-ismp = { workspace = true, features = ["unsigned"] }
pallet-ismp = { workspace = true }
pallet-ismp-relayer = { workspace = true }

# crates.io
Expand Down
1 change: 0 additions & 1 deletion modules/ismp/pallets/pallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,3 @@ try-runtime = [
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]
unsigned = []
2 changes: 1 addition & 1 deletion modules/ismp/pallets/pallet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ To use it in your runtime, you need to implement the ismp
### Dispatchable Functions

- `handle` - Handles incoming ISMP messages.
- `handle_unsigned` Unsigned variant for handling incoming messages, enabled by `feature = ["unsigned"]`
- `handle_unsigned` Unsigned variant for handling incoming messages
- `create_consensus_client` - Handles creation of various properties for a particular consensus client. Can only be called by the `AdminOrigin`.
- `update_consensus_state` - Updates consensus client properties in storage. Can only be called by the `AdminOrigin`.
- `fund_message` - In cases where the initially provided relayer fees have now become insufficient, due to a transaction fee spike on the destination chain. Allows a user to add more funds to the request to be used for delivery and execution. Should never be called on a completed request.
Expand Down
58 changes: 47 additions & 11 deletions modules/ismp/pallets/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
//! ### Dispatchable Functions
//!
//! * `handle` - Handles incoming ISMP messages.
//! * `handle_unsigned` Unsigned variant for handling incoming messages, enabled by `feature =
//! ["unsigned"]`
//! * `handle_unsigned` Unsigned variant for handling incoming messages
//! * `create_consensus_client` - Handles creation of various properties for a particular consensus
//! client. Can only be called by the `AdminOrigin`.
//! * `update_consensus_state` - Updates consensus client properties in storage. Can only be called
Expand Down Expand Up @@ -229,8 +228,14 @@ pub mod pallet {
messaging::{CreateConsensusState, Message},
router::IsmpRouter,
};
use ismp::{
handlers::MessageResult,
messaging::{hash_request, ConsensusMessage, FraudProofMessage, RequestMessage},
router::Request,
};

use sp_core::{storage::ChildInfo, H256};
#[cfg(feature = "unsigned")]

use sp_runtime::transaction_validity::{
InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError,
ValidTransaction,
Expand Down Expand Up @@ -383,6 +388,12 @@ pub mod pallet {
#[pallet::getter(fn responded)]
pub type Responded<T: Config> = StorageMap<_, Identity, H256, bool, ValueQuery>;

/// Should unsigned transactions be enabled. Preferred mode for testnet to simplify relayer
/// token acquisition, but this can be abused in production. Use with caution.
#[pallet::storage]
#[pallet::getter(fn enable_unsigned)]
pub type EnableUnsigned<T: Config> = StorageValue<_, bool, ValueQuery>;

/// Latest nonce for messages sent from this chain
#[pallet::storage]
#[pallet::getter(fn nonce)]
Expand All @@ -394,6 +405,24 @@ pub mod pallet {
pub type ChildTrieRoot<T: Config> =
StorageValue<_, <T as frame_system::Config>::Hash, ValueQuery>;

/// Genesis settings
#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
/// Should unsigned transactions be enabled. Preferred mode for testnet to simplify relayer
pub enable_unsigned_transactions: bool,
/// Phantom data
#[serde(skip)]
pub _phantom: PhantomData<T>,
}

#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
EnableUnsigned::<T>::put(self.enable_unsigned_transactions);
}
}

// Pallet implements [`Hooks`] trait to define some logic to execute in some context.
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T>
Expand Down Expand Up @@ -436,7 +465,6 @@ pub mod pallet {
/// - `messages`: the messages to handle or process.
///
/// Emits different message events based on the Message received if successful.
#[cfg(feature = "unsigned")]
#[pallet::weight(get_weight::<T>(&messages))]
#[pallet::call_index(0)]
#[frame_support::transactional]
Expand All @@ -457,7 +485,6 @@ pub mod pallet {
/// - `messages`: A set of ISMP [`Message`]s to handle or process.
///
/// Emits different message events based on the Message received if successful.
#[cfg(not(feature = "unsigned"))]
#[pallet::weight(get_weight::<T>(&messages))]
#[pallet::call_index(1)]
#[frame_support::transactional]
Expand Down Expand Up @@ -565,6 +592,18 @@ pub mod pallet {

Ok(())
}

/// Change the activation of the Enable Unsigned feature. This feature allows relayers to submit ISMP messages without fees.
#[pallet::weight(<T as frame_system::Config>::DbWeight::get().writes(1))]
#[pallet::call_index(5)]
pub fn update_enable_unsigned(
origin: OriginFor<T>,
enable_unsigned_transactions: bool,
) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;
EnableUnsigned::<T>::put(enable_unsigned_transactions);
Ok(())
}
}

/// Pallet Events
Expand Down Expand Up @@ -654,7 +693,6 @@ pub mod pallet {
}

/// This allows users execute ISMP datagrams for free. Use with caution.
#[cfg(feature = "unsigned")]
#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
Expand All @@ -665,11 +703,9 @@ pub mod pallet {
}

fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
use ismp::{
handlers::MessageResult,
messaging::{hash_request, ConsensusMessage, FraudProofMessage, RequestMessage},
router::Request,
};
if !EnableUnsigned::<T>::get() {
return Err(TransactionValidityError::Invalid(InvalidTransaction::Call));
}
let messages = match call {
Call::handle_unsigned { messages } => messages,
_ => Err(TransactionValidityError::Invalid(InvalidTransaction::Call))?,
Expand Down
3 changes: 3 additions & 0 deletions parachain/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ fn testnet_genesis(
"invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::<Vec<_>>(),
"candidacyBond": EXISTENTIAL_DEPOSIT * 16,
},
"ismp": {
"enableUnsignedTransactions": true
},
"ismpParachain": {
"parachains": vec![sibling]
},
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtimes/gargantua/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ parachains-common = { workspace = true }

# local modules
ismp = { workspace = true }
pallet-ismp = { workspace = true, features = ["unsigned"] }
pallet-ismp = { workspace = true }
pallet-fishermen = { workspace = true }
pallet-ismp-demo = { workspace = true }
pallet-ismp-runtime-api = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtimes/messier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ parachains-common = { workspace = true }

# ismp modules
ismp = { workspace = true }
pallet-ismp = { workspace = true, features = ["unsigned"] }
pallet-ismp = { workspace = true }
pallet-ismp-demo = { workspace = true }
pallet-ismp-runtime-api = { workspace = true }
ismp-parachain = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtimes/nexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ parachains-common = { workspace = true }

# ismp modules
ismp = { workspace = true }
pallet-ismp = { workspace = true, features = ["unsigned"] }
pallet-ismp = { workspace = true }
pallet-ismp-demo = { workspace = true }
pallet-ismp-runtime-api = { workspace = true }
ismp-parachain = { workspace = true }
Expand Down

0 comments on commit 4c91a85

Please sign in to comment.