Skip to content

Commit

Permalink
Committee can be smaller than CommitteeMembersCount neo-project/neo#2707
Browse files Browse the repository at this point in the history
 (#164)
  • Loading branch information
ixje authored Jun 27, 2022
1 parent 12bdc82 commit 2b4456f
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions neo3/contracts/native/fungible.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,17 +900,7 @@ def _compute_committee_members(self, snapshot: storage.Snapshot) -> Dict[cryptog
results.update({key: vm.BigInteger.zero()})
return results

# first remove blocked candidates
to_remove = []
policy = contracts.PolicyContract()
for c in candidates:
if policy.is_blocked(snapshot, to_script_hash(contracts.Contract.create_signature_redeemscript(c[0]))):
to_remove.append(c)

for c in to_remove:
candidates.remove(c)

# now sort by votes descending, then by ECPoint ascending
# sort by votes descending, then by ECPoint ascending
# we negate the value of the votes (c[1]) such that they get sorted in descending order
candidates.sort(key=lambda c: (-c[1], c[0]))
trimmed_candidates = candidates[:len(settings.standby_committee)]
Expand All @@ -923,9 +913,12 @@ def _get_candidates(self,
snapshot: storage.Snapshot) -> \
List[Tuple[cryptography.ECPoint, vm.BigInteger]]:
self._candidates = []
policy = contracts.PolicyContract()
for k, v in snapshot.storages.find(self.key_candidate.to_array()):
candidate = _CandidateState.deserialize_from_bytes(v.value)
if candidate.registered:
pubkey = cryptography.ECPoint.deserialize_from_bytes(k.value[1:])
candidate_hash = to_script_hash(contracts.Contract.create_signature_redeemscript(pubkey))
if candidate.registered and not policy.is_blocked(snapshot, candidate_hash):
# take of the CANDIDATE prefix
point = cryptography.ECPoint.deserialize_from_bytes(k.key[1:])
self._candidates.append((point, candidate.votes))
Expand Down

0 comments on commit 2b4456f

Please sign in to comment.