upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/main.h
diff options
context:
space:
mode:
authorbitflash-maintainer <noreply@bitflash.invalid>2026-09-05 22:46:52 +0000
committerbitflash-maintainer <noreply@bitflash.invalid>2026-09-05 22:46:52 +0000
commitceae3d076b5ad11ee84729ae43f14e9312896646 (patch)
tree7e9132aa871fdc01cb95268d2f5ea3bb11853ddf /src/main.h
parentbe63e83d79e7e00e6b8ca889a70e6a19886aa1d8 (diff)
parent66e0b9158d050c46b1ff2509faeee3f4573cac1c (diff)
Bring main onto the line this project actually ships
main had drifted to a history with no ancestor in common with the tree we build and deploy. It sat at be63e83 (2026-08-09) with 28 commits; the shipped line, deploy/soak-2026-08-21, had 383. The two shared nothing -- git merge-base returns no result at all -- so anyone cloning this repository landed on a default branch that was neither current nor related to the running node. The 28 commits on main were audited before this merge: every one is already present in the tree by content, including the two that are hardest to see because they were rewritten afterwards -- the payout reorg-safety work (PayoutBlockStillOnChain, since evolved to re-check on every retry rather than once at maturity) and the nostr relay certificate verification (SSL_set1_host, now with a Windows root-store path). Nothing on main is lost by this merge. Recorded as a merge rather than a force-push: main only ever moves forward, its old history stays reachable as the first parent, and this is revertible. The tree is taken wholesale from the merged branch, so main's content is now exactly what was built and tested. What this brings onto main: - compactblock: BIP152-style compact block relay ported from upstream 1.2.23, primitives and unit test only, with the RAND_bytes failure path closed and the reconstruction allocation bounded. - upstream/main 17741d9: isolated testnet parameters and genesis, optional 2 MB large pages for RandomX. Mainnet genesis verified byte-identical through upstream's BuildGenesisBlock() refactor. - deploy: every image built on bookworm so binaries run on Debian 12, and the container build now honours the RandomX and libsecp256k1 pins it had been silently ignoring since before 1.2.15. Gates at this tree: 15/15 selftests, compactblock's 17 checks, consensus constants unchanged against e4f898c apart from the pre-existing MAX_BLOCK_SIZE_GEN, mainnet genesis intact, money-log check ok.
Diffstat (limited to 'src/main.h')
-rw-r--r--src/main.h91
1 files changed, 86 insertions, 5 deletions
diff --git a/src/main.h b/src/main.h
index 27f89ac..26b3b69 100644
--- a/src/main.h
+++ b/src/main.h
@@ -33,6 +33,35 @@ static const unsigned int MAX_BLOCK_SIGOPS = 20000;
33// limit (32 MB), not a block rule. Bitcoin 0.1.0 predated the later 1 MB block 33// limit (32 MB), not a block rule. Bitcoin 0.1.0 predated the later 1 MB block
34// cap, so this tree inherited no real block-size consensus limit. 34// cap, so this tree inherited no real block-size consensus limit.
35static const unsigned int MAX_BLOCK_SIZE = 1000000; 35static const unsigned int MAX_BLOCK_SIZE = 1000000;
36// How much of that cap a template we build may fill. Half, which is what both
37// assemblers already aimed at -- this only gives the number a name and one
38// place to live. They had already drifted on how it was enforced, which is the
39// bug this exists to stop repeating.
40//
41// NOT a consensus rule. CheckBlock() decides what the network accepts; this
42// decides what we are willing to produce, and it has to stay under that.
43static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE / 2;
44
45// Room for one more transaction in a template that currently weighs
46// nBlockSize bytes and spends nBlockSigOps signature operations?
47//
48// Asked BEFORE the transaction is appended, never after. A template that has
49// already overshot is one CheckBlock() rejects, and asking afterwards only
50// measures the waste. Both assemblers call this, so neither can drift into a
51// different idea of what fits.
52//
53// Size gets a margin (half the cap); sigops do not. There is no cheap way to
54// spend the sigop budget usefully and no reason to reserve headroom in it, so
55// assembly holds itself to the same number CheckBlock() enforces -- and to the
56// same comparison. CheckBlock() fails on `> MAX_BLOCK_SIGOPS`, so a block
57// sitting exactly on the limit is valid and this has to accept it too.
58// Assembly and validation disagreeing by one is how the size bug started.
59inline bool BlockTemplateFits(unsigned int nBlockSize, unsigned int nBlockSigOps,
60 unsigned int nTxSize, unsigned int nTxSigOps)
61{
62 return (nBlockSize + nTxSize <= MAX_BLOCK_SIZE_GEN &&
63 nBlockSigOps + nTxSigOps <= MAX_BLOCK_SIGOPS);
64}
36static const int64 COIN = 100000000; 65static const int64 COIN = 100000000;
37// Total Bitflash emission: identical to Bitcoin (21 million). 66// Total Bitflash emission: identical to Bitcoin (21 million).
38// MAX_MONEY guards against the value overflow bug (CVE-2010-5139), which in 67// MAX_MONEY guards against the value overflow bug (CVE-2010-5139), which in
@@ -65,6 +94,8 @@ extern map<uint256, CBlockIndex*> mapBlockIndex;
65extern uint256 hashGenesisBlock; 94extern uint256 hashGenesisBlock;
66extern uint256 hashGenesisMerkleRoot; 95extern uint256 hashGenesisMerkleRoot;
67extern unsigned int GENESIS_NONCE; 96extern unsigned int GENESIS_NONCE;
97void SelectGenesisParams(bool fTestNetIn);
98void SelectChainParams(bool fTestNetIn);
68extern CBlockIndex* pindexGenesisBlock; 99extern CBlockIndex* pindexGenesisBlock;
69extern int nBestHeight; 100extern int nBestHeight;
70extern uint256 hashBestChain; 101extern uint256 hashBestChain;
@@ -97,7 +128,11 @@ extern bool fPoolMineBlind; // /poolmineblind: mine on even when deaf to
97extern int nHashThreads; // participant: /hashthreads override (0 = cores-1) 128extern int nHashThreads; // participant: /hashthreads override (0 = cores-1)
98extern string strPoolName; // operator: announced pool name 129extern string strPoolName; // operator: announced pool name
99extern string strPoolDashboardUrl; // operator: optional dashboard URL 130extern string strPoolDashboardUrl; // operator: optional dashboard URL
131extern string strPoolStatusFile; // operator: optional JSON status output path
132extern string strPoolRoundsFile; // operator: optional public round proof path
100extern double dPoolFeePercent; // operator: announced fee percent 133extern double dPoolFeePercent; // operator: announced fee percent
134extern bool fStratumBridge; // participant helper: local Stratum bridge
135extern int nStratumBridgePort; // local bridge listen port, default 3333
101extern bool fSoloMineTest; // /solomine: mine without requiring a peer (local test) 136extern bool fSoloMineTest; // /solomine: mine without requiring a peer (local test)
102// Threads to hash with; 0 = decide from the hardware. Set by /genproclimit. 137// Threads to hash with; 0 = decide from the hardware. Set by /genproclimit.
103extern int nMinerThreads; 138extern int nMinerThreads;
@@ -226,9 +261,9 @@ static const unsigned int HD_BIP44_PURPOSE = 44;
226static const unsigned int HD_BIP44_ACCOUNT = 0; 261static const unsigned int HD_BIP44_ACCOUNT = 0;
227static const unsigned int HD_BIP44_CHAIN_RECEIVE = 0; 262static const unsigned int HD_BIP44_CHAIN_RECEIVE = 0;
228static const unsigned int HD_BIP44_CHAIN_CHANGE = 1; 263static const unsigned int HD_BIP44_CHAIN_CHANGE = 1;
229// Provisional until Bitflash has an official SLIP-0044 assignment. 264// Official SLIP-0044 assignment (registered 2026-08-07):
230// Proposed registry row: 4346950 | BITFLASH | Bitflash. 265// 4346950 | BITFLASH | Bitflash (4346950 == 0x425446 == "BTF")
231static const unsigned int HD_BIP44_COIN_TYPE_BITFLASH_PROVISIONAL = 4346950; 266static const unsigned int HD_BIP44_COIN_TYPE_BITFLASH = 4346950;
232extern int nHDKeySchema; 267extern int nHDKeySchema;
233extern unsigned int nHDReceiveNext; // BIP44 external chain 268extern unsigned int nHDReceiveNext; // BIP44 external chain
234extern unsigned int nHDChangeNext; // BIP44 internal chain 269extern unsigned int nHDChangeNext; // BIP44 internal chain
@@ -285,6 +320,7 @@ void LimitOrphanBlocks(unsigned int nMaxOrphans);
285// distinguishable, which the dedup filter would otherwise collapse into one. 320// distinguishable, which the dedup filter would otherwise collapse into one.
286bool BitcoinMiner(int nThreadId = 1); 321bool BitcoinMiner(int nThreadId = 1);
287void ThreadRPCServer(void* parg); // rpc.cpp -- .btf pool server 322void ThreadRPCServer(void* parg); // rpc.cpp -- .btf pool server
323void ThreadStratumBridge(void* parg); // main.cpp -- local Stratum -> .btf bridge
288void GetParticipantMiningStats(uint64& sharesSent, uint64& sharesAccepted, double& hashRate); 324void GetParticipantMiningStats(uint64& sharesSent, uint64& sharesAccepted, double& hashRate);
289void SetParticipantMiningStatus(const std::string& status); 325void SetParticipantMiningStatus(const std::string& status);
290std::string GetParticipantMiningStatus(); 326std::string GetParticipantMiningStatus();
@@ -301,6 +337,7 @@ int64 GetBalance();
301struct WalletRecoveryAudit 337struct WalletRecoveryAudit
302{ 338{
303 bool fHaveSeed; 339 bool fHaveSeed;
340 bool fSeedEncryptedLocked;
304 bool fDeriveComplete; 341 bool fDeriveComplete;
305 int nSchema; 342 int nSchema;
306 unsigned int nDerivedKnown; 343 unsigned int nDerivedKnown;
@@ -320,12 +357,13 @@ struct WalletRecoveryAudit
320 WalletRecoveryAudit() 357 WalletRecoveryAudit()
321 { 358 {
322 fHaveSeed = false; 359 fHaveSeed = false;
360 fSeedEncryptedLocked = false;
323 fDeriveComplete = true; 361 fDeriveComplete = true;
324 nSchema = HD_SCHEMA_NONE; 362 nSchema = HD_SCHEMA_NONE;
325 nDerivedKnown = 0; 363 nDerivedKnown = 0;
326 nReceiveNext = 0; 364 nReceiveNext = 0;
327 nChangeNext = 0; 365 nChangeNext = 0;
328 nCoinType = HD_BIP44_COIN_TYPE_BITFLASH_PROVISIONAL; 366 nCoinType = HD_BIP44_COIN_TYPE_BITFLASH;
329 nRecoverableTx = 0; 367 nRecoverableTx = 0;
330 nLegacyTx = 0; 368 nLegacyTx = 0;
331 nRecoverableImmatureTx = 0; 369 nRecoverableImmatureTx = 0;
@@ -337,9 +375,52 @@ struct WalletRecoveryAudit
337 } 375 }
338}; 376};
339WalletRecoveryAudit GetWalletRecoveryAudit(); 377WalletRecoveryAudit GetWalletRecoveryAudit();
340bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& txNew, int64& nFeeRequiredRet); 378
379// Why a send did not go through.
380//
381// The pool's payout thread has to decide, on every failed SendMoney, whether
382// the failure was the wallet's condition (wait for it to change) or a fault
383// (something is wrong with this payment). It used to guess by re-reading
384// GetBalance() afterwards and allowing a fixed CENT of headroom for the fee.
385// That cannot work: the fee here is a step function of the SERIALISED SIZE of
386// a transaction that no longer exists, and the step is from 0 to 11 * CENT at
387// 10,000 bytes -- so a one-CENT allowance is either unnecessary or an order of
388// magnitude short, never right. A pool wallet close to broke selects many
389// small inputs BECAUSE it is close to broke, which is what pushes the
390// transaction over 10 KB, so the guess is wrong exactly when the money is
391// tight.
392//
393// The wallet already knows the answer; it just did not say. SelectCoins()
394// failing is "there is not enough spendable coin to cover the amount plus
395// whatever fee this size of transaction requires", and it is the only reason
396// CreateTransaction() can fail that is about funding rather than about the
397// wallet being broken.
398enum WalletSendResult
399{
400 WALLET_SEND_OK = 0,
401 WALLET_SEND_INSUFFICIENT_FUNDS, // coin selection could not cover amount+fee
402 WALLET_SEND_FAILED // anything else: could not build, sign or accept
403};
404
405// What the wallet did with a send request. nFeeRequired is the fee the
406// transaction turned out to need, which for a failed send is what coin
407// selection was asked for on top of the amount and could not find -- 0 if it
408// never got that far.
409struct SendMoneyOutcome
410{
411 WalletSendResult result = WALLET_SEND_OK;
412 int64 nFeeRequired = 0;
413};
414
415bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& txNew, int64& nFeeRequiredRet,
416 WalletSendResult* presultRet=NULL);
341bool CommitTransactionSpent(const CWalletTx& wtxNew); 417bool CommitTransactionSpent(const CWalletTx& wtxNew);
418// The three-argument form is kept, and kept as a distinct declaration rather
419// than a defaulted argument, because gui.cpp declares SendMoney itself instead
420// of including this header.
342bool SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew); 421bool SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew);
422bool SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew,
423 SendMoneyOutcome& outcomeRet);
343 424
344 425
345 426