mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Currently there is no mechanism for a validator to report the
version of the software it is currently running. Such reports
can be useful for those who are developing network monitoring
dashboards and server operators in general.
This commit, if merged, defines an encoding scheme to encode
a version string into a 64-bit unsigned integer and adds an
additional optional field to validations.
This commit piggybacks on "HardenedValidations" amendment to
determine whether version information should be propagated
or not.
The general encoding scheme is:
XXXXXXXX-XXXXXXXX-YYYYYYYY-YYYYYYYY-YYYYYYYY-YYYYYYYY-YYYYYYYY-YYYYYYYY
X: 16 bits identifying the particular implementation
Y: 48 bits of data specific to the implementation
The rippled-specific format (implementation ID is: 0x18 0x3B) is:
00011000-00111011-MMMMMMMM-mmmmmmmm-pppppppp-TTNNNNNN-00000000-00000000
M: 8-bit major version (0-255)
m: 8-bit minor version (0-255)
p: 8-bit patch version (0-255)
T: 11 if neither an RC nor a beta
10 if an RC
01 if a beta
N: 6-bit rc/beta number (1-63)
134 lines
3.5 KiB
C++
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, soeOPTIONAL},
|
|
{sfCloseTime, soeOPTIONAL},
|
|
{sfLoadFee, soeOPTIONAL},
|
|
{sfAmendments, soeOPTIONAL},
|
|
{sfBaseFee, soeOPTIONAL},
|
|
{sfReserveBase, soeOPTIONAL},
|
|
{sfReserveIncrement, soeOPTIONAL},
|
|
{sfSigningTime, soeREQUIRED},
|
|
{sfSigningPubKey, soeREQUIRED},
|
|
{sfSignature, soeOPTIONAL},
|
|
{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
|