Skip to content

Commit

Permalink
Use previous ledger id of replaced validation
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonianb committed Apr 26, 2017
1 parent 50184ce commit fcf2f4f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/ripple/app/consensus/RCLValidations.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ class RCLValidation
val_->setPreviousHash(hash);
}

/// Get the prior ledger hash this validation is following
uint256
getPreviousLedgerID() const
{
return val_->getPreviousHash();
}

/// Check whether the given hash matches this validation's prior hash
bool
isPreviousLedgerID(uint256 const& hash) const
Expand Down
7 changes: 6 additions & 1 deletion src/ripple/consensus/Validations.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ isCurrent(
// this validation replaced
void setPreviousLedgerID(LedgerID &);
// Get the previous validation ledger from this publishing node that
// this validation replaced
LedgerID getPreviousLedgerID() const;
// Check if this validation had the given ledger ID as its prior ledger
bool isPreviousLedgerID(LedgerID const& ) const;
Expand Down Expand Up @@ -420,7 +424,8 @@ class Validations
maybeStaleValidation.emplace(std::move(oldVal));
// Replace old val in the map and set the previous ledger ID
ins.first->second = val;
ins.first->second.setPreviousLedgerID(oldID);
ins.first->second.setPreviousLedgerID(
oldID != val.ledgerID() ? oldID : oldVal.getPreviousLedgerID());
}
else
{
Expand Down
12 changes: 9 additions & 3 deletions src/test/consensus/Validations_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Validations_test : public beast::unit_test::suite
std::string key_;
std::size_t nodeID_ = 0;
bool trusted_ = true;
std::size_t prevID_ = 0;
ID prevID_ = ID{0};
boost::optional<std::uint32_t> loadFee_;

public:
Expand Down Expand Up @@ -148,17 +148,23 @@ class Validations_test : public beast::unit_test::suite
}

void
setPreviousLedgerID(std::uint32_t const& prevID)
setPreviousLedgerID(ID const& prevID)
{
prevID_ = prevID;
}

bool
isPreviousLedgerID(std::uint32_t const& prevID) const
isPreviousLedgerID(ID const& prevID) const
{
return prevID_ == prevID;
}

ID
getPreviousLedgerID() const
{
return prevID_;
}

boost::optional<std::uint32_t>
loadFee() const
{
Expand Down

0 comments on commit fcf2f4f

Please sign in to comment.