Skip to content

Commit d95c898

Browse files
authored
Remove the ChainedBlocksDataBytes (#338)
- "ChainedBlocksDataBytes" was not really used, but required loading of all headers on startup. Removed to improve performance from 52 seconds to 42 seconds. - This was discovered independent of stratisproject/StratisFullNode#233, but linking to that issue to help Stratis and Blockcore-based blockchains to take the improvement. - #337
1 parent aff064d commit d95c898

2 files changed

Lines changed: 0 additions & 12 deletions

File tree

src/Blockcore/Consensus/Chain/ChainedHeaderTree.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ internal interface IChainedHeaderTree
4646
/// <summary>Total amount of unconsumed blocks.</summary>
4747
long UnconsumedBlocksCount { get; }
4848

49-
/// <summary>Total size of ChainedHeaders data in bytes.</summary>
50-
long ChainedBlocksDataBytes { get; }
51-
5249
/// <summary>
5350
/// Initialize the tree with consensus tip.
5451
/// </summary>
@@ -183,9 +180,6 @@ internal class ChainedHeaderTree : IChainedHeaderTree
183180
/// <inheritdoc />
184181
public long UnconsumedBlocksCount { get; private set; }
185182

186-
/// <inheritdoc />
187-
public long ChainedBlocksDataBytes { get; private set; }
188-
189183
/// <summary>A special peer identifier that represents our local node.</summary>
190184
internal const int LocalPeerId = -1;
191185

@@ -252,7 +246,6 @@ public void Initialize(ChainedHeader consensusTip)
252246
{
253247
current.Previous.Next.Add(current);
254248
this.chainedHeadersByHash.Add(current.HashBlock, current);
255-
this.ChainedBlocksDataBytes += current.Header.HeaderSize;
256249

257250
// TODO when pruned node is implemented it should be header only for pruned blocks
258251
current.BlockDataAvailability = BlockDataAvailabilityState.BlockAvailable;
@@ -263,7 +256,6 @@ public void Initialize(ChainedHeader consensusTip)
263256

264257
// Add the genesis block.
265258
this.chainedHeadersByHash.Add(current.HashBlock, current);
266-
this.ChainedBlocksDataBytes += current.Header.HeaderSize;
267259

268260
if (current.HashBlock != this.network.GenesisHash)
269261
{
@@ -607,7 +599,6 @@ private void DisconnectChainHeader(ChainedHeader header)
607599
{
608600
header.Previous.Next.Remove(header);
609601
this.chainedHeadersByHash.Remove(header.HashBlock);
610-
this.ChainedBlocksDataBytes -= header.Header.HeaderSize;
611602

612603
if (header.Block != null)
613604
{
@@ -1106,7 +1097,6 @@ private ChainedHeader CreateAndValidateNewChainedHeader(BlockHeader currentBlock
11061097

11071098
previousChainedHeader.Next.Add(newChainedHeader);
11081099
this.chainedHeadersByHash.Add(newChainedHeader.HashBlock, newChainedHeader);
1109-
this.ChainedBlocksDataBytes += newChainedHeader.Header.HeaderSize;
11101100

11111101
return newChainedHeader;
11121102
}

src/Blockcore/Consensus/ConsensusManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,8 +1459,6 @@ private void AddComponentStats(StringBuilder log)
14591459
log.AppendLine($"Tip Age: { TimeSpan.FromSeconds(tipAge).ToString(@"dd\.hh\:mm\:ss") } (maximum is { TimeSpan.FromSeconds(maxTipAge).ToString(@"dd\.hh\:mm\:ss") })");
14601460
log.AppendLine($"In IBD Stage: { (this.isIbd ? "Yes" : "No") }");
14611461

1462-
log.AppendLine($"Chained header tree size: {this.chainedHeaderTree.ChainedBlocksDataBytes.BytesToMegaBytes()} MB");
1463-
14641462
string unconsumedBlocks = this.FormatBigNumber(this.chainedHeaderTree.UnconsumedBlocksCount);
14651463

14661464
double filledPercentage = Math.Round((this.chainedHeaderTree.UnconsumedBlocksDataBytes / (double)this.maxUnconsumedBlocksDataBytes) * 100, 2);

0 commit comments

Comments
 (0)