Skip to content

Optimistic Project Funding #6994

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

Open
wants to merge 246 commits into
base: master
Choose a base branch
from
Open

Optimistic Project Funding #6994

wants to merge 246 commits into from

Conversation

ndkazu
Copy link
Contributor

@ndkazu ndkazu commented Dec 24, 2024

Description

This PR is related to this issue .
Through the introduction of the OPF pallet and the DISTRIBUTION pallet, we are handling the Optimistic Project Funding.
It allows users to nominate projects (whitelisted in OpenGov) with their DOT. This mechanism will be funded with a constant stream of DOT taken directly from inflation and distributed to projects based on the proportion of DOT that has nominated them.

Integration

Review Notes

Terminology

The constants available in the runtime for the OPF Pallet:

  • MaxProjects: Maximum number of Whitelisted projects that can be handled by the pallet.
  • VotingPeriod: Period in which people can vote. After the period has ended, the votes are counted (STOP THE COUNT) and then the funds are distributed into Spends.
  • ClaimingPeriod: Time for claiming a Spend. After the period has passed, a spend is thrown away and the funds are available again for distribution in the pot.
  • VoteValidityPeriod: Period after which all the votes are reset.

Functions

  • - register_project: Register by OpenGov, should take AccountId and project Purpose.
  • - unregister_project: Unregister by OpenGov
  • - claim: To claim a spend

Checklist

pallet-opf

  • Pallet Config
  • Helper functions
  • Extrinsics
  • Events & Tests
  • Benchmarking & weights
  • Remove Dev-mode
  • Proper documentation

@ndkazu ndkazu requested a review from a team as a code owner December 24, 2024 12:34
Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

you can open the PR as a draft until it is ready.

Or ping when it is ready.

@gui1117 gui1117 marked this pull request as draft December 29, 2024 10:13
spend_created,
};

WhiteListedProjectAccounts::<T>::insert(project_id, project_info);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is better to keep the modification of a storage to only one type, here both ProjectInfo and Pallet are tapping into WhitelistedProjectAccounts, I think it is a bit confusing.
It would make the code clearer if a storage item was used by only one type.

Comment on lines +81 to +90
pub trait Config: frame_system::Config {
type RuntimeCall: Parameter
+ UnfilteredDispatchable<RuntimeOrigin = <Self as frame_system::Config>::RuntimeOrigin>
+ From<Call<Self>>
+ Into<<Self as frame_system::Config>::RuntimeCall>
+ Into<
<Self::Governance as traits::ReferendumTrait<
<Self as frame_system::Config>::AccountId,
>>::Call,
> + GetDispatchInfo;
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that you don't need an additional associated type add bounds to a type in a supertrait you can do:

Suggested change
pub trait Config: frame_system::Config {
type RuntimeCall: Parameter
+ UnfilteredDispatchable<RuntimeOrigin = <Self as frame_system::Config>::RuntimeOrigin>
+ From<Call<Self>>
+ Into<<Self as frame_system::Config>::RuntimeCall>
+ Into<
<Self::Governance as traits::ReferendumTrait<
<Self as frame_system::Config>::AccountId,
>>::Call,
> + GetDispatchInfo;
pub trait Config: frame_system::Config<
RuntimeCall: Parameter
+ UnfilteredDispatchable<RuntimeOrigin = <Self as frame_system::Config>::RuntimeOrigin>
+ From<Call<Self>>
+ Into<
<Self::Governance as traits::ReferendumTrait<
<Self as frame_system::Config>::AccountId,
>>::Call,
> + GetDispatchInfo
>
{

) -> DispatchResult {
T::AdminOrigin::ensure_origin_or_root(origin.clone())?;
//let who = ensure_signed(origin)?;
Self::round_check()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really see the reason for writing the VotingRoundInfo of the new round in multiple step when there is only one possible way to initialize the VotingRoundInfo of a new round.

Let me explain, AFAICT register_projects_batch is the only way to start a new voting round. And what it does is:

  • fn round_check: if round index is 0 or if previous rounds has ended then start a new round with:
    • round_ending_block == round_starting_block
    • batch_submitted == false
    • time_periods == None
  • then it ensures batch_submitted is false and set it to true (regardless if the batch is empty or not)
  • then in this function body if there is at least one project it does: set round_ending_block to the correct value, and time_periods to some value.

So in conclusion if the batch is empty we have a session with batch_submitted == true but round_ending_block == round_starting_block and I don't else where in the code where we can actually setup the round. on_idle doesn't modify the round if round_ending_block == round_starting_block.

Maybe there is something I miss, or maybe you didn't intend to write batch_submitted = true when batch is empty. But something seems not good. If there is a use case for a 2 phase process then we should make it clearer in the type. (Or maybe I miss something)

Comment on lines 352 to 354
WhiteListedProjectAccounts::<T>::mutate(project_id, |value| {
*value = Some(new_infos);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
WhiteListedProjectAccounts::<T>::mutate(project_id, |value| {
*value = Some(new_infos);
});
WhiteListedProjectAccounts::<T>::insert(project_id, new_infos);

Comment on lines +582 to +584
WhiteListedProjectAccounts::<T>::mutate(project_id.clone(), |val| {
*val = Some(infos.clone())
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
WhiteListedProjectAccounts::<T>::mutate(project_id.clone(), |val| {
*val = Some(infos.clone())
});
WhiteListedProjectAccounts::<T>::insert(&project_id, &infos);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T2-pallets This PR/Issue is related to a particular pallet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants