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

Vote for committee #1491

Merged
merged 15 commits into from
Apr 15, 2020
8 changes: 4 additions & 4 deletions src/neo/Consensus/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ public void Deserialize(BinaryReader reader)
ViewNumber = reader.ReadByte();
TransactionHashes = reader.ReadSerializableArray<UInt256>();
Transaction[] transactions = reader.ReadSerializableArray<Transaction>(Block.MaxTransactionsPerBlock);
PreparationPayloads = reader.ReadNullableArray<ConsensusPayload>(Blockchain.MaxValidators);
CommitPayloads = reader.ReadNullableArray<ConsensusPayload>(Blockchain.MaxValidators);
ChangeViewPayloads = reader.ReadNullableArray<ConsensusPayload>(Blockchain.MaxValidators);
LastChangeViewPayloads = reader.ReadNullableArray<ConsensusPayload>(Blockchain.MaxValidators);
PreparationPayloads = reader.ReadNullableArray<ConsensusPayload>(Blockchain.ValidatorsCount);
CommitPayloads = reader.ReadNullableArray<ConsensusPayload>(Blockchain.ValidatorsCount);
ChangeViewPayloads = reader.ReadNullableArray<ConsensusPayload>(Blockchain.ValidatorsCount);
LastChangeViewPayloads = reader.ReadNullableArray<ConsensusPayload>(Blockchain.ValidatorsCount);
if (TransactionHashes.Length == 0 && !RequestSentOrReceived)
TransactionHashes = null;
Transactions = transactions.Length == 0 && !RequestSentOrReceived ? null : transactions.ToDictionary(p => p.Hash);
Expand Down
6 changes: 3 additions & 3 deletions src/neo/Consensus/RecoveryMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public RecoveryMessage() : base(ConsensusMessageType.RecoveryMessage)
public override void Deserialize(BinaryReader reader)
{
base.Deserialize(reader);
ChangeViewMessages = reader.ReadSerializableArray<ChangeViewPayloadCompact>(Blockchain.MaxValidators).ToDictionary(p => (int)p.ValidatorIndex);
ChangeViewMessages = reader.ReadSerializableArray<ChangeViewPayloadCompact>(Blockchain.ValidatorsCount).ToDictionary(p => (int)p.ValidatorIndex);
if (reader.ReadBoolean())
PrepareRequestMessage = reader.ReadSerializable<PrepareRequest>();
else
Expand All @@ -42,8 +42,8 @@ public override void Deserialize(BinaryReader reader)
PreparationHash = new UInt256(reader.ReadFixedBytes(preparationHashSize));
}

PreparationMessages = reader.ReadSerializableArray<PreparationPayloadCompact>(Blockchain.MaxValidators).ToDictionary(p => (int)p.ValidatorIndex);
CommitMessages = reader.ReadSerializableArray<CommitPayloadCompact>(Blockchain.MaxValidators).ToDictionary(p => (int)p.ValidatorIndex);
PreparationMessages = reader.ReadSerializableArray<PreparationPayloadCompact>(Blockchain.ValidatorsCount).ToDictionary(p => (int)p.ValidatorIndex);
CommitMessages = reader.ReadSerializableArray<CommitPayloadCompact>(Blockchain.ValidatorsCount).ToDictionary(p => (int)p.ValidatorIndex);
}

internal ConsensusPayload[] GetChangeViewPayloads(ConsensusContext context, ConsensusPayload payload)
Expand Down
52 changes: 0 additions & 52 deletions src/neo/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,57 +258,5 @@ internal static IPEndPoint Unmap(this IPEndPoint endPoint)
return endPoint;
return new IPEndPoint(endPoint.Address.Unmap(), endPoint.Port);
}

internal static BigInteger WeightedAverage<T>(this IEnumerable<T> source, Func<T, BigInteger> valueSelector, Func<T, BigInteger> weightSelector)
{
BigInteger sum_weight = BigInteger.Zero;
BigInteger sum_value = BigInteger.Zero;
foreach (T item in source)
{
BigInteger weight = weightSelector(item);
sum_weight += weight;
sum_value += valueSelector(item) * weight;
}
if (sum_value == BigInteger.Zero) return BigInteger.Zero;
return sum_value / sum_weight;
}

internal static IEnumerable<TResult> WeightedFilter<T, TResult>(this IList<T> source, double start, double end, Func<T, BigInteger> weightSelector, Func<T, BigInteger, TResult> resultSelector)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (start < 0 || start > 1) throw new ArgumentOutOfRangeException(nameof(start));
if (end < start || start + end > 1) throw new ArgumentOutOfRangeException(nameof(end));
if (weightSelector == null) throw new ArgumentNullException(nameof(weightSelector));
if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));
if (source.Count == 0 || start == end) yield break;
double amount = (double)source.Select(weightSelector).Sum();
BigInteger sum = 0;
double current = 0;
foreach (T item in source)
{
if (current >= end) break;
BigInteger weight = weightSelector(item);
sum += weight;
double old = current;
current = (double)sum / amount;
if (current <= start) continue;
if (old < start)
{
if (current > end)
{
weight = (long)((end - start) * amount);
}
else
{
weight = (long)((current - start) * amount);
}
}
else if (current > end)
{
weight = (long)((end - old) * amount);
}
yield return resultSelector(item, weight);
}
}
}
}
7 changes: 4 additions & 3 deletions src/neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Neo.Ledger
{
Expand All @@ -30,10 +29,12 @@ public class FillCompleted { }

public static readonly uint MillisecondsPerBlock = ProtocolSettings.Default.MillisecondsPerBlock;
public const uint DecrementInterval = 2000000;
public const int MaxValidators = 1024;
public static readonly uint[] GenerationAmount = { 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
public static readonly TimeSpan TimePerBlock = TimeSpan.FromMilliseconds(MillisecondsPerBlock);
public static readonly ECPoint[] StandbyValidators = ProtocolSettings.Default.StandbyValidators.OfType<string>().Select(p => ECPoint.DecodePoint(p.HexToBytes(), ECCurve.Secp256r1)).ToArray();
public static readonly byte CommitteeMembersCount = (byte)ProtocolSettings.Default.StandbyCommittee.Length;
public static readonly byte ValidatorsCount = ProtocolSettings.Default.ValidatorsCount;
public static readonly ECPoint[] StandbyCommittee = ProtocolSettings.Default.StandbyCommittee.Select(p => ECPoint.DecodePoint(p.HexToBytes(), ECCurve.Secp256r1)).ToArray();
public static readonly ECPoint[] StandbyValidators = StandbyCommittee[..ValidatorsCount];

public static readonly Block GenesisBlock = new Block
{
Expand Down
2 changes: 1 addition & 1 deletion src/neo/Network/P2P/Payloads/ConsensusData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public UInt256 Hash

void ISerializable.Deserialize(BinaryReader reader)
{
PrimaryIndex = (uint)reader.ReadVarInt(Blockchain.MaxValidators - 1);
PrimaryIndex = (uint)reader.ReadVarInt((ulong)Blockchain.ValidatorsCount - 1);
Nonce = reader.ReadUInt64();
}

Expand Down
27 changes: 23 additions & 4 deletions src/neo/ProtocolSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class ProtocolSettings
{
public uint Magic { get; }
public byte AddressVersion { get; }
public string[] StandbyValidators { get; }
public string[] StandbyCommittee { get; }
public byte ValidatorsCount { get; }
public string[] SeedList { get; }
public uint MillisecondsPerBlock { get; }
public int MemoryPoolMaxTransactions { get; }
Expand Down Expand Up @@ -47,18 +48,36 @@ private ProtocolSettings(IConfigurationSection section)
this.AddressVersion = section.GetValue("AddressVersion", (byte)0x35);
IConfigurationSection section_sv = section.GetSection("StandbyValidators");
if (section_sv.Exists())
this.StandbyValidators = section_sv.GetChildren().Select(p => p.Get<string>()).ToArray();
this.StandbyCommittee = section_sv.GetChildren().Select(p => p.Get<string>()).ToArray();
else
this.StandbyValidators = new[]
this.StandbyCommittee = new[]
{
//Validators
"03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c",
"02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093",
"03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a",
"02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554",
"024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d",
"02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e",
"02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70"
"02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70",

//Other Members
"023a36c72844610b4d34d1968662424011bf783ca9d984efa19a20babf5582f3fe",
"03708b860c1de5d87f5b151a12c2a99feebd2e8b315ee8e7cf8aa19692a9e18379",
"03c6aa6e12638b36e88adc1ccdceac4db9929575c3e03576c617c49cce7114a050",
"03204223f8c86b8cd5c89ef12e4f0dbb314172e9241e30c9ef2293790793537cf0",
"02a62c915cf19c7f19a50ec217e79fac2439bbaad658493de0c7d8ffa92ab0aa62",
"03409f31f0d66bdc2f70a9730b66fe186658f84a8018204db01c106edc36553cd0",
"0288342b141c30dc8ffcde0204929bb46aed5756b41ef4a56778d15ada8f0c6654",
"020f2887f41474cfeb11fd262e982051c1541418137c02a0f4961af911045de639",
"0222038884bbd1d8ff109ed3bdef3542e768eef76c1247aea8bc8171f532928c30",
"03d281b42002647f0113f36c7b8efb30db66078dfaaa9ab3ff76d043a98d512fde",
"02504acbc1f4b3bdad1d86d6e1a08603771db135a73e61c9d565ae06a1938cd2ad",
"0226933336f1b75baa42d42b71d9091508b638046d19abd67f4e119bf64a7cfb4d",
"03cdcea66032b82f5c30450e381e5295cae85c5e6943af716cc6b646352a6067dc",
"02cd5a5547119e24feaa7c2a0f37b8c9366216bab7054de0065c9be42084003c8a"
};
this.ValidatorsCount = section.GetValue("ValidatorsCount", (byte)7);
shargon marked this conversation as resolved.
Show resolved Hide resolved
IConfigurationSection section_sl = section.GetSection("SeedList");
if (section_sl.Exists())
this.SeedList = section_sl.GetChildren().Select(p => p.Get<string>()).ToArray();
Expand Down
2 changes: 1 addition & 1 deletion src/neo/SmartContract/Native/Tokens/GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal override bool Initialize(ApplicationEngine engine)
{
if (!base.Initialize(engine)) return false;
if (TotalSupply(engine.Snapshot) != BigInteger.Zero) return false;
UInt160 account = Contract.CreateMultiSigRedeemScript(Blockchain.StandbyValidators.Length / 2 + 1, Blockchain.StandbyValidators).ToScriptHash();
UInt160 account = Blockchain.GetConsensusAddress(Blockchain.StandbyValidators);
Mint(engine, account, 30_000_000 * Factor);
return true;
}
Expand Down
Loading