Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Add full RPC API skeletons to simplify development (#41)
Browse files Browse the repository at this point in the history
Print local binding at startup
Add executable version (--version switch)
Update API documentation
Update project README with activation information
Update performance README with automation setup
  • Loading branch information
canepat authored Apr 27, 2021
1 parent bea88d0 commit a92e4d2
Show file tree
Hide file tree
Showing 21 changed files with 1,833 additions and 192 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,36 @@ We use the standard C++20 programming language. We follow the [Google's C++ Styl
* Exceptions are allowed.
* User-defined literals are allowed.
* Maximum line length is 170, indentation is 4 spaces – see `.clang-format`.

# Activation

From the build folder (`build_[gcc, clang]_[debug, release]` according to your choice) you typically activate Silkrpc using:

```
$ silkrpc/silkrpcdaemon --target <tg_core_host_address>:9090
```

where `<tg_core_host_address>` is the hostname or IP address of the TG Core to connect to.

You can check all command-line parameters supported by Silkrpc using:

```
$ silkrpc/silkrpcdaemon --help
silkrpcdaemon: C++ implementation of ETH JSON Remote Procedure Call (RPC) daemon
Flags from main.cpp:
--chaindata (chain data path as string); default: "";
--local (HTTP JSON local binding as string <address>:<port>);
default: "localhost:8545";
--logLevel (logging level); default: c;
--target (TG Core gRPC service location as string <address>:<port>);
default: "localhost:9090";
--timeout (gRPC call timeout as 32-bit integer); default: 10000;
```

You can also check the Silkrpc executable version by:

```
$ silkrpc/silkrpcdaemon --version
silkrpcdaemon 0.0.3
```
6 changes: 3 additions & 3 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ The following table shows the current [JSON RPC API](https://eth.wiki/json-rpc/A

| Command | Availability | Notes |
| :-------------------------------------- | :----------: | -----------------------------------------: |
| web3_clientVersion | Yes | missing TG gitCommit and Go version |
| web3_clientVersion | Yes | hard-coded (needs ethbackend integration) |
| web3_sha3 | Yes | |
| | | |
| net_listening | Yes | hard-coded |
| net_listening | Yes | hard-coded (needs p2pSentry integration) |
| net_peerCount | Yes | hard-coded (needs p2pSentry integration) |
| net_version | Yes | hard-coded |
| net_version | Yes | hard-coded (needs ethbackend integration) |
| | | |
| eth_blockNumber | Yes | |
| eth_chainId | Yes | |
Expand Down
151 changes: 151 additions & 0 deletions silkrpc/commands/debug_api.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
Copyright 2020 The Silkrpc Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "debug_api.hpp"

#include <string>

#include <silkworm/common/util.hpp>

#include <silkrpc/common/constants.hpp>
#include <silkrpc/common/log.hpp>
#include <silkrpc/common/util.hpp>
#include <silkrpc/ethdb/kv/transaction_database.hpp>
#include <silkrpc/json/types.hpp>

namespace silkrpc::commands {

// https://github.com/ethereum/retesteth/wiki/RPC-Methods#debug_accountrange
asio::awaitable<void> DebugRpcApi::handle_debug_account_range(const nlohmann::json& request, nlohmann::json& reply) {
auto tx = co_await database_->begin();

try {
ethdb::kv::TransactionDatabase tx_database{*tx};

reply = make_json_error(request["id"], 500, "not yet implemented");
} catch (const std::exception& e) {
SILKRPC_ERROR << "exception: " << e.what() << "\n";
reply = make_json_error(request["id"], 100, e.what());
} catch (...) {
SILKRPC_ERROR << "unexpected exception\n";
reply = make_json_error(request["id"], 100, "unexpected exception");
}

co_await tx->close(); // RAII not (yet) available with coroutines
co_return;
}

// https://github.com/ethereum/retesteth/wiki/RPC-Methods#debug_getmodifiedaccountsbynumber
asio::awaitable<void> DebugRpcApi::handle_debug_get_modified_accounts_by_number(const nlohmann::json& request, nlohmann::json& reply) {
auto tx = co_await database_->begin();

try {
ethdb::kv::TransactionDatabase tx_database{*tx};

reply = make_json_error(request["id"], 500, "not yet implemented");
} catch (const std::exception& e) {
SILKRPC_ERROR << "exception: " << e.what() << "\n";
reply = make_json_error(request["id"], 100, e.what());
} catch (...) {
SILKRPC_ERROR << "unexpected exception\n";
reply = make_json_error(request["id"], 100, "unexpected exception");
}

co_await tx->close(); // RAII not (yet) available with coroutines
co_return;
}

// https://github.com/ethereum/retesteth/wiki/RPC-Methods#debug_getmodifiedaccountsbyhash
asio::awaitable<void> DebugRpcApi::handle_debug_get_modified_accounts_by_hash(const nlohmann::json& request, nlohmann::json& reply) {
auto tx = co_await database_->begin();

try {
ethdb::kv::TransactionDatabase tx_database{*tx};

reply = make_json_error(request["id"], 500, "not yet implemented");
} catch (const std::exception& e) {
SILKRPC_ERROR << "exception: " << e.what() << "\n";
reply = make_json_error(request["id"], 100, e.what());
} catch (...) {
SILKRPC_ERROR << "unexpected exception\n";
reply = make_json_error(request["id"], 100, "unexpected exception");
}

co_await tx->close(); // RAII not (yet) available with coroutines
co_return;
}

// https://github.com/ethereum/retesteth/wiki/RPC-Methods#debug_storagerangeat
asio::awaitable<void> DebugRpcApi::handle_debug_storage_range_at(const nlohmann::json& request, nlohmann::json& reply) {
auto tx = co_await database_->begin();

try {
ethdb::kv::TransactionDatabase tx_database{*tx};

reply = make_json_error(request["id"], 500, "not yet implemented");
} catch (const std::exception& e) {
SILKRPC_ERROR << "exception: " << e.what() << "\n";
reply = make_json_error(request["id"], 100, e.what());
} catch (...) {
SILKRPC_ERROR << "unexpected exception\n";
reply = make_json_error(request["id"], 100, "unexpected exception");
}

co_await tx->close(); // RAII not (yet) available with coroutines
co_return;
}

// https://github.com/ethereum/retesteth/wiki/RPC-Methods#debug_tracetransaction
asio::awaitable<void> DebugRpcApi::handle_debug_trace_transaction(const nlohmann::json& request, nlohmann::json& reply) {
auto tx = co_await database_->begin();

try {
ethdb::kv::TransactionDatabase tx_database{*tx};

reply = make_json_error(request["id"], 500, "not yet implemented");
} catch (const std::exception& e) {
SILKRPC_ERROR << "exception: " << e.what() << "\n";
reply = make_json_error(request["id"], 100, e.what());
} catch (...) {
SILKRPC_ERROR << "unexpected exception\n";
reply = make_json_error(request["id"], 100, "unexpected exception");
}

co_await tx->close(); // RAII not (yet) available with coroutines
co_return;
}

// https://github.com/ethereum/retesteth/wiki/RPC-Methods#debug_tracecall
asio::awaitable<void> DebugRpcApi::handle_debug_trace_call(const nlohmann::json& request, nlohmann::json& reply) {
auto tx = co_await database_->begin();

try {
ethdb::kv::TransactionDatabase tx_database{*tx};

reply = make_json_error(request["id"], 500, "not yet implemented");
} catch (const std::exception& e) {
SILKRPC_ERROR << "exception: " << e.what() << "\n";
reply = make_json_error(request["id"], 100, e.what());
} catch (...) {
SILKRPC_ERROR << "unexpected exception\n";
reply = make_json_error(request["id"], 100, "unexpected exception");
}

co_await tx->close(); // RAII not (yet) available with coroutines
co_return;
}

} // namespace silkrpc::commands
59 changes: 59 additions & 0 deletions silkrpc/commands/debug_api.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2020 The Silkrpc Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef SILKRPC_COMMANDS_DEBUG_API_HPP_
#define SILKRPC_COMMANDS_DEBUG_API_HPP_

#include <memory>

#include <silkrpc/config.hpp> // NOLINT(build/include_order)

#include <asio/awaitable.hpp>
#include <nlohmann/json.hpp>

#include <silkrpc/core/rawdb/accessors.hpp>
#include <silkrpc/json/types.hpp>
#include <silkrpc/ethdb/kv/database.hpp>

namespace silkrpc::http { class RequestHandler; }

namespace silkrpc::commands {

class DebugRpcApi {
public:
explicit DebugRpcApi(std::unique_ptr<ethdb::kv::Database>& database) : database_(database) {}
virtual ~DebugRpcApi() {}

DebugRpcApi(const DebugRpcApi&) = delete;
DebugRpcApi& operator=(const DebugRpcApi&) = delete;

protected:
asio::awaitable<void> handle_debug_account_range(const nlohmann::json& request, nlohmann::json& reply);
asio::awaitable<void> handle_debug_get_modified_accounts_by_number(const nlohmann::json& request, nlohmann::json& reply);
asio::awaitable<void> handle_debug_get_modified_accounts_by_hash(const nlohmann::json& request, nlohmann::json& reply);
asio::awaitable<void> handle_debug_storage_range_at(const nlohmann::json& request, nlohmann::json& reply);
asio::awaitable<void> handle_debug_trace_transaction(const nlohmann::json& request, nlohmann::json& reply);
asio::awaitable<void> handle_debug_trace_call(const nlohmann::json& request, nlohmann::json& reply);

private:
std::unique_ptr<ethdb::kv::Database>& database_;

friend class silkrpc::http::RequestHandler;
};

} // namespace silkrpc::commands

#endif // SILKRPC_COMMANDS_DEBUG_API_HPP_
Loading

0 comments on commit a92e4d2

Please sign in to comment.