Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proofbuilder.cpp
Show All 40 Lines | for (auto &s : stakes) { | ||||
signedStakes.push_back(s.sign(proofid)); | signedStakes.push_back(s.sign(proofid)); | ||||
} | } | ||||
stakes.clear(); | stakes.clear(); | ||||
return Proof(sequence, expirationTime, std::move(master), | return Proof(sequence, expirationTime, std::move(master), | ||||
std::move(signedStakes)); | std::move(signedStakes)); | ||||
} | } | ||||
ProofId ProofBuilder::getProofId() const { | ProofId ProofBuilder::getProofId() { | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
ss << sequence; | ss << sequence; | ||||
ss << expirationTime; | ss << expirationTime; | ||||
std::sort(stakes.begin(), stakes.end(), | |||||
[](const StakeSigner &lhs, const StakeSigner &rhs) { | |||||
return lhs.stake.getId() < rhs.stake.getId(); | |||||
}); | |||||
PiRK: This is not blocking, but wouldn't it be easier to understand the process of building the proof… | |||||
FabienAuthorUnsubmitted Done Inline ActionsThis was in fact how I did it initially, but this make it possible to return a wrong value when calling getProofId() which is brittle. Fabien: This was in fact how I did it initially, but this make it possible to return a wrong value when… | |||||
WriteCompactSize(ss, stakes.size()); | WriteCompactSize(ss, stakes.size()); | ||||
for (const auto &s : stakes) { | for (const auto &s : stakes) { | ||||
ss << s.stake; | ss << s.stake; | ||||
} | } | ||||
CHashWriter ss2(SER_GETHASH, 0); | CHashWriter ss2(SER_GETHASH, 0); | ||||
ss2 << ss.GetHash(); | ss2 << ss.GetHash(); | ||||
ss2 << master; | ss2 << master; | ||||
Show All 12 Lines |
This is not blocking, but wouldn't it be easier to understand the process of building the proof if this sort was at the beginning of ProofBuilder::build, just before getProofId is called?
Right now, this sorting which affect a class member and the order of the stakes in the serialized proof, is an undocumented side effect of what you would expect to be a simple getter.