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

dBFT 2.0 #547

Merged
merged 31 commits into from Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2c022c7
Add commit phase to consensus algorithm (#534)
erikzhang Jan 14, 2019
0ae8d62
Merge branch 'master' into consensus/improved_dbft
vncoelho Jan 14, 2019
c58cbfd
Minor fix on mempoolVerified
vncoelho Jan 14, 2019
cdedb79
Add MemoryPool Unit tests. Fix bug on initital start of Persisting th…
Jan 16, 2019
c90dec3
Merge branch 'master' into consensus/improved_dbft
Jan 16, 2019
485487f
Merge branch 'master' into consensus/improved_dbft
erikzhang Jan 24, 2019
b207227
Prevent `ConsensusService` from receiving messages before starting (#…
erikzhang Jan 24, 2019
9aa6527
Consensus recovery log (#572)
erikzhang Jan 24, 2019
0855bdc
Combine `ConsensusContext.ChangeView()` and `ConsensusContext.Reset()`
erikzhang Jan 25, 2019
0e87248
Add `PreparationHash` field to `PrepareResponse` to prevent replay at…
erikzhang Jan 27, 2019
bf0ca7c
Fixed a problem where `PrepareResponse.PreparationHash` was not assig…
erikzhang Jan 28, 2019
7304274
Load context from store only when height matches
erikzhang Jan 31, 2019
be37423
Recover nodes requesting ChangeView when possible (#579)
jsolman Feb 16, 2019
98aed4a
Merge branch 'master' into consensus/improved_dbft
erikzhang Feb 16, 2019
bf820d1
Merge branch 'master' into consensus/improved_dbft
erikzhang Feb 17, 2019
5c9568a
Fixes bug in `OnPrepareRequestReceived()`
erikzhang Feb 19, 2019
19ada04
Send `RecoveryMessage` only when `message.NewViewNumber <= context.Vi…
erikzhang Feb 19, 2019
445fa92
Fix and optimize view changing (#590)
erikzhang Feb 19, 2019
3cc0784
Allow to ignore the recovery logs
erikzhang Feb 19, 2019
68322a4
Add `isRecovering` (#594)
erikzhang Feb 20, 2019
2c56c07
Merge branch 'master' into consensus/improved_dbft
erikzhang Feb 21, 2019
2311524
Fix accepting own prepare request (#596)
jsolman Feb 21, 2019
bbcfc68
Pick some changes from #575.
erikzhang Feb 21, 2019
3b27f0a
Fixes `Prefixes`
erikzhang Feb 21, 2019
de64019
Restore transactions from saved consensus context (#598)
erikzhang Feb 22, 2019
eaeb0a5
Refactoring
erikzhang Feb 25, 2019
06dc6b9
AggressiveInlining (#606)
erikzhang Feb 25, 2019
5d5046c
Reset Block reference when consensus context is initialized after blo…
jsolman Feb 25, 2019
b9b595e
Merge branch 'master' into consensus/improved_dbft
erikzhang Feb 26, 2019
91e006c
Change `ConsensusPayload` for compatibility (#609)
erikzhang Feb 26, 2019
335d7b7
Merge branch 'master' into consensus/improved_dbft
erikzhang Mar 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 65 additions & 0 deletions neo.UnitTests/TestBlockchain.cs
@@ -0,0 +1,65 @@
using Moq;
using Neo.Cryptography.ECC;
using Neo.IO.Wrappers;
using Neo.Ledger;
using Neo.Persistence;
using System;

namespace Neo.UnitTests
{
public static class TestBlockchain
{
private static NeoSystem TheNeoSystem;

public static NeoSystem InitializeMockNeoSystem()
{
if (TheNeoSystem == null)
{
var mockSnapshot = new Mock<Snapshot>();
mockSnapshot.SetupGet(p => p.Blocks).Returns(new TestDataCache<UInt256, BlockState>());
mockSnapshot.SetupGet(p => p.Transactions).Returns(new TestDataCache<UInt256, TransactionState>());
mockSnapshot.SetupGet(p => p.Accounts).Returns(new TestDataCache<UInt160, AccountState>());
mockSnapshot.SetupGet(p => p.UnspentCoins).Returns(new TestDataCache<UInt256, UnspentCoinState>());
mockSnapshot.SetupGet(p => p.SpentCoins).Returns(new TestDataCache<UInt256, SpentCoinState>());
mockSnapshot.SetupGet(p => p.Validators).Returns(new TestDataCache<ECPoint, ValidatorState>());
mockSnapshot.SetupGet(p => p.Assets).Returns(new TestDataCache<UInt256, AssetState>());
mockSnapshot.SetupGet(p => p.Contracts).Returns(new TestDataCache<UInt160, ContractState>());
mockSnapshot.SetupGet(p => p.Storages).Returns(new TestDataCache<StorageKey, StorageItem>());
mockSnapshot.SetupGet(p => p.HeaderHashList)
.Returns(new TestDataCache<UInt32Wrapper, HeaderHashList>());
mockSnapshot.SetupGet(p => p.ValidatorsCount).Returns(new TestMetaDataCache<ValidatorsCountState>());
mockSnapshot.SetupGet(p => p.BlockHashIndex).Returns(new TestMetaDataCache<HashIndexState>());
mockSnapshot.SetupGet(p => p.HeaderHashIndex).Returns(new TestMetaDataCache<HashIndexState>());

var mockStore = new Mock<Store>();

var defaultTx = TestUtils.CreateRandomHashInvocationMockTransaction().Object;
mockStore.Setup(p => p.GetBlocks()).Returns(new TestDataCache<UInt256, BlockState>());
mockStore.Setup(p => p.GetTransactions()).Returns(new TestDataCache<UInt256, TransactionState>(
new TransactionState
{
BlockIndex = 1,
Transaction = defaultTx
}));

mockStore.Setup(p => p.GetAccounts()).Returns(new TestDataCache<UInt160, AccountState>());
mockStore.Setup(p => p.GetUnspentCoins()).Returns(new TestDataCache<UInt256, UnspentCoinState>());
mockStore.Setup(p => p.GetSpentCoins()).Returns(new TestDataCache<UInt256, SpentCoinState>());
mockStore.Setup(p => p.GetValidators()).Returns(new TestDataCache<ECPoint, ValidatorState>());
mockStore.Setup(p => p.GetAssets()).Returns(new TestDataCache<UInt256, AssetState>());
mockStore.Setup(p => p.GetContracts()).Returns(new TestDataCache<UInt160, ContractState>());
mockStore.Setup(p => p.GetStorages()).Returns(new TestDataCache<StorageKey, StorageItem>());
mockStore.Setup(p => p.GetHeaderHashList()).Returns(new TestDataCache<UInt32Wrapper, HeaderHashList>());
mockStore.Setup(p => p.GetValidatorsCount()).Returns(new TestMetaDataCache<ValidatorsCountState>());
mockStore.Setup(p => p.GetBlockHashIndex()).Returns(new TestMetaDataCache<HashIndexState>());
mockStore.Setup(p => p.GetHeaderHashIndex()).Returns(new TestMetaDataCache<HashIndexState>());
mockStore.Setup(p => p.GetSnapshot()).Returns(mockSnapshot.Object);

Console.WriteLine("initialize NeoSystem");
TheNeoSystem = new NeoSystem(mockStore.Object); // new Mock<NeoSystem>(mockStore.Object);
}

return TheNeoSystem;
}
}
}
58 changes: 55 additions & 3 deletions neo.UnitTests/TestUtils.cs
@@ -1,14 +1,21 @@
using Neo.Cryptography.ECC;
using Moq;
using Neo.Cryptography.ECC;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.VM;
using System;
using System.Collections.Generic;
using System.IO;

namespace Neo.UnitTests
{
public static class TestUtils
{
public static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism

public static byte[] GetByteArray(int length, byte firstByte)
{
{
byte[] array = new byte[length];
array[0] = firstByte;
for (int i = 1; i < length; i++)
Expand Down Expand Up @@ -95,5 +102,50 @@ private static void setupBlockBaseWithValues(BlockBase bb, UInt256 val256, out U
};
bb.Witness = scriptVal;
}
}

public static Mock<InvocationTransaction> CreateRandomHashInvocationMockTransaction()
{
var mockTx = new Mock<InvocationTransaction>
{
CallBase = true
};
mockTx.Setup(p => p.Verify(It.IsAny<Snapshot>(), It.IsAny<IEnumerable<Transaction>>())).Returns(true);
var tx = mockTx.Object;
var randomBytes = new byte[16];
TestRandom.NextBytes(randomBytes);
tx.Script = randomBytes;
tx.Attributes = new TransactionAttribute[0];
tx.Inputs = new CoinReference[0];
tx.Outputs = new TransactionOutput[0];
tx.Witnesses = new Witness[0];

return mockTx;
}

public static Mock<MinerTransaction> CreateRandomMockMinerTransaction()
{
var mockTx = new Mock<MinerTransaction>
{
CallBase = true
};
var tx = mockTx.Object;
tx.Attributes = new TransactionAttribute[0];
tx.Inputs = new CoinReference[0];
tx.Outputs = new TransactionOutput[0];
tx.Witnesses = new Witness[0];
tx.Nonce = (uint)TestRandom.Next();
return mockTx;
}

public static T CopyMsgBySerialization<T>(T serializableObj, T newObj) where T : ISerializable
{
using (MemoryStream ms = new MemoryStream(serializableObj.ToArray(), false))
using (BinaryReader reader = new BinaryReader(ms))
{
newObj.Deserialize(reader);
}

return newObj;
}
}
}