Skip to content

Commit bd91fc5

Browse files
authored
Merge pull request #3441 from AElfProject/release/1.5.0
Release v1.5.0
2 parents a5cc8dd + 9e79196 commit bd91fc5

File tree

188 files changed

+11278
-1657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+11278
-1657
lines changed

AElf.All.sln

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.CSharp.CodeOps.UnitTes
369369
EndProject
370370
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}"
371371
EndProject
372+
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}"
373+
EndProject
374+
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}"
375+
EndProject
376+
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}"
377+
EndProject
372378
Global
373379
GlobalSection(SolutionConfigurationPlatforms) = preSolution
374380
Debug|Any CPU = Debug|Any CPU
@@ -1059,6 +1065,18 @@ Global
10591065
{AB27298B-E6BE-4ACB-ADF1-64239E2A7A1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
10601066
{AB27298B-E6BE-4ACB-ADF1-64239E2A7A1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
10611067
{AB27298B-E6BE-4ACB-ADF1-64239E2A7A1C}.Release|Any CPU.Build.0 = Release|Any CPU
1068+
{860947CF-F081-4A3B-BE65-199ECE793616}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1069+
{860947CF-F081-4A3B-BE65-199ECE793616}.Debug|Any CPU.Build.0 = Debug|Any CPU
1070+
{860947CF-F081-4A3B-BE65-199ECE793616}.Release|Any CPU.ActiveCfg = Release|Any CPU
1071+
{860947CF-F081-4A3B-BE65-199ECE793616}.Release|Any CPU.Build.0 = Release|Any CPU
1072+
{C7EDD0EB-CCE7-4B06-BF1E-F9CA7F149097}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1073+
{C7EDD0EB-CCE7-4B06-BF1E-F9CA7F149097}.Debug|Any CPU.Build.0 = Debug|Any CPU
1074+
{C7EDD0EB-CCE7-4B06-BF1E-F9CA7F149097}.Release|Any CPU.ActiveCfg = Release|Any CPU
1075+
{C7EDD0EB-CCE7-4B06-BF1E-F9CA7F149097}.Release|Any CPU.Build.0 = Release|Any CPU
1076+
{64498F8C-B827-4E1C-B5FB-4B9188C839A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1077+
{64498F8C-B827-4E1C-B5FB-4B9188C839A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
1078+
{64498F8C-B827-4E1C-B5FB-4B9188C839A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
1079+
{64498F8C-B827-4E1C-B5FB-4B9188C839A8}.Release|Any CPU.Build.0 = Release|Any CPU
10621080
EndGlobalSection
10631081
GlobalSection(SolutionProperties) = preSolution
10641082
HideSolutionNode = FALSE
@@ -1245,5 +1263,8 @@ Global
12451263
{1B44277E-74EB-49B2-B8FD-05C29EE51985} = {4E54480A-D155-43ED-9736-1A5BE7957211}
12461264
{D1A00CD6-958E-4E9F-8325-354309E3029E} = {4E54480A-D155-43ED-9736-1A5BE7957211}
12471265
{AB27298B-E6BE-4ACB-ADF1-64239E2A7A1C} = {4E54480A-D155-43ED-9736-1A5BE7957211}
1266+
{860947CF-F081-4A3B-BE65-199ECE793616} = {D3950CC9-808F-4ED8-946A-79A992F3F8EF}
1267+
{C7EDD0EB-CCE7-4B06-BF1E-F9CA7F149097} = {D3950CC9-808F-4ED8-946A-79A992F3F8EF}
1268+
{64498F8C-B827-4E1C-B5FB-4B9188C839A8} = {D3950CC9-808F-4ED8-946A-79A992F3F8EF}
12481269
EndGlobalSection
12491270
EndGlobal

bench/AElf.Benchmark/VRFTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using AElf.Cryptography;
3+
using AElf.Cryptography.ECDSA;
4+
using BenchmarkDotNet.Attributes;
5+
6+
namespace AElf.Benchmark;
7+
8+
[MarkdownExporterAttribute.GitHub]
9+
public class VrfTests : BenchmarkTestBase
10+
{
11+
private ECKeyPair _key;
12+
private byte[] _alphaBytes;
13+
private byte[] _piBytes;
14+
15+
[Params(1,10,100,1000)] public int VectorCount;
16+
17+
[GlobalSetup]
18+
public void GlobalSetup()
19+
{
20+
_key = CryptoHelper.FromPrivateKey(
21+
ByteArrayHelper.HexStringToByteArray("2eaeb403475a9962ad59302ab53fa2b668d2d24bf5a2a917707e5b2f4ded392b"));
22+
var alpha = "fb779e58991c424eaaf10b3d364c3b3e756c7b435109a985e547c058964d7bd5";
23+
_alphaBytes = Convert.FromHexString(alpha);
24+
var pi = "03ea6c4bdb4a9e1ae0a17c427ec074f68cdac7a57e4f3fded1b07d20dd5385baf05a9d1e4064cd1c2c5e8608e96b7e3e2058500f178b414b8e910178f17a7a77af7e88befeabceb77cae3e9fd2e1a6c051";
25+
_piBytes = Convert.FromHexString(pi);
26+
}
27+
28+
[Benchmark]
29+
public void VrfProveTest()
30+
{
31+
for (var i = 0; i < VectorCount; i++)
32+
{
33+
CryptoHelper.ECVrfProve(_key, _alphaBytes);
34+
}
35+
}
36+
37+
[Benchmark]
38+
public void VrfVerifyTest()
39+
{
40+
for (var i = 0; i < VectorCount; i++)
41+
{
42+
CryptoHelper.ECVrfVerify(_key.PublicKey, _alphaBytes, _piBytes);
43+
}
44+
}
45+
}

contract/AElf.Contracts.Consensus.AEDPoS/AEDPoSContract.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public override Empty RecordCandidateReplacement(RecordCandidateReplacementInput
158158

159159
#region NextRound
160160

161-
public override Empty NextRound(Round input)
161+
public override Empty NextRound(NextRoundInput input)
162162
{
163163
SupplyCurrentRoundInformation();
164164
ProcessConsensusInformation(input);

contract/AElf.Contracts.Consensus.AEDPoS/AEDPoSContract_ACS4_ConsensusInformationProvider.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Linq;
22
using AElf.Standards.ACS4;
3+
using AElf.Types;
34
using Google.Protobuf;
45
using Google.Protobuf.WellKnownTypes;
56

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

6869
var pubkey = triggerInformation.Pubkey;
70+
var randomNumber = triggerInformation.RandomNumber;
6971
var consensusInformation = new AElfConsensusHeaderInformation();
7072
consensusInformation.MergeFrom(GetConsensusBlockExtraData(input, true).Value);
71-
var transactionList = GenerateTransactionListByExtraData(consensusInformation, pubkey);
73+
var transactionList = GenerateTransactionListByExtraData(consensusInformation, pubkey, randomNumber);
7274
return transactionList;
7375
}
7476

@@ -126,7 +128,7 @@ public override ValidationResult ValidateConsensusAfterExecution(BytesValue inpu
126128
}
127129

128130
private TransactionList GenerateTransactionListByExtraData(AElfConsensusHeaderInformation consensusInformation,
129-
ByteString pubkey)
131+
ByteString pubkey, ByteString randomNumber)
130132
{
131133
var round = consensusInformation.Round;
132134
var behaviour = consensusInformation.Behaviour;
@@ -140,7 +142,7 @@ private TransactionList GenerateTransactionListByExtraData(AElfConsensusHeaderIn
140142
Transactions =
141143
{
142144
GenerateTransaction(nameof(UpdateValue),
143-
round.ExtractInformationToUpdateConsensus(pubkey.ToHex()))
145+
round.ExtractInformationToUpdateConsensus(pubkey.ToHex(), randomNumber))
144146
}
145147
};
146148
case AElfConsensusBehaviour.TinyBlock:
@@ -154,7 +156,8 @@ private TransactionList GenerateTransactionListByExtraData(AElfConsensusHeaderIn
154156
{
155157
ActualMiningTime = minerInRound.ActualMiningTimes.Last(),
156158
ProducedBlocks = minerInRound.ProducedBlocks,
157-
RoundId = round.RoundIdForValidation
159+
RoundId = round.RoundIdForValidation,
160+
RandomNumber = randomNumber
158161
})
159162
}
160163
};
@@ -163,15 +166,15 @@ private TransactionList GenerateTransactionListByExtraData(AElfConsensusHeaderIn
163166
{
164167
Transactions =
165168
{
166-
GenerateTransaction(nameof(NextRound), round)
169+
GenerateTransaction(nameof(NextRound), NextRoundInput.Create(round,randomNumber))
167170
}
168171
};
169172
case AElfConsensusBehaviour.NextTerm:
170173
return new TransactionList
171174
{
172175
Transactions =
173176
{
174-
GenerateTransaction(nameof(NextTerm), round)
177+
GenerateTransaction(nameof(NextTerm), NextTermInput.Create(round,randomNumber))
175178
}
176179
};
177180
default:

contract/AElf.Contracts.Consensus.AEDPoS/AEDPoSContract_NextTerm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace AElf.Contracts.Consensus.AEDPoS;
1010
// ReSharper disable once InconsistentNaming
1111
public partial class AEDPoSContract
1212
{
13-
public override Empty NextTerm(Round input)
13+
public override Empty NextTerm(NextTermInput input)
1414
{
1515
SupplyCurrentRoundInformation();
1616
ProcessConsensusInformation(input);

contract/AElf.Contracts.Consensus.AEDPoS/AEDPoSContract_ProcessConsensusInformation.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using AElf.Sdk.CSharp;
66
using AElf.Standards.ACS10;
77
using AElf.Types;
8+
using Google.Protobuf;
89
using Google.Protobuf.WellKnownTypes;
910

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

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

32+
ByteString randomNumber = null;
33+
3134
// The only difference.
3235
switch (input)
3336
{
34-
case Round round when callerMethodName == nameof(NextRound):
35-
ProcessNextRound(round);
37+
case NextRoundInput nextRoundInput:
38+
randomNumber = nextRoundInput.RandomNumber;
39+
ProcessNextRound(nextRoundInput);
3640
break;
37-
case Round round when callerMethodName == nameof(NextTerm):
38-
ProcessNextTerm(round);
41+
case NextTermInput nextTermInput:
42+
randomNumber = nextTermInput.RandomNumber;
43+
ProcessNextTerm(nextTermInput);
3944
break;
4045
case UpdateValueInput updateValueInput:
46+
randomNumber = updateValueInput.RandomNumber;
4147
ProcessUpdateValue(updateValueInput);
4248
break;
4349
case TinyBlockInput tinyBlockInput:
50+
randomNumber = tinyBlockInput.RandomNumber;
4451
ProcessTinyBlock(tinyBlockInput);
4552
break;
4653
}
@@ -65,14 +72,12 @@ private void ProcessConsensusInformation(dynamic input, [CallerMemberName] strin
6572
Context.LogDebug(() =>
6673
$"Current round information:\n{currentRound.ToString(_processingBlockMinerPubkey)}");
6774

68-
var latestSignature = GetLatestSignature(currentRound);
69-
var previousRandomHash = State.RandomHashes[Context.CurrentHeight.Sub(1)];
70-
var randomHash = previousRandomHash == null
71-
? latestSignature
72-
: HashHelper.XorAndCompute(previousRandomHash, latestSignature);
73-
75+
var previousRandomHash = State.RandomHashes[Context.CurrentHeight.Sub(1)] ?? Hash.Empty;
76+
Assert(
77+
Context.ECVrfVerify(Context.RecoverPublicKey(), previousRandomHash.ToByteArray(),
78+
randomNumber.ToByteArray(), out var beta), "Failed to verify random number.");
79+
var randomHash = Hash.LoadFromByteArray(beta);
7480
State.RandomHashes[Context.CurrentHeight] = randomHash;
75-
7681
Context.LogDebug(() => $"New random hash generated: {randomHash} - height {Context.CurrentHeight}");
7782

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

103-
private void ProcessNextRound(Round nextRound)
108+
private void ProcessNextRound(NextRoundInput input)
104109
{
110+
var nextRound = input.ToRound();
111+
105112
RecordMinedMinerListOfCurrentRound();
106113

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

152-
private void ProcessNextTerm(Round nextRound)
159+
private void ProcessNextTerm(NextTermInput input)
153160
{
161+
var nextRound = input.ToRound();
162+
154163
RecordMinedMinerListOfCurrentRound();
155164

156165
// Count missed time slot of current round.

contract/AElf.Contracts.Consensus.AEDPoS/AElf.Contracts.Consensus.AEDPoS.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<Import Project="..\..\common.props"/>
2+
<Import Project="..\..\common.props" />
33

44
<PropertyGroup>
55
<TargetFramework>net6.0</TargetFramework>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Google.Protobuf;
2+
3+
namespace AElf.Contracts.Consensus.AEDPoS;
4+
5+
public partial class NextRoundInput
6+
{
7+
public static NextRoundInput Create(Round round, ByteString randomNumber)
8+
{
9+
return new NextRoundInput
10+
{
11+
RoundNumber = round.RoundNumber,
12+
RealTimeMinersInformation = { round.RealTimeMinersInformation },
13+
ExtraBlockProducerOfPreviousRound = round.ExtraBlockProducerOfPreviousRound,
14+
BlockchainAge = round.BlockchainAge,
15+
TermNumber = round.TermNumber,
16+
ConfirmedIrreversibleBlockHeight = round.ConfirmedIrreversibleBlockHeight,
17+
ConfirmedIrreversibleBlockRoundNumber = round.ConfirmedIrreversibleBlockRoundNumber,
18+
IsMinerListJustChanged = round.IsMinerListJustChanged,
19+
RoundIdForValidation = round.RoundIdForValidation,
20+
MainChainMinersRoundNumber = round.MainChainMinersRoundNumber,
21+
RandomNumber = randomNumber
22+
};
23+
}
24+
25+
public Round ToRound()
26+
{
27+
return new Round
28+
{
29+
RoundNumber = RoundNumber,
30+
RealTimeMinersInformation = { RealTimeMinersInformation },
31+
ExtraBlockProducerOfPreviousRound = ExtraBlockProducerOfPreviousRound,
32+
BlockchainAge = BlockchainAge,
33+
TermNumber = TermNumber,
34+
ConfirmedIrreversibleBlockHeight = ConfirmedIrreversibleBlockHeight,
35+
ConfirmedIrreversibleBlockRoundNumber = ConfirmedIrreversibleBlockRoundNumber,
36+
IsMinerListJustChanged = IsMinerListJustChanged,
37+
RoundIdForValidation = RoundIdForValidation,
38+
MainChainMinersRoundNumber = MainChainMinersRoundNumber
39+
};
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Google.Protobuf;
2+
3+
namespace AElf.Contracts.Consensus.AEDPoS;
4+
5+
public partial class NextTermInput
6+
{
7+
public static NextTermInput Create(Round round, ByteString randomNumber)
8+
{
9+
return new NextTermInput
10+
{
11+
RoundNumber = round.RoundNumber,
12+
RealTimeMinersInformation = { round.RealTimeMinersInformation },
13+
ExtraBlockProducerOfPreviousRound = round.ExtraBlockProducerOfPreviousRound,
14+
BlockchainAge = round.BlockchainAge,
15+
TermNumber = round.TermNumber,
16+
ConfirmedIrreversibleBlockHeight = round.ConfirmedIrreversibleBlockHeight,
17+
ConfirmedIrreversibleBlockRoundNumber = round.ConfirmedIrreversibleBlockRoundNumber,
18+
IsMinerListJustChanged = round.IsMinerListJustChanged,
19+
RoundIdForValidation = round.RoundIdForValidation,
20+
MainChainMinersRoundNumber = round.MainChainMinersRoundNumber,
21+
RandomNumber = randomNumber
22+
};
23+
}
24+
25+
public Round ToRound()
26+
{
27+
return new Round
28+
{
29+
RoundNumber = RoundNumber,
30+
RealTimeMinersInformation = { RealTimeMinersInformation },
31+
ExtraBlockProducerOfPreviousRound = ExtraBlockProducerOfPreviousRound,
32+
BlockchainAge = BlockchainAge,
33+
TermNumber = TermNumber,
34+
ConfirmedIrreversibleBlockHeight = ConfirmedIrreversibleBlockHeight,
35+
ConfirmedIrreversibleBlockRoundNumber = ConfirmedIrreversibleBlockRoundNumber,
36+
IsMinerListJustChanged = IsMinerListJustChanged,
37+
RoundIdForValidation = RoundIdForValidation,
38+
MainChainMinersRoundNumber = MainChainMinersRoundNumber
39+
};
40+
}
41+
}

contract/AElf.Contracts.Consensus.AEDPoS/Types/Round_ExtractInformationToUpdateConsensus.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Linq;
22
using AElf.Types;
3+
using Google.Protobuf;
34

45
namespace AElf.Contracts.Consensus.AEDPoS;
56

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

@@ -43,7 +45,8 @@ public UpdateValueInput ExtractInformationToUpdateConsensus(string pubkey)
4345
EncryptedPieces = { minerInRound.EncryptedPieces },
4446
DecryptedPieces = { decryptedPreviousInValues },
4547
MinersPreviousInValues = { minersPreviousInValues },
46-
ImpliedIrreversibleBlockHeight = minerInRound.ImpliedIrreversibleBlockHeight
48+
ImpliedIrreversibleBlockHeight = minerInRound.ImpliedIrreversibleBlockHeight,
49+
RandomNumber = randomNumber
4750
};
4851
}
4952
}

contract/AElf.Contracts.CrossChain/CrossChainContract_Helper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ private void CreateSideChainToken(SideChainCreationRequest sideChainCreationRequ
189189
Issuer = creator,
190190
IssueChainId = chainId,
191191
Symbol = sideChainCreationRequest.SideChainTokenCreationRequest.SideChainTokenSymbol,
192-
TotalSupply = sideChainCreationRequest.SideChainTokenCreationRequest.SideChainTokenTotalSupply
192+
TotalSupply = sideChainCreationRequest.SideChainTokenCreationRequest.SideChainTokenTotalSupply,
193+
Owner = creator
193194
});
194195
}
195196

0 commit comments

Comments
 (0)