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

Add: add previous block state to the block header #3045

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions src/Neo/Network/P2P/Payloads/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public sealed class Block : IEquatable<Block>, IInventory
/// </summary>
public UInt256 PrevHash => Header.PrevHash;

/// <summary>
/// The state root of the previous block.
/// </summary>
public UInt256 PrevState => Header.PrevState;

/// <summary>
/// The merkle root of the transactions.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/Neo/Network/P2P/Payloads/Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public sealed class Header : IEquatable<Header>, IVerifiable
{
private uint version;
private UInt256 prevHash;
private UInt256 prevState;
private UInt256 merkleRoot;
private ulong timestamp;
private ulong nonce;
Expand Down Expand Up @@ -58,6 +59,12 @@ public UInt256 PrevHash
set { prevHash = value; _hash = null; }
}

public UInt256 PrevState
{
get => prevState;
set { prevState = value; }
}

/// <summary>
/// The merkle root of the transactions.
/// </summary>
Expand Down Expand Up @@ -128,6 +135,7 @@ public UInt256 Hash
public int Size =>
sizeof(uint) + // Version
UInt256.Length + // PrevHash
UInt256.Length + // PrevState
UInt256.Length + // MerkleRoot
sizeof(ulong) + // Timestamp
sizeof(ulong) + // Nonce
Expand Down Expand Up @@ -163,6 +171,7 @@ void IVerifiable.DeserializeUnsigned(ref MemoryReader reader)
version = reader.ReadUInt32();
if (version > 0) throw new FormatException();
prevHash = reader.ReadSerializable<UInt256>();
prevState = reader.ReadSerializable<UInt256>();
merkleRoot = reader.ReadSerializable<UInt256>();
timestamp = reader.ReadUInt64();
nonce = reader.ReadUInt64();
Expand Down Expand Up @@ -206,6 +215,7 @@ void IVerifiable.SerializeUnsigned(BinaryWriter writer)
{
writer.Write(version);
writer.Write(prevHash);
writer.Write(prevState);
writer.Write(merkleRoot);
writer.Write(timestamp);
writer.Write(nonce);
Expand All @@ -226,6 +236,7 @@ public JObject ToJson(ProtocolSettings settings)
json["size"] = Size;
json["version"] = version;
json["previousblockhash"] = prevHash.ToString();
json["previousblockstate"] = prevState.ToString();
json["merkleroot"] = merkleRoot.ToString();
json["time"] = timestamp;
json["nonce"] = nonce.ToString("X16");
Expand Down