/// <summary> /// Creates and store a <see cref="ProvenBlockHeader" /> generated by the signaled <see cref="ChainedHeaderBlock" />. /// </summary> /// <param name="blockHeight">Height of the block used to generate its Proven Header.</param> /// <param name="chainedHeaderBlock">Block used to generate its Proven Header.</param> /// <param name="isIBD">Is node in IBD.</param> void CreateAndStoreProvenHeader(int blockHeight, ChainedHeaderBlock chainedHeaderBlock, bool isIBD) { var block = (PosBlock)chainedHeaderBlock.Block; var newProvenHeader = ((PosConsensusFactory)this.network.Consensus.ConsensusFactory).CreateProvenBlockHeader(block); var provenHeaderHash = newProvenHeader.GetHash(); this.provenBlockHeaderStore.AddToPendingBatch(newProvenHeader, new HashHeightPair(provenHeaderHash, blockHeight)); this.logger.LogDebug( "Created Proven Header at height {0} with hash {1} and adding to the pending batch to be stored.", blockHeight, provenHeaderHash); // If our node is in IBD the block will not be announced to peers. // If not in IBD the signaler may expect the block header to be of type PH. // TODO: Memory foot print: // This design will cause memory to grow over time (depending on how long the node is running) // based on the size of the Proven Headers (a proven header can be up to 1000 bytes). // This is also correct for regular header (which are 80 bytes in size). // If we want to be able to control the size of PH we will need to change the logic // in ProvenHeadersBlockStoreBehavior and load the PH from the PH store instead if (!isIBD) { chainedHeaderBlock.SetHeader(newProvenHeader); } }
/// <summary> /// Creates and store a <see cref="ProvenBlockHeader" /> generated by the signaled <see cref="ChainedHeaderBlock"/>. /// </summary> /// <param name="blockHeight">Height of the block used to generate its Proven Header.</param> /// <param name="chainedHeaderBlock">Block used to generate its Proven Header.</param> private void CreateAndStoreProvenHeader(int blockHeight, ChainedHeaderBlock chainedHeaderBlock) { PosBlock block = (PosBlock)chainedHeaderBlock.Block; ProvenBlockHeader newProvenHeader = ((PosConsensusFactory)this.network.Consensus.ConsensusFactory).CreateProvenBlockHeader(block); uint256 provenHeaderHash = newProvenHeader.GetHash(); this.provenBlockHeaderStore.AddToPendingBatch(newProvenHeader, new HashHeightPair(provenHeaderHash, blockHeight)); logger.LogTrace("Created Proven Header at height {0} with hash {1} and adding to the pending batch to be stored.", blockHeight, provenHeaderHash); chainedHeaderBlock.SetHeader(newProvenHeader); }