Skip to content

Commit

Permalink
Merge pull request #3316 from jayz22/use-hashofhash
Browse files Browse the repository at this point in the history
Use HashOfHash in LedgerHashUtils and InternalLedgerEntry

Reviewed-by: jonjove
  • Loading branch information
latobarita authored Jan 14, 2022
2 parents 02c584d + ae27c41 commit 48dcc21
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
9 changes: 5 additions & 4 deletions src/ledger/InternalLedgerEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ledger/InternalLedgerEntry.h"
#include "ledger/LedgerHashUtils.h"
#include "util/GlobalChecks.h"
#include "util/HashOfHash.h"
#include "util/XDRCereal.h"
#include "util/types.h"

Expand Down Expand Up @@ -162,12 +163,12 @@ InternalLedgerKey::hash() const
res = std::hash<stellar::LedgerKey>()(ledgerKey());
break;
case stellar::InternalLedgerEntryType::SPONSORSHIP:
res = shortHash::computeHash(stellar::ByteSlice(
sponsorshipKey().sponsoredID.ed25519().data(), 8));
res = std::hash<stellar::uint256>()(
sponsorshipKey().sponsoredID.ed25519());
break;
case stellar::InternalLedgerEntryType::SPONSORSHIP_COUNTER:
res = shortHash::computeHash(stellar::ByteSlice(
sponsorshipCounterKey().sponsoringID.ed25519().data(), 8));
res = std::hash<stellar::uint256>()(
sponsorshipCounterKey().sponsoringID.ed25519());
break;
default:
abort();
Expand Down
33 changes: 13 additions & 20 deletions src/ledger/LedgerHashUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "crypto/ShortHash.h"
#include "ledger/InternalLedgerEntry.h"
#include "util/HashOfHash.h"
#include "xdr/Stellar-ledger.h"
#include <functional>

Expand Down Expand Up @@ -48,25 +49,22 @@ getAssetHash(T const& asset)
case stellar::ASSET_TYPE_CREDIT_ALPHANUM4:
{
auto& a4 = asset.alphaNum4();
hashMix(res, stellar::shortHash::computeHash(
stellar::ByteSlice(a4.issuer.ed25519().data(), 8)));
hashMix(res, std::hash<stellar::uint256>()(a4.issuer.ed25519()));
hashMix(res, stellar::shortHash::computeHash(stellar::ByteSlice(
a4.assetCode.data(), a4.assetCode.size())));
break;
}
case stellar::ASSET_TYPE_CREDIT_ALPHANUM12:
{
auto& a12 = asset.alphaNum12();
hashMix(res, stellar::shortHash::computeHash(
stellar::ByteSlice(a12.issuer.ed25519().data(), 8)));
hashMix(res, std::hash<stellar::uint256>()(a12.issuer.ed25519()));
hashMix(res, stellar::shortHash::computeHash(stellar::ByteSlice(
a12.assetCode.data(), a12.assetCode.size())));
break;
}
case stellar::ASSET_TYPE_POOL_SHARE:
{
hashMix(res, stellar::shortHash::computeHash(stellar::ByteSlice(
getLiquidityPoolID(asset).data(), 8)));
hashMix(res, std::hash<stellar::uint256>()(getLiquidityPoolID(asset)));
break;
}
default:
Expand Down Expand Up @@ -110,23 +108,20 @@ template <> class hash<stellar::LedgerKey>
switch (lk.type())
{
case stellar::ACCOUNT:
stellar::hashMix(res,
stellar::shortHash::computeHash(stellar::ByteSlice(
lk.account().accountID.ed25519().data(), 8)));
stellar::hashMix(res, std::hash<stellar::uint256>()(
lk.account().accountID.ed25519()));
break;
case stellar::TRUSTLINE:
{
auto& tl = lk.trustLine();
stellar::hashMix(
res, stellar::shortHash::computeHash(
stellar::ByteSlice(tl.accountID.ed25519().data(), 8)));
res, std::hash<stellar::uint256>()(tl.accountID.ed25519()));
stellar::hashMix(res, hash<stellar::TrustLineAsset>()(tl.asset));
break;
}
case stellar::DATA:
stellar::hashMix(res,
stellar::shortHash::computeHash(stellar::ByteSlice(
lk.data().accountID.ed25519().data(), 8)));
stellar::hashMix(res, std::hash<stellar::uint256>()(
lk.data().accountID.ed25519()));
stellar::hashMix(
res,
stellar::shortHash::computeHash(stellar::ByteSlice(
Expand All @@ -138,14 +133,12 @@ template <> class hash<stellar::LedgerKey>
&lk.offer().offerID, sizeof(lk.offer().offerID))));
break;
case stellar::CLAIMABLE_BALANCE:
stellar::hashMix(
res, stellar::shortHash::computeHash(stellar::ByteSlice(
lk.claimableBalance().balanceID.v0().data(), 8)));
stellar::hashMix(res, std::hash<stellar::uint256>()(
lk.claimableBalance().balanceID.v0()));
break;
case stellar::LIQUIDITY_POOL:
stellar::hashMix(
res, stellar::shortHash::computeHash(stellar::ByteSlice(
lk.liquidityPool().liquidityPoolID.data(), 8)));
stellar::hashMix(res, std::hash<stellar::uint256>()(
lk.liquidityPool().liquidityPoolID));
break;
default:
abort();
Expand Down

0 comments on commit 48dcc21

Please sign in to comment.