Skip to content

Commit 9ef9b5c

Browse files
committed
Convert closeTimeMs to unix time in ms
1 parent 1a9b367 commit 9ef9b5c

53 files changed

Lines changed: 2566 additions & 2007 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/bucket/test/BucketTestUtils.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "ledger/LedgerManager.h"
1313
#include "ledger/LedgerTxn.h"
1414
#include "main/Application.h"
15+
#include "test/TxTests.h"
1516
#include "test/test.h"
1617
#include "util/ProtocolVersion.h"
1718
#include "xdr/Stellar-ledger.h"
@@ -86,9 +87,10 @@ closeLedger(Application& app, std::optional<SecretKey> skToSignValue,
8687
CLOG_INFO(Bucket, "Artificially closing ledger {} with lcl={}, buckets={}",
8788
ledgerNum, hexAbbrev(lcl.hash),
8889
hexAbbrev(app.getBucketManager().getLiveBucketList().getHash()));
89-
app.getHerder().externalizeValue(TxSetXDRFrame::makeEmpty(lcl), ledgerNum,
90-
lcl.header.scpValue.closeTime, upgrades,
91-
skToSignValue);
90+
app.getHerder().externalizeValue(
91+
TxSetXDRFrame::makeEmpty(lcl), ledgerNum,
92+
txtest::makeConsensusTime(lcl.header.scpValue.closeTime), upgrades,
93+
skToSignValue);
9294
while (lm.getLastClosedLedgerNum() < ledgerNum)
9395
{
9496
app.getClock().crank(true);

src/catchup/ApplyCheckpointWork.cpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "history/HistoryUtils.h"
1313
#include "historywork/Progress.h"
1414
#include "ledger/CheckpointRange.h"
15+
#include "ledger/LedgerHeaderUtils.h"
1516
#include "ledger/LedgerManager.h"
1617
#include "main/Application.h"
1718
#include "util/GlobalChecks.h"
@@ -286,31 +287,40 @@ ApplyCheckpointWork::getNextLedgerCloseData()
286287
}
287288

288289
// Check that we use the correct time format in the ledger header.
289-
bool const msActive = protocolVersionStartsFrom(
290-
lclHeader.header.ledgerVersion, MS_CLOSE_TIME_PROTOCOL_VERSION);
291-
if (!validateMsCloseTimeFormat(header.scpValue,
292-
/*allowMsTime=*/msActive,
293-
/*allowWholeSecondTime=*/!msActive))
290+
if (!hasValidCloseTime(header.scpValue))
294291
{
295292
throw std::runtime_error(fmt::format(
296-
FMT_STRING("ledger header for {:d} has an invalid ms close time "
297-
"(StellarValue type {:d}, closeTimeMs {:d}) under "
298-
"protocol {:d}"),
299-
header.ledgerSeq, static_cast<int32_t>(header.scpValue.ext.v()),
300-
getCloseTimeMs(header.scpValue), lclHeader.header.ledgerVersion));
293+
FMT_STRING("ledger header for {:d} has inconsistent close time "
294+
"fields: closeTime {:d}, consensus close time {}"),
295+
header.ledgerSeq, header.scpValue.closeTime,
296+
getConsensusTime(header.scpValue).toString()));
297+
}
298+
299+
bool const hasMsCloseTime = isMsCloseTimeStellarValue(header.scpValue);
300+
bool const protocolRequiresMsCloseTime =
301+
protocolHasMsCloseTime(lclHeader.header.ledgerVersion);
302+
if (hasMsCloseTime != protocolRequiresMsCloseTime)
303+
{
304+
throw std::runtime_error(fmt::format(
305+
FMT_STRING("ledger header for {:d} has a {} close time "
306+
"(StellarValue type {:d}) but protocol {:d} requires a "
307+
"{} close time"),
308+
header.ledgerSeq, hasMsCloseTime ? "millisecond" : "whole-second",
309+
static_cast<int32_t>(header.scpValue.ext.v()),
310+
lclHeader.header.ledgerVersion,
311+
protocolRequiresMsCloseTime ? "millisecond" : "whole-second"));
301312
}
302313

303-
// Check that close time never decreases
304-
if (getCloseTime(header.scpValue) <=
305-
getCloseTime(lclHeader.header.scpValue))
314+
// Close times must strictly increase from ledger to ledger
315+
auto const previousCloseTime = getConsensusTime(lclHeader.header.scpValue);
316+
auto const nextCloseTime = getConsensusTime(header.scpValue);
317+
if (nextCloseTime <= previousCloseTime)
306318
{
307319
throw std::runtime_error(fmt::format(
308320
FMT_STRING("ledger header for {:d} has a non-advancing close "
309-
"time {:d}.{:03d} (previous {:d}.{:03d})"),
310-
header.ledgerSeq, header.scpValue.closeTime,
311-
getCloseTimeMs(header.scpValue),
312-
lclHeader.header.scpValue.closeTime,
313-
getCloseTimeMs(lclHeader.header.scpValue)));
321+
"time {} (previous ledger closed at {})"),
322+
header.ledgerSeq, nextCloseTime.toString(),
323+
previousCloseTime.toString()));
314324
}
315325

316326
// We've verified the ledgerHeader (in the "trusted part of history"

src/catchup/CatchupWork.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "historywork/DownloadVerifyTxResultsWork.h"
2020
#include "historywork/GetAndUnzipRemoteFileWork.h"
2121
#include "historywork/GetHistoryArchiveStateWork.h"
22+
#include "ledger/LedgerHeaderUtils.h"
2223
#include "ledger/LedgerManager.h"
2324
#include "main/Application.h"
2425
#include "main/PersistentState.h"
@@ -69,7 +70,7 @@ setHerderStateTo(FileTransferInfo const& ft, uint32_t ledger, Application& app)
6970
app.getHerder().setTrackingSCPState(ledger, entry->header.scpValue,
7071
/* isTrackingNetwork */ false);
7172
CLOG_INFO(History, "Herder state is set! tracking={}, closeTime={}", ledger,
72-
entry->header.scpValue.closeTime);
73+
getConsensusTime(entry->header.scpValue).toString());
7374
return true;
7475
}
7576

src/herder/Herder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "Upgrades.h"
99
#include "herder/QuorumTracker.h"
1010
#include "herder/TransactionQueue.h"
11-
#include "ledger/LedgerHeaderUtils.h"
1211
#include "lib/json/json-forwards.h"
1312
#include "overlay/Peer.h"
1413
#include "overlay/StellarXDR.h"
@@ -29,6 +28,7 @@ struct EmptyTxSet
2928
};
3029
using TxSetResult = std::variant<TxSetXDRFrameConstPtr, EmptyTxSet>;
3130
class Application;
31+
class ConsensusTime;
3232
class XDROutputFileStream;
3333

3434
/*
@@ -177,7 +177,7 @@ class Herder
177177

178178
virtual void
179179
externalizeValue(TxSetXDRFrameConstPtr txSet, uint32_t ledgerSeq,
180-
CloseTime closeTime,
180+
ConsensusTime closeTime,
181181
xdr::xvector<UpgradeType, 6> const& upgrades,
182182
std::optional<SecretKey> skToSignValue = std::nullopt) = 0;
183183

@@ -229,7 +229,7 @@ class Herder
229229

230230
// helper function to craft an SCPValue
231231
virtual StellarValue
232-
makeStellarValue(Hash const& txSetHash, CloseTime closeTime,
232+
makeStellarValue(Hash const& txSetHash, ConsensusTime closeTime,
233233
xdr::xvector<UpgradeType, 6> const& upgrades,
234234
SecretKey const& s) = 0;
235235

0 commit comments

Comments
 (0)