Skip to content

Commit

Permalink
Fix consensus (neo-project#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored and Luchuan committed Jan 10, 2020
1 parent 84d1e9c commit 0f75295
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions neo/Consensus/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ public void Deserialize(BinaryReader reader)
Block.ConsensusData = reader.ReadSerializable<ConsensusData>();
ViewNumber = reader.ReadByte();
TransactionHashes = reader.ReadSerializableArray<UInt256>();
if (TransactionHashes.Length == 0)
TransactionHashes = null;
Transaction[] transactions = reader.ReadSerializableArray<Transaction>(Block.MaxTransactionsPerBlock);
Transactions = transactions.Length == 0 ? null : transactions.ToDictionary(p => p.Hash);
PreparationPayloads = new ConsensusPayload[reader.ReadVarInt(Blockchain.MaxValidators)];
for (int i = 0; i < PreparationPayloads.Length; i++)
PreparationPayloads[i] = reader.ReadBoolean() ? reader.ReadSerializable<ConsensusPayload>() : null;
Expand All @@ -119,6 +116,9 @@ public void Deserialize(BinaryReader reader)
LastChangeViewPayloads = new ConsensusPayload[reader.ReadVarInt(Blockchain.MaxValidators)];
for (int i = 0; i < LastChangeViewPayloads.Length; i++)
LastChangeViewPayloads[i] = reader.ReadBoolean() ? reader.ReadSerializable<ConsensusPayload>() : null;
if (TransactionHashes.Length == 0 && !RequestSentOrReceived)
TransactionHashes = null;
Transactions = transactions.Length == 0 && !RequestSentOrReceived ? null : transactions.ToDictionary(p => p.Hash);
}

public void Dispose()
Expand Down Expand Up @@ -340,8 +340,7 @@ public void Reset(byte viewNumber)
{
PrevHash = Snapshot.CurrentBlockHash,
Index = Snapshot.Height + 1,
NextConsensus = Blockchain.GetConsensusAddress(NativeContract.NEO.GetValidators(Snapshot).ToArray()),
ConsensusData = new ConsensusData()
NextConsensus = Blockchain.GetConsensusAddress(NativeContract.NEO.GetValidators(Snapshot).ToArray())
};
var pv = Validators;
Validators = NativeContract.NEO.GetNextBlockValidators(Snapshot);
Expand Down Expand Up @@ -390,7 +389,10 @@ public void Reset(byte viewNumber)
LastChangeViewPayloads[i] = null;
}
ViewNumber = viewNumber;
Block.ConsensusData.PrimaryIndex = GetPrimaryIndex(viewNumber);
Block.ConsensusData = new ConsensusData
{
PrimaryIndex = GetPrimaryIndex(viewNumber)
};
Block.MerkleRoot = null;
Block.Timestamp = 0;
Block.Transactions = null;
Expand Down
2 changes: 1 addition & 1 deletion neo/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private void OnChangeViewReceived(ConsensusPayload payload, ChangeView message)
if (message.NewViewNumber <= expectedView)
return;

Log($"{nameof(OnChangeViewReceived)}: height={payload.BlockIndex} view={message.ViewNumber} index={payload.ValidatorIndex} nv={message.NewViewNumber}");
Log($"{nameof(OnChangeViewReceived)}: height={payload.BlockIndex} view={message.ViewNumber} index={payload.ValidatorIndex} nv={message.NewViewNumber} reason={message.Reason}");
context.ChangeViewPayloads[payload.ValidatorIndex] = payload;
CheckExpectedView(message.NewViewNumber);
}
Expand Down

0 comments on commit 0f75295

Please sign in to comment.