Skip to content

Commit

Permalink
[FOLD] Use proper closeTime when accepting ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
bachase committed Sep 5, 2017
1 parent d5d2227 commit 73dba2e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
15 changes: 8 additions & 7 deletions src/test/consensus/Consensus_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class Consensus_test : public beast::unit_test::suite
fast, round<milliseconds>(0.2 * parms.ledgerGRANULARITY));

slow.connect(
fast, round<milliseconds>(1.1 * parms.ledgerGRANULARITY));
network, round<milliseconds>(1.1 * parms.ledgerGRANULARITY));

// All peers submit their own ID as a transaction
for (Peer* peer : network)
Expand Down Expand Up @@ -254,7 +254,7 @@ class Consensus_test : public beast::unit_test::suite
fast, round<milliseconds>(0.2 * parms.ledgerGRANULARITY));

slow.connect(
fast, round<milliseconds>(1.1 * parms.ledgerGRANULARITY));
network, round<milliseconds>(1.1 * parms.ledgerGRANULARITY));

for (Peer* peer : slow)
peer->runAsValidator = isParticipant;
Expand Down Expand Up @@ -289,11 +289,12 @@ class Consensus_test : public beast::unit_test::suite
peer->openTxs.find(Tx{1}) != peer->openTxs.end());
}

Peer* slowPeer = *slow.begin();

BEAST_EXPECT(
slowPeer->prevProposers ==
network.size() - slow.size());
Peer const* slowPeer = slow[0];
if (isParticipant)
BEAST_EXPECT(
slowPeer->prevProposers == network.size() - 1);
else
BEAST_EXPECT(slowPeer->prevProposers == fast.size());

for (Peer* peer : fast)
{
Expand Down
23 changes: 23 additions & 0 deletions src/test/consensus/LedgerTiming_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,34 @@ class LedgerTiming_test : public beast::unit_test::suite

}

void testEffCloseTime()
{
using namespace std::chrono_literals;
using tp = NetClock::time_point;
tp close;

close = effCloseTime(tp{10s}, 30s, tp{0s});
BEAST_EXPECT(close == tp{1s});

close = effCloseTime(tp{16s}, 30s, tp{0s});
BEAST_EXPECT(close == tp{30s});

close = effCloseTime(tp{16s}, 30s, tp{30s});
BEAST_EXPECT(close == tp{31s});

close = effCloseTime(tp{16s}, 30s, tp{60s});
BEAST_EXPECT(close == tp{61s});

close = effCloseTime(tp{31s}, 30s, tp{0s});
BEAST_EXPECT(close == tp{30s});
}

void
run() override
{
testGetNextLedgerTimeResolution();
testRoundCloseTime();
testEffCloseTime();
}

};
Expand Down
14 changes: 7 additions & 7 deletions src/test/csf/impl/ledgers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ LedgerOracle::nextID() const

Ledger
LedgerOracle::accept(
Ledger const& curr,
Ledger const& parent,
TxSetType const& txs,
NetClock::duration closeTimeResolution,
NetClock::time_point const& consensusCloseTime)
{
Ledger::Instance next(*curr.instance_);
Ledger::Instance next(*parent.instance_);
next.txs.insert(txs.begin(), txs.end());
next.seq = curr.seq() + Ledger::Seq{1};
next.seq = parent.seq() + Ledger::Seq{1};
next.closeTimeResolution = closeTimeResolution;
next.closeTimeAgree = consensusCloseTime != NetClock::time_point{};
if(next.closeTimeAgree)
next.closeTime = effCloseTime(
consensusCloseTime, closeTimeResolution, curr.parentCloseTime());
consensusCloseTime, closeTimeResolution, parent.closeTime());
else
next.closeTime = consensusCloseTime + 1s;
next.closeTime = parent.closeTime() + 1s;

next.parentCloseTime = curr.closeTime();
next.parentID = curr.id();
next.parentCloseTime = parent.closeTime();
next.parentID = parent.id();
auto it = instances_.left.find(next);
if (it == instances_.left.end())
{
Expand Down

0 comments on commit 73dba2e

Please sign in to comment.