@@ -252,7 +252,7 @@ LedgerManagerImpl::startNewLedger(LedgerHeader const& genesisLedger)
252
252
CLOG_INFO (Ledger, " Root account seed: {}" , skey.getStrKeySeed ().value );
253
253
auto output =
254
254
ledgerClosed (ltx, /* ledgerCloseMeta*/ nullptr , /* initialLedgerVers*/ 0 );
255
- updateCurrentLedgerState (output);
255
+ advanceLedgerPointers (output);
256
256
257
257
ltx.commit ();
258
258
}
@@ -385,8 +385,8 @@ LedgerManagerImpl::loadLastKnownLedger(bool restoreBucketlist)
385
385
}
386
386
387
387
// Step 4. Restore LedgerManager's internal state
388
- auto output = advanceLedgerPointers (*latestLedgerHeader, has);
389
- updateCurrentLedgerState (output);
388
+ auto output = advanceLedgerStateSnapshot (*latestLedgerHeader, has);
389
+ advanceLedgerPointers (output);
390
390
391
391
// Maybe truncate checkpoint files if we're restarting after a crash
392
392
// in closeLedger (in which case any modifications to the ledger state have
@@ -766,7 +766,10 @@ LedgerManagerImpl::ledgerCloseComplete(uint32_t lcl, bool calledViaExternalize,
766
766
releaseAssert (latestQueuedToApply <= latestHeardFromNetwork);
767
767
}
768
768
769
- if (lcl == latestQueuedToApply)
769
+ // Without parallel ledger close, this should always be true
770
+ bool doneApplying = lcl == latestQueuedToApply;
771
+ releaseAssert (doneApplying || mApp .getConfig ().parallelLedgerClose ());
772
+ if (doneApplying)
770
773
{
771
774
mCurrentlyApplyingLedger = false ;
772
775
}
@@ -816,8 +819,17 @@ LedgerManagerImpl::closeLedger(LedgerCloseData const& ledgerData,
816
819
817
820
LedgerTxn ltx (mApp .getLedgerTxnRoot ());
818
821
auto header = ltx.loadHeader ();
819
- auto prevHeader =
820
- threadIsMain () ? getLastClosedLedgerHeader ().header : header.current ();
822
+ // Note: closeLedger should be able to work correctly based on ledger header
823
+ // stored in LedgerTxn. The issue is that in tests LedgerTxn is sometimes
824
+ // modified manually, which changes ledger header hash compared to the
825
+ // cached one and causes tests to fail.
826
+ LedgerHeader prevHeader = header.current ();
827
+ #ifdef BUILD_TESTS
828
+ if (threadIsMain ())
829
+ {
830
+ prevHeader = getLastClosedLedgerHeader ().header ;
831
+ }
832
+ #endif
821
833
auto prevHash = xdrSha256 (prevHeader);
822
834
823
835
auto initialLedgerVers = header.current ().ledgerVersion ;
@@ -830,7 +842,8 @@ LedgerManagerImpl::closeLedger(LedgerCloseData const& ledgerData,
830
842
831
843
auto now = mApp .getClock ().now ();
832
844
mLedgerAgeClosed .Update (now - mLastClose );
833
- // mLastClose is only accessed by a single thread
845
+ // mLastClose is only accessed by a single thread, so no synchronization
846
+ // needed
834
847
mLastClose = now;
835
848
mLedgerAge .set_count (0 );
836
849
@@ -1016,7 +1029,7 @@ LedgerManagerImpl::closeLedger(LedgerCloseData const& ledgerData,
1016
1029
emitNextMeta ();
1017
1030
}
1018
1031
1019
- // The next 5 steps happen in a relatively non-obvious, subtle order.
1032
+ // The next 7 steps happen in a relatively non-obvious, subtle order.
1020
1033
// This is unfortunate and it would be nice if we could make it not
1021
1034
// be so subtle, but for the time being this is where we are.
1022
1035
//
@@ -1075,7 +1088,7 @@ LedgerManagerImpl::closeLedger(LedgerCloseData const& ledgerData,
1075
1088
[this , txs, ledgerSeq, calledViaExternalize, ledgerData,
1076
1089
ledgerOutput = std::move (closeLedgerResult)]() mutable {
1077
1090
releaseAssert (threadIsMain ());
1078
- updateCurrentLedgerState (ledgerOutput);
1091
+ advanceLedgerPointers (ledgerOutput);
1079
1092
1080
1093
// Step 5. Maybe kick off publishing on complete checkpoint files
1081
1094
auto & hm = mApp .getHistoryManager ();
@@ -1144,7 +1157,7 @@ LedgerManagerImpl::setLastClosedLedger(
1144
1157
ltx.commit ();
1145
1158
1146
1159
mRebuildInMemoryState = false ;
1147
- updateCurrentLedgerState ( advanceLedgerPointers (lastClosed.header , has));
1160
+ advanceLedgerPointers ( advanceLedgerStateSnapshot (lastClosed.header , has));
1148
1161
1149
1162
LedgerTxn ltx2 (mApp .getLedgerTxnRoot ());
1150
1163
if (protocolVersionStartsFrom (ltx2.loadHeader ().current ().ledgerVersion ,
@@ -1167,8 +1180,8 @@ LedgerManagerImpl::manuallyAdvanceLedgerHeader(LedgerHeader const& header)
1167
1180
has.fromString (mApp .getPersistentState ().getState (
1168
1181
PersistentState::kHistoryArchiveState ,
1169
1182
mApp .getDatabase ().getSession ()));
1170
- auto output = advanceLedgerPointers (header, has, false );
1171
- updateCurrentLedgerState (output);
1183
+ auto output = advanceLedgerStateSnapshot (header, has);
1184
+ advanceLedgerPointers (output);
1172
1185
}
1173
1186
1174
1187
void
@@ -1315,7 +1328,7 @@ LedgerManagerImpl::getCurrentLedgerStateSnaphot()
1315
1328
}
1316
1329
1317
1330
void
1318
- LedgerManagerImpl::updateCurrentLedgerState (CloseLedgerOutput const & output)
1331
+ LedgerManagerImpl::advanceLedgerPointers (CloseLedgerOutput const & output)
1319
1332
{
1320
1333
releaseAssert (threadIsMain ());
1321
1334
CLOG_DEBUG (
@@ -1330,9 +1343,8 @@ LedgerManagerImpl::updateCurrentLedgerState(CloseLedgerOutput const& output)
1330
1343
}
1331
1344
1332
1345
LedgerManagerImpl::CloseLedgerOutput
1333
- LedgerManagerImpl::advanceLedgerPointers (LedgerHeader const & header,
1334
- HistoryArchiveState const & has,
1335
- bool debugLog)
1346
+ LedgerManagerImpl::advanceLedgerStateSnapshot (LedgerHeader const & header,
1347
+ HistoryArchiveState const & has)
1336
1348
{
1337
1349
auto ledgerHash = xdrSha256 (header);
1338
1350
@@ -1839,7 +1851,7 @@ LedgerManagerImpl::ledgerClosed(
1839
1851
mApp .getBucketManager ().snapshotLedger (lh);
1840
1852
auto has = storeCurrentLedger (lh, /* storeHeader */ true ,
1841
1853
/* appendToCheckpoint */ true );
1842
- res = advanceLedgerPointers (lh, has);
1854
+ res = advanceLedgerStateSnapshot (lh, has);
1843
1855
});
1844
1856
1845
1857
return res;
0 commit comments