mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
scripted-diff: return error(...); ==> error(...); return false;
This is needed for the next commit. -BEGIN VERIFY SCRIPT- # Separate sed invocations to replace one-line, and two-line error(...) calls sed -i --regexp-extended 's!( +)return (error\(.*\);)!\1\2\n\1return false;!g' $( git grep -l 'return error(' ) sed -i --null-data --regexp-extended 's!( +)return (error\([^\n]*\n[^\n]*\);)!\1\2\n\1return false;!g' $( git grep -l 'return error(' ) -END VERIFY SCRIPT-
This commit is contained in:
parent
fa9a5e80ab
commit
fa1d624348
11 changed files with 178 additions and 89 deletions
|
@ -44,7 +44,8 @@ bool SerializeDB(Stream& stream, const Data& data)
|
||||||
hashwriter << Params().MessageStart() << data;
|
hashwriter << Params().MessageStart() << data;
|
||||||
stream << hashwriter.GetHash();
|
stream << hashwriter.GetHash();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
return error("%s: Serialize or I/O error - %s", __func__, e.what());
|
error("%s: Serialize or I/O error - %s", __func__, e.what());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -64,7 +65,8 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
|
||||||
if (fileout.IsNull()) {
|
if (fileout.IsNull()) {
|
||||||
fileout.fclose();
|
fileout.fclose();
|
||||||
remove(pathTmp);
|
remove(pathTmp);
|
||||||
return error("%s: Failed to open file %s", __func__, fs::PathToString(pathTmp));
|
error("%s: Failed to open file %s", __func__, fs::PathToString(pathTmp));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
|
@ -76,14 +78,16 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
|
||||||
if (!FileCommit(fileout.Get())) {
|
if (!FileCommit(fileout.Get())) {
|
||||||
fileout.fclose();
|
fileout.fclose();
|
||||||
remove(pathTmp);
|
remove(pathTmp);
|
||||||
return error("%s: Failed to flush file %s", __func__, fs::PathToString(pathTmp));
|
error("%s: Failed to flush file %s", __func__, fs::PathToString(pathTmp));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
fileout.fclose();
|
fileout.fclose();
|
||||||
|
|
||||||
// replace existing file, if any, with new file
|
// replace existing file, if any, with new file
|
||||||
if (!RenameOver(pathTmp, path)) {
|
if (!RenameOver(pathTmp, path)) {
|
||||||
remove(pathTmp);
|
remove(pathTmp);
|
||||||
return error("%s: Rename-into-place failed", __func__);
|
error("%s: Rename-into-place failed", __func__);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -82,15 +82,18 @@ bool FlatFileSeq::Flush(const FlatFilePos& pos, bool finalize)
|
||||||
{
|
{
|
||||||
FILE* file = Open(FlatFilePos(pos.nFile, 0)); // Avoid fseek to nPos
|
FILE* file = Open(FlatFilePos(pos.nFile, 0)); // Avoid fseek to nPos
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return error("%s: failed to open file %d", __func__, pos.nFile);
|
error("%s: failed to open file %d", __func__, pos.nFile);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (finalize && !TruncateFile(file, pos.nPos)) {
|
if (finalize && !TruncateFile(file, pos.nPos)) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return error("%s: failed to truncate file %d", __func__, pos.nFile);
|
error("%s: failed to truncate file %d", __func__, pos.nFile);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (!FileCommit(file)) {
|
if (!FileCommit(file)) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return error("%s: failed to commit file %d", __func__, pos.nFile);
|
error("%s: failed to commit file %d", __func__, pos.nFile);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
DirectoryCommit(m_dir);
|
DirectoryCommit(m_dir);
|
||||||
|
|
||||||
|
|
|
@ -229,7 +229,8 @@ bool BaseIndex::Commit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return error("%s: Failed to commit latest %s state", __func__, GetName());
|
error("%s: Failed to commit latest %s state", __func__, GetName());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,8 +119,9 @@ bool BlockFilterIndex::CustomInit(const std::optional<interfaces::BlockKey>& blo
|
||||||
// indicate database corruption or a disk failure, and starting the index would cause
|
// indicate database corruption or a disk failure, and starting the index would cause
|
||||||
// further corruption.
|
// further corruption.
|
||||||
if (m_db->Exists(DB_FILTER_POS)) {
|
if (m_db->Exists(DB_FILTER_POS)) {
|
||||||
return error("%s: Cannot read current %s state; index may be corrupted",
|
error("%s: Cannot read current %s state; index may be corrupted",
|
||||||
__func__, GetName());
|
__func__, GetName());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the DB_FILTER_POS is not set, then initialize to the first location.
|
// If the DB_FILTER_POS is not set, then initialize to the first location.
|
||||||
|
@ -137,10 +138,12 @@ bool BlockFilterIndex::CustomCommit(CDBBatch& batch)
|
||||||
// Flush current filter file to disk.
|
// Flush current filter file to disk.
|
||||||
AutoFile file{m_filter_fileseq->Open(pos)};
|
AutoFile file{m_filter_fileseq->Open(pos)};
|
||||||
if (file.IsNull()) {
|
if (file.IsNull()) {
|
||||||
return error("%s: Failed to open filter file %d", __func__, pos.nFile);
|
error("%s: Failed to open filter file %d", __func__, pos.nFile);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (!FileCommit(file.Get())) {
|
if (!FileCommit(file.Get())) {
|
||||||
return error("%s: Failed to commit filter file %d", __func__, pos.nFile);
|
error("%s: Failed to commit filter file %d", __func__, pos.nFile);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.Write(DB_FILTER_POS, pos);
|
batch.Write(DB_FILTER_POS, pos);
|
||||||
|
@ -160,12 +163,14 @@ bool BlockFilterIndex::ReadFilterFromDisk(const FlatFilePos& pos, const uint256&
|
||||||
try {
|
try {
|
||||||
filein >> block_hash >> encoded_filter;
|
filein >> block_hash >> encoded_filter;
|
||||||
if (Hash(encoded_filter) != hash) {
|
if (Hash(encoded_filter) != hash) {
|
||||||
return error("Checksum mismatch in filter decode.");
|
error("Checksum mismatch in filter decode.");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
filter = BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter), /*skip_decode_check=*/true);
|
filter = BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter), /*skip_decode_check=*/true);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
catch (const std::exception& e) {
|
||||||
return error("%s: Failed to deserialize block filter from disk: %s", __func__, e.what());
|
error("%s: Failed to deserialize block filter from disk: %s", __func__, e.what());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -237,8 +242,9 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
|
||||||
|
|
||||||
uint256 expected_block_hash = *Assert(block.prev_hash);
|
uint256 expected_block_hash = *Assert(block.prev_hash);
|
||||||
if (read_out.first != expected_block_hash) {
|
if (read_out.first != expected_block_hash) {
|
||||||
return error("%s: previous block header belongs to unexpected block %s; expected %s",
|
error("%s: previous block header belongs to unexpected block %s; expected %s",
|
||||||
__func__, read_out.first.ToString(), expected_block_hash.ToString());
|
__func__, read_out.first.ToString(), expected_block_hash.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_header = read_out.second.header;
|
prev_header = read_out.second.header;
|
||||||
|
@ -272,14 +278,16 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
|
||||||
|
|
||||||
for (int height = start_height; height <= stop_height; ++height) {
|
for (int height = start_height; height <= stop_height; ++height) {
|
||||||
if (!db_it.GetKey(key) || key.height != height) {
|
if (!db_it.GetKey(key) || key.height != height) {
|
||||||
return error("%s: unexpected key in %s: expected (%c, %d)",
|
error("%s: unexpected key in %s: expected (%c, %d)",
|
||||||
__func__, index_name, DB_BLOCK_HEIGHT, height);
|
__func__, index_name, DB_BLOCK_HEIGHT, height);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<uint256, DBVal> value;
|
std::pair<uint256, DBVal> value;
|
||||||
if (!db_it.GetValue(value)) {
|
if (!db_it.GetValue(value)) {
|
||||||
return error("%s: unable to read value in %s at key (%c, %d)",
|
error("%s: unable to read value in %s at key (%c, %d)",
|
||||||
__func__, index_name, DB_BLOCK_HEIGHT, height);
|
__func__, index_name, DB_BLOCK_HEIGHT, height);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.Write(DBHashKey(value.first), std::move(value.second));
|
batch.Write(DBHashKey(value.first), std::move(value.second));
|
||||||
|
@ -332,11 +340,13 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start
|
||||||
const CBlockIndex* stop_index, std::vector<DBVal>& results)
|
const CBlockIndex* stop_index, std::vector<DBVal>& results)
|
||||||
{
|
{
|
||||||
if (start_height < 0) {
|
if (start_height < 0) {
|
||||||
return error("%s: start height (%d) is negative", __func__, start_height);
|
error("%s: start height (%d) is negative", __func__, start_height);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (start_height > stop_index->nHeight) {
|
if (start_height > stop_index->nHeight) {
|
||||||
return error("%s: start height (%d) is greater than stop height (%d)",
|
error("%s: start height (%d) is greater than stop height (%d)",
|
||||||
__func__, start_height, stop_index->nHeight);
|
__func__, start_height, stop_index->nHeight);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t results_size = static_cast<size_t>(stop_index->nHeight - start_height + 1);
|
size_t results_size = static_cast<size_t>(stop_index->nHeight - start_height + 1);
|
||||||
|
@ -352,8 +362,9 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start
|
||||||
|
|
||||||
size_t i = static_cast<size_t>(height - start_height);
|
size_t i = static_cast<size_t>(height - start_height);
|
||||||
if (!db_it->GetValue(values[i])) {
|
if (!db_it->GetValue(values[i])) {
|
||||||
return error("%s: unable to read value in %s at key (%c, %d)",
|
error("%s: unable to read value in %s at key (%c, %d)",
|
||||||
__func__, index_name, DB_BLOCK_HEIGHT, height);
|
__func__, index_name, DB_BLOCK_HEIGHT, height);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
db_it->Next();
|
db_it->Next();
|
||||||
|
@ -375,8 +386,9 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!db.Read(DBHashKey(block_hash), results[i])) {
|
if (!db.Read(DBHashKey(block_hash), results[i])) {
|
||||||
return error("%s: unable to read value in %s at key (%c, %s)",
|
error("%s: unable to read value in %s at key (%c, %s)",
|
||||||
__func__, index_name, DB_BLOCK_HASH, block_hash.ToString());
|
__func__, index_name, DB_BLOCK_HASH, block_hash.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,8 +138,9 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
|
||||||
read_out.first.ToString(), expected_block_hash.ToString());
|
read_out.first.ToString(), expected_block_hash.ToString());
|
||||||
|
|
||||||
if (!m_db->Read(DBHashKey(expected_block_hash), read_out)) {
|
if (!m_db->Read(DBHashKey(expected_block_hash), read_out)) {
|
||||||
return error("%s: previous block header not found; expected %s",
|
error("%s: previous block header not found; expected %s",
|
||||||
__func__, expected_block_hash.ToString());
|
__func__, expected_block_hash.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,14 +246,16 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
|
||||||
|
|
||||||
for (int height = start_height; height <= stop_height; ++height) {
|
for (int height = start_height; height <= stop_height; ++height) {
|
||||||
if (!db_it.GetKey(key) || key.height != height) {
|
if (!db_it.GetKey(key) || key.height != height) {
|
||||||
return error("%s: unexpected key in %s: expected (%c, %d)",
|
error("%s: unexpected key in %s: expected (%c, %d)",
|
||||||
__func__, index_name, DB_BLOCK_HEIGHT, height);
|
__func__, index_name, DB_BLOCK_HEIGHT, height);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<uint256, DBVal> value;
|
std::pair<uint256, DBVal> value;
|
||||||
if (!db_it.GetValue(value)) {
|
if (!db_it.GetValue(value)) {
|
||||||
return error("%s: unable to read value in %s at key (%c, %d)",
|
error("%s: unable to read value in %s at key (%c, %d)",
|
||||||
__func__, index_name, DB_BLOCK_HEIGHT, height);
|
__func__, index_name, DB_BLOCK_HEIGHT, height);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.Write(DBHashKey(value.first), std::move(value.second));
|
batch.Write(DBHashKey(value.first), std::move(value.second));
|
||||||
|
@ -285,8 +288,9 @@ bool CoinStatsIndex::CustomRewind(const interfaces::BlockKey& current_tip, const
|
||||||
CBlock block;
|
CBlock block;
|
||||||
|
|
||||||
if (!m_chainstate->m_blockman.ReadBlockFromDisk(block, *iter_tip)) {
|
if (!m_chainstate->m_blockman.ReadBlockFromDisk(block, *iter_tip)) {
|
||||||
return error("%s: Failed to read block %s from disk",
|
error("%s: Failed to read block %s from disk",
|
||||||
__func__, iter_tip->GetBlockHash().ToString());
|
__func__, iter_tip->GetBlockHash().ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ReverseBlock(block, iter_tip)) {
|
if (!ReverseBlock(block, iter_tip)) {
|
||||||
|
@ -353,23 +357,26 @@ bool CoinStatsIndex::CustomInit(const std::optional<interfaces::BlockKey>& block
|
||||||
// exist. Any other errors indicate database corruption or a disk
|
// exist. Any other errors indicate database corruption or a disk
|
||||||
// failure, and starting the index would cause further corruption.
|
// failure, and starting the index would cause further corruption.
|
||||||
if (m_db->Exists(DB_MUHASH)) {
|
if (m_db->Exists(DB_MUHASH)) {
|
||||||
return error("%s: Cannot read current %s state; index may be corrupted",
|
error("%s: Cannot read current %s state; index may be corrupted",
|
||||||
__func__, GetName());
|
__func__, GetName());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block) {
|
if (block) {
|
||||||
DBVal entry;
|
DBVal entry;
|
||||||
if (!LookUpOne(*m_db, *block, entry)) {
|
if (!LookUpOne(*m_db, *block, entry)) {
|
||||||
return error("%s: Cannot read current %s state; index may be corrupted",
|
error("%s: Cannot read current %s state; index may be corrupted",
|
||||||
__func__, GetName());
|
__func__, GetName());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 out;
|
uint256 out;
|
||||||
m_muhash.Finalize(out);
|
m_muhash.Finalize(out);
|
||||||
if (entry.muhash != out) {
|
if (entry.muhash != out) {
|
||||||
return error("%s: Cannot read current %s state; index may be corrupted",
|
error("%s: Cannot read current %s state; index may be corrupted",
|
||||||
__func__, GetName());
|
__func__, GetName());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_transaction_output_count = entry.transaction_output_count;
|
m_transaction_output_count = entry.transaction_output_count;
|
||||||
|
@ -422,8 +429,9 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex
|
||||||
read_out.first.ToString(), expected_block_hash.ToString());
|
read_out.first.ToString(), expected_block_hash.ToString());
|
||||||
|
|
||||||
if (!m_db->Read(DBHashKey(expected_block_hash), read_out)) {
|
if (!m_db->Read(DBHashKey(expected_block_hash), read_out)) {
|
||||||
return error("%s: previous block header not found; expected %s",
|
error("%s: previous block header not found; expected %s",
|
||||||
__func__, expected_block_hash.ToString());
|
__func__, expected_block_hash.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,20 +81,24 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
|
||||||
|
|
||||||
AutoFile file{m_chainstate->m_blockman.OpenBlockFile(postx, true)};
|
AutoFile file{m_chainstate->m_blockman.OpenBlockFile(postx, true)};
|
||||||
if (file.IsNull()) {
|
if (file.IsNull()) {
|
||||||
return error("%s: OpenBlockFile failed", __func__);
|
error("%s: OpenBlockFile failed", __func__);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
CBlockHeader header;
|
CBlockHeader header;
|
||||||
try {
|
try {
|
||||||
file >> header;
|
file >> header;
|
||||||
if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) {
|
if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) {
|
||||||
return error("%s: fseek(...) failed", __func__);
|
error("%s: fseek(...) failed", __func__);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
file >> TX_WITH_WITNESS(tx);
|
file >> TX_WITH_WITNESS(tx);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
|
error("%s: Deserialize or I/O error - %s", __func__, e.what());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (tx->GetHash() != tx_hash) {
|
if (tx->GetHash() != tx_hash) {
|
||||||
return error("%s: txid mismatch", __func__);
|
error("%s: txid mismatch", __func__);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
block_hash = header.GetHash();
|
block_hash = header.GetHash();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -134,7 +134,8 @@ static bool ComputeUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, c
|
||||||
outputs[key.n] = std::move(coin);
|
outputs[key.n] = std::move(coin);
|
||||||
stats.coins_count++;
|
stats.coins_count++;
|
||||||
} else {
|
} else {
|
||||||
return error("%s: unable to read value", __func__);
|
error("%s: unable to read value", __func__);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
pcursor->Next();
|
pcursor->Next();
|
||||||
}
|
}
|
||||||
|
|
|
@ -338,7 +338,8 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
|
||||||
IntrRecvError recvr;
|
IntrRecvError recvr;
|
||||||
LogPrint(BCLog::NET, "SOCKS5 connecting %s\n", strDest);
|
LogPrint(BCLog::NET, "SOCKS5 connecting %s\n", strDest);
|
||||||
if (strDest.size() > 255) {
|
if (strDest.size() > 255) {
|
||||||
return error("Hostname too long");
|
error("Hostname too long");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
// Construct the version identifier/method selection message
|
// Construct the version identifier/method selection message
|
||||||
std::vector<uint8_t> vSocks5Init;
|
std::vector<uint8_t> vSocks5Init;
|
||||||
|
@ -358,14 +359,16 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (pchRet1[0] != SOCKSVersion::SOCKS5) {
|
if (pchRet1[0] != SOCKSVersion::SOCKS5) {
|
||||||
return error("Proxy failed to initialize");
|
error("Proxy failed to initialize");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (pchRet1[1] == SOCKS5Method::USER_PASS && auth) {
|
if (pchRet1[1] == SOCKS5Method::USER_PASS && auth) {
|
||||||
// Perform username/password authentication (as described in RFC1929)
|
// Perform username/password authentication (as described in RFC1929)
|
||||||
std::vector<uint8_t> vAuth;
|
std::vector<uint8_t> vAuth;
|
||||||
vAuth.push_back(0x01); // Current (and only) version of user/pass subnegotiation
|
vAuth.push_back(0x01); // Current (and only) version of user/pass subnegotiation
|
||||||
if (auth->username.size() > 255 || auth->password.size() > 255) {
|
if (auth->username.size() > 255 || auth->password.size() > 255) {
|
||||||
return error("Proxy username or password too long");
|
error("Proxy username or password too long");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
vAuth.push_back(auth->username.size());
|
vAuth.push_back(auth->username.size());
|
||||||
vAuth.insert(vAuth.end(), auth->username.begin(), auth->username.end());
|
vAuth.insert(vAuth.end(), auth->username.begin(), auth->username.end());
|
||||||
|
@ -375,15 +378,18 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
|
||||||
LogPrint(BCLog::PROXY, "SOCKS5 sending proxy authentication %s:%s\n", auth->username, auth->password);
|
LogPrint(BCLog::PROXY, "SOCKS5 sending proxy authentication %s:%s\n", auth->username, auth->password);
|
||||||
uint8_t pchRetA[2];
|
uint8_t pchRetA[2];
|
||||||
if (InterruptibleRecv(pchRetA, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
|
if (InterruptibleRecv(pchRetA, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
|
||||||
return error("Error reading proxy authentication response");
|
error("Error reading proxy authentication response");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (pchRetA[0] != 0x01 || pchRetA[1] != 0x00) {
|
if (pchRetA[0] != 0x01 || pchRetA[1] != 0x00) {
|
||||||
return error("Proxy authentication unsuccessful");
|
error("Proxy authentication unsuccessful");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else if (pchRet1[1] == SOCKS5Method::NOAUTH) {
|
} else if (pchRet1[1] == SOCKS5Method::NOAUTH) {
|
||||||
// Perform no authentication
|
// Perform no authentication
|
||||||
} else {
|
} else {
|
||||||
return error("Proxy requested wrong authentication method %02x", pchRet1[1]);
|
error("Proxy requested wrong authentication method %02x", pchRet1[1]);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
std::vector<uint8_t> vSocks5;
|
std::vector<uint8_t> vSocks5;
|
||||||
vSocks5.push_back(SOCKSVersion::SOCKS5); // VER protocol version
|
vSocks5.push_back(SOCKSVersion::SOCKS5); // VER protocol version
|
||||||
|
@ -403,11 +409,13 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
|
||||||
* error message. */
|
* error message. */
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return error("Error while reading proxy response");
|
error("Error while reading proxy response");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pchRet2[0] != SOCKSVersion::SOCKS5) {
|
if (pchRet2[0] != SOCKSVersion::SOCKS5) {
|
||||||
return error("Proxy failed to accept request");
|
error("Proxy failed to accept request");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (pchRet2[1] != SOCKS5Reply::SUCCEEDED) {
|
if (pchRet2[1] != SOCKS5Reply::SUCCEEDED) {
|
||||||
// Failures to connect to a peer that are not proxy errors
|
// Failures to connect to a peer that are not proxy errors
|
||||||
|
@ -415,7 +423,8 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (pchRet2[2] != 0x00) { // Reserved field must be 0
|
if (pchRet2[2] != 0x00) { // Reserved field must be 0
|
||||||
return error("Error: malformed proxy response");
|
error("Error: malformed proxy response");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
uint8_t pchRet3[256];
|
uint8_t pchRet3[256];
|
||||||
switch (pchRet2[3]) {
|
switch (pchRet2[3]) {
|
||||||
|
@ -424,26 +433,31 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
|
||||||
case SOCKS5Atyp::DOMAINNAME: {
|
case SOCKS5Atyp::DOMAINNAME: {
|
||||||
recvr = InterruptibleRecv(pchRet3, 1, g_socks5_recv_timeout, sock);
|
recvr = InterruptibleRecv(pchRet3, 1, g_socks5_recv_timeout, sock);
|
||||||
if (recvr != IntrRecvError::OK) {
|
if (recvr != IntrRecvError::OK) {
|
||||||
return error("Error reading from proxy");
|
error("Error reading from proxy");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
int nRecv = pchRet3[0];
|
int nRecv = pchRet3[0];
|
||||||
recvr = InterruptibleRecv(pchRet3, nRecv, g_socks5_recv_timeout, sock);
|
recvr = InterruptibleRecv(pchRet3, nRecv, g_socks5_recv_timeout, sock);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return error("Error: malformed proxy response");
|
error("Error: malformed proxy response");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (recvr != IntrRecvError::OK) {
|
if (recvr != IntrRecvError::OK) {
|
||||||
return error("Error reading from proxy");
|
error("Error reading from proxy");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (InterruptibleRecv(pchRet3, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
|
if (InterruptibleRecv(pchRet3, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
|
||||||
return error("Error reading from proxy");
|
error("Error reading from proxy");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
LogPrint(BCLog::NET, "SOCKS5 connected %s\n", strDest);
|
LogPrint(BCLog::NET, "SOCKS5 connected %s\n", strDest);
|
||||||
return true;
|
return true;
|
||||||
} catch (const std::runtime_error& e) {
|
} catch (const std::runtime_error& e) {
|
||||||
return error("Error during SOCKS5 proxy handshake: %s", e.what());
|
error("Error during SOCKS5 proxy handshake: %s", e.what());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,12 +131,14 @@ bool BlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, s
|
||||||
pindexNew->nTx = diskindex.nTx;
|
pindexNew->nTx = diskindex.nTx;
|
||||||
|
|
||||||
if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams)) {
|
if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams)) {
|
||||||
return error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString());
|
error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pcursor->Next();
|
pcursor->Next();
|
||||||
} else {
|
} else {
|
||||||
return error("%s: failed to read value", __func__);
|
error("%s: failed to read value", __func__);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
@ -432,7 +434,8 @@ bool BlockManager::LoadBlockIndex(const std::optional<uint256>& snapshot_blockha
|
||||||
for (CBlockIndex* pindex : vSortedByHeight) {
|
for (CBlockIndex* pindex : vSortedByHeight) {
|
||||||
if (m_interrupt) return false;
|
if (m_interrupt) return false;
|
||||||
if (previous_index && pindex->nHeight > previous_index->nHeight + 1) {
|
if (previous_index && pindex->nHeight > previous_index->nHeight + 1) {
|
||||||
return error("%s: block index is non-contiguous, index of height %d missing", __func__, previous_index->nHeight + 1);
|
error("%s: block index is non-contiguous, index of height %d missing", __func__, previous_index->nHeight + 1);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
previous_index = pindex;
|
previous_index = pindex;
|
||||||
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
|
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
|
||||||
|
@ -671,7 +674,8 @@ bool BlockManager::UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos
|
||||||
// Open history file to append
|
// Open history file to append
|
||||||
AutoFile fileout{OpenUndoFile(pos)};
|
AutoFile fileout{OpenUndoFile(pos)};
|
||||||
if (fileout.IsNull()) {
|
if (fileout.IsNull()) {
|
||||||
return error("%s: OpenUndoFile failed", __func__);
|
error("%s: OpenUndoFile failed", __func__);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write index header
|
// Write index header
|
||||||
|
@ -681,7 +685,8 @@ bool BlockManager::UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos
|
||||||
// Write undo data
|
// Write undo data
|
||||||
long fileOutPos = ftell(fileout.Get());
|
long fileOutPos = ftell(fileout.Get());
|
||||||
if (fileOutPos < 0) {
|
if (fileOutPos < 0) {
|
||||||
return error("%s: ftell failed", __func__);
|
error("%s: ftell failed", __func__);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
pos.nPos = (unsigned int)fileOutPos;
|
pos.nPos = (unsigned int)fileOutPos;
|
||||||
fileout << blockundo;
|
fileout << blockundo;
|
||||||
|
@ -700,13 +705,15 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in
|
||||||
const FlatFilePos pos{WITH_LOCK(::cs_main, return index.GetUndoPos())};
|
const FlatFilePos pos{WITH_LOCK(::cs_main, return index.GetUndoPos())};
|
||||||
|
|
||||||
if (pos.IsNull()) {
|
if (pos.IsNull()) {
|
||||||
return error("%s: no undo data available", __func__);
|
error("%s: no undo data available", __func__);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open history file to read
|
// Open history file to read
|
||||||
AutoFile filein{OpenUndoFile(pos, true)};
|
AutoFile filein{OpenUndoFile(pos, true)};
|
||||||
if (filein.IsNull()) {
|
if (filein.IsNull()) {
|
||||||
return error("%s: OpenUndoFile failed", __func__);
|
error("%s: OpenUndoFile failed", __func__);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read block
|
// Read block
|
||||||
|
@ -717,12 +724,14 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in
|
||||||
verifier >> blockundo;
|
verifier >> blockundo;
|
||||||
filein >> hashChecksum;
|
filein >> hashChecksum;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
|
error("%s: Deserialize or I/O error - %s", __func__, e.what());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify checksum
|
// Verify checksum
|
||||||
if (hashChecksum != verifier.GetHash()) {
|
if (hashChecksum != verifier.GetHash()) {
|
||||||
return error("%s: Checksum mismatch", __func__);
|
error("%s: Checksum mismatch", __func__);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -965,7 +974,8 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
|
||||||
// Open history file to append
|
// Open history file to append
|
||||||
AutoFile fileout{OpenBlockFile(pos)};
|
AutoFile fileout{OpenBlockFile(pos)};
|
||||||
if (fileout.IsNull()) {
|
if (fileout.IsNull()) {
|
||||||
return error("WriteBlockToDisk: OpenBlockFile failed");
|
error("WriteBlockToDisk: OpenBlockFile failed");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write index header
|
// Write index header
|
||||||
|
@ -975,7 +985,8 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
|
||||||
// Write block
|
// Write block
|
||||||
long fileOutPos = ftell(fileout.Get());
|
long fileOutPos = ftell(fileout.Get());
|
||||||
if (fileOutPos < 0) {
|
if (fileOutPos < 0) {
|
||||||
return error("WriteBlockToDisk: ftell failed");
|
error("WriteBlockToDisk: ftell failed");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
pos.nPos = (unsigned int)fileOutPos;
|
pos.nPos = (unsigned int)fileOutPos;
|
||||||
fileout << TX_WITH_WITNESS(block);
|
fileout << TX_WITH_WITNESS(block);
|
||||||
|
@ -993,7 +1004,8 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
|
||||||
if (block.GetUndoPos().IsNull()) {
|
if (block.GetUndoPos().IsNull()) {
|
||||||
FlatFilePos _pos;
|
FlatFilePos _pos;
|
||||||
if (!FindUndoPos(state, block.nFile, _pos, ::GetSerializeSize(blockundo) + 40)) {
|
if (!FindUndoPos(state, block.nFile, _pos, ::GetSerializeSize(blockundo) + 40)) {
|
||||||
return error("ConnectBlock(): FindUndoPos failed");
|
error("ConnectBlock(): FindUndoPos failed");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (!UndoWriteToDisk(blockundo, _pos, block.pprev->GetBlockHash())) {
|
if (!UndoWriteToDisk(blockundo, _pos, block.pprev->GetBlockHash())) {
|
||||||
return FatalError(m_opts.notifications, state, "Failed to write undo data");
|
return FatalError(m_opts.notifications, state, "Failed to write undo data");
|
||||||
|
@ -1031,24 +1043,28 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
|
||||||
// Open history file to read
|
// Open history file to read
|
||||||
AutoFile filein{OpenBlockFile(pos, true)};
|
AutoFile filein{OpenBlockFile(pos, true)};
|
||||||
if (filein.IsNull()) {
|
if (filein.IsNull()) {
|
||||||
return error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString());
|
error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read block
|
// Read block
|
||||||
try {
|
try {
|
||||||
filein >> TX_WITH_WITNESS(block);
|
filein >> TX_WITH_WITNESS(block);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
return error("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString());
|
error("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the header
|
// Check the header
|
||||||
if (!CheckProofOfWork(block.GetHash(), block.nBits, GetConsensus())) {
|
if (!CheckProofOfWork(block.GetHash(), block.nBits, GetConsensus())) {
|
||||||
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
|
error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signet only: check block solution
|
// Signet only: check block solution
|
||||||
if (GetConsensus().signet_blocks && !CheckSignetBlockSolution(block, GetConsensus())) {
|
if (GetConsensus().signet_blocks && !CheckSignetBlockSolution(block, GetConsensus())) {
|
||||||
return error("ReadBlockFromDisk: Errors in block solution at %s", pos.ToString());
|
error("ReadBlockFromDisk: Errors in block solution at %s", pos.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1062,8 +1078,9 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const CBlockIndex& index) co
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (block.GetHash() != index.GetBlockHash()) {
|
if (block.GetHash() != index.GetBlockHash()) {
|
||||||
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
|
error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
|
||||||
index.ToString(), block_pos.ToString());
|
index.ToString(), block_pos.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1074,7 +1091,8 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
|
||||||
hpos.nPos -= 8; // Seek back 8 bytes for meta header
|
hpos.nPos -= 8; // Seek back 8 bytes for meta header
|
||||||
AutoFile filein{OpenBlockFile(hpos, true)};
|
AutoFile filein{OpenBlockFile(hpos, true)};
|
||||||
if (filein.IsNull()) {
|
if (filein.IsNull()) {
|
||||||
return error("%s: OpenBlockFile failed for %s", __func__, pos.ToString());
|
error("%s: OpenBlockFile failed for %s", __func__, pos.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1090,14 +1108,16 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blk_size > MAX_SIZE) {
|
if (blk_size > MAX_SIZE) {
|
||||||
return error("%s: Block data is larger than maximum deserialization size for %s: %s versus %s", __func__, pos.ToString(),
|
error("%s: Block data is larger than maximum deserialization size for %s: %s versus %s", __func__, pos.ToString(),
|
||||||
blk_size, MAX_SIZE);
|
blk_size, MAX_SIZE);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
block.resize(blk_size); // Zeroing of memory is intentional here
|
block.resize(blk_size); // Zeroing of memory is intentional here
|
||||||
filein.read(MakeWritableByteSpan(block));
|
filein.read(MakeWritableByteSpan(block));
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
return error("%s: Read from block file failed: %s for %s", __func__, e.what(), pos.ToString());
|
error("%s: Read from block file failed: %s for %s", __func__, e.what(), pos.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -158,7 +158,8 @@ bool FillableSigningProvider::GetKey(const CKeyID &address, CKey &keyOut) const
|
||||||
bool FillableSigningProvider::AddCScript(const CScript& redeemScript)
|
bool FillableSigningProvider::AddCScript(const CScript& redeemScript)
|
||||||
{
|
{
|
||||||
if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) {
|
if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) {
|
||||||
return error("FillableSigningProvider::AddCScript(): redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
|
error("FillableSigningProvider::AddCScript(): redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
|
|
|
@ -2222,7 +2222,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||||
// problems.
|
// problems.
|
||||||
return FatalError(m_chainman.GetNotifications(), state, "Corrupt block found indicating potential hardware failure; shutting down");
|
return FatalError(m_chainman.GetNotifications(), state, "Corrupt block found indicating potential hardware failure; shutting down");
|
||||||
}
|
}
|
||||||
return error("%s: Consensus::CheckBlock: %s", __func__, state.ToString());
|
error("%s: Consensus::CheckBlock: %s", __func__, state.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify that the view's current state corresponds to the previous block
|
// verify that the view's current state corresponds to the previous block
|
||||||
|
@ -2408,7 +2409,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||||
// Any transaction validation failure in ConnectBlock is a block consensus failure
|
// Any transaction validation failure in ConnectBlock is a block consensus failure
|
||||||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
|
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
|
||||||
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
|
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
|
||||||
return error("%s: Consensus::CheckTxInputs: %s, %s", __func__, tx.GetHash().ToString(), state.ToString());
|
error("%s: Consensus::CheckTxInputs: %s, %s", __func__, tx.GetHash().ToString(), state.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
nFees += txfee;
|
nFees += txfee;
|
||||||
if (!MoneyRange(nFees)) {
|
if (!MoneyRange(nFees)) {
|
||||||
|
@ -2449,8 +2451,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||||
// Any transaction validation failure in ConnectBlock is a block consensus failure
|
// Any transaction validation failure in ConnectBlock is a block consensus failure
|
||||||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
|
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
|
||||||
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
|
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
|
||||||
return error("ConnectBlock(): CheckInputScripts on %s failed with %s",
|
error("ConnectBlock(): CheckInputScripts on %s failed with %s",
|
||||||
tx.GetHash().ToString(), state.ToString());
|
tx.GetHash().ToString(), state.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
control.Add(std::move(vChecks));
|
control.Add(std::move(vChecks));
|
||||||
}
|
}
|
||||||
|
@ -2823,7 +2826,8 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra
|
||||||
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
|
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
|
||||||
CBlock& block = *pblock;
|
CBlock& block = *pblock;
|
||||||
if (!m_blockman.ReadBlockFromDisk(block, *pindexDelete)) {
|
if (!m_blockman.ReadBlockFromDisk(block, *pindexDelete)) {
|
||||||
return error("DisconnectTip(): Failed to read block");
|
error("DisconnectTip(): Failed to read block");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
// Apply the block atomically to the chain state.
|
// Apply the block atomically to the chain state.
|
||||||
const auto time_start{SteadyClock::now()};
|
const auto time_start{SteadyClock::now()};
|
||||||
|
@ -2831,7 +2835,8 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra
|
||||||
CCoinsViewCache view(&CoinsTip());
|
CCoinsViewCache view(&CoinsTip());
|
||||||
assert(view.GetBestBlock() == pindexDelete->GetBlockHash());
|
assert(view.GetBestBlock() == pindexDelete->GetBlockHash());
|
||||||
if (DisconnectBlock(block, pindexDelete, view) != DISCONNECT_OK) {
|
if (DisconnectBlock(block, pindexDelete, view) != DISCONNECT_OK) {
|
||||||
return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
|
error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
bool flushed = view.Flush();
|
bool flushed = view.Flush();
|
||||||
assert(flushed);
|
assert(flushed);
|
||||||
|
@ -2961,7 +2966,8 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew,
|
||||||
if (!rv) {
|
if (!rv) {
|
||||||
if (state.IsInvalid())
|
if (state.IsInvalid())
|
||||||
InvalidBlockFound(pindexNew, state);
|
InvalidBlockFound(pindexNew, state);
|
||||||
return error("%s: ConnectBlock %s failed, %s", __func__, pindexNew->GetBlockHash().ToString(), state.ToString());
|
error("%s: ConnectBlock %s failed, %s", __func__, pindexNew->GetBlockHash().ToString(), state.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
time_3 = SteadyClock::now();
|
time_3 = SteadyClock::now();
|
||||||
time_connect_total += time_3 - time_2;
|
time_connect_total += time_3 - time_2;
|
||||||
|
@ -4244,7 +4250,8 @@ bool ChainstateManager::AcceptBlock(const std::shared_ptr<const CBlock>& pblock,
|
||||||
pindex->nStatus |= BLOCK_FAILED_VALID;
|
pindex->nStatus |= BLOCK_FAILED_VALID;
|
||||||
m_blockman.m_dirty_blockindex.insert(pindex);
|
m_blockman.m_dirty_blockindex.insert(pindex);
|
||||||
}
|
}
|
||||||
return error("%s: %s", __func__, state.ToString());
|
error("%s: %s", __func__, state.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Header is valid/has work, merkle tree and segwit merkle tree are good...RELAY NOW
|
// Header is valid/has work, merkle tree and segwit merkle tree are good...RELAY NOW
|
||||||
|
@ -4307,7 +4314,8 @@ bool ChainstateManager::ProcessNewBlock(const std::shared_ptr<const CBlock>& blo
|
||||||
if (m_options.signals) {
|
if (m_options.signals) {
|
||||||
m_options.signals->BlockChecked(*block, state);
|
m_options.signals->BlockChecked(*block, state);
|
||||||
}
|
}
|
||||||
return error("%s: AcceptBlock FAILED (%s)", __func__, state.ToString());
|
error("%s: AcceptBlock FAILED (%s)", __func__, state.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4315,13 +4323,15 @@ bool ChainstateManager::ProcessNewBlock(const std::shared_ptr<const CBlock>& blo
|
||||||
|
|
||||||
BlockValidationState state; // Only used to report errors, not invalidity - ignore it
|
BlockValidationState state; // Only used to report errors, not invalidity - ignore it
|
||||||
if (!ActiveChainstate().ActivateBestChain(state, block)) {
|
if (!ActiveChainstate().ActivateBestChain(state, block)) {
|
||||||
return error("%s: ActivateBestChain failed (%s)", __func__, state.ToString());
|
error("%s: ActivateBestChain failed (%s)", __func__, state.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Chainstate* bg_chain{WITH_LOCK(cs_main, return BackgroundSyncInProgress() ? m_ibd_chainstate.get() : nullptr)};
|
Chainstate* bg_chain{WITH_LOCK(cs_main, return BackgroundSyncInProgress() ? m_ibd_chainstate.get() : nullptr)};
|
||||||
BlockValidationState bg_state;
|
BlockValidationState bg_state;
|
||||||
if (bg_chain && !bg_chain->ActivateBestChain(bg_state, block)) {
|
if (bg_chain && !bg_chain->ActivateBestChain(bg_state, block)) {
|
||||||
return error("%s: [background] ActivateBestChain failed (%s)", __func__, bg_state.ToString());
|
error("%s: [background] ActivateBestChain failed (%s)", __func__, bg_state.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -4360,13 +4370,16 @@ bool TestBlockValidity(BlockValidationState& state,
|
||||||
|
|
||||||
// NOTE: CheckBlockHeader is called by CheckBlock
|
// NOTE: CheckBlockHeader is called by CheckBlock
|
||||||
if (!ContextualCheckBlockHeader(block, state, chainstate.m_blockman, chainstate.m_chainman, pindexPrev)) {
|
if (!ContextualCheckBlockHeader(block, state, chainstate.m_blockman, chainstate.m_chainman, pindexPrev)) {
|
||||||
return error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, state.ToString());
|
error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, state.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (!CheckBlock(block, state, chainparams.GetConsensus(), fCheckPOW, fCheckMerkleRoot)) {
|
if (!CheckBlock(block, state, chainparams.GetConsensus(), fCheckPOW, fCheckMerkleRoot)) {
|
||||||
return error("%s: Consensus::CheckBlock: %s", __func__, state.ToString());
|
error("%s: Consensus::CheckBlock: %s", __func__, state.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (!ContextualCheckBlock(block, state, chainstate.m_chainman, pindexPrev)) {
|
if (!ContextualCheckBlock(block, state, chainstate.m_chainman, pindexPrev)) {
|
||||||
return error("%s: Consensus::ContextualCheckBlock: %s", __func__, state.ToString());
|
error("%s: Consensus::ContextualCheckBlock: %s", __func__, state.ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (!chainstate.ConnectBlock(block, state, &indexDummy, viewNew, true)) {
|
if (!chainstate.ConnectBlock(block, state, &indexDummy, viewNew, true)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -4571,7 +4584,8 @@ bool Chainstate::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& in
|
||||||
// TODO: merge with ConnectBlock
|
// TODO: merge with ConnectBlock
|
||||||
CBlock block;
|
CBlock block;
|
||||||
if (!m_blockman.ReadBlockFromDisk(block, *pindex)) {
|
if (!m_blockman.ReadBlockFromDisk(block, *pindex)) {
|
||||||
return error("ReplayBlock(): ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
|
error("ReplayBlock(): ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const CTransactionRef& tx : block.vtx) {
|
for (const CTransactionRef& tx : block.vtx) {
|
||||||
|
@ -4596,7 +4610,8 @@ bool Chainstate::ReplayBlocks()
|
||||||
std::vector<uint256> hashHeads = db.GetHeadBlocks();
|
std::vector<uint256> hashHeads = db.GetHeadBlocks();
|
||||||
if (hashHeads.empty()) return true; // We're already in a consistent state.
|
if (hashHeads.empty()) return true; // We're already in a consistent state.
|
||||||
if (hashHeads.size() != 2) {
|
if (hashHeads.size() != 2) {
|
||||||
return error("ReplayBlocks(): unknown inconsistent state");
|
error("ReplayBlocks(): unknown inconsistent state");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_chainman.GetNotifications().progress(_("Replaying blocks…"), 0, false);
|
m_chainman.GetNotifications().progress(_("Replaying blocks…"), 0, false);
|
||||||
|
@ -4607,13 +4622,15 @@ bool Chainstate::ReplayBlocks()
|
||||||
const CBlockIndex* pindexFork = nullptr; // Latest block common to both the old and the new tip.
|
const CBlockIndex* pindexFork = nullptr; // Latest block common to both the old and the new tip.
|
||||||
|
|
||||||
if (m_blockman.m_block_index.count(hashHeads[0]) == 0) {
|
if (m_blockman.m_block_index.count(hashHeads[0]) == 0) {
|
||||||
return error("ReplayBlocks(): reorganization to unknown block requested");
|
error("ReplayBlocks(): reorganization to unknown block requested");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
pindexNew = &(m_blockman.m_block_index[hashHeads[0]]);
|
pindexNew = &(m_blockman.m_block_index[hashHeads[0]]);
|
||||||
|
|
||||||
if (!hashHeads[1].IsNull()) { // The old tip is allowed to be 0, indicating it's the first flush.
|
if (!hashHeads[1].IsNull()) { // The old tip is allowed to be 0, indicating it's the first flush.
|
||||||
if (m_blockman.m_block_index.count(hashHeads[1]) == 0) {
|
if (m_blockman.m_block_index.count(hashHeads[1]) == 0) {
|
||||||
return error("ReplayBlocks(): reorganization from unknown block requested");
|
error("ReplayBlocks(): reorganization from unknown block requested");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
pindexOld = &(m_blockman.m_block_index[hashHeads[1]]);
|
pindexOld = &(m_blockman.m_block_index[hashHeads[1]]);
|
||||||
pindexFork = LastCommonAncestor(pindexOld, pindexNew);
|
pindexFork = LastCommonAncestor(pindexOld, pindexNew);
|
||||||
|
@ -4625,12 +4642,14 @@ bool Chainstate::ReplayBlocks()
|
||||||
if (pindexOld->nHeight > 0) { // Never disconnect the genesis block.
|
if (pindexOld->nHeight > 0) { // Never disconnect the genesis block.
|
||||||
CBlock block;
|
CBlock block;
|
||||||
if (!m_blockman.ReadBlockFromDisk(block, *pindexOld)) {
|
if (!m_blockman.ReadBlockFromDisk(block, *pindexOld)) {
|
||||||
return error("RollbackBlock(): ReadBlockFromDisk() failed at %d, hash=%s", pindexOld->nHeight, pindexOld->GetBlockHash().ToString());
|
error("RollbackBlock(): ReadBlockFromDisk() failed at %d, hash=%s", pindexOld->nHeight, pindexOld->GetBlockHash().ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
LogPrintf("Rolling back %s (%i)\n", pindexOld->GetBlockHash().ToString(), pindexOld->nHeight);
|
LogPrintf("Rolling back %s (%i)\n", pindexOld->GetBlockHash().ToString(), pindexOld->nHeight);
|
||||||
DisconnectResult res = DisconnectBlock(block, pindexOld, cache);
|
DisconnectResult res = DisconnectBlock(block, pindexOld, cache);
|
||||||
if (res == DISCONNECT_FAILED) {
|
if (res == DISCONNECT_FAILED) {
|
||||||
return error("RollbackBlock(): DisconnectBlock failed at %d, hash=%s", pindexOld->nHeight, pindexOld->GetBlockHash().ToString());
|
error("RollbackBlock(): DisconnectBlock failed at %d, hash=%s", pindexOld->nHeight, pindexOld->GetBlockHash().ToString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
// If DISCONNECT_UNCLEAN is returned, it means a non-existing UTXO was deleted, or an existing UTXO was
|
// If DISCONNECT_UNCLEAN is returned, it means a non-existing UTXO was deleted, or an existing UTXO was
|
||||||
// overwritten. It corresponds to cases where the block-to-be-disconnect never had all its operations
|
// overwritten. It corresponds to cases where the block-to-be-disconnect never had all its operations
|
||||||
|
@ -4749,12 +4768,14 @@ bool Chainstate::LoadGenesisBlock()
|
||||||
const CBlock& block = params.GenesisBlock();
|
const CBlock& block = params.GenesisBlock();
|
||||||
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0, nullptr)};
|
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0, nullptr)};
|
||||||
if (blockPos.IsNull()) {
|
if (blockPos.IsNull()) {
|
||||||
return error("%s: writing genesis block to disk failed", __func__);
|
error("%s: writing genesis block to disk failed", __func__);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
CBlockIndex* pindex = m_blockman.AddToBlockIndex(block, m_chainman.m_best_header);
|
CBlockIndex* pindex = m_blockman.AddToBlockIndex(block, m_chainman.m_best_header);
|
||||||
m_chainman.ReceivedBlockTransactions(block, pindex, blockPos);
|
m_chainman.ReceivedBlockTransactions(block, pindex, blockPos);
|
||||||
} catch (const std::runtime_error& e) {
|
} catch (const std::runtime_error& e) {
|
||||||
return error("%s: failed to write genesis block: %s", __func__, e.what());
|
error("%s: failed to write genesis block: %s", __func__, e.what());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue