mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
@@ -21,45 +21,30 @@
|
||||
#define RIPPLE_TEST_MANUALTIMEKEEPER_H_INCLUDED
|
||||
|
||||
#include <ripple/core/TimeKeeper.h>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
class ManualTimeKeeper : public TimeKeeper
|
||||
{
|
||||
public:
|
||||
ManualTimeKeeper();
|
||||
|
||||
void
|
||||
run(std::vector<std::string> const& servers) override;
|
||||
|
||||
time_point
|
||||
now() const override;
|
||||
|
||||
time_point
|
||||
closeTime() const override;
|
||||
|
||||
void
|
||||
adjustCloseTime(std::chrono::duration<std::int32_t> amount) override;
|
||||
|
||||
std::chrono::duration<std::int32_t>
|
||||
nowOffset() const override;
|
||||
|
||||
std::chrono::duration<std::int32_t>
|
||||
closeOffset() const override;
|
||||
|
||||
void
|
||||
set(time_point now);
|
||||
|
||||
private:
|
||||
// Adjust system_clock::time_point for NetClock epoch
|
||||
static time_point
|
||||
adjust(std::chrono::system_clock::time_point when);
|
||||
std::atomic<time_point> now_{};
|
||||
|
||||
std::mutex mutable mutex_;
|
||||
std::chrono::duration<std::int32_t> closeOffset_;
|
||||
time_point now_;
|
||||
public:
|
||||
ManualTimeKeeper() = default;
|
||||
|
||||
time_point
|
||||
now() const override
|
||||
{
|
||||
return now_.load();
|
||||
}
|
||||
|
||||
void
|
||||
set(time_point now)
|
||||
{
|
||||
now_.store(now);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012-2015 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/ManualTimeKeeper.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
ManualTimeKeeper::ManualTimeKeeper() : closeOffset_{}, now_(0s)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ManualTimeKeeper::run(std::vector<std::string> const& servers)
|
||||
{
|
||||
}
|
||||
|
||||
auto
|
||||
ManualTimeKeeper::now() const -> time_point
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
return now_;
|
||||
}
|
||||
|
||||
auto
|
||||
ManualTimeKeeper::closeTime() const -> time_point
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
return now_ + closeOffset_;
|
||||
}
|
||||
|
||||
void
|
||||
ManualTimeKeeper::adjustCloseTime(std::chrono::duration<std::int32_t> amount)
|
||||
{
|
||||
// Copied from TimeKeeper::adjustCloseTime
|
||||
using namespace std::chrono;
|
||||
auto const s = amount.count();
|
||||
std::lock_guard lock(mutex_);
|
||||
// Take large offsets, ignore small offsets,
|
||||
// push the close time towards our wall time.
|
||||
if (s > 1)
|
||||
closeOffset_ += seconds((s + 3) / 4);
|
||||
else if (s < -1)
|
||||
closeOffset_ += seconds((s - 3) / 4);
|
||||
else
|
||||
closeOffset_ = (closeOffset_ * 3) / 4;
|
||||
}
|
||||
|
||||
std::chrono::duration<std::int32_t>
|
||||
ManualTimeKeeper::nowOffset() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
std::chrono::duration<std::int32_t>
|
||||
ManualTimeKeeper::closeOffset() const
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
return closeOffset_;
|
||||
}
|
||||
|
||||
void
|
||||
ManualTimeKeeper::set(time_point now)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
now_ = now;
|
||||
}
|
||||
|
||||
auto
|
||||
ManualTimeKeeper::adjust(std::chrono::system_clock::time_point when)
|
||||
-> time_point
|
||||
{
|
||||
return time_point(std::chrono::duration_cast<duration>(
|
||||
when.time_since_epoch() - days(10957)));
|
||||
}
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
@@ -20,9 +20,9 @@
|
||||
#include <ripple/app/ledger/Ledger.h>
|
||||
#include <ripple/app/ledger/LedgerMaster.h>
|
||||
#include <ripple/app/misc/Manifest.h>
|
||||
#include <ripple/basics/random.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/beast/utility/Journal.h>
|
||||
#include <ripple/core/TimeKeeper.h>
|
||||
#include <ripple/overlay/Compression.h>
|
||||
#include <ripple/overlay/Message.h>
|
||||
#include <ripple/overlay/impl/Handshake.h>
|
||||
@@ -227,8 +227,7 @@ public:
|
||||
auto transaction = std::make_shared<protocol::TMTransaction>();
|
||||
transaction->set_rawtransaction(usdTxBlob);
|
||||
transaction->set_status(protocol::tsNEW);
|
||||
auto tk = make_TimeKeeper(logs.journal("TimeKeeper"));
|
||||
transaction->set_receivetimestamp(tk->now().time_since_epoch().count());
|
||||
transaction->set_receivetimestamp(rand_int<std::uint64_t>());
|
||||
transaction->set_deferred(true);
|
||||
|
||||
return transaction;
|
||||
@@ -263,19 +262,23 @@ public:
|
||||
ledgerData->set_error(protocol::TMReplyError::reNO_LEDGER);
|
||||
ledgerData->mutable_nodes()->Reserve(n);
|
||||
uint256 parentHash(0);
|
||||
|
||||
NetClock::duration const resolution{10};
|
||||
NetClock::time_point ct{resolution};
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
LedgerInfo info;
|
||||
auto tk = make_TimeKeeper(logs.journal("TimeKeeper"));
|
||||
info.seq = i;
|
||||
info.parentCloseTime = tk->now();
|
||||
info.parentCloseTime = ct;
|
||||
info.hash = ripple::sha512Half(i);
|
||||
info.txHash = ripple::sha512Half(i + 1);
|
||||
info.accountHash = ripple::sha512Half(i + 2);
|
||||
info.parentHash = parentHash;
|
||||
info.drops = XRPAmount(10);
|
||||
info.closeTimeResolution = tk->now().time_since_epoch();
|
||||
info.closeTime = tk->now();
|
||||
info.closeTimeResolution = resolution;
|
||||
info.closeTime = ct;
|
||||
ct += resolution;
|
||||
parentHash = ledgerHash(info);
|
||||
Serializer nData;
|
||||
ripple::addRaw(info, nData);
|
||||
@@ -341,7 +344,7 @@ public:
|
||||
Serializer s1;
|
||||
st.add(s1);
|
||||
list->set_signature(s1.data(), s1.size());
|
||||
list->set_blob(strHex(s.getString()));
|
||||
list->set_blob(strHex(s.slice()));
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -375,7 +378,7 @@ public:
|
||||
st.add(s1);
|
||||
auto& blob = *list->add_blobs();
|
||||
blob.set_signature(s1.data(), s1.size());
|
||||
blob.set_blob(strHex(s.getString()));
|
||||
blob.set_blob(strHex(s.slice()));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user