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

Restore transactions from saved consensus context #598

Merged
merged 4 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions neo/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,21 @@ private void OnStart(Start options)
{
Log("OnStart");
started = true;
bool loadedState = !options.IgnoreRecoveryLogs && context.Load(store);
if (loadedState && context.State.HasFlag(ConsensusState.CommitSent))
if (!options.IgnoreRecoveryLogs && context.Load(store))
{
CheckPreparations();
return;
if (context.Transactions != null)
{
Sender.Ask<Blockchain.FillCompleted>(new Blockchain.FillMemoryPool
{
Transactions = context.Transactions.Values
}).Wait();
}
if (context.State.HasFlag(ConsensusState.CommitSent))
{
CheckPreparations();
return;
}
}

InitializeConsensus(0);
// Issue a ChangeView with NewViewNumber of 0 to request recovery messages on start-up.
if (context.BlockIndex == Blockchain.Singleton.HeaderHeight + 1)
Expand Down
14 changes: 14 additions & 0 deletions neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ApplicationExecuted { public Transaction Transaction; public Applic
public class PersistCompleted { public Block Block; }
public class Import { public IEnumerable<Block> Blocks; }
public class ImportCompleted { }
public class FillMemoryPool { public IEnumerable<Transaction> Transactions; }
public class FillCompleted { }

public static readonly uint SecondsPerBlock = ProtocolSettings.Default.SecondsPerBlock;
public const uint DecrementInterval = 2000000;
Expand Down Expand Up @@ -253,6 +255,15 @@ private void AddUnverifiedBlockToCache(Block block)
blocks.AddLast(block);
}

private void OnFillMemoryPool(IEnumerable<Transaction> transactions)
{
//TODO: Fill the memory pool with the transactions from the consensus context
// Step 1: Remove all the transactions in the memory pool
// Step 2: Add the transactions from the consensus context to the memory pool
// Step 3: Add the original transactions to the memory pool
jsolman marked this conversation as resolved.
Show resolved Hide resolved
Sender.Tell(new FillCompleted());
}

private RelayResultReason OnNewBlock(Block block)
{
if (block.Index <= Height)
Expand Down Expand Up @@ -406,6 +417,9 @@ protected override void OnReceive(object message)
case Import import:
OnImport(import.Blocks);
break;
case FillMemoryPool fill:
OnFillMemoryPool(fill.Transactions);
break;
case Header[] headers:
OnNewHeaders(headers);
break;
Expand Down
2 changes: 1 addition & 1 deletion neo/NeoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal void ResumeNodeStartup()
public void StartConsensus(Wallet wallet, Store consensus_store = null, bool ignoreRecoveryLogs = false)
{
Consensus = ActorSystem.ActorOf(ConsensusService.Props(this.LocalNode, this.TaskManager, consensus_store ?? store, wallet));
Consensus.Tell(new ConsensusService.Start { IgnoreRecoveryLogs = ignoreRecoveryLogs });
Consensus.Tell(new ConsensusService.Start { IgnoreRecoveryLogs = ignoreRecoveryLogs }, Blockchain);
}

public void StartNode(int port = 0, int wsPort = 0, int minDesiredConnections = Peer.DefaultMinDesiredConnections,
Expand Down