Skip to content
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

bump substrate; handle removal of AccoundId32::default, add MaxEncodedLen support for some pallets #133

Merged
merged 20 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3a307f0
bump sp-runtime, sp-keyring to v4.1.0-dev
clangenb Jan 26, 2022
7e9e6a8
bump rust-toolchain: 2022-01-26
clangenb Jan 26, 2022
ecea8bb
cargo update
clangenb Jan 26, 2022
56e4e9d
[sybil-gate-template] change from `ValueQuery` to `OptionQuery` where…
clangenb Jan 26, 2022
1adadc0
[scheduler] change from `ValueQuery` to `OptionQuery` where needed
clangenb Jan 26, 2022
2d8e493
[communities] change from `ValueQuery` to `OptionQuery` where needed
clangenb Jan 27, 2022
edd26ef
update `GeoHash` to const generic version
clangenb Jan 27, 2022
7b765e7
[primitives] derive `MaxEncodedLen` for most types.
clangenb Jan 27, 2022
69cfb21
[bazaar] add `pallet::without_storage_info` because we can't satisfy …
clangenb Jan 27, 2022
4015131
[ceremonies] derive `MaxEncodedLen` for some stuff
clangenb Jan 27, 2022
b1e2734
[ceremonies] use OptionQuery where necessary
clangenb Jan 27, 2022
7070344
[ceremonies] add `pallet::without_storage_info` because we can't sati…
clangenb Jan 27, 2022
77aa933
[communities] incorporate GeoHash changes
clangenb Jan 27, 2022
a049013
fix tests compilation; issue_rewards test fails.
clangenb Jan 27, 2022
3d4f14a
[ceremonies] fix issue_rewards test.
clangenb Jan 27, 2022
1830113
[ceremonies] improve code readability
clangenb Jan 27, 2022
8dc7448
bump [email protected] and remove patches for it.
clangenb Jan 27, 2022
cefbeb6
bump [email protected] and remove patches for it.
clangenb Jan 27, 2022
5067faf
[ceremonies] better logs
clangenb Jan 27, 2022
066770d
fix rebase errors
clangenb Jan 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
619 changes: 329 additions & 290 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ members = [

#[patch."https://github.com/encointer/substrate-fixed"]
#substrate-fixed = { path = "../substrate-fixed"}
#
#[patch."https://github.com/encointer/typenum"]
#typenum = { path = "../typenum"}

#[patch."https://github.com/encointer/geohash"]
#geohash = { path = "../geohash"}
2 changes: 1 addition & 1 deletion balances/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ encointer-communities = { package = "pallet-encointer-communities", path = "../c
frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }
frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }
sp-std = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }
sp-runtime = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }
sp-runtime = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }

[dev-dependencies]
approx = "0.5.0"
Expand Down
2 changes: 1 addition & 1 deletion bazaar/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate
sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
1 change: 1 addition & 0 deletions bazaar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub mod pallet {

#[pallet::pallet]
#[pallet::generate_store(pub (super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);
Comment on lines +51 to 52
Copy link
Member Author

Choose a reason for hiding this comment

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

Substrate will make this forbidden in the future. By then, we need to have completely solved #132.


#[pallet::call]
Expand Down
2 changes: 1 addition & 1 deletion ceremonies/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ encointer-scheduler = { package = "pallet-encointer-scheduler", path = "../sched
frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }
frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }
pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }
sp-runtime = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }
sp-runtime = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }
sp-std = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion ceremonies/assignment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
encointer-primitives = { path = "../../primitives", default-features = false }

# substrate deps
sp-runtime = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }
sp-runtime = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }
sp-std = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "master" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion ceremonies/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate
sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { version = "4.1.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
93 changes: 64 additions & 29 deletions ceremonies/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub mod pallet {

#[pallet::pallet]
#[pallet::generate_store(pub (super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::config]
Expand Down Expand Up @@ -95,10 +96,11 @@ pub mod pallet {
reputable: T::AccountId,
) -> DispatchResultWithPostInfo {
let sender = ensure_signed(origin)?;
ensure!(
sender == <encointer_scheduler::Pallet<T>>::ceremony_master(),
Error::<T>::AuthorizationRequired
);

let master = <encointer_scheduler::Pallet<T>>::ceremony_master()
.ok_or(Error::<T>::AuthorizationRequired)?;
ensure!(sender == master, Error::<T>::AuthorizationRequired);

let cindex = <encointer_scheduler::Pallet<T>>::current_ceremony_index();
<ParticipantReputation<T>>::insert(
&(cid, cindex - 1),
Expand Down Expand Up @@ -459,7 +461,7 @@ pub mod pallet {
Blake2_128Concat,
ParticipantIndexType,
T::AccountId,
ValueQuery,
OptionQuery,
>;

#[pallet::storage]
Expand Down Expand Up @@ -488,7 +490,7 @@ pub mod pallet {
Blake2_128Concat,
ParticipantIndexType,
T::AccountId,
ValueQuery,
OptionQuery,
>;

#[pallet::storage]
Expand Down Expand Up @@ -517,7 +519,7 @@ pub mod pallet {
Blake2_128Concat,
ParticipantIndexType,
T::AccountId,
ValueQuery,
OptionQuery,
>;

#[pallet::storage]
Expand Down Expand Up @@ -546,7 +548,7 @@ pub mod pallet {
Blake2_128Concat,
ParticipantIndexType,
T::AccountId,
ValueQuery,
OptionQuery,
>;

#[pallet::storage]
Expand Down Expand Up @@ -619,7 +621,7 @@ pub mod pallet {
Blake2_128Concat,
AttestationIndexType,
Vec<T::AccountId>,
ValueQuery,
OptionQuery,
>;

#[pallet::storage]
Expand Down Expand Up @@ -1037,28 +1039,56 @@ impl<T: Config> Pallet<T> {
);
for p in bootstrappers_reputables {
if p < assigned.bootstrappers {
result.push(Self::bootstrapper_registry(community_ceremony, &(p + 1))); //safe; small number per meetup
//safe; small number per meetup
match Self::bootstrapper_registry(community_ceremony, &(p + 1)) {
Some(bs) => result.push(bs),
None => error!(
target: LOG,
"[Ceremonies::get_meetup_participants] Bootstrapper not found!!"
),
}
} else if p < assigned.bootstrappers + assigned.reputables {
result.push(Self::reputable_registry(
//safe; small number per meetup
match Self::reputable_registry(
community_ceremony,
&(p - assigned.bootstrappers + 1), //safe; small number per meetup
));
&(p - assigned.bootstrappers + 1),
) {
Some(r) => result.push(r),
None => error!(
target: LOG,
"[Ceremonies::get_meetup_participants] Reputable not found!!"
),
};
}
}

let endorsees =
assignment_fn_inverse(meetup_index, params.endorsees, meetup_count, assigned.endorsees);
for p in endorsees {
if p < assigned.endorsees {
result.push(Self::endorsee_registry(community_ceremony, &(p + 1))); //safe; <= number of meetup participants
//safe; small number per meetup
match Self::endorsee_registry(community_ceremony, &(p + 1)) {
Some(e) => result.push(e),
None => error!(
target: LOG,
"[Ceremonies::get_meetup_participants] Endorsee not found!!"
),
};
}
}

let newbies =
assignment_fn_inverse(meetup_index, params.newbies, meetup_count, assigned.newbies);
for p in newbies {
if p < assigned.newbies {
result.push(Self::newbie_registry(community_ceremony, &(p + 1))); //safe; <= number of meetup participants
//safe; small number per meetup
match Self::newbie_registry(community_ceremony, &(p + 1)) {
Some(n) => result.push(n),
None => error!(
target: LOG,
"[Ceremonies::get_meetup_participants] Newbie not found!!"
),
};
}
}

Expand Down Expand Up @@ -1110,30 +1140,35 @@ impl<T: Config> Pallet<T> {
);
continue
}
let attestees = Self::attestation_registry(

match Self::attestation_registry(
(cid, cindex),
&Self::attestation_index((*cid, cindex), &participant),
);
if attestees.len() < (n_honest_participants - 1) as usize {
debug!(
target: LOG,
"skipped participant because didn't testify for honest peers: {:?}",
participant
);
continue
}
) {
Some(attestees) =>
if attestees.len() < (n_honest_participants - 1) as usize {
debug!(
target: LOG,
"skipped participant because didn't testify for honest peers: {:?}",
participant
);
continue
},
None => continue,
};

let mut was_attested_count = 0u32;
for other_participant in &meetup_participants {
if other_participant == participant {
continue
}
let attestees_from_other = Self::attestation_registry(
if let Some(attestees_from_other) = Self::attestation_registry(
(cid, cindex),
&Self::attestation_index((cid, cindex), &other_participant),
);
if attestees_from_other.contains(&participant) {
was_attested_count += 1; // <= number of meetup participants
) {
if attestees_from_other.contains(&participant) {
was_attested_count += 1; // <= number of meetup participants
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions ceremonies/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ impl_encointer_balances!(TestRuntime);
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<TestRuntime>().unwrap();
encointer_communities::GenesisConfig::<TestRuntime> {
community_master: AccountId::from(AccountKeyring::Alice),
community_master: Some(AccountKeyring::Alice.to_account_id()),
}
.assimilate_storage(&mut t)
.unwrap();
encointer_scheduler::GenesisConfig::<TestRuntime> {
current_phase: CeremonyPhaseType::REGISTERING,
current_ceremony_index: 1,
ceremony_master: AccountId::from(AccountKeyring::Alice),
ceremony_master: Some(AccountKeyring::Alice.to_account_id()),
phase_durations: vec![
(CeremonyPhaseType::REGISTERING, ONE_DAY),
(CeremonyPhaseType::ASSIGNING, ONE_DAY),
Expand Down
40 changes: 20 additions & 20 deletions ceremonies/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ fn registering_participant_works() {
assert_eq!(EncointerCeremonies::bootstrapper_count((cid, cindex)), 2);

assert_eq!(EncointerCeremonies::bootstrapper_index((cid, cindex), &bob), 2);
assert_eq!(EncointerCeremonies::bootstrapper_registry((cid, cindex), &1), alice);
assert_eq!(EncointerCeremonies::bootstrapper_registry((cid, cindex), &2), bob);
assert_eq!(EncointerCeremonies::bootstrapper_registry((cid, cindex), &1).unwrap(), alice);
assert_eq!(EncointerCeremonies::bootstrapper_registry((cid, cindex), &2).unwrap(), bob);

let newbies = add_population(2, 2);
let newbie_1 = account_id(&newbies[0]);
Expand All @@ -329,10 +329,10 @@ fn registering_participant_works() {
assert_ok!(register(newbie_2.clone(), cid, None));
assert_eq!(EncointerCeremonies::newbie_count((cid, cindex)), 2);
assert_eq!(EncointerCeremonies::newbie_index((cid, cindex), &newbie_1), 1);
assert_eq!(EncointerCeremonies::newbie_registry((cid, cindex), &1), newbie_1);
assert_eq!(EncointerCeremonies::newbie_registry((cid, cindex), &1).unwrap(), newbie_1);

assert_eq!(EncointerCeremonies::newbie_index((cid, cindex), &newbie_2), 2);
assert_eq!(EncointerCeremonies::newbie_registry((cid, cindex), &2), newbie_2);
assert_eq!(EncointerCeremonies::newbie_registry((cid, cindex), &2).unwrap(), newbie_2);

let newbies = add_population(2, 4);
let endorsee_1 = account_id(&newbies[0]);
Expand All @@ -359,10 +359,10 @@ fn registering_participant_works() {
assert_eq!(EncointerCeremonies::bootstrapper_count((cid, cindex)), 2);

assert_eq!(EncointerCeremonies::endorsee_index((cid, cindex), &endorsee_1), 1);
assert_eq!(EncointerCeremonies::endorsee_registry((cid, cindex), &1), endorsee_1);
assert_eq!(EncointerCeremonies::endorsee_registry((cid, cindex), &1).unwrap(), endorsee_1);

assert_eq!(EncointerCeremonies::endorsee_index((cid, cindex), &endorsee_2), 2);
assert_eq!(EncointerCeremonies::endorsee_registry((cid, cindex), &2), endorsee_2);
assert_eq!(EncointerCeremonies::endorsee_registry((cid, cindex), &2).unwrap(), endorsee_2);

// Registering Reputables is tested in grow_population_works.
});
Expand Down Expand Up @@ -412,7 +412,7 @@ fn attest_claims_works() {

assert_eq!(EncointerCeremonies::attestation_count((cid, cindex)), 2);
assert_eq!(EncointerCeremonies::attestation_index((cid, cindex), &account_id(&bob)), 2);
let wit_vec = EncointerCeremonies::attestation_registry((cid, cindex), &2);
let wit_vec = EncointerCeremonies::attestation_registry((cid, cindex), &2).unwrap();
assert!(wit_vec.len() == 2);
assert!(wit_vec.contains(&account_id(&alice)));
assert!(wit_vec.contains(&account_id(&ferdie)));
Expand Down Expand Up @@ -446,7 +446,7 @@ fn attest_claims_for_non_participant_fails_silently() {
3,
);
assert_eq!(EncointerCeremonies::attestation_count((cid, cindex)), 1);
let wit_vec = EncointerCeremonies::attestation_registry((cid, cindex), &1);
let wit_vec = EncointerCeremonies::attestation_registry((cid, cindex), &1).unwrap();
assert!(wit_vec.contains(&account_id(&alice)) == false);
assert!(wit_vec.len() == 1);
});
Expand Down Expand Up @@ -500,7 +500,7 @@ fn attest_claims_with_non_participant_fails_silently() {
3,
);
assert_eq!(EncointerCeremonies::attestation_count((cid, cindex)), 1);
let wit_vec = EncointerCeremonies::attestation_registry((cid, cindex), &1);
let wit_vec = EncointerCeremonies::attestation_registry((cid, cindex), &1).unwrap();
assert!(wit_vec.contains(&account_id(&eve)) == false);
assert!(wit_vec.len() == 1);
});
Expand Down Expand Up @@ -537,7 +537,7 @@ fn attest_claims_with_wrong_meetup_index_fails() {
Origin::signed(account_id(&alice)),
alice_claims
));
let attestees = EncointerCeremonies::attestation_registry((cid, cindex), &1);
let attestees = EncointerCeremonies::attestation_registry((cid, cindex), &1).unwrap();
assert!(attestees.contains(&account_id(&ferdie)) == false);
assert!(attestees.len() == 1);
});
Expand Down Expand Up @@ -574,7 +574,7 @@ fn attest_claims_with_wrong_ceremony_index_fails() {
Origin::signed(account_id(&alice)),
alice_attestations
));
let wit_vec = EncointerCeremonies::attestation_registry((cid, cindex), &1);
let wit_vec = EncointerCeremonies::attestation_registry((cid, cindex), &1).unwrap();
assert!(wit_vec.contains(&account_id(&ferdie)) == false);
assert!(wit_vec.len() == 1);
});
Expand Down Expand Up @@ -604,7 +604,7 @@ fn attest_claims_with_wrong_timestamp_fails() {
)
.is_err());
let wit_vec = EncointerCeremonies::attestation_registry((cid, cindex), &1);
assert!(wit_vec.len() == 0);
assert!(wit_vec.is_none());
});
}

Expand Down Expand Up @@ -634,7 +634,7 @@ fn attest_claims_with_wrong_location_fails() {
)
.is_err());
let wit_vec = EncointerCeremonies::attestation_registry((cid, cindex), &1);
assert!(wit_vec.len() == 0);
assert!(wit_vec.is_none());
});
}

Expand Down Expand Up @@ -1097,15 +1097,18 @@ fn ceremony_index_and_purging_registry_works() {
let reputation_lifetime = <TestRuntime as Config>::ReputationLifetime::get();

assert_ok!(register(alice.clone(), cid, None));
assert_eq!(EncointerCeremonies::bootstrapper_registry((cid, cindex), &1), alice);
assert_eq!(EncointerCeremonies::bootstrapper_registry((cid, cindex), &1).unwrap(), alice);

for _ in 0..reputation_lifetime {
run_to_next_phase();
run_to_next_phase();
run_to_next_phase();

// still not purged
assert_eq!(EncointerCeremonies::bootstrapper_registry((cid, cindex), &1), alice);
assert_eq!(
EncointerCeremonies::bootstrapper_registry((cid, cindex), &1).unwrap(),
alice
);
}

// only after n=ReputationLifetimes cycles everything should be purged
Expand All @@ -1117,11 +1120,8 @@ fn ceremony_index_and_purging_registry_works() {
let new_cindex = EncointerScheduler::current_ceremony_index();
assert_eq!(new_cindex, cindex + reputation_lifetime + 1);
assert_eq!(EncointerCeremonies::bootstrapper_count((cid, cindex)), 0);
assert_eq!(
EncointerCeremonies::bootstrapper_registry((cid, cindex), &1),
AccountId::default()
);
assert_eq!(EncointerCeremonies::bootstrapper_index((cid, cindex), &alice), NONE);
assert_eq!(EncointerCeremonies::bootstrapper_registry((cid, cindex), &1), None);
assert_eq!(EncointerCeremonies::bootstrapper_index((cid, cindex), &alice), 0);
});
}

Expand Down
Loading