Skip to content

Commit

Permalink
Fix block tip check
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Nov 18, 2023
1 parent 496f209 commit 111019c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions NineChronicles.Headless/BlockChainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ public UnaryResult<Dictionary<byte[], byte[]>> GetSheets(
IEnumerable<byte[]> addressBytesList,
byte[] stateRootHashBytes)
{
var stateRootHash = new HashDigest<SHA256>(stateRootHashBytes);
var result = new Dictionary<byte[], byte[]>();
List<Address> addresses = new List<Address>();
foreach (var b in addressBytesList)
Expand All @@ -226,13 +225,18 @@ public UnaryResult<Dictionary<byte[], byte[]>> GetSheets(
addresses.Add(address);
}
}
IReadOnlyList<IValue> values = _blockChain.GetAccountState(_blockChain.Tip.Hash).GetStates(addresses);
for (int i = 0; i < addresses.Count; i++)

if (addresses.Any())
{
var address = addresses[i];
var value = _codec.Encode(values[i] ?? Null.Value);
_memoryCache.Set(address.ToString(), value);
result.TryAdd(address.ToByteArray(), value);
var stateRootHash = new HashDigest<SHA256>(stateRootHashBytes);
IReadOnlyList<IValue> values = _blockChain.GetAccountState(stateRootHash).GetStates(addresses);
for (int i = 0; i < addresses.Count; i++)
{
var address = addresses[i];
var value = _codec.Encode(values[i] ?? Null.Value);
_memoryCache.Set(address.ToString(), value);
result.TryAdd(address.ToByteArray(), value);
}
}

return new UnaryResult<Dictionary<byte[], byte[]>>(result);
Expand Down

0 comments on commit 111019c

Please sign in to comment.