Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ledger replay logic (RIPD-1547) #2477

Closed
wants to merge 1 commit into from

Conversation

bachase
Copy link
Collaborator

@bachase bachase commented Apr 11, 2018

This extracts the ledger replay logic into a standalone function for future reuse.

@ximinez I'm tagging you to review the middle commit, which is the change we had discussed to use a ReadView for the TxQ update.

@sublimator
Copy link
Contributor

sublimator commented Apr 11, 2018 via email

@ripplelabs-jenkins
Copy link
Collaborator

ripplelabs-jenkins commented Apr 11, 2018

Jenkins Build Summary

Built from this commit

Built at 20180416 - 14:32:25

Test Results

Build Type Log Result Status
docs logfile 1 cases, 0 failed, t: 2s PASS ✅
clang.debug.unity logfile 1022 cases, 0 failed, t: 251s PASS ✅
coverage logfile 1022 cases, 0 failed, t: 619s PASS ✅
clang.debug.nounity logfile 1020 cases, 0 failed, t: 247s PASS ✅
clang.debug.unity,
PARALLEL_TESTS=false
logfile 1022 cases, 0 failed, t: 488s PASS ✅
gcc.debug.nounity logfile 1020 cases, 0 failed, t: 103s PASS ✅
gcc.debug.unity logfile 1022 cases, 0 failed, t: 244s PASS ✅
clang.release.unity logfile 1021 cases, 0 failed, t: 329s PASS ✅
msvc.debug logfile 1018 cases, 0 failed, t: 565s PASS ✅
gcc.release.unity logfile 1021 cases, 0 failed, t: 349s PASS ✅
gcc.debug.unity
-Dstatic=true
logfile 1022 cases, 0 failed, t: 243s PASS ✅
msvc.debug,
PROJECT_NAME=rippled_classic
logfile 1018 cases, 0 failed, t: 1179s PASS ✅
msvc.release logfile 1017 cases, 0 failed, t: 506s PASS ✅

@scottschurr
Copy link
Collaborator

I'm not sure what's going on with the Travis and AppVeyor CI failures. It looks like there's some sort of collision going between this branch, which is based on -b3, and -b4, which removed BeastConfig.h. The specific failure is:

/home/travis/build/ripple/rippled/src/ripple/app/ledger/impl/BuildLedger.cpp:20:25: fatal error: BeastConfig.h: No such file or directory

Maybe rebasing to -b4 would help? I dunno...

@bachase
Copy link
Collaborator Author

bachase commented Apr 12, 2018

Rebased on 1.0.0-b4. 🤦‍♂️ for missing that initially.

@codecov-io
Copy link

codecov-io commented Apr 12, 2018

Codecov Report

Merging #2477 into develop will increase coverage by 0.02%.
The diff coverage is 84.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #2477      +/-   ##
==========================================
+ Coverage    70.67%   70.7%   +0.02%     
==========================================
  Files          696     699       +3     
  Lines        54436   54454      +18     
==========================================
+ Hits         38473   38500      +27     
+ Misses       15963   15954       -9
Impacted Files Coverage Δ
src/ripple/app/ledger/LedgerMaster.h 100% <ø> (+16.66%) ⬆️
src/ripple/app/consensus/RCLConsensus.h 80% <ø> (ø) ⬆️
src/ripple/app/misc/TxQ.h 97.05% <ø> (ø) ⬆️
src/ripple/app/misc/impl/TxQ.cpp 95.75% <ø> (ø) ⬆️
src/ripple/app/misc/NetworkOPs.cpp 63.64% <0%> (-0.05%) ⬇️
src/ripple/app/main/Application.cpp 58.55% <0%> (+0.38%) ⬆️
src/ripple/app/ledger/LedgerReplay.h 100% <100%> (ø)
src/ripple/app/ledger/impl/LedgerReplay.cpp 100% <100%> (ø)
src/ripple/app/ledger/impl/BuildLedger.cpp 86.11% <86.11%> (ø)
src/ripple/app/consensus/RCLConsensus.cpp 65.34% <92.85%> (-1.89%) ⬇️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1eece9b...4b778ea. Read the comment docs.

Copy link
Contributor

@HowardHinnant HowardHinnant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job.


} // namespace ripple

#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pico-nit: newline here.

Copy link
Contributor

@nbougalis nbougalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Left minor comments; nothing major.

applyTransaction(
app_, accum, *tx.second, false, tapNO_CHECK_SIGN, j_);
assert(replayData->parent()->info().hash == previousLedger.id());
return buildLedger(*replayData, tapNO_CHECK_SIGN, app_, j_);
}
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove the else here. You have a return in the if part of the branch.

{
std::shared_ptr<Ledger const> parent_;
std::shared_ptr<Ledger const> replay_;
std::map<int, std::shared_ptr<STTx const>> orderedTxns_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key should be std::uint32_t (the type of sfTransactionIndex).


/** Apply a set of consensus transactions to a ledger.

Typically the txFilter is used to reject transactions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There no longer is a txFilter argument passed to this function, so this comment is out of date.

Copy link
Collaborator

@scottschurr scottschurr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice cleanup! I especially like that you can pass a ReadView to TxQ::processClosedLedger. I left a few thoughts to consider, but spotted no real mistakes.

/** Apply a set of consensus transactions to a ledger.

Typically the txFilter is used to reject transactions
that already accepted in the prior ledger.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment? txFilter is no longer an argument.

assert(!accum.open());
if (replay)
std::shared_ptr<Ledger> buildLCL = [&]() {
auto replayData = ledgerMaster_.releaseReplay();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto const?

{
auto buildLCL = std::make_shared<Ledger>(*parent, closeTime);

auto const v2_enabled = buildLCL->rules().enabled(featureSHAMapV2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go ahead and declare v2_enabled as bool. And if you brace initialize it then narrowing is disabled. So if someone changes the return type of enabled() the compiler will catch them.


int asf = buildLCL->stateMap().flushDirty(
hotACCOUNT_NODE, buildLCL->info().seq);
int tmf = buildLCL->txMap().flushDirty(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int consts?

for (auto const& item : replay_->txMap())
{
auto txPair = replay_->txRead(item.key());
auto txIndex = (*txPair.second)[sfTransactionIndex];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto const?

{
auto txPair = replay_->txRead(item.key());
auto txIndex = (*txPair.second)[sfTransactionIndex];
orderedTxns_.emplace(txIndex, txPair.first);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be a hair more efficient if we move the shared_ptr in txPair.first. Consider...

orderedTxns_.emplace(txIndex, std::move (txPair.first));

The auto makes that possible optimization invisible in the text, eh? Tradeoffs....

auto txID = item.key();
auto txPair = replayLedger->txRead (txID);
auto txIndex = (*txPair.second)[sfTransactionIndex];
std::shared_ptr<STTx const> const & tx = it.second;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pico nit: space between const and & is atypical?

auto buildLCL = std::make_shared<Ledger>(*parent, closeTime);

auto const v2_enabled = buildLCL->rules().enabled(featureSHAMapV2);
auto v2_transition = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like v2_transition is unused?

auto lastClosedParent =
ledgerMaster.getLedgerByHash(lastClosed->info().parentHash);

auto replayed = buildLedger(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lastClosed, lastClosedParent, and replayed can all be const I think...

Copy link
Collaborator

@scottschurr scottschurr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks great to me! Thanks.

@bachase bachase added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Apr 13, 2018
Also switch to use ReadView for TxQ updates.
Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I did a light review of the entire PR. Looks good. I'm still surprised the TxQ change actually works. 😀

env.app(),
env.journal);

BEAST_EXPECT(replayed->info().hash == lastClosed->info().hash);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this test.

@seelabs
Copy link
Collaborator

seelabs commented May 16, 2018

In 1.1.0-b1

@seelabs seelabs closed this May 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants