Skip to content

Commit 3a7e0a2

Browse files
committed
Merge bitcoin/bitcoin#24513: CChainState -> Chainstate
00eeb31 scripted-diff: rename CChainState -> Chainstate (James O'Beirne) Pull request description: Alright alright alright, I know: we hate refactors. We especially hate cosmetic refactors. Nobody knows better than I that changing broad swaths of code out from under our already-abused collaborators, only to send a cascade of rebase bankruptcies, is annoying at best and sadistic at worst. And for a rename! The indignation! But just for a second, imagine yourself. Programming `bitcoin/bitcoin`, on a sandy beach beneath a lapis lazuli sky. You go to type the name of what is probably the most commonly used data structure in the codebase, and you *only hit shift once*. What could you do in such a world? You could do anything. [The only limit is yourself.](https://zombo.com/) --- So maybe you like the idea of this patch but really don't want to deal with rebasing. You're in luck! Here're the commands that will bail you out of rebase bankruptcy: ```sh git rebase -i $(git merge-base HEAD master) \ -x 'sed -i "s/CChainState/Chainstate/g" $(git ls-files | grep -E ".*\.(py|cpp|h)$") && git commit --amend --no-edit' # <commit changed?> git add -u && git rebase --continue ``` --- ~~Anyway I'm not sure how serious I am about this, but I figured it was worth proposing.~~ I have decided I am very serious about this. Maybe we can have nice things every once in a while? ACKs for top commit: MarcoFalke: cr ACK 00eeb31 hebasto: ACK 00eeb31 glozow: ACK 00eeb31, thanks for being the one to propose this w0xlt: ACK bitcoin/bitcoin@00eeb31 Tree-SHA512: b828a99780614a9b74f7a9c347ce0687de6f8d75232840f5ffc26e02bbb25a3b1f5f9deabbe44f82ada01459586ee8452a3ee2da05d1b3c48558c8df6f49e1b1
2 parents 141540a + 00eeb31 commit 3a7e0a2

33 files changed

+154
-154
lines changed

doc/design/assumeutxo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ be of use.
4141

4242
Chainstate within the system goes through a number of phases when UTXO snapshots are
4343
used, as managed by `ChainstateManager`. At various points there can be multiple
44-
`CChainState` objects in existence to facilitate both maintaining the network tip and
44+
`Chainstate` objects in existence to facilitate both maintaining the network tip and
4545
performing historical validation of the assumed-valid chain.
4646

4747
It is worth noting that though there are multiple separate chainstates, those
@@ -53,7 +53,7 @@ data.
5353

5454
### "Normal" operation via initial block download
5555

56-
`ChainstateManager` manages a single CChainState object, for which
56+
`ChainstateManager` manages a single Chainstate object, for which
5757
`m_snapshot_blockhash` is null. This chainstate is (maybe obviously)
5858
considered active. This is the "traditional" mode of operation for bitcoind.
5959

doc/developer-notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ void CTxMemPool::UpdateTransactionsFromBlock(...)
962962

963963
```C++
964964
// validation.h
965-
class CChainState
965+
class Chainstate
966966
{
967967
protected:
968968
...
@@ -983,7 +983,7 @@ public:
983983
}
984984

985985
// validation.cpp
986-
bool CChainState::PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
986+
bool Chainstate::PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
987987
{
988988
AssertLockNotHeld(m_chainstate_mutex);
989989
AssertLockNotHeld(::cs_main);

src/bitcoin-chainstate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int main(int argc, char* argv[])
104104
}
105105
}
106106

107-
for (CChainState* chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) {
107+
for (Chainstate* chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) {
108108
BlockValidationState state;
109109
if (!chainstate->ActivateBestChain(state, nullptr)) {
110110
std::cerr << "Failed to connect best block (" << state.ToString() << ")" << std::endl;
@@ -253,7 +253,7 @@ int main(int argc, char* argv[])
253253
GetMainSignals().FlushBackgroundCallbacks();
254254
{
255255
LOCK(cs_main);
256-
for (CChainState* chainstate : chainman.GetAll()) {
256+
for (Chainstate* chainstate : chainman.GetAll()) {
257257
if (chainstate->CanFlushToDisk()) {
258258
chainstate->ForceFlushStateToDisk();
259259
chainstate->ResetCoinsViews();

src/index/base.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class CBlock;
1414
class CBlockIndex;
15-
class CChainState;
15+
class Chainstate;
1616
namespace interfaces {
1717
class Chain;
1818
} // namespace interfaces
@@ -94,7 +94,7 @@ class BaseIndex : public CValidationInterface
9494

9595
protected:
9696
std::unique_ptr<interfaces::Chain> m_chain;
97-
CChainState* m_chainstate{nullptr};
97+
Chainstate* m_chainstate{nullptr};
9898

9999
void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex) override;
100100

src/init.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void Shutdown(NodeContext& node)
263263
// FlushStateToDisk generates a ChainStateFlushed callback, which we should avoid missing
264264
if (node.chainman) {
265265
LOCK(cs_main);
266-
for (CChainState* chainstate : node.chainman->GetAll()) {
266+
for (Chainstate* chainstate : node.chainman->GetAll()) {
267267
if (chainstate->CanFlushToDisk()) {
268268
chainstate->ForceFlushStateToDisk();
269269
}
@@ -294,7 +294,7 @@ void Shutdown(NodeContext& node)
294294

295295
if (node.chainman) {
296296
LOCK(cs_main);
297-
for (CChainState* chainstate : node.chainman->GetAll()) {
297+
for (Chainstate* chainstate : node.chainman->GetAll()) {
298298
if (chainstate->CanFlushToDisk()) {
299299
chainstate->ForceFlushStateToDisk();
300300
chainstate->ResetCoinsViews();
@@ -1542,7 +1542,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15421542
if (fPruneMode) {
15431543
if (!fReindex) {
15441544
LOCK(cs_main);
1545-
for (CChainState* chainstate : chainman.GetAll()) {
1545+
for (Chainstate* chainstate : chainman.GetAll()) {
15461546
uiInterface.InitMessage(_("Pruning blockstore…").translated);
15471547
chainstate->PruneAndFlush();
15481548
}

src/kernel/mempool_persist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace kernel {
3737

3838
static const uint64_t MEMPOOL_DUMP_VERSION = 1;
3939

40-
bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, CChainState& active_chainstate, FopenFn mockable_fopen_function)
40+
bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active_chainstate, FopenFn mockable_fopen_function)
4141
{
4242
if (load_path.empty()) return false;
4343

src/kernel/mempool_persist.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <fs.h>
99

10-
class CChainState;
10+
class Chainstate;
1111
class CTxMemPool;
1212

1313
namespace kernel {
@@ -19,7 +19,7 @@ bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path,
1919

2020
/** Load the mempool from disk. */
2121
bool LoadMempool(CTxMemPool& pool, const fs::path& load_path,
22-
CChainState& active_chainstate,
22+
Chainstate& active_chainstate,
2323
fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
2424

2525
} // namespace kernel

src/node/blockstorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
882882
// We can't hold cs_main during ActivateBestChain even though we're accessing
883883
// the chainman unique_ptrs since ABC requires us not to be holding cs_main, so retrieve
884884
// the relevant pointers before the ABC call.
885-
for (CChainState* chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) {
885+
for (Chainstate* chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) {
886886
BlockValidationState state;
887887
if (!chainstate->ActivateBestChain(state, nullptr)) {
888888
LogPrintf("Failed to connect best block (%s)\n", state.ToString());

src/node/blockstorage.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CBlockFileInfo;
2626
class CBlockUndo;
2727
class CChain;
2828
class CChainParams;
29-
class CChainState;
29+
class Chainstate;
3030
class ChainstateManager;
3131
struct CCheckpointData;
3232
struct FlatFilePos;
@@ -75,12 +75,12 @@ struct PruneLockInfo {
7575
* Maintains a tree of blocks (stored in `m_block_index`) which is consulted
7676
* to determine where the most-work tip is.
7777
*
78-
* This data is used mostly in `CChainState` - information about, e.g.,
78+
* This data is used mostly in `Chainstate` - information about, e.g.,
7979
* candidate tips is not maintained here.
8080
*/
8181
class BlockManager
8282
{
83-
friend CChainState;
83+
friend Chainstate;
8484
friend ChainstateManager;
8585

8686
private:

src/node/chainstate.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace node {
2828
ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSizes& cache_sizes,
2929
const ChainstateLoadOptions& options)
3030
{
31-
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
31+
auto is_coinsview_empty = [&](Chainstate* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
3232
return options.reindex || options.reindex_chainstate || chainstate->CoinsTip().GetBestBlock().IsNull();
3333
};
3434

@@ -101,7 +101,7 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
101101
// At this point we're either in reindex or we've loaded a useful
102102
// block tree into BlockIndex()!
103103

104-
for (CChainState* chainstate : chainman.GetAll()) {
104+
for (Chainstate* chainstate : chainman.GetAll()) {
105105
chainstate->InitCoinsDB(
106106
/*cache_size_bytes=*/cache_sizes.coins_db,
107107
/*in_memory=*/options.coins_db_in_memory,
@@ -140,7 +140,7 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
140140
if (!options.reindex) {
141141
auto chainstates{chainman.GetAll()};
142142
if (std::any_of(chainstates.begin(), chainstates.end(),
143-
[](const CChainState* cs) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return cs->NeedsRedownload(); })) {
143+
[](const Chainstate* cs) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return cs->NeedsRedownload(); })) {
144144
return {ChainstateLoadStatus::FAILURE, strprintf(_("Witness data for blocks after height %d requires validation. Please restart with -reindex."),
145145
chainman.GetConsensus().SegwitHeight)};
146146
};
@@ -151,13 +151,13 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
151151

152152
ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager& chainman, const ChainstateLoadOptions& options)
153153
{
154-
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
154+
auto is_coinsview_empty = [&](Chainstate* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
155155
return options.reindex || options.reindex_chainstate || chainstate->CoinsTip().GetBestBlock().IsNull();
156156
};
157157

158158
LOCK(cs_main);
159159

160-
for (CChainState* chainstate : chainman.GetAll()) {
160+
for (Chainstate* chainstate : chainman.GetAll()) {
161161
if (!is_coinsview_empty(chainstate)) {
162162
const CBlockIndex* tip = chainstate->m_chain.Tip();
163163
if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) {

0 commit comments

Comments
 (0)