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

Rename committee to council #2155

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion src/neo/Consensus/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public void Reset(byte viewNumber)
PrevHash = Snapshot.CurrentBlockHash,
Index = Snapshot.Height + 1,
NextConsensus = Blockchain.GetConsensusAddress(
NativeContract.NEO.ShouldRefreshCommittee(Snapshot.Height + 1) ?
NativeContract.NEO.ShouldRefreshCouncil(Snapshot.Height + 1) ?
NativeContract.NEO.ComputeNextBlockValidators(Snapshot) :
NativeContract.NEO.GetNextBlockValidators(Snapshot))
};
Expand Down
4 changes: 2 additions & 2 deletions src/neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class RelayResult { public IInventory Inventory; public VerifyResult Resu

public static readonly uint MillisecondsPerBlock = ProtocolSettings.Default.MillisecondsPerBlock;
public static readonly TimeSpan TimePerBlock = TimeSpan.FromMilliseconds(MillisecondsPerBlock);
public static readonly ECPoint[] StandbyCommittee = ProtocolSettings.Default.StandbyCommittee.Select(p => ECPoint.DecodePoint(p.HexToBytes(), ECCurve.Secp256r1)).ToArray();
public static readonly ECPoint[] StandbyValidators = StandbyCommittee[0..ProtocolSettings.Default.ValidatorsCount];
public static readonly ECPoint[] StandbyCouncil = ProtocolSettings.Default.StandbyCouncil.Select(p => ECPoint.DecodePoint(p.HexToBytes(), ECCurve.Secp256r1)).ToArray();
public static readonly ECPoint[] StandbyValidators = StandbyCouncil[0..ProtocolSettings.Default.ValidatorsCount];

public static readonly Block GenesisBlock = new Block
{
Expand Down
4 changes: 2 additions & 2 deletions src/neo/Network/P2P/Payloads/HighPriorityAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ protected override void SerializeWithoutType(BinaryWriter writer)

public override bool Verify(StoreView snapshot, Transaction tx)
{
UInt160 committee = NativeContract.NEO.GetCommitteeAddress(snapshot);
return tx.Signers.Any(p => p.Account.Equals(committee));
UInt160 council = NativeContract.NEO.GetCouncilAddress(snapshot);
return tx.Signers.Any(p => p.Account.Equals(council));
}
}
}
2 changes: 1 addition & 1 deletion src/neo/Network/P2P/Payloads/Witness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Neo.Network.P2P.Payloads
public class Witness : ISerializable
{
/// <summary>
/// This is designed to allow a MultiSig 21/11 (committee)
/// This is designed to allow a MultiSig 21/11 (council)
/// Invocation = 11 * (64 + 2) = 726
/// </summary>
private const int MaxInvocationScript = 1024;
Expand Down
12 changes: 6 additions & 6 deletions src/neo/ProtocolSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class ProtocolSettings
{
public uint Magic { get; }
public byte AddressVersion { get; }
public string[] StandbyCommittee { get; }
public int CommitteeMembersCount { get; }
public string[] StandbyCouncil { get; }
public int CouncilMembersCount { get; }
public int ValidatorsCount { get; }
public string[] SeedList { get; }
public uint MillisecondsPerBlock { get; }
Expand Down Expand Up @@ -48,11 +48,11 @@ private ProtocolSettings(IConfigurationSection section)
{
this.Magic = section.GetValue("Magic", 0x4F454Eu);
this.AddressVersion = section.GetValue("AddressVersion", (byte)0x35);
IConfigurationSection section_sc = section.GetSection("StandbyCommittee");
IConfigurationSection section_sc = section.GetSection("StandbyCouncil");
if (section_sc.Exists())
this.StandbyCommittee = section_sc.GetChildren().Select(p => p.Get<string>()).ToArray();
this.StandbyCouncil = section_sc.GetChildren().Select(p => p.Get<string>()).ToArray();
else
this.StandbyCommittee = new[]
this.StandbyCouncil = new[]
{
//Validators
"03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c",
Expand All @@ -79,7 +79,7 @@ private ProtocolSettings(IConfigurationSection section)
"03cdcea66032b82f5c30450e381e5295cae85c5e6943af716cc6b646352a6067dc",
"02cd5a5547119e24feaa7c2a0f37b8c9366216bab7054de0065c9be42084003c8a"
};
this.CommitteeMembersCount = StandbyCommittee.Length;
this.CouncilMembersCount = StandbyCouncil.Length;
this.ValidatorsCount = section.GetValue("ValidatorsCount", (byte)7);
IConfigurationSection section_sl = section.GetSection("SeedList");
if (section_sl.Exists())
Expand Down
2 changes: 1 addition & 1 deletion src/neo/SmartContract/Native/DesignateContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void DesignateAsRole(ApplicationEngine engine, Role role, ECPoint[] node
throw new ArgumentException();
if (!Enum.IsDefined(typeof(Role), role))
throw new ArgumentOutOfRangeException(nameof(role));
if (!CheckCommittee(engine))
if (!CheckCouncil(engine))
throw new InvalidOperationException(nameof(DesignateAsRole));
if (engine.Snapshot.PersistingBlock is null)
throw new InvalidOperationException(nameof(DesignateAsRole));
Expand Down
2 changes: 1 addition & 1 deletion src/neo/SmartContract/Native/ManagementContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private long GetMinimumDeploymentFee(StoreView snapshot)
private void SetMinimumDeploymentFee(ApplicationEngine engine, BigInteger value)
{
if (value < 0) throw new ArgumentOutOfRangeException(nameof(value));
if (!CheckCommittee(engine)) throw new InvalidOperationException();
if (!CheckCouncil(engine)) throw new InvalidOperationException();
engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_MinimumDeploymentFee)).Set(value);
}

Expand Down
6 changes: 3 additions & 3 deletions src/neo/SmartContract/Native/NativeContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ protected NativeContract()
contractsHashDictionary.Add(Hash, this);
}

protected bool CheckCommittee(ApplicationEngine engine)
protected bool CheckCouncil(ApplicationEngine engine)
{
UInt160 committeeMultiSigAddr = NEO.GetCommitteeAddress(engine.Snapshot);
return engine.CheckWitnessInternal(committeeMultiSigAddr);
UInt160 councilMultiSigAddr = NEO.GetCouncilAddress(engine.Snapshot);
return engine.CheckWitnessInternal(councilMultiSigAddr);
}

private protected KeyBuilder CreateStorageKey(byte prefix)
Expand Down
94 changes: 47 additions & 47 deletions src/neo/SmartContract/Native/NeoToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public sealed class NeoToken : Nep17Token<NeoToken.NeoAccountState>

private const byte Prefix_VotersCount = 1;
private const byte Prefix_Candidate = 33;
private const byte Prefix_Committee = 14;
private const byte Prefix_Council = 14;
private const byte Prefix_GasPerBlock = 29;
private const byte Prefix_VoterRewardPerCommittee = 23;
private const byte Prefix_VoterRewardPerCouncil = 23;

private const byte NeoHolderRewardRatio = 10;
private const byte CommitteeRewardRatio = 10;
private const byte CouncilRewardRatio = 10;
private const byte VoterRewardRatio = 80;

internal NeoToken()
Expand Down Expand Up @@ -75,12 +75,12 @@ private BigInteger CalculateBonus(StoreView snapshot, ECPoint vote, BigInteger v
BigInteger neoHolderReward = CalculateNeoHolderReward(snapshot, value, start, end);
if (vote is null) return neoHolderReward;

byte[] border = CreateStorageKey(Prefix_VoterRewardPerCommittee).Add(vote).ToArray();
byte[] keyStart = CreateStorageKey(Prefix_VoterRewardPerCommittee).Add(vote).AddBigEndian(start).ToArray();
byte[] border = CreateStorageKey(Prefix_VoterRewardPerCouncil).Add(vote).ToArray();
byte[] keyStart = CreateStorageKey(Prefix_VoterRewardPerCouncil).Add(vote).AddBigEndian(start).ToArray();
(_, var item) = snapshot.Storages.FindRange(keyStart, border, SeekDirection.Backward).FirstOrDefault();
BigInteger startRewardPerNeo = item ?? BigInteger.Zero;

byte[] keyEnd = CreateStorageKey(Prefix_VoterRewardPerCommittee).Add(vote).AddBigEndian(end).ToArray();
byte[] keyEnd = CreateStorageKey(Prefix_VoterRewardPerCouncil).Add(vote).AddBigEndian(end).ToArray();
(_, item) = snapshot.Storages.FindRange(keyEnd, border, SeekDirection.Backward).FirstOrDefault();
BigInteger endRewardPerNeo = item ?? BigInteger.Zero;

Expand Down Expand Up @@ -110,18 +110,18 @@ private void CheckCandidate(StoreView snapshot, ECPoint pubkey, CandidateState c
{
if (!candidate.Registered && candidate.Votes.IsZero)
{
foreach (var (rewardKey, _) in snapshot.Storages.Find(CreateStorageKey(Prefix_VoterRewardPerCommittee).Add(pubkey).ToArray()).ToArray())
foreach (var (rewardKey, _) in snapshot.Storages.Find(CreateStorageKey(Prefix_VoterRewardPerCouncil).Add(pubkey).ToArray()).ToArray())
snapshot.Storages.Delete(rewardKey);
snapshot.Storages.Delete(CreateStorageKey(Prefix_Candidate).Add(pubkey));
}
}

public bool ShouldRefreshCommittee(uint height) => height % ProtocolSettings.Default.CommitteeMembersCount == 0;
public bool ShouldRefreshCouncil(uint height) => height % ProtocolSettings.Default.CouncilMembersCount == 0;

internal override void Initialize(ApplicationEngine engine)
{
var cachedCommittee = new CachedCommittee(Blockchain.StandbyCommittee.Select(p => (p, BigInteger.Zero)));
engine.Snapshot.Storages.Add(CreateStorageKey(Prefix_Committee), new StorageItem(cachedCommittee));
var cachedCouncil = new CachedCouncil(Blockchain.StandbyCouncil.Select(p => (p, BigInteger.Zero)));
engine.Snapshot.Storages.Add(CreateStorageKey(Prefix_Council), new StorageItem(cachedCouncil));
engine.Snapshot.Storages.Add(CreateStorageKey(Prefix_VotersCount), new StorageItem(new byte[0]));

// Initialize economic parameters
Expand All @@ -132,43 +132,43 @@ internal override void Initialize(ApplicationEngine engine)

internal override void OnPersist(ApplicationEngine engine)
{
// Set next committee
if (ShouldRefreshCommittee(engine.Snapshot.PersistingBlock.Index))
// Set next council
if (ShouldRefreshCouncil(engine.Snapshot.PersistingBlock.Index))
{
StorageItem storageItem = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_Committee));
var cachedCommittee = storageItem.GetInteroperable<CachedCommittee>();
cachedCommittee.Clear();
cachedCommittee.AddRange(ComputeCommitteeMembers(engine.Snapshot));
StorageItem storageItem = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_Council));
var cachedCouncil = storageItem.GetInteroperable<CachedCouncil>();
cachedCouncil.Clear();
cachedCouncil.AddRange(ComputeCouncilMembers(engine.Snapshot));
}
}

internal override void PostPersist(ApplicationEngine engine)
{
// Distribute GAS for committee
// Distribute GAS for council

int m = ProtocolSettings.Default.CommitteeMembersCount;
int m = ProtocolSettings.Default.CouncilMembersCount;
int n = ProtocolSettings.Default.ValidatorsCount;
int index = (int)(engine.Snapshot.PersistingBlock.Index % (uint)m);
var gasPerBlock = GetGasPerBlock(engine.Snapshot);
var committee = GetCommitteeFromCache(engine.Snapshot);
var pubkey = committee.ElementAt(index).PublicKey;
var council = GetCouncilFromCache(engine.Snapshot);
var pubkey = council.ElementAt(index).PublicKey;
var account = Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash();
GAS.Mint(engine, account, gasPerBlock * CommitteeRewardRatio / 100, false);
GAS.Mint(engine, account, gasPerBlock * CouncilRewardRatio / 100, false);

// Record the cumulative reward of the voters of committee
// Record the cumulative reward of the voters of council

if (ShouldRefreshCommittee(engine.Snapshot.PersistingBlock.Index))
if (ShouldRefreshCouncil(engine.Snapshot.PersistingBlock.Index))
{
BigInteger voterRewardOfEachCommittee = gasPerBlock * VoterRewardRatio * 100000000L * m / (m + n) / 100; // Zoom in 100000000 times, and the final calculation should be divided 100000000L
for (index = 0; index < committee.Count; index++)
BigInteger voterRewardOfEachCouncil = gasPerBlock * VoterRewardRatio * 100000000L * m / (m + n) / 100; // Zoom in 100000000 times, and the final calculation should be divided 100000000L
for (index = 0; index < council.Count; index++)
{
var member = committee.ElementAt(index);
var factor = index < n ? 2 : 1; // The `voter` rewards of validator will double than other committee's
var member = council.ElementAt(index);
var factor = index < n ? 2 : 1; // The `voter` rewards of validator will double than other council's
if (member.Votes > 0)
{
BigInteger voterSumRewardPerNEO = factor * voterRewardOfEachCommittee / member.Votes;
StorageKey voterRewardKey = CreateStorageKey(Prefix_VoterRewardPerCommittee).Add(member.PublicKey).AddBigEndian(engine.Snapshot.PersistingBlock.Index + 1);
byte[] border = CreateStorageKey(Prefix_VoterRewardPerCommittee).Add(member.PublicKey).ToArray();
BigInteger voterSumRewardPerNEO = factor * voterRewardOfEachCouncil / member.Votes;
StorageKey voterRewardKey = CreateStorageKey(Prefix_VoterRewardPerCouncil).Add(member.PublicKey).AddBigEndian(engine.Snapshot.PersistingBlock.Index + 1);
byte[] border = CreateStorageKey(Prefix_VoterRewardPerCouncil).Add(member.PublicKey).ToArray();
(_, var item) = engine.Snapshot.Storages.FindRange(voterRewardKey.ToArray(), border, SeekDirection.Backward).FirstOrDefault();
voterSumRewardPerNEO += (item ?? BigInteger.Zero);
engine.Snapshot.Storages.Add(voterRewardKey, new StorageItem(voterSumRewardPerNEO));
Expand All @@ -182,7 +182,7 @@ private bool SetGasPerBlock(ApplicationEngine engine, BigInteger gasPerBlock)
{
if (gasPerBlock < 0 || gasPerBlock > 10 * GAS.Factor)
throw new ArgumentOutOfRangeException(nameof(gasPerBlock));
if (!CheckCommittee(engine)) return false;
if (!CheckCouncil(engine)) return false;

uint index = engine.Snapshot.PersistingBlock.Index + 1;
StorageItem entry = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_GasPerBlock).AddBigEndian(index), () => new StorageItem(gasPerBlock));
Expand Down Expand Up @@ -289,41 +289,41 @@ private bool Vote(ApplicationEngine engine, UInt160 account, ECPoint voteTo)
}

[ContractMethod(1_00000000, CallFlags.ReadStates)]
public ECPoint[] GetCommittee(StoreView snapshot)
public ECPoint[] GetCouncil(StoreView snapshot)
{
return GetCommitteeFromCache(snapshot).Select(p => p.PublicKey).OrderBy(p => p).ToArray();
return GetCouncilFromCache(snapshot).Select(p => p.PublicKey).OrderBy(p => p).ToArray();
}

public UInt160 GetCommitteeAddress(StoreView snapshot)
public UInt160 GetCouncilAddress(StoreView snapshot)
{
ECPoint[] committees = GetCommittee(snapshot);
return Contract.CreateMultiSigRedeemScript(committees.Length - (committees.Length - 1) / 2, committees).ToScriptHash();
ECPoint[] councils = GetCouncil(snapshot);
return Contract.CreateMultiSigRedeemScript(councils.Length - (councils.Length - 1) / 2, councils).ToScriptHash();
}

private CachedCommittee GetCommitteeFromCache(StoreView snapshot)
private CachedCouncil GetCouncilFromCache(StoreView snapshot)
{
return snapshot.Storages[CreateStorageKey(Prefix_Committee)].GetInteroperable<CachedCommittee>();
return snapshot.Storages[CreateStorageKey(Prefix_Council)].GetInteroperable<CachedCouncil>();
}

internal ECPoint[] ComputeNextBlockValidators(StoreView snapshot)
{
return ComputeCommitteeMembers(snapshot).Select(p => p.PublicKey).Take(ProtocolSettings.Default.ValidatorsCount).OrderBy(p => p).ToArray();
return ComputeCouncilMembers(snapshot).Select(p => p.PublicKey).Take(ProtocolSettings.Default.ValidatorsCount).OrderBy(p => p).ToArray();
}

private IEnumerable<(ECPoint PublicKey, BigInteger Votes)> ComputeCommitteeMembers(StoreView snapshot)
private IEnumerable<(ECPoint PublicKey, BigInteger Votes)> ComputeCouncilMembers(StoreView snapshot)
{
decimal votersCount = (decimal)(BigInteger)snapshot.Storages[CreateStorageKey(Prefix_VotersCount)];
decimal voterTurnout = votersCount / (decimal)TotalAmount;
var candidates = GetCandidates(snapshot);
if (voterTurnout < EffectiveVoterTurnout || candidates.Length < ProtocolSettings.Default.CommitteeMembersCount)
return Blockchain.StandbyCommittee.Select(p => (p, candidates.FirstOrDefault(k => k.PublicKey.Equals(p)).Votes));
return candidates.OrderByDescending(p => p.Votes).ThenBy(p => p.PublicKey).Take(ProtocolSettings.Default.CommitteeMembersCount);
if (voterTurnout < EffectiveVoterTurnout || candidates.Length < ProtocolSettings.Default.CouncilMembersCount)
return Blockchain.StandbyCouncil.Select(p => (p, candidates.FirstOrDefault(k => k.PublicKey.Equals(p)).Votes));
return candidates.OrderByDescending(p => p.Votes).ThenBy(p => p.PublicKey).Take(ProtocolSettings.Default.CouncilMembersCount);
}

[ContractMethod(1_00000000, CallFlags.ReadStates)]
public ECPoint[] GetNextBlockValidators(StoreView snapshot)
{
return GetCommitteeFromCache(snapshot)
return GetCouncilFromCache(snapshot)
.Take(ProtocolSettings.Default.ValidatorsCount)
.Select(p => p.PublicKey)
.OrderBy(p => p)
Expand Down Expand Up @@ -370,13 +370,13 @@ public StackItem ToStackItem(ReferenceCounter referenceCounter)
}
}

public class CachedCommittee : List<(ECPoint PublicKey, BigInteger Votes)>, IInteroperable
public class CachedCouncil : List<(ECPoint PublicKey, BigInteger Votes)>, IInteroperable
{
public CachedCommittee()
public CachedCouncil()
{
}

public CachedCommittee(IEnumerable<(ECPoint PublicKey, BigInteger Votes)> collection) : base(collection)
public CachedCouncil(IEnumerable<(ECPoint PublicKey, BigInteger Votes)> collection) : base(collection)
{
}

Expand Down
Loading