diff --git a/neo.UnitTests/TestBlockchain.cs b/neo.UnitTests/TestBlockchain.cs index b456dc820b..175a6ebfba 100644 --- a/neo.UnitTests/TestBlockchain.cs +++ b/neo.UnitTests/TestBlockchain.cs @@ -32,6 +32,7 @@ public static NeoSystem InitializeMockNeoSystem() mockSnapshot.SetupGet(p => p.HeaderHashIndex).Returns(new TestMetaDataCache()); var mockStore = new Mock(); + mockStore.Setup(p => p.Get(Consensus.Helper.CN_Context, It.IsAny())).Returns((byte[]) null); var defaultTx = TestUtils.CreateRandomHashInvocationMockTransaction().Object; mockStore.Setup(p => p.GetBlocks()).Returns(new TestDataCache()); diff --git a/neo.UnitTests/UT_Consensus.cs b/neo.UnitTests/UT_Consensus.cs index 741241978d..5168f53db5 100644 --- a/neo.UnitTests/UT_Consensus.cs +++ b/neo.UnitTests/UT_Consensus.cs @@ -5,7 +5,6 @@ using Moq; using Neo.Consensus; using Neo.Cryptography; -using Neo.IO; using Neo.Ledger; using Neo.Network.P2P; using Neo.Network.P2P.Payloads; diff --git a/neo/Consensus/Helper.cs b/neo/Consensus/Helper.cs index 9a5df8fe9f..16cf0f0778 100644 --- a/neo/Consensus/Helper.cs +++ b/neo/Consensus/Helper.cs @@ -1,5 +1,7 @@ using Neo.IO; +using Neo.Network.P2P.Payloads; using Neo.Persistence; +using System.Collections.Generic; using System.IO; namespace Neo.Consensus @@ -34,5 +36,12 @@ public static bool Load(this IConsensusContext context, Store store) return true; } } + + public static IEnumerable RetreiveTransactionsFromSavedConsensusContext(Store consensusStore) + { + IConsensusContext context = new ConsensusContext(null); + context.Load(consensusStore); + return context.Transactions?.Values ?? (IEnumerable)new Transaction[0]; + } } } diff --git a/neo/Ledger/Blockchain.cs b/neo/Ledger/Blockchain.cs index a2cf256e76..9e69661292 100644 --- a/neo/Ledger/Blockchain.cs +++ b/neo/Ledger/Blockchain.cs @@ -148,8 +148,9 @@ static Blockchain() public Blockchain(NeoSystem system, Store store) { this.system = system; - this.MemPool = new MemoryPool(system, MemoryPoolMaxTransactions); this.Store = store; + this.MemPool = new MemoryPool(system, MemoryPoolMaxTransactions); + lock (lockObj) { if (singleton != null) diff --git a/neo/NeoSystem.cs b/neo/NeoSystem.cs index 91acf4c61e..e34e5b06ec 100644 --- a/neo/NeoSystem.cs +++ b/neo/NeoSystem.cs @@ -27,13 +27,13 @@ public class NeoSystem : IDisposable public IActorRef Consensus { get; private set; } public RpcServer RpcServer { get; private set; } - private readonly Store store; + private readonly Store consensusStore; private Peer.Start start_message = null; private bool suspend = false; - public NeoSystem(Store store) + public NeoSystem(Store store, Store consensusStore = null) { - this.store = store; + this.consensusStore = consensusStore ?? store; this.Blockchain = ActorSystem.ActorOf(Ledger.Blockchain.Props(this, store)); this.LocalNode = ActorSystem.ActorOf(Network.P2P.LocalNode.Props(this)); this.TaskManager = ActorSystem.ActorOf(Network.P2P.TaskManager.Props(this)); @@ -65,9 +65,9 @@ internal void ResumeNodeStartup() } } - public void StartConsensus(Wallet wallet, Store consensus_store = null, bool ignoreRecoveryLogs = false) + public void StartConsensus(Wallet wallet, bool ignoreRecoveryLogs = false) { - Consensus = ActorSystem.ActorOf(ConsensusService.Props(this.LocalNode, this.TaskManager, consensus_store ?? store, wallet)); + Consensus = ActorSystem.ActorOf(ConsensusService.Props(this.LocalNode, this.TaskManager, consensusStore, wallet)); Consensus.Tell(new ConsensusService.Start { IgnoreRecoveryLogs = ignoreRecoveryLogs }); } @@ -83,6 +83,10 @@ public void StartConsensus(Wallet wallet, Store consensus_store = null, bool ign }; if (!suspend) { + var consensusTransactions = Neo.Consensus.Helper.RetreiveTransactionsFromSavedConsensusContext(consensusStore); + foreach (var tx in consensusTransactions) + Blockchain.Tell(tx, ActorRefs.NoSender); + LocalNode.Tell(start_message); start_message = null; }