Skip to content

Commit

Permalink
Remove POW, disable broken validation
Browse files Browse the repository at this point in the history
  • Loading branch information
CryptAxe committed Jan 24, 2024
1 parent 12a1c60 commit 860d906
Show file tree
Hide file tree
Showing 26 changed files with 220 additions and 368 deletions.
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ libbitcoin_node_a_SOURCES = \
rpc/net.cpp \
rpc/node.cpp \
rpc/output_script.cpp \
rpc/rawtransaction.cpp \
# TODO rpc/rawtransaction.cpp \
rpc/server.cpp \
rpc/server_util.cpp \
rpc/signmessage.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoin-chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ int main(int argc, char* argv[])
bool new_block;
auto sc = std::make_shared<submitblock_StateCatcher>(block.GetHash());
RegisterSharedValidationInterface(sc);
bool accepted = chainman.ProcessNewBlock(blockptr, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/&new_block);
bool accepted = chainman.ProcessNewBlock(blockptr, /*force_processing=*/true, /*new_block=*/&new_block);
UnregisterSharedValidationInterface(sc);
if (!new_block && accepted) {
std::cerr << "duplicate" << std::endl;
Expand Down
5 changes: 5 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ const CChainParams &Params() {
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const ChainType chain)
{
switch (chain) {
case ChainType::TESTNET:
case ChainType::MAIN:
case ChainType::REGTEST:
case ChainType::SIGNET:
return CChainParams::Main();
/*
case ChainType::TESTNET:
return CChainParams::TestNet();
case ChainType::SIGNET: {
Expand All @@ -123,6 +127,7 @@ std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, c
ReadRegTestArgs(args, opts);
return CChainParams::RegTest(opts);
}
*/
}
assert(false);
}
Expand Down
6 changes: 2 additions & 4 deletions src/kernel/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class CTestNetParams : public CChainParams {
m_assumed_blockchain_size = 42;
m_assumed_chain_state_size = 3;

genesis = CreateGenesisBlock(1296688602, 414098458, 0x1d00ffff, 1, 50 * COIN);
genesis = CreateGenesisBlock(1296688602, 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"));
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
Expand All @@ -217,8 +217,6 @@ class CTestNetParams : public CChainParams {

bech32_hrp = "tb";

vFixedSeeds = std::vector<uint8_t>(std::begin(chainparams_seed_test), std::end(chainparams_seed_test));

fDefaultConsistencyChecks = false;
m_is_mockable_chain = false;

Expand Down Expand Up @@ -330,7 +328,7 @@ class SigNetParams : public CChainParams {
nDefaultPort = 38333;
nPruneAfterHeight = 1000;

genesis = CreateGenesisBlock(1598918400, 52613770, 0x1e0377ae, 1, 50 * COIN);
genesis = CreateGenesisBlock(1598918400, 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6"));
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
Expand Down
211 changes: 111 additions & 100 deletions src/net_processing.cpp

Large diffs are not rendered by default.

22 changes: 9 additions & 13 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <kernel/chainparams.h>
#include <kernel/messagestartchars.h>
#include <logging.h>
#include <pow.h>
#include <reverse_iterator.h>
#include <signet.h>
#include <streams.h>
Expand Down Expand Up @@ -93,7 +92,7 @@ bool BlockTreeDB::ReadFlag(const std::string& name, bool& fValue)
return true;
}

bool BlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, const util::SignalInterrupt& interrupt)
bool BlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&, const uint256&)> insertBlockIndex, const util::SignalInterrupt& interrupt)
{
AssertLockHeld(::cs_main);
std::unique_ptr<CDBIterator> pcursor(NewIterator());
Expand All @@ -107,24 +106,20 @@ bool BlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, s
CDiskBlockIndex diskindex;
if (pcursor->GetValue(diskindex)) {
// Construct block index object
CBlockIndex* pindexNew = insertBlockIndex(diskindex.ConstructBlockHash());
pindexNew->pprev = insertBlockIndex(diskindex.hashPrev);
// // TODO insert mainblock hash here
// TODO
CBlockIndex* pindexNew; // = insertBlockIndex(diskindex.ConstructBlockHash());
// TODO pindexNew->pprev = insertBlockIndex(diskindex.hashPrev);
pindexNew->nHeight = diskindex.nHeight;
pindexNew->nFile = diskindex.nFile;
pindexNew->nDataPos = diskindex.nDataPos;
pindexNew->nUndoPos = diskindex.nUndoPos;
pindexNew->nVersion = diskindex.nVersion;
pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
pindexNew->nTime = diskindex.nTime;
pindexNew->nBits = diskindex.nBits;
pindexNew->nNonce = diskindex.nNonce;
pindexNew->nStatus = diskindex.nStatus;
pindexNew->nTx = diskindex.nTx;

if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams)) {
return error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString());
}

pcursor->Next();
} else {
return error("%s: failed to read value", __func__);
Expand Down Expand Up @@ -389,9 +384,10 @@ CBlockIndex* BlockManager::InsertBlockIndex(const uint256& hash, const uint256&

bool BlockManager::LoadBlockIndex(const std::optional<uint256>& snapshot_blockhash)
{
if (!m_block_tree_db->LoadBlockIndexGuts(consensus_params, [this](const uint256& hash, const uint256& hashMainBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return this->InsertBlockIndex(hash, hashMainBlock); })) {
return false;
}
// TODO
//if (!m_block_tree_db->LoadBlockIndexGuts(GetParams(), [this](const uint256& hash, const uint256& hashMainBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return this->InsertBlockIndex(hash, hashMainBlock); })) {
// return false;
//}

if (snapshot_blockhash) {
const std::optional<AssumeutxoData> maybe_au_data = GetParams().AssumeutxoForBlockhash(*snapshot_blockhash);
Expand Down
2 changes: 1 addition & 1 deletion src/node/blockstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BlockTreeDB : public CDBWrapper
void ReadReindexing(bool& fReindexing);
bool WriteFlag(const std::string& name, bool fValue);
bool ReadFlag(const std::string& name, bool& fValue);
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, const util::SignalInterrupt& interrupt)
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&, const uint256&)> insertBlockIndex, const util::SignalInterrupt& interrupt)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
};
} // namespace kernel
Expand Down
1 change: 0 additions & 1 deletion src/node/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <sidechainclient.h>
#include <timedata.h>
#include <util/moneystr.h>
#include <util/system.h>
#include <txdb.h>
#include <validation.h>

Expand Down
6 changes: 4 additions & 2 deletions src/policy/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
if (subscript.GetSigOpCount(true) > MAX_P2SH_SIGOPS) {
return false;
}
} else if (whichType == TxoutType::TX_BARE_DEFAULT_CHECK_TEMPLATE_VERIFY_HASH) {
if (tx.vin[i].scriptSig.size() != 0) return false;
}
// TODO
//else if (whichType == TxoutType::TX_BARE_DEFAULT_CHECK_TEMPLATE_VERIFY_HASH) {
// if (tx.vin[i].scriptSig.size() != 0) return false;
// }

}

Expand Down
5 changes: 3 additions & 2 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <prevector.h>
#include <script/script.h>
#include <serialize.h>
#include <streams.h>
#include <uint256.h>

#include <cstddef>
Expand Down Expand Up @@ -215,7 +216,7 @@ struct CMutableTransaction;
*/
template<typename Stream, typename TxType>
inline void UnserializeTransaction(TxType& tx, Stream& s) {
const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);
const bool fAllowWitness = false; // TODO !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);

s >> tx.nVersion;
unsigned char flags = 0;
Expand Down Expand Up @@ -254,7 +255,7 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) {

template<typename Stream, typename TxType>
inline void SerializeTransaction(const TxType& tx, Stream& s) {
const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);
const bool fAllowWitness = false; // TODO !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);

s << tx.nVersion;
unsigned char flags = 0;
Expand Down
18 changes: 13 additions & 5 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2608,9 +2608,11 @@ UniValue CreateUTXOSnapshot(
return result;
}


static RPCHelpMan refreshbmm()
{
return RPCHelpMan{"refreshbmm",
return RPCHelpMan{
"refreshbmm",
"Refresh automated BMM. Basic testing implementation.\n",
{
{"amount", RPCArg::Type::NUM, RPCArg::Optional::NO, "Amount to pay mainchain miner for including BMM request."},
Expand All @@ -2628,11 +2630,18 @@ static RPCHelpMan refreshbmm()
{RPCResult::Type::NUM, "nfees", ""},
{RPCResult::Type::STR, "txid", ""},
{RPCResult::Type::STR, "error", ""},
}},
}
},
RPCExamples{
HelpExampleCli("refreshbmm", "")
+ HelpExampleRpc("refreshbmm", "")
+ HelpExampleRpc("refreshbmm", "")},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
LOCK(cs_main);

ChainstateManager& chainman = EnsureAnyChainman(request.context);
NodeContext& node = EnsureAnyNodeContext(request.context);

Chainstate& active_chainstate = chainman.ActiveChainstate();

CTxMemPool& mempool = EnsureMemPool(node);
Expand Down Expand Up @@ -2747,7 +2756,6 @@ return RPCHelpMan{

data.pushKV("blocks", (int)chain.Height());
data.pushKV("bestblockhash", tip->GetBlockHash().GetHex());
data.pushKV("difficulty", (double)GetDifficulty(tip));
data.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), tip));
data.pushKV("coins_db_cache_bytes", cs.m_coinsdb_cache_size_bytes);
data.pushKV("coins_tip_cache_bytes", cs.m_coinstip_cache_size_bytes);
Expand Down Expand Up @@ -2887,7 +2895,7 @@ void RegisterBlockchainRPCCommands(CRPCTable& t)
{"blockchain", &scanblocks},
{"blockchain", &getblockfilter},
{"blockchain", &dumptxoutset},
{"blockchain", &loadtxoutset},
//{"blockchain", &loadtxoutset},
{"blockchain", &getchainstates},
{"hidden", &invalidateblock},
{"hidden", &reconsiderblock},
Expand Down
8 changes: 0 additions & 8 deletions src/rpc/blockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ struct NodeContext;

static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;

/**
* Get the difficulty of the net wrt to the given block index.
*
* @return A floating point number that is a multiple of the main net minimum
* difficulty (4295032833 hashes).
*/
double GetDifficulty(const CBlockIndex* blockindex);

/** Callback for when block tip changed. */
void RPCNotifyBlockChange(const CBlockIndex*);

Expand Down
9 changes: 5 additions & 4 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ PartiallySignedTransaction ProcessPSBT(const std::string& psbt_string, const std
// Note that SignPSBTInput does a lot more than just constructing ECDSA signatures.
// We only actually care about those if our signing provider doesn't hide private
// information, as is the case with `descriptorprocesspsbt`
SignPSBTInput(provider, psbtx, /*index=*/i, &txdata, sighash_type, /*out_sigdata=*/nullptr, finalize);
// TODO SignPSBTInput(provider, psbtx, /*index=*/i, &txdata, sighash_type, /*out_sigdata=*/nullptr, finalize);
}

// Update script/keypath information using descriptor data.
Expand Down Expand Up @@ -557,7 +557,7 @@ static RPCHelpMan decodescript()
case TxoutType::SCRIPTHASH:
case TxoutType::WITNESS_UNKNOWN:
case TxoutType::WITNESS_V1_TAPROOT:
case TxoutType::TX_BARE_DEFAULT_CHECK_TEMPLATE_VERIFY_HASH:
// TODO case TxoutType::TX_BARE_DEFAULT_CHECK_TEMPLATE_VERIFY_HASH:
// Should not be wrapped
return false;
} // no default case, so the compiler can warn about missing cases
Expand Down Expand Up @@ -600,7 +600,7 @@ static RPCHelpMan decodescript()
case TxoutType::WITNESS_V0_KEYHASH:
case TxoutType::WITNESS_V0_SCRIPTHASH:
case TxoutType::WITNESS_V1_TAPROOT:
case TxoutType::TX_BARE_DEFAULT_CHECK_TEMPLATE_VERIFY_HASH:
// TODO case TxoutType::TX_BARE_DEFAULT_CHECK_TEMPLATE_VERIFY_HASH:
// Should not be wrapped
return false;
} // no default case, so the compiler can warn about missing cases
Expand Down Expand Up @@ -1726,7 +1726,8 @@ static RPCHelpMan utxoupdatepsbt()
// Fill the inputs
PrecomputedTransactionData txdata = PrecomputePSBTData(psbtx);
for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) {
PSBTInput& input = psbtx.inputs.at(i);
// TODO
//PSBTInput& input = psbtx.inputs.at(i);

if (input.non_witness_utxo || !input.witness_utxo.IsNull()) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void RegisterMiningRPCCommands(CRPCTable &tableRPC);
void RegisterNodeRPCCommands(CRPCTable&);
void RegisterNetRPCCommands(CRPCTable&);
void RegisterOutputScriptRPCCommands(CRPCTable&);
void RegisterRawTransactionRPCCommands(CRPCTable &tableRPC);
// TODO void RegisterRawTransactionRPCCommands(CRPCTable &tableRPC);
void RegisterSignMessageRPCCommands(CRPCTable&);
void RegisterSignerRPCCommands(CRPCTable &tableRPC);
void RegisterTxoutProofRPCCommands(CRPCTable&);
Expand All @@ -30,7 +30,7 @@ static inline void RegisterAllCoreRPCCommands(CRPCTable &t)
RegisterNodeRPCCommands(t);
RegisterNetRPCCommands(t);
RegisterOutputScriptRPCCommands(t);
RegisterRawTransactionRPCCommands(t);
// TODO RegisterRawTransactionRPCCommands(t);
RegisterSignMessageRPCCommands(t);
#ifdef ENABLE_EXTERNAL_SIGNER
RegisterSignerRPCCommands(t);
Expand Down
6 changes: 3 additions & 3 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,7 @@ uint256 GetSpentScriptsSHA256(const std::vector<CTxOut>& outputs_spent)
template <class T>
uint256 GetScriptSigsSHA256(const T& txTo)
{
CHashWriter ss(SER_GETHASH, 0);
CHashWriter ss(SER_DISK);
for (const auto& in : txTo.vin) {
ss << in.scriptSig;
}
Expand All @@ -1576,7 +1576,7 @@ uint256 GetScriptSigsSHA256(const T& txTo)
template<typename TxType>
uint256 GetDefaultCheckTemplateVerifyHashWithScript(const TxType& tx, const uint256& outputs_hash, const uint256& sequences_hash,
const uint256& scriptSig_hash, const uint32_t input_index) {
auto h = CHashWriter(SER_GETHASH, 0)
auto h = CHashWriter(SER_DISK)
<< tx.nVersion
<< tx.nLockTime
<< scriptSig_hash
Expand All @@ -1591,7 +1591,7 @@ uint256 GetDefaultCheckTemplateVerifyHashWithScript(const TxType& tx, const uint
template<typename TxType>
uint256 GetDefaultCheckTemplateVerifyHashEmptyScript(const TxType& tx, const uint256& outputs_hash, const uint256& sequences_hash,
const uint32_t input_index) {
auto h = CHashWriter(SER_GETHASH, 0)
auto h = CHashWriter(SER_DISK)
<< tx.nVersion
<< tx.nLockTime
<< uint32_t(tx.vin.size())
Expand Down
Loading

0 comments on commit 860d906

Please sign in to comment.