|
6 | 6 | #include <evo/cbtx.h> |
7 | 7 | #include <evo/specialtx.h> |
8 | 8 | #include <llmq/blockprocessor.h> |
9 | | -#include <llmq/chainlocks.h> |
10 | 9 | #include <llmq/commitment.h> |
11 | 10 | #include <llmq/options.h> |
12 | 11 | #include <llmq/quorums.h> |
@@ -217,129 +216,6 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre |
217 | 216 | return true; |
218 | 217 | } |
219 | 218 |
|
220 | | -bool CheckCbTxBestChainlock(const CCbTx& cbTx, const CBlockIndex* pindex, |
221 | | - const llmq::CChainLocksHandler& chainlock_handler, BlockValidationState& state) |
222 | | -{ |
223 | | - if (cbTx.nVersion < CCbTx::Version::CLSIG_AND_BALANCE) { |
224 | | - return true; |
225 | | - } |
226 | | - |
227 | | - static Mutex cached_mutex; |
228 | | - static const CBlockIndex* cached_pindex GUARDED_BY(cached_mutex){nullptr}; |
229 | | - static std::optional<std::pair<CBLSSignature, uint32_t>> cached_chainlock GUARDED_BY(cached_mutex){std::nullopt}; |
230 | | - |
231 | | - auto best_clsig = chainlock_handler.GetBestChainLock(); |
232 | | - if (best_clsig.getHeight() == pindex->nHeight - 1 && cbTx.bestCLHeightDiff == 0 && cbTx.bestCLSignature == best_clsig.getSig()) { |
233 | | - // matches our best clsig which still hold values for the previous block |
234 | | - LOCK(cached_mutex); |
235 | | - cached_chainlock = std::make_pair(cbTx.bestCLSignature, cbTx.bestCLHeightDiff); |
236 | | - cached_pindex = pindex; |
237 | | - return true; |
238 | | - } |
239 | | - |
240 | | - std::optional<std::pair<CBLSSignature, uint32_t>> prevBlockCoinbaseChainlock{std::nullopt}; |
241 | | - if (LOCK(cached_mutex); cached_pindex == pindex->pprev) { |
242 | | - prevBlockCoinbaseChainlock = cached_chainlock; |
243 | | - } |
244 | | - if (!prevBlockCoinbaseChainlock.has_value()) { |
245 | | - prevBlockCoinbaseChainlock = GetNonNullCoinbaseChainlock(pindex->pprev); |
246 | | - } |
247 | | - // If std::optional prevBlockCoinbaseChainlock is empty, then up to the previous block, coinbase Chainlock is null. |
248 | | - if (prevBlockCoinbaseChainlock.has_value()) { |
249 | | - // Previous block Coinbase has a non-null Chainlock: current block's Chainlock must be non-null and at least as new as the previous one |
250 | | - if (!cbTx.bestCLSignature.IsValid()) { |
251 | | - // IsNull() doesn't exist for CBLSSignature: we assume that a non valid BLS sig is null |
252 | | - return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-null-clsig"); |
253 | | - } |
254 | | - if (cbTx.bestCLHeightDiff > prevBlockCoinbaseChainlock.value().second + 1) { |
255 | | - return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-older-clsig"); |
256 | | - } |
257 | | - } |
258 | | - |
259 | | - // IsNull() doesn't exist for CBLSSignature: we assume that a valid BLS sig is non-null |
260 | | - if (cbTx.bestCLSignature.IsValid()) { |
261 | | - int curBlockCoinbaseCLHeight = pindex->nHeight - static_cast<int>(cbTx.bestCLHeightDiff) - 1; |
262 | | - if (best_clsig.getHeight() == curBlockCoinbaseCLHeight && best_clsig.getSig() == cbTx.bestCLSignature) { |
263 | | - // matches our best (but outdated) clsig, no need to verify it again |
264 | | - LOCK(cached_mutex); |
265 | | - cached_chainlock = std::make_pair(cbTx.bestCLSignature, cbTx.bestCLHeightDiff); |
266 | | - cached_pindex = pindex; |
267 | | - return true; |
268 | | - } |
269 | | - uint256 curBlockCoinbaseCLBlockHash = pindex->GetAncestor(curBlockCoinbaseCLHeight)->GetBlockHash(); |
270 | | - if (chainlock_handler.VerifyChainLock(llmq::CChainLockSig(curBlockCoinbaseCLHeight, curBlockCoinbaseCLBlockHash, cbTx.bestCLSignature)) != llmq::VerifyRecSigStatus::Valid) { |
271 | | - return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-invalid-clsig"); |
272 | | - } |
273 | | - LOCK(cached_mutex); |
274 | | - cached_chainlock = std::make_pair(cbTx.bestCLSignature, cbTx.bestCLHeightDiff); |
275 | | - cached_pindex = pindex; |
276 | | - } else if (cbTx.bestCLHeightDiff != 0) { |
277 | | - // Null bestCLSignature is allowed only with bestCLHeightDiff = 0 |
278 | | - return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-cldiff"); |
279 | | - } |
280 | | - |
281 | | - return true; |
282 | | -} |
283 | | - |
284 | | -bool CalcCbTxBestChainlock(const llmq::CChainLocksHandler& chainlock_handler, const CBlockIndex* pindexPrev, |
285 | | - uint32_t& bestCLHeightDiff, CBLSSignature& bestCLSignature) |
286 | | -{ |
287 | | - auto best_clsig = chainlock_handler.GetBestChainLock(); |
288 | | - if (best_clsig.getHeight() < Params().GetConsensus().DeploymentHeight(Consensus::DEPLOYMENT_V19)) { |
289 | | - // We don't want legacy BLS ChainLocks in CbTx (can happen on regtest/devenets) |
290 | | - best_clsig = llmq::CChainLockSig{}; |
291 | | - } |
292 | | - if (best_clsig.getHeight() == pindexPrev->nHeight) { |
293 | | - // Our best CL is the newest one possible |
294 | | - bestCLHeightDiff = 0; |
295 | | - bestCLSignature = best_clsig.getSig(); |
296 | | - return true; |
297 | | - } |
298 | | - |
299 | | - auto prevBlockCoinbaseChainlock = GetNonNullCoinbaseChainlock(pindexPrev); |
300 | | - if (prevBlockCoinbaseChainlock.has_value()) { |
301 | | - // Previous block Coinbase contains a non-null CL: We must insert the same sig or a better (newest) one |
302 | | - if (best_clsig.IsNull()) { |
303 | | - // We don't know any CL, therefore inserting the CL of the previous block |
304 | | - bestCLHeightDiff = prevBlockCoinbaseChainlock->second + 1; |
305 | | - bestCLSignature = prevBlockCoinbaseChainlock->first; |
306 | | - return true; |
307 | | - } |
308 | | - |
309 | | - // We check if our best CL is newer than the one from previous block Coinbase |
310 | | - int curCLHeight = best_clsig.getHeight(); |
311 | | - int prevCLHeight = pindexPrev->nHeight - static_cast<int>(prevBlockCoinbaseChainlock->second) - 1; |
312 | | - if (curCLHeight < prevCLHeight) { |
313 | | - // Our best CL isn't newer: inserting CL from previous block |
314 | | - bestCLHeightDiff = prevBlockCoinbaseChainlock->second + 1; |
315 | | - bestCLSignature = prevBlockCoinbaseChainlock->first; |
316 | | - } |
317 | | - else { |
318 | | - // Our best CL is newer |
319 | | - bestCLHeightDiff = pindexPrev->nHeight - best_clsig.getHeight(); |
320 | | - bestCLSignature = best_clsig.getSig(); |
321 | | - } |
322 | | - |
323 | | - return true; |
324 | | - } |
325 | | - else { |
326 | | - // Previous block Coinbase has no CL. We can either insert null or any valid CL |
327 | | - if (best_clsig.IsNull()) { |
328 | | - // We don't know any CL, therefore inserting a null CL |
329 | | - bestCLHeightDiff = 0; |
330 | | - bestCLSignature.Reset(); |
331 | | - return false; |
332 | | - } |
333 | | - |
334 | | - // Inserting our best CL |
335 | | - bestCLHeightDiff = pindexPrev->nHeight - best_clsig.getHeight(); |
336 | | - bestCLSignature = chainlock_handler.GetBestChainLock().getSig(); |
337 | | - |
338 | | - return true; |
339 | | - } |
340 | | -} |
341 | | - |
342 | | - |
343 | 219 | std::string CCbTx::ToString() const |
344 | 220 | { |
345 | 221 | return strprintf("CCbTx(nVersion=%d, nHeight=%d, merkleRootMNList=%s, merkleRootQuorums=%s, bestCLHeightDiff=%d, bestCLSig=%s, creditPoolBalance=%d.%08d)", |
|
0 commit comments