Files
rippled/src/ripple/protocol/impl/STValidation.cpp
Nik Bougalis 268e28a278 Tune relaying of untrusted proposals & validations:
In deciding whether to relay a proposal or validation, a server would
consider whether it was issued by a validator on that server's UNL.

While both trusted proposals and validations were always relayed,
the code prioritized relaying of untrusted proposals over untrusted
validations. While not technically incorrect, validations are
generally more "valuable" because they are required during the
consensus process, whereas proposals are not, strictly, required.

The commit introduces two new configuration options, allowing server
operators to fine-tune the relaying behavior:

The `[relay_proposals]` option controls the relaying behavior for
proposals received by this server. It has two settings: "trusted"
and "all" and the default is "trusted".

The `[relay_validations]` options controls the relaying behavior for
validations received by this server. It has two settings: "trusted"
and "all" and the default is "all".

This change does not require an amendment as it does not affect
transaction processing.
2020-05-26 18:36:06 -07:00

134 lines
3.5 KiB
C++

//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/basics/Log.h>
#include <ripple/basics/contract.h>
#include <ripple/json/to_string.h>
#include <ripple/protocol/HashPrefix.h>
#include <ripple/protocol/STValidation.h>
namespace ripple {
SOTemplate const&
STValidation::validationFormat()
{
// We can't have this be a magic static at namespace scope because
// it relies on the SField's below being initialized, and we can't
// guarantee the initialization order.
static SOTemplate const format{
{sfFlags, soeREQUIRED},
{sfLedgerHash, soeREQUIRED},
{sfLedgerSequence, soeREQUIRED},
{sfCloseTime, soeOPTIONAL},
{sfLoadFee, soeOPTIONAL},
{sfAmendments, soeOPTIONAL},
{sfBaseFee, soeOPTIONAL},
{sfReserveBase, soeOPTIONAL},
{sfReserveIncrement, soeOPTIONAL},
{sfSigningTime, soeREQUIRED},
{sfSigningPubKey, soeREQUIRED},
{sfSignature, soeREQUIRED},
{sfConsensusHash, soeOPTIONAL},
{sfCookie, soeDEFAULT},
{sfValidatedHash, soeOPTIONAL},
{sfServerVersion, soeOPTIONAL},
};
return format;
};
uint256
STValidation::getSigningHash() const
{
return STObject::getSigningHash(HashPrefix::validation);
}
uint256
STValidation::getLedgerHash() const
{
return getFieldH256(sfLedgerHash);
}
uint256
STValidation::getConsensusHash() const
{
return getFieldH256(sfConsensusHash);
}
NetClock::time_point
STValidation::getSignTime() const
{
return NetClock::time_point{NetClock::duration{getFieldU32(sfSigningTime)}};
}
NetClock::time_point
STValidation::getSeenTime() const
{
return seenTime_;
}
bool
STValidation::isValid() const
{
try
{
if (publicKeyType(getSignerPublic()) != KeyType::secp256k1)
return false;
return verifyDigest(
getSignerPublic(),
getSigningHash(),
makeSlice(getFieldVL(sfSignature)),
getFlags() & vfFullyCanonicalSig);
}
catch (std::exception const&)
{
JLOG(debugLog().error()) << "Exception validating validation";
return false;
}
}
PublicKey
STValidation::getSignerPublic() const
{
return PublicKey(makeSlice(getFieldVL(sfSigningPubKey)));
}
bool
STValidation::isFull() const
{
return (getFlags() & vfFullValidation) != 0;
}
Blob
STValidation::getSignature() const
{
return getFieldVL(sfSignature);
}
Blob
STValidation::getSerialized() const
{
Serializer s;
add(s);
return s.peekData();
}
} // namespace ripple