Skip to content

Commit 7ab385c

Browse files
author
Joshua Mir
committed
fixed attestation registration
- known issue: all attestations in a given block get assigned to the same attestors
1 parent b80a662 commit 7ab385c

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

pallet-datdot/src/lib.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ decl_module!{
443443

444444

445445
native::info!("submitProof; challengeIndex: {:#?}", challenge_index);
446-
let challenge_attestors = Self::get_attestors_for(challenge_index);
446+
let mut challenge_attestors = Self::get_attestors_for(challenge_index);
447+
native::info!("submitProof; challengeAttestors: {:#?}", challenge_attestors);
447448
<ChallengeAttestors>::insert(&challenge_index, &challenge_attestors);
448449
Self::deposit_event(RawEvent::AttestPhase(challenge_index, challenge_attestors));
449450
Self::clear_challenge(account, challenge_index);
@@ -544,31 +545,22 @@ decl_module!{
544545
fn register_attestor(origin){
545546
let account = ensure_signed(origin)?;
546547
let mut att_count = <AttestorsCount>::get();
547-
let last = att_count.last();
548-
match last {
549-
Some(last_index) => {
550-
let user_index_option = att_count.pop();
551-
let current_user_index = match user_index_option {
552-
Some(x) => x,
553-
None => 0,
554-
};
555-
match current_user_index.checked_add(1){
556-
Some(i) => {
557-
<Attestors<T>>::insert(&i, &account);
558-
let mut atts = <AttestorsCount>::get();
559-
atts.push(i);
560-
<AttestorsCount>::put(atts);
561-
<ActiveAttestors>::mutate(|mut att_vec|{
562-
att_vec.push(i);
563-
att_vec.sort_unstable();
564-
att_vec.dedup();
565-
});
566-
},
567-
None => (),
568-
}
569-
},
570-
None => (),
571-
}
548+
let user_index_option = att_count.pop();
549+
let current_user_index = match user_index_option {
550+
Some(x) => x,
551+
None => 0,
552+
};
553+
let i = current_user_index.saturating_add(1);
554+
<Attestors<T>>::insert(&i, &account);
555+
let mut atts = <AttestorsCount>::get();
556+
atts.push(i);
557+
<AttestorsCount>::put(atts);
558+
let mut att_vec = <ActiveAttestors>::get();
559+
att_vec.push(i);
560+
att_vec.sort_unstable();
561+
att_vec.dedup();
562+
native::info!("registerAttestor; att_vec: {:#?}", att_vec);
563+
<ActiveAttestors>::put(att_vec);
572564
}
573565

574566
#[weight = 10000]
@@ -787,6 +779,9 @@ decl_module!{
787779
MINIMUM_WEIGHT
788780
}
789781
*/ //some bug here, on_initialize breaks
782+
// consider turning this into a schedulable
783+
// "anyone calls" function (verify_challenges),
784+
// like submit_scheduled_challenge
790785
fn on_finalize(n: T::BlockNumber) {
791786
for (challenge_index, user_index) in <ChallengeMap>::iter() {
792787
let user = <SelectedUsers<T>>::get(user_index);
@@ -829,8 +824,11 @@ impl<T: Trait> Module<T> {
829824
if attestors.expected_attestors.len() > 0{
830825
return attestors
831826
} else {
827+
let mut expected_attestors = Self::get_random_attestors();
828+
expected_attestors.sort_unstable();
829+
expected_attestors.dedup();
832830
return ChallengeAttestations {
833-
expected_attestors: Self::get_random_attestors(),
831+
expected_attestors: expected_attestors,
834832
expected_friends: attestors.expected_friends,
835833
completed: attestors.completed,
836834
}
@@ -985,6 +983,7 @@ impl<T: Trait> Module<T> {
985983
for attestor in (0..T::AttestorsPerChallenge::get()).map(pick_attestor){
986984
random_select.push(*attestor);
987985
}
986+
<Nonce>::put(nonce+1);
988987
random_select
989988
},
990989
}

0 commit comments

Comments
 (0)