From 45f7819aba9b25a4277d5ac2da31313f44f75e77 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Thu, 8 Oct 2015 13:40:01 -0400 Subject: [PATCH] adding some hashing methods to db for debugging --- libraries/db/include/graphene/db/flat_index.hpp | 8 ++++++++ libraries/db/include/graphene/db/generic_index.hpp | 13 ++++++++++++- libraries/db/include/graphene/db/index.hpp | 1 + libraries/db/include/graphene/db/object.hpp | 7 +++++++ libraries/db/include/graphene/db/simple_index.hpp | 7 +++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/libraries/db/include/graphene/db/flat_index.hpp b/libraries/db/include/graphene/db/flat_index.hpp index 06eb3826..a2b7e036 100644 --- a/libraries/db/include/graphene/db/flat_index.hpp +++ b/libraries/db/include/graphene/db/flat_index.hpp @@ -87,6 +87,14 @@ namespace graphene { namespace db { } FC_CAPTURE_AND_RETHROW() } + virtual fc::uint128 hash()const override { + fc::uint128 result; + for( const auto& ptr : _objects ) + result += ptr.hash(); + + return result; + } + class const_iterator { public: diff --git a/libraries/db/include/graphene/db/generic_index.hpp b/libraries/db/include/graphene/db/generic_index.hpp index 837df43d..4a4ff71b 100644 --- a/libraries/db/include/graphene/db/generic_index.hpp +++ b/libraries/db/include/graphene/db/generic_index.hpp @@ -90,8 +90,19 @@ namespace graphene { namespace chain { const index_type& indices()const { return _indices; } + virtual fc::uint128 hash()const override { + fc::uint128 result; + for( const auto& ptr : _indices ) + { + result += ptr.hash(); + } + + return result; + } + private: - index_type _indices; + fc::uint128 _current_hash; + index_type _indices; }; /** diff --git a/libraries/db/include/graphene/db/index.hpp b/libraries/db/include/graphene/db/index.hpp index 514a79e5..6c175e20 100644 --- a/libraries/db/include/graphene/db/index.hpp +++ b/libraries/db/include/graphene/db/index.hpp @@ -122,6 +122,7 @@ namespace graphene { namespace db { } virtual void inspect_all_objects(std::function inspector)const = 0; + virtual fc::uint128 hash()const = 0; virtual void add_observer( const shared_ptr& ) = 0; }; diff --git a/libraries/db/include/graphene/db/object.hpp b/libraries/db/include/graphene/db/object.hpp index 16ff3fba..94068f50 100644 --- a/libraries/db/include/graphene/db/object.hpp +++ b/libraries/db/include/graphene/db/object.hpp @@ -18,6 +18,8 @@ #pragma once #include #include +#include +#include namespace graphene { namespace db { @@ -67,6 +69,7 @@ namespace graphene { namespace db { virtual void move_from( object& obj ) = 0; virtual variant to_variant()const = 0; virtual vector pack()const = 0; + virtual fc::uint128 hash()const = 0; }; /** @@ -91,6 +94,10 @@ namespace graphene { namespace db { } virtual variant to_variant()const { return variant( static_cast(*this) ); } virtual vector pack()const { return fc::raw::pack( static_cast(*this) ); } + virtual fc::uint128 hash()const { + auto tmp = this->pack(); + return fc::city_hash_crc_128( tmp.data(), tmp.size() ); + } }; typedef flat_map annotation_map; diff --git a/libraries/db/include/graphene/db/simple_index.hpp b/libraries/db/include/graphene/db/simple_index.hpp index 9c4b0742..9e0a612f 100644 --- a/libraries/db/include/graphene/db/simple_index.hpp +++ b/libraries/db/include/graphene/db/simple_index.hpp @@ -92,6 +92,13 @@ namespace graphene { namespace db { } } FC_CAPTURE_AND_RETHROW() } + virtual fc::uint128 hash()const override { + fc::uint128 result; + for( const auto& ptr : _objects ) + result += ptr->hash(); + + return result; + } class const_iterator {