Skip to content

Commit

Permalink
1545 First pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
kladkogex committed Nov 25, 2024
1 parent 3f6c03f commit 09d589b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
30 changes: 12 additions & 18 deletions libbatched-io/batched_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,52 +40,47 @@ class batched_db : public db_face {
public:
void open( std::shared_ptr< dev::db::DatabaseFace > _db ) { m_db = _db; }
bool is_open() const { return !!m_db; }
void insert( dev::db::Slice _key, dev::db::Slice _value ) override {
void insert( dev::db::Slice _key, dev::db::Slice _value ) {
std::lock_guard< std::mutex > batch_lock( m_batch_mutex );
ensure_batch();
m_batch->insert( _key, _value );
}
void kill( dev::db::Slice _key ) override {
void kill( dev::db::Slice _key ) {
std::lock_guard< std::mutex > batch_lock( m_batch_mutex );
ensure_batch();
m_batch->kill( _key );
}
void revert() override {
virtual void revert() {
std::lock_guard< std::mutex > batch_lock( m_batch_mutex );
if ( m_batch )
m_batch.reset();
m_db->discardCreatedBatches();
}
void commit( const std::string& test_crash_string = std::string() ) override {
virtual void commit( const std::string& test_crash_string = std::string() ) {
std::lock_guard< std::mutex > batch_lock( m_batch_mutex );
ensure_batch();
test_crash_before_commit( test_crash_string );
m_db->commit( std::move( m_batch ) );
}

// readonly
std::string lookup( dev::db::Slice _key ) const override { return m_db->lookup( _key ); }

bool exists( dev::db::Slice _key ) const override { return m_db->exists( _key ); }

void forEach( std::function< bool( dev::db::Slice, dev::db::Slice ) > f ) const override {
virtual std::string lookup( dev::db::Slice _key ) const { return m_db->lookup( _key ); }
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 );
m_db->forEach( f );
}

void forEachWithPrefix( std::string& _prefix,
std::function< bool( dev::db::Slice, dev::db::Slice ) > f ) const override {
virtual void forEachWithPrefix(
std::string& _prefix, std::function< bool( dev::db::Slice, dev::db::Slice ) > f ) const {
std::lock_guard< std::mutex > foreach_lock( m_batch_mutex );
m_db->forEachWithPrefix( _prefix, f );
}

~batched_db() override {
// all batches should be either commit()'ted or revert()'ed!
assert( !m_batch );
}
virtual ~batched_db() = default;

protected:
void recover() override { /*nothing*/
void recover() { /*nothing*/
}
};

Expand Down Expand Up @@ -142,11 +137,10 @@ class read_only_snap_based_batched_db : public db_face {
virtual ~read_only_snap_based_batched_db() = default;

protected:
void recover() override { /*nothing*/
void recover() { /*nothing*/
}
};


class db_splitter {
private:
std::shared_ptr< db_face > m_backend;
Expand Down
5 changes: 5 additions & 0 deletions libethereum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ void Client::initStateFromDiskOrGenesis() {
void Client::init( WithExisting _forceAction, u256 _networkId ) {
DEV_TIMED_FUNCTION_ABOVE( 500 );
m_networkId = _networkId;

initStateFromDiskOrGenesis();

// LAZY. TODO: move genesis state construction/commiting to stateDB opening and have this
// just take the root from the genesis block.

m_preSeal = bc().genesisBlock( m_state );

m_postSeal = m_preSeal;
Expand Down
29 changes: 27 additions & 2 deletions libweb3jsonrpc/AdminEth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,34 @@ h256 AdminEth::blockHash( string const& _blockNumberOrHash ) const {
}
}

Json::Value AdminEth::admin_eth_vmTrace( string const&, int, string const& _session ) {
Json::Value AdminEth::admin_eth_vmTrace(
string const& /*_blockNumberOrHash*/, int _txIndex, string const& _session ) {
RPC_ADMIN;
throw jsonrpc::JsonRpcException( "Usupported API call" );

Json::Value ret;

if ( _txIndex < 0 )
throw jsonrpc::JsonRpcException( "Negative index" );
Block block = m_eth.latestBlock();
if ( ( unsigned ) _txIndex < block.pending().size() ) {
try {
Transaction t = block.pending()[_txIndex];
State s;
throw std::logic_error( "Historical state is not supported in Skale state" );
// Executive e(s, block, _txIndex, m_eth.blockChain());
// StandardTrace st;
// st.setShowMnemonics();
// e.initialize(t);
// if (!e.execute())
// e.go(st.functionToExecuteOnEachOperation());
// e.finalize();
// Json::Reader().parse(st.json(), ret);
} catch ( Exception const& _e ) {
cwarn << diagnostic_information( _e );
}
}

return ret;
}

Json::Value AdminEth::admin_eth_getReceiptByHashAndIndex(
Expand Down

0 comments on commit 09d589b

Please sign in to comment.