Skip to content

Commit

Permalink
#1870 dont change core node api
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev committed Feb 21, 2025
1 parent a86e3ba commit 9552302
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 11 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ add_subdirectory( libdevcore )
add_subdirectory( libdevcrypto )
add_subdirectory( libp2p )

add_subdirectory( libhistoric )
add_subdirectory( libskale )
if ( HISTORIC_STATE )
add_subdirectory( libhistoric )
endif()

add_subdirectory( libskale )

add_subdirectory( libethcore )
add_subdirectory( libevm )
Expand Down
8 changes: 8 additions & 0 deletions libbatched-io/batched_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ class db_operations_face {
virtual void kill( dev::db::Slice _key ) = 0;

// readonly
#ifdef HISTORIC_STATE
virtual std::string lookup( dev::db::Slice _key ) const { return lookup( _key, UINT64_MAX ); }
virtual std::string lookup( dev::db::Slice _key, uint64_t _rootBlockNumber ) const {
assert( _rootBlockNumber == UINT64_MAX );
( void ) _rootBlockNumber;
return lookup( _key );
}
#else
virtual std::string lookup( dev::db::Slice _key ) const = 0;
#endif
virtual bool exists( dev::db::Slice _key ) const = 0;
virtual void forEach( std::function< bool( dev::db::Slice, dev::db::Slice ) > f ) const = 0;
virtual void forEachWithPrefix(
Expand Down Expand Up @@ -69,9 +73,13 @@ class batched_db : public db_face {
}

// readonly
#ifdef HISTORIC_STATE
virtual std::string lookup( dev::db::Slice _key, uint64_t _rootBlockTimestamp ) const {
return m_db->lookup( _key, _rootBlockTimestamp );
}
#else
virtual std::string lookup( dev::db::Slice _key ) const { return m_db->lookup( _key ); }
#endif
virtual bool exists( dev::db::Slice _key ) const { return m_db->exists( _key ); }
virtual void forEach( std::function< bool( dev::db::Slice, dev::db::Slice ) > f ) const {
std::lock_guard< std::mutex > foreach_lock( m_batch_mutex );
Expand Down
5 changes: 5 additions & 0 deletions libdevcore/RotatingHistoricState.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ class RotatingHistoricState : public DatabaseFace {
return ioBackend->currentPiece();
}

#ifdef HISTORIC_STATE
using DatabaseFace::lookup; // 1-argument version
virtual std::string lookup( Slice _key, uint64_t _rootBlockNumber ) const;
#else
std::string lookup( Slice _key, uint64_t _rootBlockNumber ) const;
virtual std::string lookup( Slice _key ) const { return lookup( _key, UINT64_MAX ); };
#endif
virtual bool exists( Slice _key ) const;
virtual void insert( Slice _key, Slice _value );
virtual void kill( Slice _key );
Expand Down
29 changes: 24 additions & 5 deletions libdevcore/TrieDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,36 @@ class GenericTrieDB {
~GenericTrieDB() {}

void open( DB* _db ) { m_db = _db; }
void open( DB* _db, h256 const& _root, Verification _v = Verification::Normal,
uint64_t _rootBlockNumber = UINT64_MAX ) {
void open( DB* _db, h256 const& _root, Verification _v = Verification::Normal
#ifdef HISTORIC_STATE
,
uint64_t _rootBlockNumber = UINT64_MAX
#endif
) {
m_db = _db;
setRoot( _root, _v, _rootBlockNumber );
setRoot( _root, _v
#ifdef HISTORIC_STATE
,
_rootBlockNumber
#endif
);
}

void init() {
setRoot( forceInsertNode( &RLPNull ) );
assert( node( m_root ).size() );
}

void setRoot( h256 const& _root, Verification _v = Verification::Normal,
uint64_t _rootBlockNumber = UINT64_MAX ) {
void setRoot( h256 const& _root, Verification _v = Verification::Normal
#ifdef HISTORIC_STATE
,
uint64_t _rootBlockNumber = UINT64_MAX
#endif
) {
m_root = _root;
#ifdef HISTORIC_STATE
m_rootBlockNumber = _rootBlockNumber;
#endif
if ( _v == Verification::Normal ) {
if ( m_root == EmptyTrie && !m_db->exists( m_root ) )
init();
Expand Down Expand Up @@ -287,7 +302,11 @@ class GenericTrieDB {
bool isTwoItemNode( RLP const& _n ) const;
std::string deref( RLP const& _n ) const;

#ifdef HISTORIC_STATE
std::string node( h256 const& _h ) const { return m_db->lookup( _h, m_rootBlockNumber ); }
#else
std::string node( h256 const& _h ) const { return m_db->lookup( _h ); }
#endif

// These are low-level node insertion functions that just go straight through into the DB.
h256 forceInsertNode( bytesConstRef _v ) {
Expand Down
4 changes: 4 additions & 0 deletions libdevcore/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ class WriteBatchFace {
class DatabaseFace {
public:
virtual ~DatabaseFace() = default;
#ifdef HISTORIC_STATE
virtual std::string lookup( Slice _key ) const { return lookup( _key, UINT64_MAX ); }
virtual std::string lookup( Slice _key, uint64_t _rootBlockNumber ) const {
assert( _rootBlockNumber == UINT64_MAX );
( void ) _rootBlockNumber;
return lookup( _key );
}
#else
virtual std::string lookup( Slice _key ) const = 0;
#endif
virtual bool exists( Slice _key ) const = 0;
virtual void insert( Slice _key, Slice _value ) = 0;
virtual void kill( Slice _key ) = 0;
Expand Down
5 changes: 4 additions & 1 deletion libethereum/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ target_include_directories( ethereum PRIVATE "${UTILS_INCLUDE_DIR}" ${SKUTILS_IN
${CMAKE_SOURCE_DIR}/libconsensus/jsoncpp/include
${CMAKE_SOURCE_DIR}/libconsensus/spdlog/include
${CMAKE_SOURCE_DIR}/libconsensus/libjson/include)
target_link_libraries( ethereum PUBLIC evm ethcore p2p devcrypto devcore skale PRIVATE historic skutils snappy
target_link_libraries( ethereum PUBLIC evm ethcore p2p devcrypto devcore skale PRIVATE skutils snappy
jsoncpp # ${CMAKE_SOURCE_DIR}/libconsensus/jsoncpp/build/src/lib_json/libjsoncpp.a
Boost::fiber Boost::context Boost::chrono
batched-io
)
if (HISTORIC_STATE)
target_link_libraries(ethereum PRIVATE historic)
endif()

#target_compile_options( ethereum PRIVATE -Weffc++ )
#target_compile_options( ethereum PRIVATE -Wno-error=effc++ )
5 changes: 4 additions & 1 deletion libskale/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ target_include_directories( skale PUBLIC
${CMAKE_SOURCE_DIR}/libconsensus/jsoncpp/include
)

target_link_libraries(skale PRIVATE ethereum web3jsonrpc historic skutils
target_link_libraries(skale PRIVATE ethereum web3jsonrpc skutils
"${DEPS_INSTALL_ROOT}/lib/libzmq.a"
"${DEPS_INSTALL_ROOT}/lib/libsodium.a"
bls
pthread
)
if (HISTORIC_STATE)
target_link_libraries(skale PUBLIC historic)
endif()
target_compile_options( skale PRIVATE
-Wno-error=deprecated-copy -Wno-error=unused-result -Wno-error=unused-parameter -Wno-unused-variable -Wno-error=maybe-uninitialized
-Wno-nonnull
Expand Down
15 changes: 15 additions & 0 deletions libskale/OverlayDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ void ClassicOverlayDB::insert( h256 const& _h, bytesConstRef _v ) {
}
}

#ifdef HISTORIC_STATE
std::string ClassicOverlayDB::lookup( h256 const& _h, uint64_t _rootBlockNumber ) const {
#if DEV_GUARDED_DB
ReadGuard l( x_this );
Expand All @@ -664,6 +665,20 @@ std::string ClassicOverlayDB::lookup( h256 const& _h, uint64_t _rootBlockNumber
return "";
return m_db_face->lookup( skale::slicing::toSlice( _h ), _rootBlockNumber );
}
#else
std::string ClassicOverlayDB::lookup( h256 const& _h ) const {
#if DEV_GUARDED_DB
ReadGuard l( x_this );
#endif
auto it = m_cacheMain.find( _h );
if ( it != m_cacheMain.end() )
return it->second.first;

if ( !m_db_face )
return "";
return m_db_face->lookup( skale::slicing::toSlice( _h ) );
}
#endif

bool ClassicOverlayDB::exists( h256 const& _h ) const {
#if DEV_GUARDED_DB
Expand Down
4 changes: 4 additions & 0 deletions libskale/OverlayDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ class ClassicOverlayDB {
// block for HistoricState
void insert( dev::h256 const& _h, dev::bytesConstRef _v );

#ifdef HISTORIC_STATE
std::string lookup( dev::h256 const& _h ) const { return lookup( _h, UINT64_MAX ); }
std::string lookup( dev::h256 const& _h, uint64_t _rootBlockNumber ) const;
#else
std::string lookup( dev::h256 const& _h ) const;
#endif

bool exists( dev::h256 const& _h ) const;

Expand Down
4 changes: 3 additions & 1 deletion skaled/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ target_link_libraries(
${EXECUTABLE_NAME}
PRIVATE
ethereum
historic
ethashseal
evm
web3jsonrpc
Expand All @@ -32,6 +31,9 @@ target_link_libraries(
idn2
batched-io
)
if (HISTORIC_STATE)
target_link_libraries(${EXECUTABLE_NAME} PRIVATE historic)
endif()
if (CONSENSUS)
target_link_libraries(${EXECUTABLE_NAME} PRIVATE consensus)
endif()
Expand Down
5 changes: 4 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ if( APPLE )
endif()
target_include_directories(testeth PRIVATE ${UTILS_INCLUDE_DIR} ../libconsensus/spdlog/include)
target_link_libraries(testeth PRIVATE
ethereum historic ethashseal web3jsonrpc devcrypto devcore skale-buildinfo ${LIB_NAME_cryptopp} yaml-cpp binaryen::binaryen
ethereum ethashseal web3jsonrpc devcrypto devcore skale-buildinfo ${LIB_NAME_cryptopp} yaml-cpp binaryen::binaryen
skutils
Boost::system Boost::program_options
jsonrpccpp-client # ${CMAKE_SOURCE_DIR}/libconsensus/libjson-rpc-cpp/build/lib/libjsonrpccpp-client.a
Expand All @@ -91,6 +91,9 @@ target_link_libraries(testeth PRIVATE
${DEPS_INSTALL_ROOT}/lib/liblzma.a
batched-io
)
if (HISTORIC_STATE)
target_link_libraries(testeth PRIVATE historic)
endif()
if (CONSENSUS)
target_link_libraries(testeth PRIVATE consensus)
endif()
Expand Down

0 comments on commit 9552302

Please sign in to comment.