From 21c4cc932a340f18f72460869ff23a42e8ff8eee Mon Sep 17 00:00:00 2001 From: Jim8y Date: Sun, 31 Dec 2023 12:01:04 +0800 Subject: [PATCH] add previous block state to the block header --- src/Neo/Network/P2P/Payloads/Block.cs | 5 +++++ src/Neo/Network/P2P/Payloads/Header.cs | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Neo/Network/P2P/Payloads/Block.cs b/src/Neo/Network/P2P/Payloads/Block.cs index 955bf98bf6..8584814d4e 100644 --- a/src/Neo/Network/P2P/Payloads/Block.cs +++ b/src/Neo/Network/P2P/Payloads/Block.cs @@ -46,6 +46,11 @@ public sealed class Block : IEquatable, IInventory /// public UInt256 PrevHash => Header.PrevHash; + /// + /// The state root of the previous block. + /// + public UInt256 PrevState => Header.PrevState; + /// /// The merkle root of the transactions. /// diff --git a/src/Neo/Network/P2P/Payloads/Header.cs b/src/Neo/Network/P2P/Payloads/Header.cs index d971ac2aaa..22a9af89d4 100644 --- a/src/Neo/Network/P2P/Payloads/Header.cs +++ b/src/Neo/Network/P2P/Payloads/Header.cs @@ -27,6 +27,7 @@ public sealed class Header : IEquatable
, IVerifiable { private uint version; private UInt256 prevHash; + private UInt256 prevState; private UInt256 merkleRoot; private ulong timestamp; private ulong nonce; @@ -57,6 +58,12 @@ public UInt256 PrevHash set { prevHash = value; _hash = null; } } + public UInt256 PrevState + { + get => prevState; + set { prevState = value; } + } + /// /// The merkle root of the transactions. /// @@ -127,6 +134,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 @@ -162,6 +170,7 @@ void IVerifiable.DeserializeUnsigned(ref MemoryReader reader) version = reader.ReadUInt32(); if (version > 0) throw new FormatException(); prevHash = reader.ReadSerializable(); + prevState = reader.ReadSerializable(); merkleRoot = reader.ReadSerializable(); timestamp = reader.ReadUInt64(); nonce = reader.ReadUInt64(); @@ -205,6 +214,7 @@ void IVerifiable.SerializeUnsigned(BinaryWriter writer) { writer.Write(version); writer.Write(prevHash); + writer.Write(prevState); writer.Write(merkleRoot); writer.Write(timestamp); writer.Write(nonce); @@ -225,6 +235,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");