Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public AddressIndexerData GetOrCreateAddress(string address)
{
if (!this.TryGetValue(address, out AddressIndexerData data))
{
this.logger.Debug("Not found in cache.");
this.logger.LogDebug("Not found in cache.");
data = this.addressIndexerDataCollection.FindById(address) ?? new AddressIndexerData() { Address = address, BalanceChanges = new List<AddressBalanceChange>() };
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public void SaveAllItems()
{
CacheItem[] dirtyItems = this.Keys.Where(x => x.Dirty).ToArray();

this.logger.Debug("Saving {0} dirty items.", dirtyItems.Length);
this.logger.LogDebug("Saving {0} dirty items.", dirtyItems.Length);

List<AddressIndexerData> toUpsert = dirtyItems.Select(x => x.Value).ToList();

Expand All @@ -91,7 +91,7 @@ public void SaveAllItems()
foreach (CacheItem dirtyItem in dirtyItems)
dirtyItem.Dirty = false;

this.logger.Debug("Saved dirty items.");
this.logger.LogDebug("Saved dirty items.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void Initialize()
// The transaction index is needed in the event of a reorg.
if (!this.storeSettings.AddressIndex)
{
this.logger.Trace("(-)[DISABLED]");
this.logger.LogTrace("(-)[DISABLED]");
return;
}

Expand All @@ -194,15 +194,15 @@ public void Initialize()

this.addressIndexRepository = new AddressIndexRepository(this.db);

this.logger.Debug("Address indexing is enabled.");
this.logger.LogDebug("Address indexing is enabled.");

this.tipDataStore = this.db.GetCollection<AddressIndexerTipData>(DbTipDataKey);

lock (this.lockObject)
{
AddressIndexerTipData tipData = this.tipDataStore.FindAll().FirstOrDefault();

this.logger.Debug("Tip data: '{0}'.", tipData == null ? "null" : tipData.ToString());
this.logger.LogDebug("Tip data: '{0}'.", tipData == null ? "null" : tipData.ToString());

this.IndexerTip = tipData == null ? this.chainIndexer.Genesis : this.consensusManager.Tip.FindAncestorOrSelf(new uint256(tipData.TipHashBytes));

Expand All @@ -222,7 +222,7 @@ public void Initialize()

this.RewindAndSave(this.IndexerTip);

this.logger.Debug("Indexer initialized at '{0}'.", this.IndexerTip);
this.logger.LogDebug("Indexer initialized at '{0}'.", this.IndexerTip);

this.indexingTask = Task.Run(async () => await this.IndexAddressesContinuouslyAsync().ConfigureAwait(false));

Expand All @@ -239,26 +239,26 @@ private async Task IndexAddressesContinuouslyAsync()
{
if (this.dateTimeProvider.GetUtcNow() - this.lastFlushTime > this.flushChangesInterval)
{
this.logger.Debug("Flushing changes.");
this.logger.LogDebug("Flushing changes.");

this.SaveAll();

this.lastFlushTime = this.dateTimeProvider.GetUtcNow();

this.logger.Debug("Flush completed.");
this.logger.LogDebug("Flush completed.");
}

if (this.cancellation.IsCancellationRequested)
{
this.logger.Debug("Cancelled loop.");
this.logger.LogDebug("Cancelled loop.");
break;
}

ChainedHeader nextHeader = this.consensusManager.Tip.GetAncestor(this.IndexerTip.Height + 1);

if (nextHeader == null)
{
this.logger.Debug("Next header wasn't found. Waiting.");
this.logger.LogDebug("Next header wasn't found. Waiting.");

try
{
Expand All @@ -275,7 +275,7 @@ private async Task IndexAddressesContinuouslyAsync()
{
ChainedHeader lastCommonHeader = nextHeader.FindFork(this.IndexerTip);

this.logger.Debug("Reorganization detected. Rewinding till '{0}'.", lastCommonHeader);
this.logger.LogDebug("Reorganization detected. Rewinding till '{0}'.", lastCommonHeader);

this.RewindAndSave(lastCommonHeader);

Expand All @@ -294,7 +294,7 @@ private async Task IndexAddressesContinuouslyAsync()

if (blockToProcess == null)
{
this.logger.Debug("Next block wasn't found. Waiting.");
this.logger.LogDebug("Next block wasn't found. Waiting.");

try
{
Expand Down Expand Up @@ -322,7 +322,7 @@ private async Task IndexAddressesContinuouslyAsync()

if (!success)
{
this.logger.Debug("Failed to process next block. Waiting.");
this.logger.LogDebug("Failed to process next block. Waiting.");

try
{
Expand Down Expand Up @@ -357,7 +357,7 @@ private void RewindAndSave(ChainedHeader rewindToHeader)
indexData.BalanceChanges.RemoveAll(x => x.BalanceChangedHeight > rewindToHeader.Height);
}

this.logger.Debug("Rewinding changes for {0} addresses.", affectedAddresses.Count);
this.logger.LogDebug("Rewinding changes for {0} addresses.", affectedAddresses.Count);

// Rewind all the way back to the fork point.
this.outpointsRepository.RewindDataAboveHeight(rewindToHeader.Height);
Expand All @@ -370,14 +370,14 @@ private void RewindAndSave(ChainedHeader rewindToHeader)

private void SaveAll()
{
this.logger.Debug("Saving address indexer.");
this.logger.LogDebug("Saving address indexer.");

lock (this.lockObject)
{
this.logger.Debug("Saving addr indexer repo.");
this.logger.LogDebug("Saving addr indexer repo.");
this.addressIndexRepository.SaveAllItems();

this.logger.Debug("Saving outpoints repo.");
this.logger.LogDebug("Saving outpoints repo.");
this.outpointsRepository.SaveAllItems();

AddressIndexerTipData tipData = this.tipDataStore.FindAll().FirstOrDefault();
Expand All @@ -388,13 +388,13 @@ private void SaveAll()
tipData.Height = this.IndexerTip.Height;
tipData.TipHashBytes = this.IndexerTip.HashBlock.ToBytes();

this.logger.Debug("Saving tip data.");
this.logger.LogDebug("Saving tip data.");

this.tipDataStore.Upsert(tipData);
this.lastSavedHeight = this.IndexerTip.Height;
}

this.logger.Debug("Address indexer saved.");
this.logger.LogDebug("Address indexer saved.");
}

private void AddInlineStats(StringBuilder benchLog)
Expand All @@ -411,7 +411,7 @@ private void AddInlineStats(StringBuilder benchLog)
/// <returns><c>true</c> if block was sucessfully processed.</returns>
private bool ProcessBlock(Block block, ChainedHeader header)
{
this.logger.Trace("Processing block " + header.ToString());
this.logger.LogTrace("Processing block " + header.ToString());

lock (this.lockObject)
{
Expand Down Expand Up @@ -460,8 +460,8 @@ private bool ProcessBlock(Block block, ChainedHeader header)

if (!this.outpointsRepository.TryGetOutPointData(consumedOutput, out OutPointData consumedOutputData))
{
this.logger.Error("Missing outpoint data for {0}.", consumedOutput);
this.logger.Trace("(-)[MISSING_OUTPOINTS_DATA]");
this.logger.LogError("Missing outpoint data for {0}.", consumedOutput);
this.logger.LogTrace("(-)[MISSING_OUTPOINTS_DATA]");
throw new Exception($"Missing outpoint data for {consumedOutput}");
}

Expand Down Expand Up @@ -523,7 +523,7 @@ private bool ProcessBlock(Block block, ChainedHeader header)
this.outpointsRepository.RemoveOutPointData(consumedOutPoint);
}

this.logger.Trace("Block processed.");
this.logger.LogTrace("Block processed.");
return true;
}

Expand Down Expand Up @@ -554,7 +554,7 @@ private void ProcessBalanceChangeLocked(int height, string address, Money amount
{
this.addressIndexRepository.AddOrUpdate(indexData.Address, indexData, indexData.BalanceChanges.Count + 1);

this.logger.Trace("(-)[TOO_FEW_CHANGE_RECORDS]");
this.logger.LogTrace("(-)[TOO_FEW_CHANGE_RECORDS]");
return;
}

Expand All @@ -574,14 +574,14 @@ private void ProcessBalanceChangeLocked(int height, string address, Money amount

if ((change.BalanceChangedHeight) < heightThreshold && i < CompactionAmount)
{
this.logger.Debug("Balance change: {0} was selected for compaction. Compacted balance now: {1}.", change, compacted[0].Satoshi);
this.logger.LogDebug("Balance change: {0} was selected for compaction. Compacted balance now: {1}.", change, compacted[0].Satoshi);

if (change.Deposited)
compacted[0].Satoshi += change.Satoshi;
else
compacted[0].Satoshi -= change.Satoshi;

this.logger.Debug("New compacted balance: {0}.", compacted[0].Satoshi);
this.logger.LogDebug("New compacted balance: {0}.", compacted[0].Satoshi);
}
else
compacted.Add(change);
Expand Down Expand Up @@ -620,7 +620,7 @@ public AddressBalancesResult GetAddressBalances(string[] addresses, int minConfi

long balance = indexData.BalanceChanges.Where(x => x.BalanceChangedHeight <= maxAllowedHeight).CalculateBalance();

this.logger.Debug("Address: {0}, balance: {1}.", address, balance);
this.logger.LogDebug("Address: {0}, balance: {1}.", address, balance);
result.Balances.Add(new AddressBalanceResult(address, new Money(balance)));
}

Expand Down Expand Up @@ -735,13 +735,13 @@ public LastBalanceDecreaseTransactionModel GetLastBalanceDecreaseTransaction(str
{
if (this.addressIndexRepository == null)
{
this.logger.Trace("(-)[NOT_INITIALIZED]");
this.logger.LogTrace("(-)[NOT_INITIALIZED]");
return (false, "Address indexer is not initialized.");
}

if (!this.IsSynced())
{
this.logger.Trace("(-)[NOT_SYNCED]");
this.logger.LogTrace("(-)[NOT_SYNCED]");
return (false, "Address indexer is not synced.");
}

Expand All @@ -751,15 +751,15 @@ public LastBalanceDecreaseTransactionModel GetLastBalanceDecreaseTransaction(str
/// <inheritdoc/>
public void Dispose()
{
this.logger.Debug("Disposing.");
this.logger.LogDebug("Disposing.");

this.cancellation.Cancel();

this.indexingTask?.GetAwaiter().GetResult();

this.db?.Dispose();

this.logger.Debug("Disposed.");
this.logger.LogDebug("Disposed.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public bool TryGetOutPointData(OutPoint outPoint, out OutPointData outPointData)
{
if (this.TryGetValue(outPoint.ToString(), out outPointData))
{
this.logger.Trace("(-)[FOUND_IN_CACHE]:true");
this.logger.LogTrace("(-)[FOUND_IN_CACHE]:true");
return true;
}

Expand All @@ -84,7 +84,7 @@ public bool TryGetOutPointData(OutPoint outPoint, out OutPointData outPointData)
if (outPointData != null)
{
this.AddOutPointData(outPointData);
this.logger.Trace("(-)[FOUND_IN_DATABASE]:true");
this.logger.LogTrace("(-)[FOUND_IN_DATABASE]:true");
return true;
}

Expand All @@ -93,7 +93,7 @@ public bool TryGetOutPointData(OutPoint outPoint, out OutPointData outPointData)

public void SaveAllItems()
{
this.logger.Debug("Saving all items.");
this.logger.LogDebug("Saving all items.");
lock (this.LockObject)
{
CacheItem[] dirtyItems = this.Keys.Where(x => x.Dirty).ToArray();
Expand All @@ -102,7 +102,7 @@ public void SaveAllItems()
foreach (CacheItem dirtyItem in dirtyItems)
dirtyItem.Dirty = false;

this.logger.Debug("{0} items saved.", dirtyItems.Length);
this.logger.LogDebug("{0} items saved.", dirtyItems.Length);
}

}
Expand All @@ -123,9 +123,9 @@ public void PurgeOldRewindData(int height)
{
lock (this.LockObject)
{
this.logger.Info("AddressIndexer: started purging rewind data items.");
this.logger.LogInformation("AddressIndexer: started purging rewind data items.");
int purgedCount = this.addressIndexerRewindData.Delete(x => x.BlockHeight < height);
this.logger.Info("AddressIndexer: Purged {0} rewind data items.", purgedCount);
this.logger.LogInformation("AddressIndexer: Purged {0} rewind data items.", purgedCount);
}
}

Expand All @@ -137,7 +137,7 @@ public void RewindDataAboveHeight(int height)
{
IEnumerable<AddressIndexerRewindData> toRestore = this.addressIndexerRewindData.Find(x => x.BlockHeight > height);

this.logger.Debug("Restoring data for {0} blocks.", toRestore.Count());
this.logger.LogDebug("Restoring data for {0} blocks.", toRestore.Count());

foreach (AddressIndexerRewindData rewindData in toRestore)
{
Expand Down
Loading