Skip to content

Commit

Permalink
Merge branch 'main' into optional-fellowship-switch
Browse files Browse the repository at this point in the history
  • Loading branch information
samelamin authored Dec 5, 2023
2 parents d0338a3 + eb0f559 commit 7978aa8
Show file tree
Hide file tree
Showing 18 changed files with 215 additions and 82 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build-on-self-hosted-runner
name: test-features
on:
workflow_dispatch:
push:
Expand Down Expand Up @@ -35,9 +35,9 @@ jobs:
ephemeral: true

test-features:
needs: create-runner
runs-on: ${{ needs.create-runner.outputs.label }}
steps:
needs: create-runner
runs-on: ${{ needs.create-runner.outputs.label }}
steps:
- uses: actions/checkout@v4

- name: Set HOME
Expand All @@ -50,16 +50,9 @@ jobs:
toolchain: nightly-2023-05-22
target: wasm32-unknown-unknown
override: true
components: rustfmt, clippy

- name: Install Dependencies
run: sudo apt install protobuf-compiler clang build-essential -y

- name: 🫠 rustfmt 🫠
uses: actions-rs/cargo@v1
with:
command: fmt
args: --check

- name: Run tests with benchmarks
run: cargo test --features runtime-benchmarks
37 changes: 37 additions & 0 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: cargo-fmt
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- "**.md"
pull_request:
branches:
- main
paths-ignore:
- "**.md"

jobs:
cargo-fmt:
runs-on: ${{ needs.create-runner.outputs.label }}
steps:
- uses: actions/checkout@v4

- name: Set HOME
run: echo "HOME=/home/ubuntu" >> ${GITHUB_ENV}

- name: Install minimal nightly Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2023-05-22
target: wasm32-unknown-unknown
override: true
components: rustfmt, clippy

- name: 🫠 rustfmt 🫠
uses: actions-rs/cargo@v1
with:
command: fmt
args: --check
6 changes: 3 additions & 3 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ async fn start_node_impl(
config: parachain_config,
keystore: params.keystore_container.keystore(),
backend,
network: network.clone(),
network,
sync_service: sync_service.clone(),
system_rpc_tx,
tx_handler_controller,
Expand Down Expand Up @@ -318,7 +318,7 @@ async fn start_node_impl(
&task_manager,
relay_chain_interface.clone(),
transaction_pool,
sync_service.clone(),
sync_service,
params.keystore_container.keystore(),
relay_chain_slot_duration,
para_id,
Expand Down Expand Up @@ -395,7 +395,7 @@ fn start_consensus(
client.clone(),
transaction_pool,
prometheus_registry,
telemetry.clone(),
telemetry,
);

let proposer = Proposer::new(proposer_factory);
Expand Down
5 changes: 5 additions & 0 deletions pallets/disputes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ pub mod pallet {
}
}

#[derive(Clone, Copy, PartialEq, Debug, Encode, Decode, TypeInfo)]
pub struct DisputeVotes<T> {
pub votes: T,
}

#[derive(Clone, Copy, PartialEq, Debug, Encode, Decode, TypeInfo)]
pub enum DisputeResult {
Success = 0,
Expand Down
1 change: 1 addition & 0 deletions pallets/fellowship/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub mod v0 {
weight = weight.saturating_add(T::DbWeight::get().reads_writes(2, 1));
} else {
log::warn!("Skipping v1, should be removed from Executive");
log::warn!("on_chain = {:?}, current = {:?}", onchain, current);
weight = weight.saturating_add(T::DbWeight::get().reads(1));
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/grants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub mod pallet {
);

let mut contributions = BTreeMap::new();
let _ = assigned_approvers.iter().for_each(|approver_id| {
assigned_approvers.iter().for_each(|approver_id| {
contributions.insert(
approver_id.clone(),
Contribution {
Expand Down
8 changes: 4 additions & 4 deletions pallets/grants/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ impl pallet_disputes::traits::DisputeRaiser<AccountId> for MockDisputeRaiser {
type MaxJurySize = MaxJuryMembers;
type MaxSpecifics = MaxMilestonesPerProject;
fn raise_dispute(
dispute_key: Self::DisputeKey,
raised_by: AccountId,
jury: BoundedVec<AccountId, Self::MaxJurySize>,
specific_ids: BoundedVec<Self::SpecificId, Self::MaxSpecifics>,
_dispute_key: Self::DisputeKey,
_raised_by: AccountId,
_jury: BoundedVec<AccountId, Self::MaxJurySize>,
_specific_ids: BoundedVec<Self::SpecificId, Self::MaxSpecifics>,
) -> Result<(), DispatchError> {
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/proposals/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ sp_api::decl_runtime_apis! {
where AccountId: codec::Codec + Ord,
{
fn get_project_account_by_id(project_id: u32) -> AccountId;
fn get_all_project_data(project_id: u32) -> Option<(Vec<u8>, Vec<u8>)>;
fn get_all_project_data(project_id: u32) -> (Option<Vec<u8>>, Option<Vec<u8>>, Option<Vec<u8>>, Vec<u32>);
}
}
10 changes: 8 additions & 2 deletions pallets/proposals/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ where
#[method(name = "proposals_getProjectKitty")]
fn project_account_id(&self, project_id: u32) -> RpcResult<AccountId>;
#[method(name = "proposals_getAllProjectData")]
fn all_project_data(&self, project_id: u32) -> RpcResult<Option<(Vec<u8>, Vec<u8>)>>;
fn all_project_data(
&self,
project_id: u32,
) -> RpcResult<(Option<Vec<u8>>, Option<Vec<u8>>, Option<Vec<u8>>, Vec<u32>)>;
}

pub struct Proposals<C, B> {
Expand Down Expand Up @@ -76,7 +79,10 @@ where
api.get_project_account_by_id(at, project_id)
.map_err(runtime_error_into_rpc_err)
}
fn all_project_data(&self, project_id: u32) -> RpcResult<Option<(Vec<u8>, Vec<u8>)>> {
fn all_project_data(
&self,
project_id: u32,
) -> RpcResult<(Option<Vec<u8>>, Option<Vec<u8>>, Option<Vec<u8>>, Vec<u32>)> {
let api = self.client.runtime_api();
let at = self.client.info().best_hash;

Expand Down
14 changes: 8 additions & 6 deletions pallets/proposals/src/impls/pallet_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ impl<T: Config> Pallet<T> {
Ok::<(), DispatchError>(())
})?;

ProjectInVoting::<T>::insert(project_key, milestone_key, ());

Self::deposit_event(Event::MilestoneSubmitted(who, project_key, milestone_key));
Self::deposit_event(Event::VotingRoundCreated(project_key));
Ok(().into())
Expand Down Expand Up @@ -306,25 +308,25 @@ impl<T: Config> Pallet<T> {
}

pub(crate) fn close_voting_round(
project_key: ProjectKey,
_project_key: ProjectKey,
user_has_voted_key: (ProjectKey, RoundType, MilestoneKey),
) -> Result<(), DispatchError> {
let (project_key, _round_type, milestone_key) = user_has_voted_key;
// Prevent further voting.
let exp_block =
Rounds::<T>::take((project_key, user_has_voted_key.2), RoundType::VotingRound)
.ok_or(Error::<T>::VotingRoundNotStarted)?;
let exp_block = Rounds::<T>::take((project_key, milestone_key), RoundType::VotingRound)
.ok_or(Error::<T>::VotingRoundNotStarted)?;
// Prevent hook from calling.
RoundsExpiring::<T>::remove(exp_block);
// Allow future votes to occur on this milestone
IndividualVoteStore::<T>::try_mutate(project_key, |maybe_individual_votes| {
if let Some(individual_votes) = maybe_individual_votes {
individual_votes.clear_milestone_votes(user_has_voted_key.2);
individual_votes.clear_milestone_votes(milestone_key);
} else {
return Err(Error::<T>::IndividualVoteNotFound.into());
}
Ok::<(), DispatchError>(())
})?;

ProjectInVoting::<T>::remove(project_key, milestone_key);
Ok(())
}
}
Expand Down
19 changes: 18 additions & 1 deletion pallets/proposals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub mod pallet {
type AssetSignerOrigin: EnsureOrigin<Self::RuntimeOrigin>;
}

const STORAGE_VERSION: StorageVersion = StorageVersion::new(6);
const STORAGE_VERSION: StorageVersion = StorageVersion::new(7);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
Expand Down Expand Up @@ -210,6 +210,8 @@ pub mod pallet {
ValueQuery,
>;

// TODO: Check if this is in use.
/// A helper to find what projects / milestones are in a dispute.
#[pallet::storage]
pub type ProjectsInDispute<T> = StorageMap<
_,
Expand All @@ -219,6 +221,19 @@ pub mod pallet {
ValueQuery,
>;

/// Projects in Voting round.
/// A helper for the runtime api so we dont have to iterate over the Rounds Double map.
#[pallet::storage]
pub type ProjectInVoting<T> = StorageDoubleMap<
_,
Blake2_128Concat,
ProjectKey,
Blake2_128Concat,
MilestoneKey,
(),
ValueQuery,
>;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
Expand Down Expand Up @@ -369,6 +384,8 @@ pub mod pallet {
individual_votes.clear_milestone_votes(*milestone_key);
}
});

ProjectInVoting::<T>::remove(project_key, milestone_key);
}
// Votes of no confidence do not finaliese automatically
RoundType::VoteOfNoConfidence => {
Expand Down
16 changes: 12 additions & 4 deletions pallets/proposals/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,8 @@ pub mod v7 {
let onchain = <Pallet<T> as GetStorageVersion>::on_chain_storage_version();

ensure!(
<T as Config>::MaxJuryMembers::get() < u8::MAX as u32,
<<T as Config>::JurySelector as SelectJury<AccountIdOf<T>>>::JurySize::get()
< u8::MAX as u32,
"Max jury members must be smaller than u8"
);

Expand Down Expand Up @@ -770,6 +771,9 @@ pub mod v7 {
#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
log::warn!( target: "pallet-proposals", "Running post_upgrade()");
Projects::<T>::iter().for_each(|(_k, project)| {
assert!(project.jury.len() > 0, "jury size must be > 0");
});

ensure!(
Pallet::<T>::current_storage_version() == 7,
Expand All @@ -793,8 +797,6 @@ pub mod v7 {
v5::FundingType::Grant(_) => crate::FundingPath::WaitForFunding,
};

let jury = <T::JurySelector as SelectJury<AccountIdOf<T>>>::select_jury();

let refund_locations: BoundedVec<(Locality<AccountIdOf<T>>, Percent), T::MaximumContributorsPerProject> = match project.funding_type {
v5::FundingType::Proposal => crate::Pallet::<T>::convert_contributions_to_refund_locations(&project.contributions),
v5::FundingType::Brief => crate::Pallet::<T>::convert_contributions_to_refund_locations(&project.contributions),
Expand All @@ -812,6 +814,12 @@ pub mod v7 {
},
};

let jury = match project.funding_type {
v5::FundingType::Grant(_) => project.contributions.keys().cloned().collect::<Vec<AccountIdOf<T>>>(),
v5::FundingType::Brief => <T::JurySelector as SelectJury<AccountIdOf<T>>>::select_jury().to_vec(),
_ => <T::JurySelector as SelectJury<AccountIdOf<T>>>::select_jury().to_vec(),
};

let mut new_milestones: BoundedBTreeMilestones<T> = BoundedBTreeMap::new();
project.milestones.iter().for_each(|(_ms_key, ms): (&MilestoneKey, &v6::V6Milestone)| {
// assume that if its approved then its been withdrawn.
Expand Down Expand Up @@ -844,7 +852,7 @@ pub mod v7 {
cancelled: project.cancelled,
deposit_id: project.deposit_id,
refund_locations,
jury,
jury: jury.try_into().expect("contributions bound is larger than jury bound, reduce contribution bound or increase jury bound."),
on_creation_funding,
refunded_funds: Zero::zero(),
};
Expand Down
5 changes: 3 additions & 2 deletions pallets/proposals/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::*;
use common_types::CurrencyId;
use frame_support::{assert_ok, BoundedVec};
use frame_support::BoundedVec;
use frame_system::EventRecord;
use orml_traits::{MultiCurrency, MultiReservableCurrency};
use orml_traits::MultiReservableCurrency;

use pallet_disputes::traits::DisputeHooks;
use sp_arithmetic::per_things::Percent;
Expand All @@ -13,6 +13,7 @@ use sp_std::convert::TryInto;

#[cfg(feature = "runtime-benchmarks")]
use frame_benchmarking::account;
use frame_support::assert_ok;
#[cfg(feature = "runtime-benchmarks")]
use sp_std::vec::Vec;

Expand Down
Loading

0 comments on commit 7978aa8

Please sign in to comment.