diff --git a/neo/Consensus/ConsensusContext.cs b/neo/Consensus/ConsensusContext.cs index 4574d70f7e..f96409318a 100644 --- a/neo/Consensus/ConsensusContext.cs +++ b/neo/Consensus/ConsensusContext.cs @@ -19,9 +19,9 @@ namespace Neo.Consensus internal class ConsensusContext : IDisposable, ISerializable { /// - /// Prefix for saving consensus state. + /// Key for saving consensus state. /// - public const byte CN_Context = 0xf4; + private static readonly byte[] ConsensusStateKey = { 0xf4 }; public Block Block; public byte ViewNumber; @@ -143,7 +143,7 @@ public uint GetPrimaryIndex(byte viewNumber) public bool Load() { - byte[] data = store.Get(CN_Context, new byte[0]); + byte[] data = store.Get(ConsensusStateKey); if (data is null || data.Length == 0) return false; using (MemoryStream ms = new MemoryStream(data, false)) using (BinaryReader reader = new BinaryReader(ms)) @@ -401,7 +401,7 @@ public void Reset(byte viewNumber) public void Save() { - store.PutSync(CN_Context, new byte[0], this.ToArray()); + store.PutSync(ConsensusStateKey, this.ToArray()); } public void Serialize(BinaryWriter writer) diff --git a/neo/Persistence/LevelDB/LevelDBStore.cs b/neo/Persistence/LevelDB/LevelDBStore.cs index bb6ac26698..805c1fe915 100644 --- a/neo/Persistence/LevelDB/LevelDBStore.cs +++ b/neo/Persistence/LevelDB/LevelDBStore.cs @@ -34,9 +34,9 @@ public void Dispose() db.Dispose(); } - public override byte[] Get(byte prefix, byte[] key) + public override byte[] Get(byte[] key) { - if (!db.TryGet(ReadOptions.Default, SliceBuilder.Begin(prefix).Add(key), out Slice slice)) + if (!db.TryGet(ReadOptions.Default, key, out Slice slice)) return null; return slice.ToArray(); } @@ -81,14 +81,14 @@ public override MetaDataCache GetHeaderHashIndex() return new DbMetaDataCache(db, null, null, Prefixes.IX_CurrentHeader); } - public override void Put(byte prefix, byte[] key, byte[] value) + public override void Put(byte[] key, byte[] value) { - db.Put(WriteOptions.Default, SliceBuilder.Begin(prefix).Add(key), value); + db.Put(WriteOptions.Default, key, value); } - public override void PutSync(byte prefix, byte[] key, byte[] value) + public override void PutSync(byte[] key, byte[] value) { - db.Put(new WriteOptions { Sync = true }, SliceBuilder.Begin(prefix).Add(key), value); + db.Put(new WriteOptions { Sync = true }, key, value); } } } diff --git a/neo/Persistence/Store.cs b/neo/Persistence/Store.cs index 3dc7127f3a..eab5c182b9 100644 --- a/neo/Persistence/Store.cs +++ b/neo/Persistence/Store.cs @@ -14,7 +14,7 @@ public abstract class Store : IPersistence MetaDataCache IPersistence.BlockHashIndex => GetBlockHashIndex(); MetaDataCache IPersistence.HeaderHashIndex => GetHeaderHashIndex(); - public abstract byte[] Get(byte prefix, byte[] key); + public abstract byte[] Get(byte[] key); public abstract DataCache GetBlocks(); public abstract DataCache GetTransactions(); public abstract DataCache GetContracts(); @@ -22,8 +22,8 @@ public abstract class Store : IPersistence public abstract DataCache GetHeaderHashList(); public abstract MetaDataCache GetBlockHashIndex(); public abstract MetaDataCache GetHeaderHashIndex(); - public abstract void Put(byte prefix, byte[] key, byte[] value); - public abstract void PutSync(byte prefix, byte[] key, byte[] value); + public abstract void Put(byte[] key, byte[] value); + public abstract void PutSync(byte[] key, byte[] value); public abstract Snapshot GetSnapshot(); }