Skip to content

Commit

Permalink
44 hard fork to increase amount of pow (#45)
Browse files Browse the repository at this point in the history
Added new code called "Proof of Node" (PoN) that uses deep lookups on various blockchain parameters to make GPU and ASIC difficult to implement and difficult to improve performance compared to a CPU. This is fed into the sha256 on each loop (up to 256 attempts). Validation requires looping up to 256 times, on average it will take half the attempts (128) because uniform random variable approximation. Increasing the number of mining utxos will quickly require a new computer to increase hashrate. Greedy mining will now come at a cost.
  • Loading branch information
bitcoin-pow committed May 3, 2024
1 parent d061586 commit c368798
Show file tree
Hide file tree
Showing 36 changed files with 1,473 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "cppdbg",
"request": "launch",
"program": "/home/ubuntu/dev/BitcoinPoW/src/qt/bitcoin-qt",
"args": ["--emergencymining=1","--rescan=0"],
"args": ["--emergencymining=1","--rescan=0", "--miningthreads=18", "--cpuloading=80"],
//"args": ["--listen=0", "--server=0"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ BitcoinPoW is Bitcoin using proof of work(PoW) and proof of transactions (PoT) t
Combining PoW and PoT results in a highly mining distributed system where every wallet is forced to solo mine.
----------------

The BTCW Hard Fork
----------------
BTCW is too close to a PoS system, where users just let their ONE computer fill up with utxos.
The hard fork pushes BTCW a little closer to PoW territory by making it 256 times quicker to maximize loading on a computer.
```
Satoshi's original Bitcoin has become very mining centralized. One of the longest active BTC developers
(Luke Dashjr) has recently posted his worry on his new mining pool site www.ocean.xyz
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AC_PREREQ([2.69])
define(_CLIENT_VERSION_MAJOR, 26)
define(_CLIENT_VERSION_MINOR, 1)
define(_CLIENT_VERSION_MINOR, 2)
define(_CLIENT_VERSION_REVISION, 1)
define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_RC, 0)
Expand Down
1 change: 1 addition & 0 deletions doc/build-unix.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ This example lists the steps necessary to setup and build a command line only di
Portable Linux build
-------------------
git clone https://github.com/bitcoin-pow/BitcoinPoW.git
cd BitcoinPoW
cd depends
make
cd ..
Expand Down
13 changes: 7 additions & 6 deletions doc/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
26.1.1 Release Notes (BTCW)
26.2.1 Release Notes (BTCW)
==================

Bitcoin Core version 26.1.1 is now available from:
Bitcoin Core version 26.2.1 is now available from:

<https://github.com/bitcoin-pow/BitcoinPoW/releases>

Expand Down Expand Up @@ -39,17 +39,18 @@ unsupported systems.
Notable changes
===============

### Wallet

- https://github.com/bitcoin-pow/BitcoinPoW/issues/38 - Restore creation of legacy wallet
Hardforked BTCW to require more cpus.

Addressed the following issue:
```
The growth of computers was too slow and allowed for too much hashrate per computing device.
```

Credits
=======

Thanks to everyone who directly contributed to this release:

- mraksoll4
- FluffyFunction

As well as to everyone that helped with translations on
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ BITCOIN_CORE_H = \
util/string.h \
util/syserror.h \
util/thread.h \
util/thread_pool.h \
util/threadinterrupt.h \
util/threadnames.h \
util/time.h \
Expand Down
4 changes: 2 additions & 2 deletions src/bench/block_assemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ static void AssembleBlock(benchmark::Bench& bench)

// Collect some loose transactions that spend the coinbases of our mined blocks
constexpr size_t NUM_BLOCKS{200};
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY() + 1> txs;
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
CMutableTransaction tx;
tx.vin.emplace_back(MineBlock(test_setup->m_node, P2WSH_OP_TRUE));
tx.vin.back().scriptWitness = witness;
tx.vout.emplace_back(1337, P2WSH_OP_TRUE);
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
if (NUM_BLOCKS - b >= (COINBASE_MATURITY()))
txs.at(b) = MakeTransactionRef(tx);
}
{
Expand Down
6 changes: 3 additions & 3 deletions src/bench/wallet_create_tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type

// Check available balance
auto bal = WITH_LOCK(wallet.cs_wallet, return wallet::AvailableCoins(wallet).GetTotalAmount()); // Cache
assert(bal == 50 * COIN * (chain_size - COINBASE_MATURITY));
assert(bal == 50 * COIN * (chain_size - COINBASE_MATURITY()));

wallet::CCoinControl coin_control;
coin_control.m_allow_other_inputs = allow_other_inputs;
Expand Down Expand Up @@ -167,12 +167,12 @@ static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType

// Check available balance
auto bal = WITH_LOCK(wallet.cs_wallet, return wallet::AvailableCoins(wallet).GetTotalAmount()); // Cache
assert(bal == 50 * COIN * (chain_size - COINBASE_MATURITY));
assert(bal == 50 * COIN * (chain_size - COINBASE_MATURITY()));

bench.epochIterations(2).run([&] {
LOCK(wallet.cs_wallet);
const auto& res = wallet::AvailableCoins(wallet);
assert(res.All().size() == (chain_size - COINBASE_MATURITY) * 2);
assert(res.All().size() == (chain_size - COINBASE_MATURITY()) * 2);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* for both bitcoind and bitcoin-qt, to make it harder for attackers to
* target servers or GUI users specifically.
*/
const std::string CLIENT_NAME("SatoshiPoW");
const std::string CLIENT_NAME("Bitcoin-PoW");


#ifdef HAVE_BUILD_INFO
Expand Down
15 changes: 14 additions & 1 deletion src/consensus/consensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,21 @@ static const unsigned int MAX_BLOCK_SERIALIZED_SIZE = 4000000;
static const unsigned int MAX_BLOCK_WEIGHT = 4000000;
/** The maximum allowed number of signature check operations in a block (network rule) */
static const int64_t MAX_BLOCK_SIGOPS_COST = 80000;
/** The fork start height of SatoshiPoW (network rule) */
static const int64_t BITCOIN_POW256_START_HEIGHT = 23333;
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
static const int COINBASE_MATURITY = 2;
constexpr int COINBASE_MATURITY()
{
return 6;
}
constexpr int COINBASE_MATURITY( int n )
{
if ( n < BITCOIN_POW256_START_HEIGHT )
{
return 2;
}
return COINBASE_MATURITY();
}

static const int WITNESS_SCALE_FACTOR = 4;

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 @@ -180,7 +180,7 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state,
assert(!coin.IsSpent());

// If prev is coinbase, check that it's matured
if ((coin.IsCoinBase() || coin.IsCoinStake()) && nSpendHeight - coin.nHeight < COINBASE_MATURITY) {
if ((coin.IsCoinBase() || coin.IsCoinStake()) && nSpendHeight - coin.nHeight < COINBASE_MATURITY(coin.nHeight)) {
return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "bad-txns-premature-spend-of-coinbase",
strprintf("tried to spend coinbase at depth %d", nSpendHeight - coin.nHeight));
}
Expand Down
1 change: 0 additions & 1 deletion src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry

if (have_undo) {
const CAmount fee = amt_total_in - amt_total_out;
CHECK_NONFATAL(MoneyRange(fee));
entry.pushKV("fee", ValueFromAmount(fee));
}

Expand Down
3 changes: 2 additions & 1 deletion src/crypto/sha256.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) 2014-2022 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <crypto/sha256.h>
#include <crypto/common.h>

Expand Down
3 changes: 2 additions & 1 deletion src/crypto/sha256_x86_shani.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
// Based on https://github.com/noloader/SHA-Intrinsics/blob/master/sha256-x86.c,
// Written and placed in public domain by Jeffrey Walton.
// Based on code from Intel, and by Sean Gulley for the miTLS project.

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#ifdef ENABLE_X86_SHANI

#include <stdint.h>
Expand Down
3 changes: 2 additions & 1 deletion src/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Copyright (c) 2009-2022 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#ifndef BITCOIN_HASH_H
#define BITCOIN_HASH_H

Expand Down
21 changes: 12 additions & 9 deletions src/kernel/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class CMainParams : public CChainParams {
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.nLastPOWBlock = 10;
consensus.nEnableHeaderSignatureHeight = 0;
consensus.nCheckpointSpan = COINBASE_MATURITY;
consensus.nCheckpointSpan = COINBASE_MATURITY();

consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = false;
Expand All @@ -133,7 +133,7 @@ class CMainParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_TAPROOT].min_activation_height = 0; // Dec 2023

// The best chain should have at least this much work. - getblockchaininfo
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000001c26335955d6a04722");
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000004f035d8e9ebf9aef4c");

// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
Expand All @@ -148,9 +148,9 @@ class CMainParams : public CChainParams {
pchMessageStart[2] = 0xb4;
pchMessageStart[3] = 0xd9;
nDefaultPort = 8555;
nPruneAfterHeight = 8000;
m_assumed_blockchain_size = 6;
m_assumed_chain_state_size = 5;
nPruneAfterHeight = 1000000;
m_assumed_blockchain_size = 30;
m_assumed_chain_state_size = 30;

uint32_t nTime=1701708401;
uint32_t nNonce=1108068075;
Expand Down Expand Up @@ -232,6 +232,9 @@ class CMainParams : public CChainParams {
{ 6060, uint256S("0xce046f1a67958b6d4acbc2a0ed6d194d7e4ed231232a6a146b7ff8d94a8b45c3")},
{ 10515, uint256S("0xdd8ff6535d448ecc560882d95ead78272c1a7a6da6b86150e762b33b5c6f8650")},
{ 14180, uint256S("0xef939cd95e947bd72357b754dd75503347b80fbb68a6435b0da7ecdea1da3ae2")},
{ 21111, uint256S("0x7067cd7104e32708f4094cf626c4afcdee8af1a76a5969daa95122b2c0346e5a")},
// BitcoinPoW to More PoW fork
//{ 23333 uint256S("0x????")},
}
};

Expand All @@ -241,9 +244,9 @@ class CMainParams : public CChainParams {

chainTxData = ChainTxData{
// Data from RPC: getchaintxstats
/* nTime */ 1710090556,
/* nTxCount */ 17492862,
/* dTxRate */ 0.3191135464352717,
/* nTime */ 1714362313,
/* nTxCount */ 18749063,
/* dTxRate */ 0.2879754883092357,
};
}
};
Expand Down Expand Up @@ -279,7 +282,7 @@ class CTestNetParams : public CChainParams {
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.nLastPOWBlock = 10;
consensus.nEnableHeaderSignatureHeight = 0;
consensus.nCheckpointSpan = COINBASE_MATURITY;
consensus.nCheckpointSpan = COINBASE_MATURITY();

consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = false;
Expand Down
53 changes: 20 additions & 33 deletions src/node/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Copyright (c) 2009-2022 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <node/miner.h>

#include <common/args.h>
Expand Down Expand Up @@ -290,7 +291,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc

if (pTotalFees)
*pTotalFees = nFees;
LogPrintf("CreateNewBlock(): block weight: %u txs: %u fees: %ld sigops %d\n", GetBlockWeight(*pblock), nBlockTx, nFees, nBlockSigOpsCost);
//LogPrintf("CreateNewBlock(): block weight: %u txs: %u fees: %ld sigops %d\n", GetBlockWeight(*pblock), nBlockTx, nFees, nBlockSigOpsCost);

// Fill in header
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
Expand Down Expand Up @@ -613,6 +614,8 @@ bool CheckStake(ChainstateManager& chainman, const std::shared_ptr<const CBlock>

void ThreadStakeMiner(wallet::CWallet& wallet, CConnman& connman, ChainstateManager& chainman, const CTxMemPool& mempool)
{
SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL);

s_mining_thread_exiting.store(false, std::memory_order_relaxed);
s_mining_allowed.store(true, std::memory_order_relaxed);

Expand Down Expand Up @@ -652,7 +655,7 @@ void ThreadStakeMiner(wallet::CWallet& wallet, CConnman& connman, ChainstateMana
s_cpu_loading = 0;
continue;
}
// Don't disable PoS mining for no connections if in regtest mode
// Don't disable mining for no connections if in regtest mode
if (!gArgs.GetBoolArg("-emergencymining", false)) {
while (connman.GetNodeCount(ConnectionDirection::Both) < 3 || chainman.IsInitialBlockDownload()) {
wallet.m_last_coin_stake_search_interval = 0;
Expand Down Expand Up @@ -680,11 +683,11 @@ void ThreadStakeMiner(wallet::CWallet& wallet, CConnman& connman, ChainstateMana

// Cannot mine with 0 connections.
if (connman.GetNodeCount(ConnectionDirection::Both) == 0 ) {
UninterruptibleSleep(std::chrono::milliseconds{1000});
wallet.m_last_coin_stake_search_interval = 0;
s_hashes_per_second = 0;
s_cpu_loading = 0;
continue;
UninterruptibleSleep(std::chrono::milliseconds{1000});
wallet.m_last_coin_stake_search_interval = 0;
s_hashes_per_second = 0;
s_cpu_loading = 0;
continue;
}

//
Expand Down Expand Up @@ -720,28 +723,12 @@ void ThreadStakeMiner(wallet::CWallet& wallet, CConnman& connman, ChainstateMana
stop_time = GetTime<std::chrono::milliseconds>().count();
while (true)
{
UninterruptibleSleep(std::chrono::milliseconds{10});
// Sliding window results in solving the same soluions many times for the sake of sending
// a mined block at a different time, this could result in a higher chance of the network
// accepting a mined block, however the time aligment in BTC is very good and this may
// just be overkill. Simplifying the mining by removing the sliding window and mining
// as many hashes as possible in each second internal.
//UninterruptibleSleep(std::chrono::milliseconds{1});
uint32_t newTime=GetAdjustedTime64();

// Hashes/sec is equal to the number of coins if the delta was less than 1 second..
// If more than 1 second, then the hashrate is still the the number of coins in the set,
// but the loading is over
int64_t delta = stop_time - start_time;
if ( delta <= 1000 )
{
s_hashes_per_second = setCoins.size() / 1.0;
s_cpu_loading = delta/10.0;
}
else
{
s_hashes_per_second = 100 * setCoins.size() / delta;
s_cpu_loading = 100.0;
}
s_hashes_per_second = 256 * s_coin_loop_prev_max_idx.load(std::memory_order_relaxed);; // 256 is extra PoW sha256()
s_cpu_loading = delta/10.0 > 100 ? 100.0 : delta/10.0; // This is loading % for a single core that is active.

if ( newTime > beginningTime )
{
Expand All @@ -753,12 +740,12 @@ void ThreadStakeMiner(wallet::CWallet& wallet, CConnman& connman, ChainstateMana

uint32_t i=beginningTime;

if ( profiler < 200 )
{
LogPrintf("ThreadStakeMiner(): BEGIN===================\n");
LogPrintf("ThreadStakeMiner(): nTime: %d SIZE: %d\n", i, setCoins.size());
profiler++;
}
// if ( profiler < 200 )
// {
// LogPrintf("ThreadStakeMiner(): BEGIN===================\n");
// LogPrintf("ThreadStakeMiner(): nTime: %d SIZE: %d\n", i, setCoins.size());
// profiler++;
// }

// The information is needed for status bar to determine if the staker is trying to create block and when it will be created approximately,
if (wallet.m_last_coin_stake_search_time == 0) wallet.m_last_coin_stake_search_time = GetAdjustedTime64(); // startup timestamp
Expand Down
Loading

0 comments on commit c368798

Please sign in to comment.