forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLedgerManagerImpl.h
144 lines (111 loc) · 4.47 KB
/
LedgerManagerImpl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma once
// Copyright 2014 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#include "util/asio.h"
#include "history/HistoryManager.h"
#include "ledger/LedgerManager.h"
#include "ledger/SyncingLedgerChain.h"
#include "main/PersistentState.h"
#include "transactions/TransactionFrame.h"
#include "xdr/Stellar-ledger.h"
#include <string>
/*
Holds the current ledger
Applies the tx set to the last ledger to get the next one
Hands the old ledger off to the history
*/
namespace medida
{
class Timer;
class Counter;
class Histogram;
}
namespace stellar
{
class AbstractLedgerTxn;
class Application;
class Database;
class LedgerTxnHeader;
class LedgerManagerImpl : public LedgerManager
{
LedgerHeaderHistoryEntry mLastClosedLedger;
protected:
Application& mApp;
private:
medida::Timer& mTransactionApply;
medida::Histogram& mTransactionCount;
medida::Histogram& mOperationCount;
medida::Counter& mInternalErrorCount;
medida::Timer& mLedgerClose;
medida::Timer& mLedgerAgeClosed;
medida::Counter& mLedgerAge;
medida::Counter& mPrefetchHitRate;
VirtualClock::time_point mLastClose;
medida::Counter& mSyncingLedgersSize;
uint32_t mCatchupTriggerLedger{0};
CatchupState mCatchupState{CatchupState::NONE};
void addToSyncingLedgers(LedgerCloseData const& ledgerData);
void startCatchupIf(uint32_t lastReceivedLedgerSeq);
void historyCaughtup(asio::error_code const& ec,
CatchupWork::ProgressState progressState,
LedgerHeaderHistoryEntry const& lastClosed,
CatchupConfiguration::Mode catchupMode);
void processFeesSeqNums(std::vector<TransactionFramePtr>& txs,
AbstractLedgerTxn& ltxOuter, int64_t baseFee);
void applyTransactions(std::vector<TransactionFramePtr>& txs,
AbstractLedgerTxn& ltx,
TransactionResultSet& txResultSet);
void ledgerClosed(AbstractLedgerTxn& ltx);
void storeCurrentLedger(LedgerHeader const& header);
void prefetchTransactionData(std::vector<TransactionFramePtr>& txs);
void prefetchTxSourceIds(std::vector<TransactionFramePtr>& txs);
enum class CloseLedgerIfResult
{
CLOSED,
TOO_OLD,
TOO_NEW
};
CloseLedgerIfResult closeLedgerIf(LedgerCloseData const& ledgerData);
State mState;
void setState(State s);
protected:
virtual void transferLedgerEntriesToBucketList(AbstractLedgerTxn& ltx,
uint32_t ledgerSeq,
uint32_t ledgerVers);
SyncingLedgerChain mSyncingLedgers;
void applyBufferedLedgers();
void setCatchupState(CatchupState s);
void advanceLedgerPointers(LedgerHeader const& header);
void initializeCatchup(LedgerCloseData const& ledgerData);
void continueCatchup(LedgerCloseData const& ledgerData);
void finalizeCatchup(LedgerCloseData const& ledgerData);
void logTxApplyMetrics(AbstractLedgerTxn& ltx, size_t numTxs,
size_t numOps);
public:
LedgerManagerImpl(Application& app);
void bootstrap() override;
State getState() const override;
CatchupState getCatchupState() const override;
std::string getStateHuman() const override;
void valueExternalized(LedgerCloseData const& ledgerData) override;
uint32_t getLastMaxTxSetSize() const override;
int64_t getLastMinBalance(uint32_t ownerCount) const override;
uint32_t getLastReserve() const override;
uint32_t getLastTxFee() const override;
uint32_t getLastClosedLedgerNum() const override;
uint64_t secondsSinceLastLedgerClose() const override;
void syncMetrics() override;
void startNewLedger(LedgerHeader genesisLedger);
void startNewLedger() override;
void loadLastKnownLedger(
std::function<void(asio::error_code const& ec)> handler) override;
LedgerHeaderHistoryEntry const& getLastClosedLedgerHeader() const override;
HistoryArchiveState getLastClosedLedgerHAS() override;
Database& getDatabase() override;
void startCatchup(CatchupConfiguration configuration) override;
void closeLedger(LedgerCloseData const& ledgerData) override;
void deleteOldEntries(Database& db, uint32_t ledgerSeq,
uint32_t count) override;
};
}