Skip to content

Commit 096f472

Browse files
JimmyshargonNGDAdmin
authored
[Neo Core Store] Rename various snapshots. (#3406)
* rename snapshot * Remove warning --------- Co-authored-by: Shargon <[email protected]> Co-authored-by: NGD Admin <[email protected]>
1 parent 6c29bde commit 096f472

File tree

31 files changed

+167
-95
lines changed

31 files changed

+167
-95
lines changed

benchmarks/Neo.Benchmarks/Benchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private static void Run(string name, string poc)
6767
Script = Convert.FromBase64String(poc),
6868
Witnesses = Array.Empty<Witness>()
6969
};
70-
using var snapshot = system.GetSnapshot();
70+
using var snapshot = system.GetSnapshotCache();
7171
using var engine = ApplicationEngine.Create(TriggerType.Application, tx, snapshot, system.GenesisBlock, protocol, tx.SystemFee);
7272
engine.LoadScript(tx.Script);
7373
Stopwatch stopwatch = Stopwatch.StartNew();

src/Neo.GUI/GUI/MainForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private void timer1_Tick(object sender, EventArgs e)
201201
check_nep5_balance = false;
202202
UInt160[] addresses = Service.CurrentWallet.GetAccounts().Select(p => p.ScriptHash).ToArray();
203203
if (addresses.Length == 0) return;
204-
using var snapshot = Service.NeoSystem.GetSnapshot();
204+
using var snapshot = Service.NeoSystem.GetSnapshotCache();
205205
foreach (UInt160 assetId in NEP5Watched)
206206
{
207207
byte[] script;

src/Neo/Ledger/Blockchain.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ private void OnTransaction(Transaction tx)
421421

422422
private void Persist(Block block)
423423
{
424-
using (SnapshotCache snapshot = system.GetSnapshot())
424+
using (SnapshotCache snapshot = system.GetSnapshotCache())
425425
{
426426
List<ApplicationExecuted> all_application_executed = new();
427427
TransactionState[] transactionStates;
@@ -439,7 +439,7 @@ private void Persist(Block block)
439439
all_application_executed.Add(application_executed);
440440
transactionStates = engine.GetState<TransactionState[]>();
441441
}
442-
DataCache clonedSnapshot = snapshot.CreateSnapshot();
442+
DataCache clonedSnapshot = snapshot.CloneCache();
443443
// Warning: Do not write into variable snapshot directly. Write into variable clonedSnapshot and commit instead.
444444
foreach (TransactionState transactionState in transactionStates)
445445
{
@@ -453,7 +453,7 @@ private void Persist(Block block)
453453
}
454454
else
455455
{
456-
clonedSnapshot = snapshot.CreateSnapshot();
456+
clonedSnapshot = snapshot.CloneCache();
457457
}
458458
ApplicationExecuted application_executed = new(engine);
459459
Context.System.EventStream.Publish(application_executed);

src/Neo/NeoSystem.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,24 @@ public void SuspendNodeStartup()
275275
/// <summary>
276276
/// Gets a snapshot of the blockchain storage.
277277
/// </summary>
278-
/// <returns></returns>
278+
/// <returns>An instance of <see cref="SnapshotCache"/></returns>
279+
[Obsolete("This method is obsolete, use GetSnapshotCache instead.")]
279280
public SnapshotCache GetSnapshot()
280281
{
281282
return new SnapshotCache(store.GetSnapshot());
282283
}
283284

285+
/// <summary>
286+
/// Gets a snapshot of the blockchain storage with an execution cache.
287+
/// With the snapshot, we have the latest state of the blockchain, with the cache,
288+
/// we can run transactions in a sandboxed environment.
289+
/// </summary>
290+
/// <returns>An instance of <see cref="SnapshotCache"/></returns>
291+
public SnapshotCache GetSnapshotCache()
292+
{
293+
return new SnapshotCache(store.GetSnapshot());
294+
}
295+
284296
/// <summary>
285297
/// Determines whether the specified transaction exists in the memory pool or storage.
286298
/// </summary>

src/Neo/Persistence/DataCache.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,21 @@ public virtual void Commit()
152152
/// Creates a snapshot, which uses this instance as the underlying storage.
153153
/// </summary>
154154
/// <returns>The snapshot of this instance.</returns>
155+
[Obsolete("CreateSnapshot is deprecated, please use CloneCache instead.")]
155156
public DataCache CreateSnapshot()
156157
{
157158
return new ClonedCache(this);
158159
}
159160

161+
/// <summary>
162+
/// Creates a clone of the snapshot cache, which uses this instance as the underlying storage.
163+
/// </summary>
164+
/// <returns>The <see cref="DataCache"/> of this <see cref="SnapshotCache"/> instance.</returns>
165+
public DataCache CloneCache()
166+
{
167+
return new ClonedCache(this);
168+
}
169+
160170
/// <summary>
161171
/// Deletes an entry from the cache.
162172
/// </summary>

src/Neo/SmartContract/ApplicationEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public ExecutionContext LoadScript(Script script, int rvcount = -1, int initialP
460460
// Create and configure context
461461
ExecutionContext context = CreateContext(script, rvcount, initialPosition);
462462
ExecutionContextState state = context.GetState<ExecutionContextState>();
463-
state.Snapshot = Snapshot?.CreateSnapshot();
463+
state.Snapshot = Snapshot?.CloneCache();
464464
configureState?.Invoke(state);
465465

466466
// Load context

src/Neo/SmartContract/Helper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ internal static bool VerifyWitness(this IVerifiable verifiable, ProtocolSettings
326326
{
327327
return false;
328328
}
329-
using (ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, verifiable, snapshot?.CreateSnapshot(), null, settings, datoshi))
329+
using (ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, verifiable, snapshot?.CloneCache(), null, settings, datoshi))
330330
{
331331
if (witness.VerificationScript.Length == 0)
332332
{

src/Neo/Wallets/Helper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public static long CalculateNetworkFee(this Transaction tx, DataCache snapshot,
133133
size += Array.Empty<byte>().GetVarSize() + invSize;
134134

135135
// Check verify cost
136-
using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.CreateSnapshot(), settings: settings, gas: maxExecutionCost);
136+
using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.CloneCache(), settings: settings, gas: maxExecutionCost);
137137
engine.LoadContract(contract, md, CallFlags.ReadOnly);
138138
if (invocationScript != null) engine.LoadScript(invocationScript, configureState: p => p.CallFlags = CallFlags.None);
139139
if (engine.Execute() == VMState.FAULT) throw new ArgumentException($"Smart contract {contract.Hash} verification fault.");

src/Neo/Wallets/Wallet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ private Transaction MakeTransaction(DataCache snapshot, ReadOnlyMemory<byte> scr
574574
};
575575

576576
// will try to execute 'transfer' script to check if it works
577-
using (ApplicationEngine engine = ApplicationEngine.Run(script, snapshot.CreateSnapshot(), tx, settings: ProtocolSettings, gas: maxGas, persistingBlock: persistingBlock))
577+
using (ApplicationEngine engine = ApplicationEngine.Run(script, snapshot.CloneCache(), tx, settings: ProtocolSettings, gas: maxGas, persistingBlock: persistingBlock))
578578
{
579579
if (engine.State == VMState.FAULT)
580580
{

src/Plugins/DBFTPlugin/Consensus/ConsensusContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public void Reset(byte viewNumber)
192192
if (viewNumber == 0)
193193
{
194194
Snapshot?.Dispose();
195-
Snapshot = neoSystem.GetSnapshot();
195+
Snapshot = neoSystem.GetSnapshotCache();
196196
uint height = NativeContract.Ledger.CurrentIndex(Snapshot);
197197
Block = new Block
198198
{

0 commit comments

Comments
 (0)