| 3793 | } |
| 3794 | |
| 3795 | bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool *fNewBlock) |
| 3796 | { |
| 3797 | AssertLockNotHeld(cs_main); |
| 3798 | |
| 3799 | { |
| 3800 | CBlockIndex *pindex = nullptr; |
| 3801 | if (fNewBlock) *fNewBlock = false; |
| 3802 | CValidationState state; |
| 3803 | // Ensure that CheckBlock() passes before calling AcceptBlock, as |
| 3804 | // belt-and-suspenders. |
| 3805 | bool ret = CheckBlock(*pblock, state, chainparams.GetConsensus()); |
| 3806 | |
| 3807 | LOCK(cs_main); |
| 3808 | |
| 3809 | if (ret) { |
| 3810 | // Store to disk |
| 3811 | ret = g_chainstate.AcceptBlock(pblock, state, chainparams, &pindex, fForceProcessing, nullptr, fNewBlock); |
| 3812 | } |
| 3813 | if (!ret) { |
| 3814 | GetMainSignals().BlockChecked(*pblock, state); |
| 3815 | return error("%s: AcceptBlock FAILED (%s)", __func__, FormatStateMessage(state)); |
| 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | NotifyHeaderTip(); |
| 3820 | |
| 3821 | CValidationState state; // Only used to report errors, not invalidity - ignore it |
| 3822 | if (!g_chainstate.ActivateBestChain(state, chainparams, pblock)) |
| 3823 | return error("%s: ActivateBestChain failed (%s)", __func__, FormatStateMessage(state)); |
| 3824 | |
| 3825 | return true; |
| 3826 | } |
| 3827 | |
| 3828 | bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot) |
| 3829 | { |