Skip to content

Commit

Permalink
Merge pull request #3441 from AElfProject/release/1.5.0
Browse files Browse the repository at this point in the history
Release v1.5.0
  • Loading branch information
jason-aelf authored Jul 19, 2023
2 parents a5cc8dd + 9e79196 commit bd91fc5
Show file tree
Hide file tree
Showing 188 changed files with 11,278 additions and 1,657 deletions.
21 changes: 21 additions & 0 deletions AElf.All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.CSharp.CodeOps.UnitTes
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.SmartContract.ExecutionPluginForUserContractFee.Tests.TestContract", "test\AElf.Kernel.SmartContract.ExecutionPluginForUserContractFee.Tests.TestContract\AElf.Kernel.SmartContract.ExecutionPluginForUserContractFee.Tests.TestContract.csproj", "{AB27298B-E6BE-4ACB-ADF1-64239E2A7A1C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Contracts.TestContract.Vote", "test\AElf.Contracts.TestContract.Vote\AElf.Contracts.TestContract.Vote.csproj", "{860947CF-F081-4A3B-BE65-199ECE793616}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Contracts.TestContract.MockParliament", "test\AElf.Contracts.TestContract.MockParliament\AElf.Contracts.TestContract.MockParliament.csproj", "{C7EDD0EB-CCE7-4B06-BF1E-F9CA7F149097}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Contracts.TestContract.VirtualAddress", "test\AElf.Contracts.TestContract.VirtualAddress\AElf.Contracts.TestContract.VirtualAddress.csproj", "{64498F8C-B827-4E1C-B5FB-4B9188C839A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1059,6 +1065,18 @@ Global
{AB27298B-E6BE-4ACB-ADF1-64239E2A7A1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB27298B-E6BE-4ACB-ADF1-64239E2A7A1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB27298B-E6BE-4ACB-ADF1-64239E2A7A1C}.Release|Any CPU.Build.0 = Release|Any CPU
{860947CF-F081-4A3B-BE65-199ECE793616}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{860947CF-F081-4A3B-BE65-199ECE793616}.Debug|Any CPU.Build.0 = Debug|Any CPU
{860947CF-F081-4A3B-BE65-199ECE793616}.Release|Any CPU.ActiveCfg = Release|Any CPU
{860947CF-F081-4A3B-BE65-199ECE793616}.Release|Any CPU.Build.0 = Release|Any CPU
{C7EDD0EB-CCE7-4B06-BF1E-F9CA7F149097}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7EDD0EB-CCE7-4B06-BF1E-F9CA7F149097}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7EDD0EB-CCE7-4B06-BF1E-F9CA7F149097}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7EDD0EB-CCE7-4B06-BF1E-F9CA7F149097}.Release|Any CPU.Build.0 = Release|Any CPU
{64498F8C-B827-4E1C-B5FB-4B9188C839A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64498F8C-B827-4E1C-B5FB-4B9188C839A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64498F8C-B827-4E1C-B5FB-4B9188C839A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64498F8C-B827-4E1C-B5FB-4B9188C839A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1245,5 +1263,8 @@ Global
{1B44277E-74EB-49B2-B8FD-05C29EE51985} = {4E54480A-D155-43ED-9736-1A5BE7957211}
{D1A00CD6-958E-4E9F-8325-354309E3029E} = {4E54480A-D155-43ED-9736-1A5BE7957211}
{AB27298B-E6BE-4ACB-ADF1-64239E2A7A1C} = {4E54480A-D155-43ED-9736-1A5BE7957211}
{860947CF-F081-4A3B-BE65-199ECE793616} = {D3950CC9-808F-4ED8-946A-79A992F3F8EF}
{C7EDD0EB-CCE7-4B06-BF1E-F9CA7F149097} = {D3950CC9-808F-4ED8-946A-79A992F3F8EF}
{64498F8C-B827-4E1C-B5FB-4B9188C839A8} = {D3950CC9-808F-4ED8-946A-79A992F3F8EF}
EndGlobalSection
EndGlobal
45 changes: 45 additions & 0 deletions bench/AElf.Benchmark/VRFTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using AElf.Cryptography;
using AElf.Cryptography.ECDSA;
using BenchmarkDotNet.Attributes;

namespace AElf.Benchmark;

[MarkdownExporterAttribute.GitHub]
public class VrfTests : BenchmarkTestBase
{
private ECKeyPair _key;
private byte[] _alphaBytes;
private byte[] _piBytes;

[Params(1,10,100,1000)] public int VectorCount;

[GlobalSetup]
public void GlobalSetup()
{
_key = CryptoHelper.FromPrivateKey(
ByteArrayHelper.HexStringToByteArray("2eaeb403475a9962ad59302ab53fa2b668d2d24bf5a2a917707e5b2f4ded392b"));
var alpha = "fb779e58991c424eaaf10b3d364c3b3e756c7b435109a985e547c058964d7bd5";
_alphaBytes = Convert.FromHexString(alpha);
var pi = "03ea6c4bdb4a9e1ae0a17c427ec074f68cdac7a57e4f3fded1b07d20dd5385baf05a9d1e4064cd1c2c5e8608e96b7e3e2058500f178b414b8e910178f17a7a77af7e88befeabceb77cae3e9fd2e1a6c051";
_piBytes = Convert.FromHexString(pi);
}

[Benchmark]
public void VrfProveTest()
{
for (var i = 0; i < VectorCount; i++)
{
CryptoHelper.ECVrfProve(_key, _alphaBytes);
}
}

[Benchmark]
public void VrfVerifyTest()
{
for (var i = 0; i < VectorCount; i++)
{
CryptoHelper.ECVrfVerify(_key.PublicKey, _alphaBytes, _piBytes);
}
}
}
2 changes: 1 addition & 1 deletion contract/AElf.Contracts.Consensus.AEDPoS/AEDPoSContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public override Empty RecordCandidateReplacement(RecordCandidateReplacementInput

#region NextRound

public override Empty NextRound(Round input)
public override Empty NextRound(NextRoundInput input)
{
SupplyCurrentRoundInformation();
ProcessConsensusInformation(input);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using AElf.Standards.ACS4;
using AElf.Types;
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;

Expand Down Expand Up @@ -66,9 +67,10 @@ public override TransactionList GenerateConsensusTransactions(BytesValue input)
"Data to request consensus information should contain pubkey.");

var pubkey = triggerInformation.Pubkey;
var randomNumber = triggerInformation.RandomNumber;
var consensusInformation = new AElfConsensusHeaderInformation();
consensusInformation.MergeFrom(GetConsensusBlockExtraData(input, true).Value);
var transactionList = GenerateTransactionListByExtraData(consensusInformation, pubkey);
var transactionList = GenerateTransactionListByExtraData(consensusInformation, pubkey, randomNumber);
return transactionList;
}

Expand Down Expand Up @@ -126,7 +128,7 @@ public override ValidationResult ValidateConsensusAfterExecution(BytesValue inpu
}

private TransactionList GenerateTransactionListByExtraData(AElfConsensusHeaderInformation consensusInformation,
ByteString pubkey)
ByteString pubkey, ByteString randomNumber)
{
var round = consensusInformation.Round;
var behaviour = consensusInformation.Behaviour;
Expand All @@ -140,7 +142,7 @@ private TransactionList GenerateTransactionListByExtraData(AElfConsensusHeaderIn
Transactions =
{
GenerateTransaction(nameof(UpdateValue),
round.ExtractInformationToUpdateConsensus(pubkey.ToHex()))
round.ExtractInformationToUpdateConsensus(pubkey.ToHex(), randomNumber))
}
};
case AElfConsensusBehaviour.TinyBlock:
Expand All @@ -154,7 +156,8 @@ private TransactionList GenerateTransactionListByExtraData(AElfConsensusHeaderIn
{
ActualMiningTime = minerInRound.ActualMiningTimes.Last(),
ProducedBlocks = minerInRound.ProducedBlocks,
RoundId = round.RoundIdForValidation
RoundId = round.RoundIdForValidation,
RandomNumber = randomNumber
})
}
};
Expand All @@ -163,15 +166,15 @@ private TransactionList GenerateTransactionListByExtraData(AElfConsensusHeaderIn
{
Transactions =
{
GenerateTransaction(nameof(NextRound), round)
GenerateTransaction(nameof(NextRound), NextRoundInput.Create(round,randomNumber))
}
};
case AElfConsensusBehaviour.NextTerm:
return new TransactionList
{
Transactions =
{
GenerateTransaction(nameof(NextTerm), round)
GenerateTransaction(nameof(NextTerm), NextTermInput.Create(round,randomNumber))
}
};
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace AElf.Contracts.Consensus.AEDPoS;
// ReSharper disable once InconsistentNaming
public partial class AEDPoSContract
{
public override Empty NextTerm(Round input)
public override Empty NextTerm(NextTermInput input)
{
SupplyCurrentRoundInformation();
ProcessConsensusInformation(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using AElf.Sdk.CSharp;
using AElf.Standards.ACS10;
using AElf.Types;
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;

namespace AElf.Contracts.Consensus.AEDPoS;
Expand All @@ -28,19 +29,25 @@ private void ProcessConsensusInformation(dynamic input, [CallerMemberName] strin

State.RoundBeforeLatestExecution.Value = GetCurrentRoundInformation(new Empty());

ByteString randomNumber = null;

// The only difference.
switch (input)
{
case Round round when callerMethodName == nameof(NextRound):
ProcessNextRound(round);
case NextRoundInput nextRoundInput:
randomNumber = nextRoundInput.RandomNumber;
ProcessNextRound(nextRoundInput);
break;
case Round round when callerMethodName == nameof(NextTerm):
ProcessNextTerm(round);
case NextTermInput nextTermInput:
randomNumber = nextTermInput.RandomNumber;
ProcessNextTerm(nextTermInput);
break;
case UpdateValueInput updateValueInput:
randomNumber = updateValueInput.RandomNumber;
ProcessUpdateValue(updateValueInput);
break;
case TinyBlockInput tinyBlockInput:
randomNumber = tinyBlockInput.RandomNumber;
ProcessTinyBlock(tinyBlockInput);
break;
}
Expand All @@ -65,14 +72,12 @@ private void ProcessConsensusInformation(dynamic input, [CallerMemberName] strin
Context.LogDebug(() =>
$"Current round information:\n{currentRound.ToString(_processingBlockMinerPubkey)}");

var latestSignature = GetLatestSignature(currentRound);
var previousRandomHash = State.RandomHashes[Context.CurrentHeight.Sub(1)];
var randomHash = previousRandomHash == null
? latestSignature
: HashHelper.XorAndCompute(previousRandomHash, latestSignature);

var previousRandomHash = State.RandomHashes[Context.CurrentHeight.Sub(1)] ?? Hash.Empty;
Assert(
Context.ECVrfVerify(Context.RecoverPublicKey(), previousRandomHash.ToByteArray(),
randomNumber.ToByteArray(), out var beta), "Failed to verify random number.");
var randomHash = Hash.LoadFromByteArray(beta);
State.RandomHashes[Context.CurrentHeight] = randomHash;

Context.LogDebug(() => $"New random hash generated: {randomHash} - height {Context.CurrentHeight}");

if (!State.IsMainChain.Value && currentRound.RoundNumber > 1) Release();
Expand Down Expand Up @@ -100,8 +105,10 @@ private Hash GetLatestSignature(Round currentRound)
return latestSignature;
}

private void ProcessNextRound(Round nextRound)
private void ProcessNextRound(NextRoundInput input)
{
var nextRound = input.ToRound();

RecordMinedMinerListOfCurrentRound();

TryToGetCurrentRoundInformation(out var currentRound);
Expand Down Expand Up @@ -149,8 +156,10 @@ private void ProcessNextRound(Round nextRound)
Assert(TryToUpdateRoundNumber(nextRound.RoundNumber), "Failed to update round number.");
}

private void ProcessNextTerm(Round nextRound)
private void ProcessNextTerm(NextTermInput input)
{
var nextRound = input.ToRound();

RecordMinedMinerListOfCurrentRound();

// Count missed time slot of current round.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props"/>
<Import Project="..\..\common.props" />

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand Down
41 changes: 41 additions & 0 deletions contract/AElf.Contracts.Consensus.AEDPoS/Types/NextRoundInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Google.Protobuf;

namespace AElf.Contracts.Consensus.AEDPoS;

public partial class NextRoundInput
{
public static NextRoundInput Create(Round round, ByteString randomNumber)
{
return new NextRoundInput
{
RoundNumber = round.RoundNumber,
RealTimeMinersInformation = { round.RealTimeMinersInformation },
ExtraBlockProducerOfPreviousRound = round.ExtraBlockProducerOfPreviousRound,
BlockchainAge = round.BlockchainAge,
TermNumber = round.TermNumber,
ConfirmedIrreversibleBlockHeight = round.ConfirmedIrreversibleBlockHeight,
ConfirmedIrreversibleBlockRoundNumber = round.ConfirmedIrreversibleBlockRoundNumber,
IsMinerListJustChanged = round.IsMinerListJustChanged,
RoundIdForValidation = round.RoundIdForValidation,
MainChainMinersRoundNumber = round.MainChainMinersRoundNumber,
RandomNumber = randomNumber
};
}

public Round ToRound()
{
return new Round
{
RoundNumber = RoundNumber,
RealTimeMinersInformation = { RealTimeMinersInformation },
ExtraBlockProducerOfPreviousRound = ExtraBlockProducerOfPreviousRound,
BlockchainAge = BlockchainAge,
TermNumber = TermNumber,
ConfirmedIrreversibleBlockHeight = ConfirmedIrreversibleBlockHeight,
ConfirmedIrreversibleBlockRoundNumber = ConfirmedIrreversibleBlockRoundNumber,
IsMinerListJustChanged = IsMinerListJustChanged,
RoundIdForValidation = RoundIdForValidation,
MainChainMinersRoundNumber = MainChainMinersRoundNumber
};
}
}
41 changes: 41 additions & 0 deletions contract/AElf.Contracts.Consensus.AEDPoS/Types/NextTermInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Google.Protobuf;

namespace AElf.Contracts.Consensus.AEDPoS;

public partial class NextTermInput
{
public static NextTermInput Create(Round round, ByteString randomNumber)
{
return new NextTermInput
{
RoundNumber = round.RoundNumber,
RealTimeMinersInformation = { round.RealTimeMinersInformation },
ExtraBlockProducerOfPreviousRound = round.ExtraBlockProducerOfPreviousRound,
BlockchainAge = round.BlockchainAge,
TermNumber = round.TermNumber,
ConfirmedIrreversibleBlockHeight = round.ConfirmedIrreversibleBlockHeight,
ConfirmedIrreversibleBlockRoundNumber = round.ConfirmedIrreversibleBlockRoundNumber,
IsMinerListJustChanged = round.IsMinerListJustChanged,
RoundIdForValidation = round.RoundIdForValidation,
MainChainMinersRoundNumber = round.MainChainMinersRoundNumber,
RandomNumber = randomNumber
};
}

public Round ToRound()
{
return new Round
{
RoundNumber = RoundNumber,
RealTimeMinersInformation = { RealTimeMinersInformation },
ExtraBlockProducerOfPreviousRound = ExtraBlockProducerOfPreviousRound,
BlockchainAge = BlockchainAge,
TermNumber = TermNumber,
ConfirmedIrreversibleBlockHeight = ConfirmedIrreversibleBlockHeight,
ConfirmedIrreversibleBlockRoundNumber = ConfirmedIrreversibleBlockRoundNumber,
IsMinerListJustChanged = IsMinerListJustChanged,
RoundIdForValidation = RoundIdForValidation,
MainChainMinersRoundNumber = MainChainMinersRoundNumber
};
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using AElf.Types;
using Google.Protobuf;

namespace AElf.Contracts.Consensus.AEDPoS;

Expand All @@ -10,8 +11,9 @@ public partial class Round
/// will record this purpose to their FinalOrderOfNextRound field.
/// </summary>
/// <param name="pubkey"></param>
/// <param name="randomNumber"></param>
/// <returns></returns>
public UpdateValueInput ExtractInformationToUpdateConsensus(string pubkey)
public UpdateValueInput ExtractInformationToUpdateConsensus(string pubkey, ByteString randomNumber)
{
if (!RealTimeMinersInformation.ContainsKey(pubkey)) return null;

Expand Down Expand Up @@ -43,7 +45,8 @@ public UpdateValueInput ExtractInformationToUpdateConsensus(string pubkey)
EncryptedPieces = { minerInRound.EncryptedPieces },
DecryptedPieces = { decryptedPreviousInValues },
MinersPreviousInValues = { minersPreviousInValues },
ImpliedIrreversibleBlockHeight = minerInRound.ImpliedIrreversibleBlockHeight
ImpliedIrreversibleBlockHeight = minerInRound.ImpliedIrreversibleBlockHeight,
RandomNumber = randomNumber
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ private void CreateSideChainToken(SideChainCreationRequest sideChainCreationRequ
Issuer = creator,
IssueChainId = chainId,
Symbol = sideChainCreationRequest.SideChainTokenCreationRequest.SideChainTokenSymbol,
TotalSupply = sideChainCreationRequest.SideChainTokenCreationRequest.SideChainTokenTotalSupply
TotalSupply = sideChainCreationRequest.SideChainTokenCreationRequest.SideChainTokenTotalSupply,
Owner = creator
});
}

Expand Down
Loading

0 comments on commit bd91fc5

Please sign in to comment.