Fix proposal relaying (RIPD-1057):

Stash the signature so we can relay a proposal later
This commit is contained in:
JoelKatz
2015-12-07 12:06:19 -08:00
committed by Nik Bougalis
parent bb944466f2
commit 4f40e94c99
4 changed files with 52 additions and 13 deletions

View File

@@ -27,6 +27,7 @@
namespace ripple {
// Used to construct received proposals
LedgerProposal::LedgerProposal (
uint256 const& pLgr,
std::uint32_t seq,
@@ -47,6 +48,8 @@ LedgerProposal::LedgerProposal (
mTime = std::chrono::steady_clock::now ();
}
// Used to construct local proposals
// CAUTION: publicKey_ not set
LedgerProposal::LedgerProposal (
RippleAddress const& publicKey,
uint256 const& prevLgr,
@@ -74,10 +77,10 @@ uint256 LedgerProposal::getSigningHash () const
mCurrentHash);
}
bool LedgerProposal::checkSign (std::string const& signature) const
bool LedgerProposal::checkSign () const
{
return mPublicKey.verifyNodePublic(
getSigningHash(), signature, ECDSA::not_strict);
getSigningHash(), signature_, ECDSA::not_strict);
}
bool LedgerProposal::changePosition (
@@ -100,13 +103,12 @@ void LedgerProposal::bowOut ()
mProposeSeq = seqLeave;
}
Blob LedgerProposal::sign (RippleAddress const& privateKey)
Blob const& LedgerProposal::sign (RippleAddress const& privateKey)
{
Blob ret;
privateKey.signNodePrivate (getSigningHash (), ret);
privateKey.signNodePrivate (getSigningHash (), signature_);
mSuppression = proposalUniqueId (mCurrentHash, mPreviousLedger, mProposeSeq,
mCloseTime, mPublicKey.getNodePublic (), ret);
return ret;
mCloseTime, mPublicKey.getNodePublic (), signature_);
return signature_;
}
Json::Value LedgerProposal::getJson () const

View File

@@ -68,7 +68,7 @@ public:
NetClock::time_point closeTime);
uint256 getSigningHash () const;
bool checkSign (std::string const& signature) const;
bool checkSign () const;
NodeID const& getPeerID () const
{
@@ -82,6 +82,10 @@ public:
{
return mPreviousLedger;
}
RippleAddress const& getPublicKey () const
{
return mPublicKey;
}
uint256 const& getSuppressionID () const
{
return mSuppression;
@@ -95,7 +99,17 @@ public:
return mCloseTime;
}
Blob sign (RippleAddress const& privateKey);
Blob const& sign (RippleAddress const& privateKey);
void setSignature (Blob sig)
{
signature_ = sig;
}
Blob const& getSignature () const
{
return signature_;
}
bool isPrevLedger (uint256 const& pl) const
{
@@ -140,6 +154,7 @@ private:
NodeID mPeerID;
RippleAddress mPublicKey;
PublicKey publicKey_;
Blob signature_;
std::chrono::steady_clock::time_point mTime;
};

View File

@@ -1324,7 +1324,7 @@ void LedgerConsensusImp::propose ()
Blob const pubKey = mValPublic.getNodePublic ();
prop.set_nodepubkey (&pubKey[0], pubKey.size ());
Blob const sig = mOurPosition->sign (mValPrivate);
Blob const& sig = mOurPosition->sign (mValPrivate);
prop.set_signature (&sig[0], sig.size ());
app_.overlay().send(prop);
@@ -1650,7 +1650,28 @@ void LedgerConsensusImp::playbackProposals ()
if (proposal->isPrevLedger (mPrevLedgerHash) &&
peerPosition (proposal))
{
// FIXME: Should do delayed relay
// Now that we know this proposal
// is useful, relay it
protocol::TMProposeSet prop;
prop.set_proposeseq (
proposal->getProposeSeq ());
prop.set_closetime (
proposal->getCloseTime ().time_since_epoch().count());
prop.set_currenttxhash (
proposal->getCurrentHash().begin(), 256 / 8);
prop.set_previousledger (
proposal->getPrevLedger().begin(), 256 / 8);
auto const pubKey = proposal->getPublicKey().getNodePublic ();
prop.set_nodepubkey (&pubKey[0], pubKey.size());
auto const& signature = proposal->getSignature();
prop.set_signature (&signature[0], signature.size());
app_.overlay().relay (
prop, proposal->getSuppressionID ());
}
});
}

View File

@@ -1289,6 +1289,7 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMProposeSet> const& m)
NetClock::time_point{NetClock::duration{set.closetime()}},
signerPublic, PublicKey(makeSlice(set.nodepubkey())),
suppression);
proposal->setSignature (Blob (set.signature().begin(), set.signature().end()));
std::weak_ptr<PeerImp> weak = shared_from_this();
app_.getJobQueue ().addJob (
@@ -1902,7 +1903,7 @@ PeerImp::checkPropose (Job& job,
assert (packet);
protocol::TMProposeSet& set = *packet;
if (! cluster() && ! proposal->checkSign (set.signature ()))
if (! cluster() && ! proposal->checkSign ())
{
p_journal_.warning <<
"Proposal fails sig check";