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

Small Ledger cleanups and improvements: #330

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/ripple_app/consensus/LedgerConsensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,6 @@ class LedgerConsensusImp
}

newLCL->setAccepted (closeTime, mCloseResolution, closeTimeCorrect);
newLCL->updateHash ();
newLCL->setImmutable ();
getApp().getLedgerMaster().storeLedger(newLCL);

WriteLog (lsDEBUG, LedgerConsensus)
Expand Down
7 changes: 5 additions & 2 deletions src/ripple_app/ledger/Ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ Ledger::~Ledger ()

void Ledger::setImmutable ()
{
// Updates the hash and marks the ledger and its maps immutable

updateHash ();
mImmutable = true;

Expand All @@ -245,8 +247,8 @@ void Ledger::updateHash ()
mAccountHash.zero ();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we not extract this as a constant, perhaps even bring it into the system tuning constants?


// VFALCO TODO Fix this hard coded magic number 118
Serializer s (118);
// VFALCO TODO Fix this hard coded magic number 122
Serializer s (122);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to ask another question :-)

Why is this 122 rather than the 128, used here:

https://github.com/ripple/rippled/blob/ledger-cleanups/src/ripple_app/ledger/Ledger.cpp#L589

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would assume one actually computed it and one just rounded up. We should have constants for the length of a serialized ledger without the hash prefix and the length with a hash prefix. Without a hash prefix, a ledger header is 118 bytes. With one, it's 122.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this question speaks to the need to have sensible symbolic constant names; it's ironic that we changed the magic number inside the comment instead of actually addressing the issue pointed out by the comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried to come up with a sensible way to do it and couldn't without devoting more time to it than it seemed worth.

s.add32 (HashPrefix::ledgerMaster);
addRaw (s);
mHash = s.getSHA512Half ();
Expand Down Expand Up @@ -296,6 +298,7 @@ void Ledger::addRaw (Serializer& s) const
void Ledger::setAccepted (std::uint32_t closeTime, int closeResolution, bool correctCloseTime)
{
// used when we witnessed the consensus
// Rounds the close time, updates the hash, and sets the ledger accepted and immutable
Copy link
Contributor

Choose a reason for hiding this comment

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

Tiny quibble - could I get you to put a period at the end of the sentence, and/or change it to "sets the ledger to be"? I had (for some reason) difficulty parsing this sentence the first few times and thought you'd missed a second line.

assert (mClosed && !mAccepted);
mCloseTime = correctCloseTime ? roundCloseTime (closeTime, closeResolution) : closeTime;
mCloseResolution = closeResolution;
Expand Down