bool AcceptPendingSyncCheckpoint()
  {
    LOCK(cs_hashSyncCheckpoint);
    if(hashPendingCheckpoint != 0 && mapBlockIndex.count(hashPendingCheckpoint))
    {
      if(!ValidateSyncCheckpoint(hashPendingCheckpoint))
      {
        hashPendingCheckpoint = 0;
        checkpointMessagePending.SetNull();
        return false;
      }

      CTxDB txdb;
      CBlockIndex *pindexCheckpoint = mapBlockIndex[hashPendingCheckpoint];
      if(!pindexCheckpoint->IsInMainChain())
      {
        CBlock block;
        if(!block.ReadFromDisk(pindexCheckpoint))
          return error("AcceptPendingSyncCheckpoint: ReadFromDisk failed for sync checkpoint %s",
                       hashPendingCheckpoint.ToString().c_str());
        if(!block.SetBestChain(txdb, pindexCheckpoint))
        {
          hashInvalidCheckpoint = hashPendingCheckpoint;
          return error("AcceptPendingSyncCheckpoint: SetBestChain failed for sync checkpoint %s",
                       hashPendingCheckpoint.ToString().c_str());
        }
      }
      txdb.Close();

      if(!WriteSyncCheckpoint(hashPendingCheckpoint))
        return error("AcceptPendingSyncCheckpoint(): failed to write sync checkpoint %s",
                     hashPendingCheckpoint.ToString().c_str());

      hashPendingCheckpoint = 0;
      checkpointMessage = checkpointMessagePending;
      checkpointMessagePending.SetNull();
      printf("AcceptPendingSyncCheckpoint : sync-checkpoint at %s\n", hashSyncCheckpoint.ToString().c_str());
      // relay the checkpoint
      if(!checkpointMessage.IsNull())
      {
        BOOST_FOREACH(CNode* pnode, vNodes)
          checkpointMessage.RelayTo(pnode);
      }
      return true;
    }
    return false;
  }
Exemple #2
0
    bool AcceptPendingSyncCheckpoint()
    {
        LOCK(cs_hashSyncCheckpoint);
        if (hashPendingCheckpoint != 0 && mapBlockIndex.count(hashPendingCheckpoint))
        {
            if (!ValidateSyncCheckpoint(hashPendingCheckpoint))
            {
                hashPendingCheckpoint = 0;
                checkpointMessagePending.SetNull();
                LogPrintf("AcceptPendingSyncCheckpoint: FAIL1\n");
                return false;
            }

            CBlockIndex* pindexCheckpoint = mapBlockIndex[hashPendingCheckpoint];
            if (IsSyncCheckpointEnforced() && !pindexCheckpoint->IsInMainChain())
            {
                CBlock block;
                if (!ReadBlockFromDisk(block, pindexCheckpoint))
                    return error("AcceptPendingSyncCheckpoint: ReadFromDisk failed for sync checkpoint %s", hashPendingCheckpoint.ToString().c_str());
                CValidationState state;
                LogPrintf("AcceptPendingSyncCheckpoint: ConnectTip\n");
                // if (!SetBestChain(state, pindexCheckpoint))
                if (!ConnectTip(state, pindexCheckpoint))
                {
                    hashInvalidCheckpoint = hashPendingCheckpoint;
                    return error("AcceptPendingSyncCheckpoint: SetBestChain failed for sync checkpoint %s", hashPendingCheckpoint.ToString().c_str());
                }
            }

            if (!WriteSyncCheckpoint(hashPendingCheckpoint))
                return error("AcceptPendingSyncCheckpoint(): failed to write sync checkpoint %s", hashPendingCheckpoint.ToString().c_str());
            hashPendingCheckpoint = 0;
            checkpointMessage = checkpointMessagePending;
            checkpointMessagePending.SetNull();
            LogPrintf("AcceptPendingSyncCheckpoint : sync-checkpoint at %s\n", hashSyncCheckpoint.ToString().c_str());
            // relay the checkpoint
            if (!checkpointMessage.IsNull())
            {
                BOOST_FOREACH(CNode* pnode, vNodes)
                    checkpointMessage.RelayTo(pnode);
            }
            return true;
        }
        return false;
    }