diff options
| author | bitflash-maintainer <noreply@bitflash.invalid> | 2026-09-06 01:53:03 +0000 |
|---|---|---|
| committer | bitflash-maintainer <noreply@bitflash.invalid> | 2026-09-06 01:53:03 +0000 |
| commit | ef9f06d43fc6577c15df2256abbb25b20d4227b8 (patch) | |
| tree | 7e9132aa871fdc01cb95268d2f5ea3bb11853ddf /src/main.h | |
| parent | be63e83d79e7e00e6b8ca889a70e6a19886aa1d8 (diff) | |
| parent | ceae3d076b5ad11ee84729ae43f14e9312896646 (diff) | |
Bring main onto the line this project actually ships (incl. the 1.2.23 compactblock port)
Closes #6, #7, #8, #11, #35, #34, #29, #28, #27, and #16
See merge request !16
Diffstat (limited to 'src/main.h')
| -rw-r--r-- | src/main.h | 91 |
1 files changed, 86 insertions, 5 deletions
| @@ -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. |
| 35 | static const unsigned int MAX_BLOCK_SIZE = 1000000; | 35 | static 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. | ||
| 43 | static 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. | ||
| 59 | inline 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 | } | ||
| 36 | static const int64 COIN = 100000000; | 65 | static 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; | |||
| 65 | extern uint256 hashGenesisBlock; | 94 | extern uint256 hashGenesisBlock; |
| 66 | extern uint256 hashGenesisMerkleRoot; | 95 | extern uint256 hashGenesisMerkleRoot; |
| 67 | extern unsigned int GENESIS_NONCE; | 96 | extern unsigned int GENESIS_NONCE; |
| 97 | void SelectGenesisParams(bool fTestNetIn); | ||
| 98 | void SelectChainParams(bool fTestNetIn); | ||
| 68 | extern CBlockIndex* pindexGenesisBlock; | 99 | extern CBlockIndex* pindexGenesisBlock; |
| 69 | extern int nBestHeight; | 100 | extern int nBestHeight; |
| 70 | extern uint256 hashBestChain; | 101 | extern uint256 hashBestChain; |
| @@ -97,7 +128,11 @@ extern bool fPoolMineBlind; // /poolmineblind: mine on even when deaf to | |||
| 97 | extern int nHashThreads; // participant: /hashthreads override (0 = cores-1) | 128 | extern int nHashThreads; // participant: /hashthreads override (0 = cores-1) |
| 98 | extern string strPoolName; // operator: announced pool name | 129 | extern string strPoolName; // operator: announced pool name |
| 99 | extern string strPoolDashboardUrl; // operator: optional dashboard URL | 130 | extern string strPoolDashboardUrl; // operator: optional dashboard URL |
| 131 | extern string strPoolStatusFile; // operator: optional JSON status output path | ||
| 132 | extern string strPoolRoundsFile; // operator: optional public round proof path | ||
| 100 | extern double dPoolFeePercent; // operator: announced fee percent | 133 | extern double dPoolFeePercent; // operator: announced fee percent |
| 134 | extern bool fStratumBridge; // participant helper: local Stratum bridge | ||
| 135 | extern int nStratumBridgePort; // local bridge listen port, default 3333 | ||
| 101 | extern bool fSoloMineTest; // /solomine: mine without requiring a peer (local test) | 136 | extern 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. |
| 103 | extern int nMinerThreads; | 138 | extern int nMinerThreads; |
| @@ -226,9 +261,9 @@ static const unsigned int HD_BIP44_PURPOSE = 44; | |||
| 226 | static const unsigned int HD_BIP44_ACCOUNT = 0; | 261 | static const unsigned int HD_BIP44_ACCOUNT = 0; |
| 227 | static const unsigned int HD_BIP44_CHAIN_RECEIVE = 0; | 262 | static const unsigned int HD_BIP44_CHAIN_RECEIVE = 0; |
| 228 | static const unsigned int HD_BIP44_CHAIN_CHANGE = 1; | 263 | static 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") |
| 231 | static const unsigned int HD_BIP44_COIN_TYPE_BITFLASH_PROVISIONAL = 4346950; | 266 | static const unsigned int HD_BIP44_COIN_TYPE_BITFLASH = 4346950; |
| 232 | extern int nHDKeySchema; | 267 | extern int nHDKeySchema; |
| 233 | extern unsigned int nHDReceiveNext; // BIP44 external chain | 268 | extern unsigned int nHDReceiveNext; // BIP44 external chain |
| 234 | extern unsigned int nHDChangeNext; // BIP44 internal chain | 269 | extern 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. |
| 286 | bool BitcoinMiner(int nThreadId = 1); | 321 | bool BitcoinMiner(int nThreadId = 1); |
| 287 | void ThreadRPCServer(void* parg); // rpc.cpp -- .btf pool server | 322 | void ThreadRPCServer(void* parg); // rpc.cpp -- .btf pool server |
| 323 | void ThreadStratumBridge(void* parg); // main.cpp -- local Stratum -> .btf bridge | ||
| 288 | void GetParticipantMiningStats(uint64& sharesSent, uint64& sharesAccepted, double& hashRate); | 324 | void GetParticipantMiningStats(uint64& sharesSent, uint64& sharesAccepted, double& hashRate); |
| 289 | void SetParticipantMiningStatus(const std::string& status); | 325 | void SetParticipantMiningStatus(const std::string& status); |
| 290 | std::string GetParticipantMiningStatus(); | 326 | std::string GetParticipantMiningStatus(); |
| @@ -301,6 +337,7 @@ int64 GetBalance(); | |||
| 301 | struct WalletRecoveryAudit | 337 | struct 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 | }; |
| 339 | WalletRecoveryAudit GetWalletRecoveryAudit(); | 377 | WalletRecoveryAudit GetWalletRecoveryAudit(); |
| 340 | bool 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. | ||
| 398 | enum 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. | ||
| 409 | struct SendMoneyOutcome | ||
| 410 | { | ||
| 411 | WalletSendResult result = WALLET_SEND_OK; | ||
| 412 | int64 nFeeRequired = 0; | ||
| 413 | }; | ||
| 414 | |||
| 415 | bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& txNew, int64& nFeeRequiredRet, | ||
| 416 | WalletSendResult* presultRet=NULL); | ||
| 341 | bool CommitTransactionSpent(const CWalletTx& wtxNew); | 417 | bool 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. | ||
| 342 | bool SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew); | 421 | bool SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew); |
| 422 | bool SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, | ||
| 423 | SendMoneyOutcome& outcomeRet); | ||
| 343 | 424 | ||
| 344 | 425 | ||
| 345 | 426 | ||