@@ -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,20 @@ LedgerManagerImpl::closeLedger(LedgerCloseData const& ledgerData,
816
819
817
820
LedgerTxn ltx (mApp .getLedgerTxnRoot ());
818
821
auto header = ltx.loadHeader ();
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 somtimes
824
+ // modified manually, which changes ledger header hash compared to the
825
+ // cached one and causes tests to fail.
819
826
auto prevHeader =
820
- threadIsMain () ? getLastClosedLedgerHeader ().header : header.current ();
827
+ #ifdef BUILD_TESTS
828
+ if (app.getConfig ().MODE_USES_IN_MEMORY_LEDGER )
829
+ {
830
+ releaseAssert (threadIsMain ());
831
+ getLastClosedLedgerHeader ().header ;
832
+ }
833
+ else
834
+ #endif
835
+ header.current ();
821
836
auto prevHash = xdrSha256 (prevHeader);
822
837
823
838
auto initialLedgerVers = header.current ().ledgerVersion ;
@@ -830,7 +845,8 @@ LedgerManagerImpl::closeLedger(LedgerCloseData const& ledgerData,
830
845
831
846
auto now = mApp .getClock ().now ();
832
847
mLedgerAgeClosed .Update (now - mLastClose );
833
- // mLastClose is only accessed by a single thread
848
+ // mLastClose is only accessed by a single thread, so no synchronization
849
+ // needed
834
850
mLastClose = now;
835
851
mLedgerAge .set_count (0 );
836
852
@@ -1016,7 +1032,7 @@ LedgerManagerImpl::closeLedger(LedgerCloseData const& ledgerData,
1016
1032
emitNextMeta ();
1017
1033
}
1018
1034
1019
- // The next 5 steps happen in a relatively non-obvious, subtle order.
1035
+ // The next 7 steps happen in a relatively non-obvious, subtle order.
1020
1036
// This is unfortunate and it would be nice if we could make it not
1021
1037
// be so subtle, but for the time being this is where we are.
1022
1038
//
@@ -1075,7 +1091,7 @@ LedgerManagerImpl::closeLedger(LedgerCloseData const& ledgerData,
1075
1091
[this , txs, ledgerSeq, calledViaExternalize, ledgerData,
1076
1092
ledgerOutput = std::move (closeLedgerResult)]() mutable {
1077
1093
releaseAssert (threadIsMain ());
1078
- updateCurrentLedgerState (ledgerOutput);
1094
+ advanceLedgerPointers (ledgerOutput);
1079
1095
1080
1096
// Step 5. Maybe kick off publishing on complete checkpoint files
1081
1097
auto & hm = mApp .getHistoryManager ();
@@ -1144,7 +1160,7 @@ LedgerManagerImpl::setLastClosedLedger(
1144
1160
ltx.commit ();
1145
1161
1146
1162
mRebuildInMemoryState = false ;
1147
- updateCurrentLedgerState ( advanceLedgerPointers (lastClosed.header , has));
1163
+ advanceLedgerPointers ( advanceLedgerStateSnapshot (lastClosed.header , has));
1148
1164
1149
1165
LedgerTxn ltx2 (mApp .getLedgerTxnRoot ());
1150
1166
if (protocolVersionStartsFrom (ltx2.loadHeader ().current ().ledgerVersion ,
@@ -1167,8 +1183,8 @@ LedgerManagerImpl::manuallyAdvanceLedgerHeader(LedgerHeader const& header)
1167
1183
has.fromString (mApp .getPersistentState ().getState (
1168
1184
PersistentState::kHistoryArchiveState ,
1169
1185
mApp .getDatabase ().getSession ()));
1170
- auto output = advanceLedgerPointers (header, has, false );
1171
- updateCurrentLedgerState (output);
1186
+ auto output = advanceLedgerStateSnapshot (header, has);
1187
+ advanceLedgerPointers (output);
1172
1188
}
1173
1189
1174
1190
void
@@ -1315,7 +1331,7 @@ LedgerManagerImpl::getCurrentLedgerStateSnaphot()
1315
1331
}
1316
1332
1317
1333
void
1318
- LedgerManagerImpl::updateCurrentLedgerState (CloseLedgerOutput const & output)
1334
+ LedgerManagerImpl::advanceLedgerPointers (CloseLedgerOutput const & output)
1319
1335
{
1320
1336
releaseAssert (threadIsMain ());
1321
1337
CLOG_DEBUG (
@@ -1330,9 +1346,8 @@ LedgerManagerImpl::updateCurrentLedgerState(CloseLedgerOutput const& output)
1330
1346
}
1331
1347
1332
1348
LedgerManagerImpl::CloseLedgerOutput
1333
- LedgerManagerImpl::advanceLedgerPointers (LedgerHeader const & header,
1334
- HistoryArchiveState const & has,
1335
- bool debugLog)
1349
+ LedgerManagerImpl::advanceLedgerStateSnapshot (LedgerHeader const & header,
1350
+ HistoryArchiveState const & has)
1336
1351
{
1337
1352
auto ledgerHash = xdrSha256 (header);
1338
1353
@@ -1839,7 +1854,7 @@ LedgerManagerImpl::ledgerClosed(
1839
1854
mApp .getBucketManager ().snapshotLedger (lh);
1840
1855
auto has = storeCurrentLedger (lh, /* storeHeader */ true ,
1841
1856
/* appendToCheckpoint */ true );
1842
- res = advanceLedgerPointers (lh, has);
1857
+ res = advanceLedgerStateSnapshot (lh, has);
1843
1858
});
1844
1859
1845
1860
return res;
0 commit comments