private bool IsVotingOnMultisigMember(VotingData votingData) { IFederationMember member = GetMemberVotedOn(votingData); // Ignore votes on multisig-members. return(member != null && this.federationManager.IsMultisigMember(member.PubKey)); }
public Poll GetPendingPollByVotingData(VotingData votingData) { if (this.pendingPollsByVotingData.TryGetValue(votingData, out Poll poll)) { // The poll should no longer be in this collection if its not pending. Guard.Assert(poll.IsPending); return(poll); } return(null); }
/// <summary>Schedules a vote for the next time when the block will be mined.</summary> /// <exception cref="InvalidOperationException">Thrown in case caller is not a federation member.</exception> public void ScheduleVote(VotingData votingData) { if (!this.federationManager.IsFederationMember) { this.logger.LogTrace("(-)[NOT_FED_MEMBER]"); throw new InvalidOperationException("Not a federation member!"); } lock (this.locker) { this.scheduledVotingData.Add(votingData); } }
/// <inheritdoc /> public void RevertChange(VotingData data) { switch (data.Key) { case VoteKey.AddFederationMember: this.RemoveFederationMember(data.Data); break; case VoteKey.KickFederationMember: this.AddFederationMember(data.Data); break; } }
public IFederationMember GetMemberVotedOn(VotingData votingData) { if (votingData.Key != VoteKey.AddFederationMember && votingData.Key != VoteKey.KickFederationMember) { return(null); } if (!(this.network.Consensus.ConsensusFactory is PoAConsensusFactory poaConsensusFactory)) { return(null); } return(poaConsensusFactory.DeserializeFederationMember(votingData.Data)); }
/// <summary>Schedules a vote for the next time when the block will be mined.</summary> /// <exception cref="InvalidOperationException">Thrown in case caller is not a federation member.</exception> public void ScheduleVote(VotingData votingData) { this.EnsureInitialized(); if (!this.federationManager.IsFederationMember) { this.logger.LogTrace("(-)[NOT_FED_MEMBER]"); throw new InvalidOperationException("Not a federation member!"); } lock (this.locker) { this.scheduledVotingData.Add(votingData); } this.logger.LogDebug("Vote was scheduled with key: {0}.", votingData.Key); }
private bool IsVotingOnMultisigMember(VotingData votingData) { if (votingData.Key != VoteKey.AddFederationMember && votingData.Key != VoteKey.KickFederationMember) { return(false); } if (!(this.network.Consensus.ConsensusFactory is PoAConsensusFactory poaConsensusFactory)) { return(false); } IFederationMember member = poaConsensusFactory.DeserializeFederationMember(votingData.Data); // Ignore votes on multisig-members. return(FederationVotingController.IsMultisigMember(this.network, member.PubKey)); }
/// <inheritdoc /> public string ConvertToString(VotingData data) { string action = $"Action:'{data.Key}'"; switch (data.Key) { case VoteKey.AddFederationMember: case VoteKey.KickFederationMember: IFederationMember federationMember = this.consensusFactory.DeserializeFederationMember(data.Data); return($"{action},FederationMember:'{federationMember}'"); case VoteKey.WhitelistHash: case VoteKey.RemoveHash: var hash = new uint256(data.Data); return($"{action},Hash:'{hash}'"); } return("unknown (not supported voting data key)"); }
/// <summary>Checks pending polls against finished polls and removes pending polls that will make no difference and basically are redundant.</summary> /// <remarks>All access should be protected by <see cref="locker"/>.</remarks> private void CleanFinishedPollsLocked() { // We take polls that are not pending (collected enough votes in favor) but not executed yet (maxReorg blocks // didn't pass since the vote that made the poll pass). We can't just take not pending polls because of the // following scenario: federation adds a hash or fed member or does any other revertable action, then reverts // the action (removes the hash) and then reapplies it again. To allow for this scenario we have to exclude // executed polls here. List <Poll> finishedPolls = this.polls.Where(x => !x.IsPending && !x.IsExecuted).ToList(); for (int i = this.scheduledVotingData.Count - 1; i >= 0; i--) { VotingData currentScheduledData = this.scheduledVotingData[i]; // Remove scheduled voting data that can be found in finished polls that were not yet executed. if (finishedPolls.Any(x => x.VotingData == currentScheduledData)) { this.scheduledVotingData.RemoveAt(i); } } }
/// <inheritdoc /> public void ApplyChange(VotingData data) { switch (data.Key) { case VoteKey.AddFederationMember: this.AddFederationMember(data.Data); break; case VoteKey.KickFederationMember: this.RemoveFederationMember(data.Data); break; case VoteKey.WhitelistHash: this.AddHash(data.Data); break; case VoteKey.RemoveHash: this.RemoveHash(data.Data); break; } }
public VotingDataModel(VotingData votingData) { this.Key = votingData.Key.ToString(); this.Hash = (new uint256(votingData.Data)).ToString(); }