/// <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.CleanFinishedPollsLocked(); } this.logger.LogDebug("Vote was scheduled with key: {0}.", votingData.Key); }
/// <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 RevertChange(VotingData data) { switch (data.Key) { case VoteKey.AddFederationMember: this.RemoveFederationMember(data.Data); break; case VoteKey.KickFederationMember: this.AddFederationMember(data.Data); break; case VoteKey.WhitelistHash: this.RemoveHash(data.Data); break; case VoteKey.RemoveHash: this.AddHash(data.Data); break; } }
public VotingDataModel(VotingData votingData) { this.Key = votingData.Key.ToString(); this.Hash = (new uint256(votingData.Data)).ToString(); }