Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang committed Jan 30, 2021
1 parent 2618a19 commit b740ec7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
3 changes: 1 addition & 2 deletions neo-cli/CLI/MainService.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ partial class MainService
[ConsoleCommand("export blocks", Category = "Blockchain Commands")]
private void OnExportBlocksStartCountCommand(uint start, uint count = uint.MaxValue, string path = null)
{
using var snapshot = Blockchain.Singleton.GetSnapshot();
uint height = NativeContract.Ledger.CurrentIndex(snapshot);
uint height = NativeContract.Ledger.CurrentIndex(Blockchain.Singleton.View);
if (height < start)
{
Console.WriteLine("Error: invalid start height.");
Expand Down
3 changes: 1 addition & 2 deletions neo-cli/CLI/MainService.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ private void OnShowStateCommand()
Console.CursorVisible = false;
Console.Clear();

using var snapshot = Blockchain.Singleton.GetSnapshot();
uint height = NativeContract.Ledger.CurrentIndex(snapshot);
uint height = NativeContract.Ledger.CurrentIndex(Blockchain.Singleton.View);
Task broadcast = Task.Run(async () =>
{
while (!cancel.Token.IsCancellationRequested)
Expand Down
13 changes: 5 additions & 8 deletions neo-cli/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,16 @@ private static IEnumerable<Block> GetBlocks(Stream stream, bool read_start = fal
uint start = read_start ? r.ReadUInt32() : 0;
uint count = r.ReadUInt32();
uint end = start + count - 1;
using var snapshot = Blockchain.Singleton.GetSnapshot();
uint blockHeight = NativeContract.Ledger.CurrentIndex(snapshot);
if (end <= blockHeight) yield break;
uint currentHeight = NativeContract.Ledger.CurrentIndex(Blockchain.Singleton.View);
if (end <= currentHeight) yield break;
for (uint height = start; height <= end; height++)
{
var size = r.ReadInt32();
if (size > Message.PayloadMaxSize)
throw new ArgumentException($"Block {height} exceeds the maximum allowed size");

byte[] array = r.ReadBytes(size);
if (height > blockHeight)
if (height > currentHeight)
{
Block block = array.AsSerializable<Block>();
yield return block;
Expand Down Expand Up @@ -217,8 +216,7 @@ private IEnumerable<Block> GetBlocksFromFile()
IsCompressed = p.EndsWith(".zip")
}).OrderBy(p => p.Start);

using var snapshot = Blockchain.Singleton.GetSnapshot();
uint height = NativeContract.Ledger.CurrentIndex(snapshot);
uint height = NativeContract.Ledger.CurrentIndex(Blockchain.Singleton.View);
foreach (var path in paths)
{
if (path.Start > height + 1) break;
Expand Down Expand Up @@ -530,8 +528,7 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI
}
}

var snapshot = Blockchain.Singleton.GetSnapshot();
ContractState contract = NativeContract.ContractManagement.GetContract(snapshot, scriptHash);
ContractState contract = NativeContract.ContractManagement.GetContract(Blockchain.Singleton.View, scriptHash);
if (contract == null)
{
Console.WriteLine("Contract does not exist.");
Expand Down
4 changes: 2 additions & 2 deletions neo-cli/neo-cli.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Copyright>2016-2020 The Neo Project</Copyright>
<AssemblyTitle>Neo.CLI</AssemblyTitle>
Expand Down

0 comments on commit b740ec7

Please sign in to comment.