@@ -77,22 +77,29 @@ std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash)
77
77
txCoinbase.vout [1 ].nValue = txCoinbase.vout [0 ].nValue ;
78
78
txCoinbase.vout [0 ].nValue = 0 ;
79
79
txCoinbase.vin [0 ].scriptWitness .SetNull ();
80
+ // Always pad with OP_0 at the end to avoid bad-cb-length error
81
+ txCoinbase.vin [0 ].scriptSig = CScript{} << WITH_LOCK (::cs_main, return m_node.chainman ->m_blockman .LookupBlockIndex (prev_hash)->nHeight + 1 ) << OP_0;
80
82
pblock->vtx [0 ] = MakeTransactionRef (std::move (txCoinbase));
81
83
82
84
return pblock;
83
85
}
84
86
85
87
std::shared_ptr<CBlock> MinerTestingSetup::FinalizeBlock (std::shared_ptr<CBlock> pblock)
86
88
{
87
- LOCK ( cs_main); // For m_node.chainman->m_blockman.LookupBlockIndex
88
- GenerateCoinbaseCommitment (*pblock, m_node. chainman -> m_blockman . LookupBlockIndex (pblock-> hashPrevBlock ) , Params ().GetConsensus ());
89
+ const CBlockIndex* prev_block{ WITH_LOCK (:: cs_main, return m_node.chainman ->m_blockman .LookupBlockIndex (pblock-> hashPrevBlock ))};
90
+ GenerateCoinbaseCommitment (*pblock, prev_block , Params ().GetConsensus ());
89
91
90
92
pblock->hashMerkleRoot = BlockMerkleRoot (*pblock);
91
93
92
94
while (!CheckProofOfWork (pblock->GetHash (), pblock->nBits , Params ().GetConsensus ())) {
93
95
++(pblock->nNonce );
94
96
}
95
97
98
+ // submit block header, so that miner can get the block height from the
99
+ // global state and the node has the topology of the chain
100
+ BlockValidationState ignored;
101
+ BOOST_CHECK (Assert (m_node.chainman )->ProcessNewBlockHeaders ({pblock->GetBlockHeader ()}, ignored, Params ()));
102
+
96
103
return pblock;
97
104
}
98
105
@@ -147,13 +154,6 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
147
154
}
148
155
149
156
bool ignored;
150
- BlockValidationState state;
151
- std::vector<CBlockHeader> headers;
152
- std::transform (blocks.begin (), blocks.end (), std::back_inserter (headers), [](std::shared_ptr<const CBlock> b) { return b->GetBlockHeader (); });
153
-
154
- // Process all the headers so we understand the toplogy of the chain
155
- BOOST_CHECK (Assert (m_node.chainman )->ProcessNewBlockHeaders (headers, state, Params ()));
156
-
157
157
// Connect the genesis block and drain any outstanding events
158
158
BOOST_CHECK (Assert (m_node.chainman )->ProcessNewBlock (Params (), std::make_shared<CBlock>(Params ().GenesisBlock ()), true , &ignored));
159
159
SyncWithValidationInterfaceQueue ();
0 commit comments