Rename extern/global variables to g_varName instead of varName to avoid shadowing
This commit is contained in:
@@ -12,7 +12,7 @@ extern "C" {
|
||||
|
||||
typedef struct Autolykos2Context Autolykos2Context;
|
||||
|
||||
extern uint64_t autolykos2_sleepBetweenHashOperationsMicroseconds;
|
||||
extern uint64_t g_autolykos2_sleepBetweenHashOperationsMicroseconds;
|
||||
|
||||
Autolykos2Context* Autolykos2_Create(void);
|
||||
void Autolykos2_Destroy(Autolykos2Context* ctx);
|
||||
|
||||
@@ -43,7 +43,7 @@ KHASH_INIT(balance_sheet_map_m, key32_t, balance_sheet_entry_t, 1, hash_key32, e
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
extern khash_t(balance_sheet_map_m)* sheetMap;
|
||||
extern khash_t(balance_sheet_map_m)* g_sheetMap;
|
||||
|
||||
void BalanceSheet_Init();
|
||||
int BalanceSheet_Insert(balance_sheet_entry_t entry);
|
||||
|
||||
@@ -37,7 +37,7 @@ typedef struct blockchain {
|
||||
* an epoch once the *following* entry has been computed, so it is valid on
|
||||
* [0, dagEpochsComputed - 1).
|
||||
*
|
||||
* Guarded by `dagCacheLock`, which is always taken AFTER `chainLock` and is never held across a
|
||||
* Guarded by `dagCacheLock`, which is always taken AFTER `g_chainLock` and is never held across a
|
||||
* call back into chain.c.
|
||||
**/
|
||||
dag_epoch_state_t* dagEpochs;
|
||||
@@ -106,7 +106,7 @@ uint64_t Chain_ReorgPenaltyForDepth(uint64_t reorgDepth);
|
||||
**/
|
||||
bool Chain_BlockRespectsSenderOrdering(const block_t* block);
|
||||
|
||||
// Recompute `currentSupply` and `currentReward` from the in-memory chain blocks.
|
||||
// Recompute `g_currentSupply` and `g_currentReward` from the in-memory chain blocks.
|
||||
// Returns true on success and updates runtime state globals.
|
||||
bool Chain_RecomputeRuntimeState(blockchain_t* chain);
|
||||
|
||||
@@ -120,15 +120,15 @@ bool Chain_LoadBlockFromFile(const char* dirpath, uint64_t blockNumber, bool loa
|
||||
|
||||
// Difficulty
|
||||
// Retarget for the block at `height`, measured over the window [height - INTERVAL, height - 1].
|
||||
// `chain` must hold blocks 0..height-1. Takes no locks; safe to call while holding `chainLock`.
|
||||
// `chain` must hold blocks 0..height-1. Takes no locks; safe to call while holding `g_chainLock`.
|
||||
uint32_t Chain_ComputeTargetAtHeight(blockchain_t* chain, uint64_t height, uint32_t currentTarget);
|
||||
|
||||
// The consensus-required difficultyTarget for the block at `height`, derived from the chain alone.
|
||||
// Takes no locks; safe to call while holding `chainLock`.
|
||||
// Takes no locks; safe to call while holding `g_chainLock`.
|
||||
uint32_t Chain_GetTargetForHeight(blockchain_t* chain, uint64_t height);
|
||||
|
||||
// Refresh runtime state derived from the chain tip (difficulty target, epoch DAG).
|
||||
// Call after any change to the tip. Must NOT be called while holding `chainLock`.
|
||||
// Call after any change to the tip. Must NOT be called while holding `g_chainLock`.
|
||||
void Chain_OnTipAdvanced(blockchain_t* chain);
|
||||
|
||||
// DAG
|
||||
@@ -145,7 +145,7 @@ void Chain_OnTipAdvanced(blockchain_t* chain);
|
||||
* true when validating or mining a block at that height. Returns false if it cannot produce both
|
||||
* values; callers MUST treat that as an invalid proof rather than falling back to a default.
|
||||
*
|
||||
* Takes `chainLock` for reading internally. Must NOT be called while holding it.
|
||||
* Takes `g_chainLock` for reading internally. Must NOT be called while holding it.
|
||||
**/
|
||||
bool Chain_DagParamsForHeight(blockchain_t* chain, uint64_t blockHeight,
|
||||
size_t* outDagBytes, uint8_t outSeed[32]);
|
||||
@@ -155,7 +155,7 @@ bool Chain_DagParamsForHeight(blockchain_t* chain, uint64_t blockHeight,
|
||||
bool Chain_ComputeBlockWork(uint32_t difficultyTargetBits, uint256_t* outWork);
|
||||
|
||||
// Summed work of the chain's blocks over the half-open range [from, to).
|
||||
// Takes no locks; safe to call while holding `chainLock`.
|
||||
// Takes no locks; safe to call while holding `g_chainLock`.
|
||||
bool Chain_ComputeWorkRange(blockchain_t* chain, size_t from, size_t to, uint256_t* outWork);
|
||||
|
||||
// Summed work of a candidate branch that is not (yet) part of the chain.
|
||||
|
||||
+7
-7
@@ -208,7 +208,7 @@ static const uint64_t TAIL_EMISSION = 750000000000ULL; // 0.75 coins per block f
|
||||
// Phase 3: update once per effective epoch and keep a fixed per-block reward for that epoch.
|
||||
//
|
||||
// The *AtHeight variants take the height directly and never call Chain_Size/Chain_GetBlockCopy, so
|
||||
// they are safe to call from inside a chainLock critical section. chainLock is a non-recursive
|
||||
// they are safe to call from inside a g_chainLock critical section. g_chainLock is a non-recursive
|
||||
// pthread_rwlock_t: taking it for reading while this thread already holds it for writing deadlocks
|
||||
// as soon as another thread is queued for the write lock.
|
||||
static inline uint64_t GetInflationRateRewardAtHeight(uint256_t currentSupply, uint64_t height) {
|
||||
@@ -218,8 +218,8 @@ static inline uint64_t GetInflationRateRewardAtHeight(uint256_t currentSupply, u
|
||||
: 1;
|
||||
|
||||
if (height == 0) {
|
||||
currentReward = TAIL_EMISSION;
|
||||
return currentReward;
|
||||
g_currentReward = TAIL_EMISSION;
|
||||
return g_currentReward;
|
||||
}
|
||||
|
||||
if (height % effectiveEpochLength == 0) {
|
||||
@@ -242,11 +242,11 @@ static inline uint64_t GetInflationRateRewardAtHeight(uint256_t currentSupply, u
|
||||
}
|
||||
|
||||
uint64_t inflationPerBlock = quotient.limbs[0];
|
||||
currentReward = (inflationPerBlock > TAIL_EMISSION) ? inflationPerBlock : TAIL_EMISSION;
|
||||
return currentReward;
|
||||
g_currentReward = (inflationPerBlock > TAIL_EMISSION) ? inflationPerBlock : TAIL_EMISSION;
|
||||
return g_currentReward;
|
||||
}
|
||||
|
||||
return (currentReward > TAIL_EMISSION) ? currentReward : TAIL_EMISSION;
|
||||
return (g_currentReward > TAIL_EMISSION) ? g_currentReward : TAIL_EMISSION;
|
||||
}
|
||||
|
||||
static inline uint64_t GetInflationRateReward(uint256_t currentSupply, blockchain_t* chain) {
|
||||
@@ -313,7 +313,7 @@ static inline uint64_t CalculateBlockReward(uint256_t currentSupply, blockchain_
|
||||
|
||||
// Hashing DAG: see Chain_DagParamsForHeight in block/chain.h. Both the size and the epoch seed are
|
||||
// derived from the chain by that one function, so the mining and verification paths cannot drift
|
||||
// apart. The previous CalculateTargetDAGSize/GetNextDAGSeed pair lived here, took chainLock
|
||||
// apart. The previous CalculateTargetDAGSize/GetNextDAGSeed pair lived here, took g_chainLock
|
||||
// internally, was not epoch-aligned, and disagreed with the verifier's own copy in main.c.
|
||||
|
||||
#endif
|
||||
|
||||
+12
-12
@@ -8,22 +8,22 @@
|
||||
#include <block/chain.h>
|
||||
#include <pthread.h>
|
||||
|
||||
extern uint64_t currentBlockHeight;
|
||||
extern blockchain_t* currentChain;
|
||||
extern uint256_t currentSupply;
|
||||
extern uint64_t currentReward;
|
||||
extern uint32_t difficultyTarget;
|
||||
extern const char* chainDataDir;
|
||||
extern unsigned short listenPort;
|
||||
extern bool echoPeersEnabled;
|
||||
extern bool forceOrphanReorgEnabled;
|
||||
extern uint64_t g_currentBlockHeight;
|
||||
extern blockchain_t* g_currentChain;
|
||||
extern uint256_t g_currentSupply;
|
||||
extern uint64_t g_currentReward;
|
||||
extern uint32_t g_difficultyTarget;
|
||||
extern const char* g_chainDataDir;
|
||||
extern unsigned short g_listenPort;
|
||||
extern bool g_echoPeersEnabled;
|
||||
extern bool g_forceOrphanReorgEnabled;
|
||||
// Random per-run identity of this node, advertised in HELLO/ACK_HELLO. A host can be reachable
|
||||
// under many addresses (especially over IPv6), so an (ip, port) endpoint is not a peer identity:
|
||||
// this nonce is what lets us recognise our own connections and a peer we already talk to.
|
||||
extern uint64_t localNodeId;
|
||||
extern uint64_t g_localNodeId;
|
||||
|
||||
// Global synchronization primitives for runtime state
|
||||
extern pthread_rwlock_t chainLock; // protects chain structure and related mutations
|
||||
extern pthread_mutex_t balanceSheetLock; // protects balance sheet map
|
||||
extern pthread_rwlock_t g_chainLock; // protects chain structure and related mutations
|
||||
extern pthread_mutex_t g_balanceSheetLock; // protects balance sheet map
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ KHASH_INIT(tx_mempool_map_m, key32_t, signed_transaction_t, 1, hash_key32, eq_ke
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
extern khash_t(tx_mempool_map_m)* txMempool;
|
||||
extern khash_t(tx_mempool_map_m)* g_txMempool;
|
||||
|
||||
void TxMempool_Init();
|
||||
// Assumed that the transation was confirmed to be valid
|
||||
|
||||
Reference in New Issue
Block a user