diff options
Diffstat (limited to 'src/main.h')
| -rw-r--r-- | src/main.h | 88 |
1 files changed, 87 insertions, 1 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 |
| @@ -41,6 +70,12 @@ static const int64 MAX_MONEY = 21000000 * COIN; | |||
| 41 | inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } | 70 | inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } |
| 42 | static const int64 CENT = 1000000; | 71 | static const int64 CENT = 1000000; |
| 43 | static const int COINBASE_MATURITY = 100; | 72 | static const int COINBASE_MATURITY = 100; |
| 73 | // Depth at which a coinbase we mined is actually usable. CMerkleTx::GetCredit | ||
| 74 | // values a coinbase at zero until GetBlocksToMaturity() reaches 0, which is | ||
| 75 | // this depth -- not COINBASE_MATURITY. Anything that plans to *spend* mined | ||
| 76 | // coin must gate on this, or it will try to pay out of a balance the wallet | ||
| 77 | // still reports as zero. Both rules live here so they cannot drift apart. | ||
| 78 | static const int COINBASE_SPENDABLE_DEPTH = COINBASE_MATURITY + 20; | ||
| 44 | 79 | ||
| 45 | // Bitflash difficulty floor. The PoW is RandomX (memory-hard), ~1000x slower | 80 | // Bitflash difficulty floor. The PoW is RandomX (memory-hard), ~1000x slower |
| 46 | // per hash than SHA-256d, so the target is much easier than Bitcoin's to let a | 81 | // per hash than SHA-256d, so the target is much easier than Bitcoin's to let a |
| @@ -86,6 +121,11 @@ extern int nMineMode; | |||
| 86 | // something a previous session wrote. | 121 | // something a previous session wrote. |
| 87 | extern bool fMineModeFromCommandLine; | 122 | extern bool fMineModeFromCommandLine; |
| 88 | extern string strParticipantPool; // participant: pool .btf address | 123 | extern string strParticipantPool; // participant: pool .btf address |
| 124 | extern string strPayoutAddress; // participant: /payoutaddr override (mine without a wallet) | ||
| 125 | extern string strPayoutFile; // participant: /payoutfile address list, rotated per reconnect | ||
| 126 | extern bool fPoolNoAnnounce; // /noannounce: suppress pool announcements | ||
| 127 | extern bool fPoolMineBlind; // /poolmineblind: mine on even when deaf to every peer | ||
| 128 | extern int nHashThreads; // participant: /hashthreads override (0 = cores-1) | ||
| 89 | extern string strPoolName; // operator: announced pool name | 129 | extern string strPoolName; // operator: announced pool name |
| 90 | extern string strPoolDashboardUrl; // operator: optional dashboard URL | 130 | extern string strPoolDashboardUrl; // operator: optional dashboard URL |
| 91 | extern string strPoolStatusFile; // operator: optional JSON status output path | 131 | extern string strPoolStatusFile; // operator: optional JSON status output path |
| @@ -98,6 +138,9 @@ extern bool fSoloMineTest; // /solomine: mine without requiring a peer (local te | |||
| 98 | extern int nMinerThreads; | 138 | extern int nMinerThreads; |
| 99 | // Resolves the automatic case into a real count. | 139 | // Resolves the automatic case into a real count. |
| 100 | int MinerThreadCount(); | 140 | int MinerThreadCount(); |
| 141 | // Hash threads one participant session runs; resolves /hashthreads. Not the | ||
| 142 | // same number as MinerThreadCount(), and only ONE session ever runs. | ||
| 143 | int ParticipantHashThreadCount(); | ||
| 101 | extern bool gPoolServerRunning; // GUI/startup state | 144 | extern bool gPoolServerRunning; // GUI/startup state |
| 102 | extern volatile bool gPoolRunning; // runtime pool server loop flag (rpc.cpp) | 145 | extern volatile bool gPoolRunning; // runtime pool server loop flag (rpc.cpp) |
| 103 | 146 | ||
| @@ -332,9 +375,52 @@ struct WalletRecoveryAudit | |||
| 332 | } | 375 | } |
| 333 | }; | 376 | }; |
| 334 | WalletRecoveryAudit GetWalletRecoveryAudit(); | 377 | WalletRecoveryAudit GetWalletRecoveryAudit(); |
| 335 | 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); | ||
| 336 | 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. | ||
| 337 | 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); | ||
| 338 | 424 | ||
| 339 | 425 | ||
| 340 | 426 | ||