Skip to content

Commit

Permalink
Node: Fixed bug with improper block generation upon cut-through of ol…
Browse files Browse the repository at this point in the history
…d-new UTXOs.
  • Loading branch information
valdok committed Jan 21, 2019
1 parent adca6a9 commit 671c21e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions node/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,16 +1555,8 @@ bool NodeProcessor::GenerateNewBlock(BlockContext& bc)
nSizeEstimated = GenerateNewBlockInternal(bc);

if (nSizeEstimated)
{
bc.m_Hdr.m_Height = h;

if (BlockContext::Mode::Assemble != bc.m_Mode)
{
bc.m_Block.NormalizeE(); // kernels must be normalized before the header is generated
GenerateNewHdr(bc);
}
}

verify(HandleValidatedTx(bc.m_Block.get_Reader(), h, false)); // undo changes

// reset input maturities
Expand All @@ -1577,9 +1569,19 @@ bool NodeProcessor::GenerateNewBlock(BlockContext& bc)
if (BlockContext::Mode::Assemble == bc.m_Mode)
return true;

size_t nCutThrough = bc.m_Block.NormalizeP(); // right before serialization
size_t nCutThrough = bc.m_Block.Normalize(); // right before serialization
nCutThrough; // remove "unused var" warning

// The effect of the cut-through block may be different than it was during block construction, because the consumed and created UTXOs (removed by cut-through) could have different maturities.
// Hence - we need to re-apply the block after the cut-throught, evaluate the definition, and undo the changes (once again).
if (!HandleValidatedTx(bc.m_Block.get_Reader(), h, true))
{
LOG_WARNING() << "couldn't apply block after cut-through!";
return false; // ?!
}
GenerateNewHdr(bc);
verify(HandleValidatedTx(bc.m_Block.get_Reader(), h, false)); // undo changes


Serializer ser;

Expand Down

0 comments on commit 671c21e

Please sign in to comment.