Skip to content

Commit

Permalink
Ensure that the block is valid before relay it on CheckCommits (neo-p…
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored and Luchuan committed Jan 10, 2020
1 parent d54458b commit 7723d9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
17 changes: 3 additions & 14 deletions neo.UnitTests/Consensus/UT_ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Neo.Consensus;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.Wallets;
using System;
Expand Down Expand Up @@ -119,6 +118,8 @@ private Block SignBlock(ConsensusContext context)
{
context.Block.MerkleRoot = null;

// Fake commits

for (int x = 0; x < _validatorKeys.Length; x++)
{
_context.MyIndex = x;
Expand All @@ -127,19 +128,7 @@ private Block SignBlock(ConsensusContext context)
_context.CommitPayloads[_context.MyIndex] = com;
}

// Manual block sign

Contract contract = Contract.CreateMultiSigContract(context.M, context.Validators);
ContractParametersContext sc = new ContractParametersContext(context.Block);
for (int i = 0, j = 0; i < context.Validators.Length && j < context.M; i++)
{
if (context.CommitPayloads[i]?.ConsensusMessage.ViewNumber != context.ViewNumber) continue;
sc.AddSignature(contract, context.Validators[i], context.CommitPayloads[i].GetDeserializedMessage<Commit>().Signature);
j++;
}
context.Block.Witness = sc.GetWitnesses()[0];
context.Block.Transactions = context.TransactionHashes.Select(p => context.Transactions[p]).ToArray();
return context.Block;
return context.CreateBlock();
}

private void EnsureContext(ConsensusContext context, params Transaction[] expected)
Expand Down
1 change: 1 addition & 0 deletions neo/Consensus/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public ConsensusContext(Wallet wallet, Store store)

public Block CreateBlock()
{
EnsureHeader();
Contract contract = Contract.CreateMultiSigContract(M, Validators);
ContractParametersContext sc = new ContractParametersContext(Block);
for (int i = 0, j = 0; i < Validators.Length && j < M; i++)
Expand Down

0 comments on commit 7723d9b

Please sign in to comment.