-
Notifications
You must be signed in to change notification settings - Fork 695
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
Task(bump) Pallet Salary #5163
base: master
Are you sure you want to change the base?
Task(bump) Pallet Salary #5163
Conversation
The CI pipeline was cancelled due to failure one of the required jobs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for taking this up!
@@ -146,6 +165,7 @@ parameter_types! { | |||
} | |||
|
|||
impl Config for Test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use derive_impl
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we need to
|
||
#[pallet::hooks] | ||
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> { | ||
#[cfg(feature = "experimental")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove experimental now and get this audited. Thoughts @kianenigma @ggwpez ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, some comments
@@ -247,6 +249,10 @@ std = [ | |||
"xcm/std", | |||
] | |||
|
|||
experimental = [ | |||
"pallet-salary/experimental", | |||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use experimental by default for the westend testnet.
pub trait Config<I: 'static = ()>: | ||
CreateInherent<frame_system::Call<Self>> + frame_system::Config | ||
{ | ||
type RuntimeTask: frame_support::traits::Task | ||
+ IsType<<Self as frame_system::Config>::RuntimeTask> | ||
+ From<Task<Self, I>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this new associated type. Instead you can bound From<Task<..>>
directly in the supertrait bound:
pub trait Config<I: 'static = ()>: | |
CreateInherent<frame_system::Call<Self>> + frame_system::Config | |
{ | |
type RuntimeTask: frame_support::traits::Task | |
+ IsType<<Self as frame_system::Config>::RuntimeTask> | |
+ From<Task<Self, I>>; | |
pub trait Config<I: 'static = ()>: | |
CreateInherent<frame_system::Call<Self>> + frame_system::Config<RuntimeTask: From<Task<Self, I>>> | |
{ |
match res { | ||
Ok(_) => log::info!(target: LOG_TARGET, "Submitted the task."), | ||
Err(e) => log::error!(target: LOG_TARGET, "Error submitting task: {:?}", e), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So every block we try to submit the task?
Is submitting a transaction so cheap? Maybe we should at least verify the task condition before trying to submit it.
maybe we can use the task list here.
@@ -382,6 +394,54 @@ pub mod pallet { | |||
} | |||
} | |||
|
|||
#[pallet::tasks_experimental] | |||
impl<T: Config<I>, I: 'static> Pallet<T, I> { | |||
#[pallet::task_list(vec![].into_iter())] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could have an actual task list: return a vector with one element ()
if now >= startus.cycle_start+cycle_period
, no?
#[pallet::task_condition(|| { | ||
let now = frame_system::Pallet::<T>::block_number(); | ||
let cycle_period = Pallet::<T, I>::cycle_period(); | ||
let mut status = Status::<T, I>::get().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to unwrap here. we should return false:
let mut status = Status::<T, I>::get().unwrap(); | |
let Some(mut status) = Status::<T, I>::get() else { return false }; |
- name: staging-xcm-builder | ||
bump: patch | ||
- name: pallet-salary | ||
bump: patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bounding of CreateInherent
breaks semver.
bump: patch | |
bump: major |
"frame-support/experimental", | ||
"frame-system/experimental", | ||
"pallet-salary/experimental", | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this new feature?
@@ -741,7 +835,8 @@ pub type TxExtension = ( | |||
frame_system::CheckEra<Runtime>, | |||
frame_system::CheckNonce<Runtime>, | |||
frame_system::CheckWeight<Runtime>, | |||
cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim<Runtime>, | |||
pallet_transaction_payment::ChargeTransactionPayment<Runtime>, | |||
frame_metadata_hash_extension::CheckMetadataHash<Runtime>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? I understand it is better to have it. But I am afraid it breaks stuff.
pub type SignedPayload = generic::SignedPayload<RuntimeCall, TxExtension>; | ||
|
||
impl frame_system::offchain::SigningTypes for Runtime { | ||
type Public = <Signature as Verify>::Signer; | ||
type Signature = Signature; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed no?
pub type SignedPayload = generic::SignedPayload<RuntimeCall, TxExtension>; | |
impl frame_system::offchain::SigningTypes for Runtime { | |
type Public = <Signature as Verify>::Signer; | |
type Signature = Signature; | |
} |
/// Submits a transaction with the node's public and signature type. Adheres to the signed extension | ||
/// format of the chain. | ||
impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime | ||
where | ||
RuntimeCall: From<LocalCall>, | ||
{ | ||
fn create_signed_transaction< | ||
C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>, | ||
>( | ||
call: RuntimeCall, | ||
public: <Signature as Verify>::Signer, | ||
account: AccountId, | ||
nonce: <Runtime as frame_system::Config>::Nonce, | ||
) -> Option<UncheckedExtrinsic> { | ||
use sp_runtime::traits::StaticLookup; | ||
// take the biggest period possible. | ||
let period = | ||
BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64; | ||
|
||
let current_block = System::block_number() | ||
.saturated_into::<u64>() | ||
// The `System::block_number` is initialized with `n+1`, | ||
// so the actual block number is `n`. | ||
.saturating_sub(1); | ||
let tip = 0; | ||
let tx_ext: TxExtension = ( | ||
frame_system::CheckNonZeroSender::<Runtime>::new(), | ||
frame_system::CheckSpecVersion::<Runtime>::new(), | ||
frame_system::CheckTxVersion::<Runtime>::new(), | ||
frame_system::CheckGenesis::<Runtime>::new(), | ||
frame_system::CheckMortality::<Runtime>::from(generic::Era::mortal( | ||
period, | ||
current_block, | ||
)), | ||
frame_system::CheckNonce::<Runtime>::from(nonce), | ||
frame_system::CheckWeight::<Runtime>::new(), | ||
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip), | ||
frame_metadata_hash_extension::CheckMetadataHash::<Runtime>::new(true), | ||
) | ||
.into(); | ||
let raw_payload = SignedPayload::new(call, tx_ext) | ||
.map_err(|e| { | ||
log::warn!("Unable to create signed payload: {:?}", e); | ||
}) | ||
.ok()?; | ||
let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?; | ||
let (call, tx_ext, _) = raw_payload.deconstruct(); | ||
let address = <Runtime as frame_system::Config>::Lookup::unlookup(account); | ||
let transaction = UncheckedExtrinsic::new_signed(call, address, signature, tx_ext); | ||
Some(transaction) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed no?
/// Submits a transaction with the node's public and signature type. Adheres to the signed extension | |
/// format of the chain. | |
impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime | |
where | |
RuntimeCall: From<LocalCall>, | |
{ | |
fn create_signed_transaction< | |
C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>, | |
>( | |
call: RuntimeCall, | |
public: <Signature as Verify>::Signer, | |
account: AccountId, | |
nonce: <Runtime as frame_system::Config>::Nonce, | |
) -> Option<UncheckedExtrinsic> { | |
use sp_runtime::traits::StaticLookup; | |
// take the biggest period possible. | |
let period = | |
BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64; | |
let current_block = System::block_number() | |
.saturated_into::<u64>() | |
// The `System::block_number` is initialized with `n+1`, | |
// so the actual block number is `n`. | |
.saturating_sub(1); | |
let tip = 0; | |
let tx_ext: TxExtension = ( | |
frame_system::CheckNonZeroSender::<Runtime>::new(), | |
frame_system::CheckSpecVersion::<Runtime>::new(), | |
frame_system::CheckTxVersion::<Runtime>::new(), | |
frame_system::CheckGenesis::<Runtime>::new(), | |
frame_system::CheckMortality::<Runtime>::from(generic::Era::mortal( | |
period, | |
current_block, | |
)), | |
frame_system::CheckNonce::<Runtime>::from(nonce), | |
frame_system::CheckWeight::<Runtime>::new(), | |
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip), | |
frame_metadata_hash_extension::CheckMetadataHash::<Runtime>::new(true), | |
) | |
.into(); | |
let raw_payload = SignedPayload::new(call, tx_ext) | |
.map_err(|e| { | |
log::warn!("Unable to create signed payload: {:?}", e); | |
}) | |
.ok()?; | |
let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?; | |
let (call, tx_ext, _) = raw_payload.deconstruct(); | |
let address = <Runtime as frame_system::Config>::Lookup::unlookup(account); | |
let transaction = UncheckedExtrinsic::new_signed(call, address, signature, tx_ext); | |
Some(transaction) | |
} | |
} |
Resolves #4545
Blocked on #5194