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

Hide the prefix in the store #1070

Merged
merged 2 commits into from
Aug 28, 2019
Merged
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
8 changes: 4 additions & 4 deletions neo/Consensus/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace Neo.Consensus
internal class ConsensusContext : IDisposable, ISerializable
{
/// <summary>
/// Prefix for saving consensus state.
/// Key for saving consensus state.
/// </summary>
public const byte CN_Context = 0xf4;
private static readonly byte[] ConsensusStateKey = { 0xf4 };

public Block Block;
public byte ViewNumber;
Expand Down Expand Up @@ -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);
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
if (data is null || data.Length == 0) return false;
using (MemoryStream ms = new MemoryStream(data, false))
using (BinaryReader reader = new BinaryReader(ms))
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions neo/Persistence/LevelDB/LevelDBStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
return null;
return slice.ToArray();
}
Expand Down Expand Up @@ -81,14 +81,14 @@ public override MetaDataCache<HashIndexState> GetHeaderHashIndex()
return new DbMetaDataCache<HashIndexState>(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);
}
}
}
6 changes: 3 additions & 3 deletions neo/Persistence/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ public abstract class Store : IPersistence
MetaDataCache<HashIndexState> IPersistence.BlockHashIndex => GetBlockHashIndex();
MetaDataCache<HashIndexState> IPersistence.HeaderHashIndex => GetHeaderHashIndex();

public abstract byte[] Get(byte prefix, byte[] key);
public abstract byte[] Get(byte[] key);
public abstract DataCache<UInt256, TrimmedBlock> GetBlocks();
public abstract DataCache<UInt256, TransactionState> GetTransactions();
public abstract DataCache<UInt160, ContractState> GetContracts();
public abstract DataCache<StorageKey, StorageItem> GetStorages();
public abstract DataCache<UInt32Wrapper, HeaderHashList> GetHeaderHashList();
public abstract MetaDataCache<HashIndexState> GetBlockHashIndex();
public abstract MetaDataCache<HashIndexState> 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();
}
Expand Down