Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bench/verify_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void VerifyScriptBench(benchmark::Bench& bench)
{
ECC_Context ecc_context{};

const uint32_t flags{SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH};
const script_verify_flags flags{SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH};
const int witnessversion = 0;

// Key pair.
Expand Down
6 changes: 3 additions & 3 deletions src/binana.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_binana_info(path):
return data

def gen_binana_h(data, header, depjson):
script_verify_bit = 30 # count backwards; 31 is assumed unused in unit tests
script_verify_bit = 60 # count backwards; note: 63 is assumed unused in unit tests

defines = {a: [] for a in "DEPLOYMENTS DEPLOYMENTS_SIGNET DEPLOYMENTS_REGTEST DEPLOYMENTS_GBT VERIFY_FLAGS VERIFY_FLAGS_NAMES STANDARD_VERIFY_FLAGS OPCODES OPCODE_NAMES SUCCESS_OPCODES SCRIPTERR SCRIPTERR_STRING SCRIPTERR_TEST_NAMES CONSENSUS_CHECKS POLICY_CHECKS".split()}

Expand Down Expand Up @@ -90,7 +90,7 @@ def gen_binana_h(data, header, depjson):
if b.get("scriptverify", False):
jsoninfo["script_flags"].append(dep)

defines["VERIFY_FLAGS"].append(f'SCRIPT_VERIFY_{dep} = (1U << {script_verify_bit}),')
defines["VERIFY_FLAGS"].append(f'SCRIPT_VERIFY_{dep} = (1ULL << {script_verify_bit}),')
script_verify_bit -= 1

defines["VERIFY_FLAGS_NAMES"].append(f'{{ "{dep}", SCRIPT_VERIFY_{dep} }},')
Expand All @@ -102,7 +102,7 @@ def gen_binana_h(data, header, depjson):
discourage = False
if b.get("scriptverify", False) and b.get("scriptverify_discourage", False):
discourage = True
defines["VERIFY_FLAGS"].append(f'SCRIPT_VERIFY_DISCOURAGE_{dep} = (1U << {script_verify_bit}),')
defines["VERIFY_FLAGS"].append(f'SCRIPT_VERIFY_DISCOURAGE_{dep} = (1ULL << {script_verify_bit}),')
script_verify_bit -= 1

defines["VERIFY_FLAGS_NAMES"].append(f'{{ "DISCOURAGE_{dep}", SCRIPT_VERIFY_DISCOURAGE_{dep} }},')
Expand Down
6 changes: 3 additions & 3 deletions src/bitcoin-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ static std::string sigver2str(SigVersion sigver)
return "unknown";
}

static uint32_t parse_verify_flags(const std::string& strFlags)
static script_verify_flags parse_verify_flags(const std::string& strFlags)
{
if (strFlags.empty() || strFlags == "MANDATORY") return MANDATORY_SCRIPT_VERIFY_FLAGS;
if (strFlags == "STANDARD") return STANDARD_SCRIPT_VERIFY_FLAGS;
if (strFlags == "NONE") return 0;

unsigned int flags = 0;
script_verify_flags flags = 0;
std::vector<std::string> words = util::SplitString(strFlags, ',');

for (const std::string& word : words)
Expand Down Expand Up @@ -220,7 +220,7 @@ static int EvalScript(const ArgsManager& argsman, const std::vector<std::string>
{
UniValue result{UniValue::VOBJ};

uint32_t flags{0};
script_verify_flags flags{0};
PrecomputedTransactionData txdata;
ScriptExecutionData execdata;

Expand Down
3 changes: 2 additions & 1 deletion src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define BITCOIN_CONSENSUS_PARAMS_H

#include <binana.h>
#include <script/verify_flags.h>
#include <uint256.h>

#include <array>
Expand Down Expand Up @@ -83,7 +84,7 @@ struct Params {
* - buried in the chain, and
* - fail if the default script verify flags are applied.
*/
std::map<uint256, uint32_t> script_flag_exceptions;
std::map<uint256, script_verify_flags> script_flag_exceptions;
/** Block height and hash at which BIP34 becomes active */
int BIP34Height;
uint256 BIP34Hash;
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
return nSigOps;
}

int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& inputs, uint32_t flags)
int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& inputs, script_verify_flags flags)
{
int64_t nSigOps = GetLegacySigOpCount(tx) * WITNESS_SCALE_FACTOR;

Expand Down
3 changes: 2 additions & 1 deletion src/consensus/tx_verify.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define BITCOIN_CONSENSUS_TX_VERIFY_H

#include <consensus/amount.h>
#include <script/verify_flags.h>

#include <stdint.h>
#include <vector>
Expand Down Expand Up @@ -52,7 +53,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& ma
* @param[in] flags Script verification flags
* @return Total signature operation cost of tx
*/
int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& inputs, uint32_t flags);
int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& inputs, script_verify_flags flags);

/**
* Check if transaction is final and can be included in a block with the
Expand Down
8 changes: 4 additions & 4 deletions src/deploymentinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::optional<Consensus::BuriedDeployment> GetBuriedDeployment(const std::string
}

#define FLAG_NAME(flag) {std::string(#flag), SCRIPT_VERIFY_##flag}
const std::map<std::string, uint32_t> g_verify_flag_names{
const std::map<std::string, script_verify_flag_name> g_verify_flag_names{
FLAG_NAME(P2SH),
FLAG_NAME(STRICTENC),
FLAG_NAME(DERSIG),
Expand All @@ -83,21 +83,21 @@ const std::map<std::string, uint32_t> g_verify_flag_names{
};
#undef FLAG_NAME

std::vector<std::string> GetScriptFlagNames(uint32_t flags)
std::vector<std::string> GetScriptFlagNames(script_verify_flags flags)
{
std::vector<std::string> res;
if (flags == SCRIPT_VERIFY_NONE) {
return res;
}
uint32_t leftover = flags;
script_verify_flags leftover = flags;
for (const auto& [name, flag] : g_verify_flag_names) {
if ((flags & flag) != 0) {
res.push_back(name);
leftover &= ~flag;
}
}
if (leftover != 0) {
res.push_back(strprintf("0x%08x", leftover));
res.push_back(strprintf("0x%08x", leftover.as_int()));
}
return res;
}
5 changes: 3 additions & 2 deletions src/deploymentinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define BITCOIN_DEPLOYMENTINFO_H

#include <consensus/params.h>
#include <script/verify_flags.h>

#include <array>
#include <cassert>
Expand Down Expand Up @@ -34,8 +35,8 @@ inline std::string DeploymentName(Consensus::DeploymentPos pos)

std::optional<Consensus::BuriedDeployment> GetBuriedDeployment(const std::string_view deployment_name);

extern const std::map<std::string, uint32_t> g_verify_flag_names;
extern const std::map<std::string, script_verify_flag_name> g_verify_flag_names;

std::vector<std::string> GetScriptFlagNames(uint32_t flags);
std::vector<std::string> GetScriptFlagNames(script_verify_flags flags);

#endif // BITCOIN_DEPLOYMENTINFO_H
6 changes: 3 additions & 3 deletions src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static constexpr unsigned int MAX_DUST_OUTPUTS_PER_TX{1};
* Note that this does not affect consensus validity; see GetBlockScriptFlags()
* for that.
*/
static constexpr unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS{SCRIPT_VERIFY_P2SH |
static constexpr script_verify_flags MANDATORY_SCRIPT_VERIFY_FLAGS{SCRIPT_VERIFY_P2SH |
SCRIPT_VERIFY_DERSIG |
SCRIPT_VERIFY_NULLDUMMY |
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY |
Expand All @@ -113,7 +113,7 @@ static constexpr unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS{SCRIPT_VERIFY_P2SH |
* the additional (non-mandatory) rules here, to improve forwards and
* backwards compatibility.
*/
static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS{MANDATORY_SCRIPT_VERIFY_FLAGS |
static constexpr script_verify_flags STANDARD_SCRIPT_VERIFY_FLAGS{MANDATORY_SCRIPT_VERIFY_FLAGS |
SCRIPT_VERIFY_STRICTENC |
SCRIPT_VERIFY_MINIMALDATA |
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS |
Expand All @@ -134,7 +134,7 @@ static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS{MANDATORY_SCRIPT_VERI
};

/** For convenience, standard but not mandatory verify flags. */
static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS{STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS};
static constexpr script_verify_flags STANDARD_NOT_MANDATORY_VERIFY_FLAGS{STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS};

/** Used as the flags parameter to sequence and nLocktime checks in non-consensus code. */
static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS{LOCKTIME_VERIFY_SEQUENCE};
Expand Down
2 changes: 2 additions & 0 deletions src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ add_library(bitcoinqt STATIC EXCLUDE_FROM_ALL
clientmodel.h
csvmodelwriter.cpp
csvmodelwriter.h
freespacechecker.cpp
freespacechecker.h
guiutil.cpp
guiutil.h
initexecutor.cpp
Expand Down
58 changes: 58 additions & 0 deletions src/qt/freespacechecker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2011-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <qt/freespacechecker.h>

#include <qt/guiutil.h>
#include <util/fs.h>

#include <QDir>
#include <QString>

#include <cstdint>

void FreespaceChecker::check()
{
QString dataDirStr = intro->getPathToCheck();
fs::path dataDir = GUIUtil::QStringToPath(dataDirStr);
uint64_t freeBytesAvailable = 0;
int replyStatus = ST_OK;
QString replyMessage = tr("A new data directory will be created.");

/* Find first parent that exists, so that fs::space does not fail */
fs::path parentDir = dataDir;
fs::path parentDirOld = fs::path();
while(parentDir.has_parent_path() && !fs::exists(parentDir))
{
parentDir = parentDir.parent_path();

/* Check if we make any progress, break if not to prevent an infinite loop here */
if (parentDirOld == parentDir)
break;

parentDirOld = parentDir;
}

try {
freeBytesAvailable = fs::space(parentDir).available;
if(fs::exists(dataDir))
{
if(fs::is_directory(dataDir))
{
QString separator = "<code>" + QDir::toNativeSeparators("/") + tr("name") + "</code>";
replyStatus = ST_OK;
replyMessage = tr("Directory already exists. Add %1 if you intend to create a new directory here.").arg(separator);
} else {
replyStatus = ST_ERROR;
replyMessage = tr("Path already exists, and is not a directory.");
}
}
} catch (const fs::filesystem_error&)
{
/* Parent directory does not exist or is not accessible */
replyStatus = ST_ERROR;
replyMessage = tr("Cannot create data directory here.");
}
Q_EMIT reply(replyStatus, replyMessage, freeBytesAvailable);
}
50 changes: 50 additions & 0 deletions src/qt/freespacechecker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2011-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_QT_FREESPACECHECKER_H
#define BITCOIN_QT_FREESPACECHECKER_H

#include <QObject>
#include <QString>
#include <QtGlobal>

/* Check free space asynchronously to prevent hanging the UI thread.

Up to one request to check a path is in flight to this thread; when the check()
function runs, the current path is requested from the associated Intro object.
The reply is sent back through a signal.

This ensures that no queue of checking requests is built up while the user is
still entering the path, and that always the most recently entered path is checked as
soon as the thread becomes available.
*/
class FreespaceChecker : public QObject
{
Q_OBJECT

public:
class PathQuery
{
public:
virtual QString getPathToCheck() = 0;
};

explicit FreespaceChecker(PathQuery* intro) : intro{intro} {}

enum Status {
ST_OK,
ST_ERROR
};

public Q_SLOTS:
void check();

Q_SIGNALS:
void reply(int status, const QString &message, quint64 available);

private:
PathQuery* intro;
};

#endif // BITCOIN_QT_FREESPACECHECKER_H
Loading
Loading