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

Commit a92e4d2

Browse files
authored
Add full RPC API skeletons to simplify development (#41)
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
1 parent bea88d0 commit a92e4d2

21 files changed

+1833
-192
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,36 @@ We use the standard C++20 programming language. We follow the [Google's C++ Styl
9696
* Exceptions are allowed.
9797
* User-defined literals are allowed.
9898
* Maximum line length is 170, indentation is 4 spaces – see `.clang-format`.
99+
100+
# Activation
101+
102+
From the build folder (`build_[gcc, clang]_[debug, release]` according to your choice) you typically activate Silkrpc using:
103+
104+
```
105+
$ silkrpc/silkrpcdaemon --target <tg_core_host_address>:9090
106+
```
107+
108+
where `<tg_core_host_address>` is the hostname or IP address of the TG Core to connect to.
109+
110+
You can check all command-line parameters supported by Silkrpc using:
111+
112+
```
113+
$ silkrpc/silkrpcdaemon --help
114+
silkrpcdaemon: C++ implementation of ETH JSON Remote Procedure Call (RPC) daemon
115+
116+
Flags from main.cpp:
117+
--chaindata (chain data path as string); default: "";
118+
--local (HTTP JSON local binding as string <address>:<port>);
119+
default: "localhost:8545";
120+
--logLevel (logging level); default: c;
121+
--target (TG Core gRPC service location as string <address>:<port>);
122+
default: "localhost:9090";
123+
--timeout (gRPC call timeout as 32-bit integer); default: 10000;
124+
```
125+
126+
You can also check the Silkrpc executable version by:
127+
128+
```
129+
$ silkrpc/silkrpcdaemon --version
130+
silkrpcdaemon 0.0.3
131+
```

docs/API.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ The following table shows the current [JSON RPC API](https://eth.wiki/json-rpc/A
44

55
| Command | Availability | Notes |
66
| :-------------------------------------- | :----------: | -----------------------------------------: |
7-
| web3_clientVersion | Yes | missing TG gitCommit and Go version |
7+
| web3_clientVersion | Yes | hard-coded (needs ethbackend integration) |
88
| web3_sha3 | Yes | |
99
| | | |
10-
| net_listening | Yes | hard-coded |
10+
| net_listening | Yes | hard-coded (needs p2pSentry integration) |
1111
| net_peerCount | Yes | hard-coded (needs p2pSentry integration) |
12-
| net_version | Yes | hard-coded |
12+
| net_version | Yes | hard-coded (needs ethbackend integration) |
1313
| | | |
1414
| eth_blockNumber | Yes | |
1515
| eth_chainId | Yes | |

silkrpc/commands/debug_api.cpp

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
Copyright 2020 The Silkrpc Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#include "debug_api.hpp"
18+
19+
#include <string>
20+
21+
#include <silkworm/common/util.hpp>
22+
23+
#include <silkrpc/common/constants.hpp>
24+
#include <silkrpc/common/log.hpp>
25+
#include <silkrpc/common/util.hpp>
26+
#include <silkrpc/ethdb/kv/transaction_database.hpp>
27+
#include <silkrpc/json/types.hpp>
28+
29+
namespace silkrpc::commands {
30+
31+
// https://github.com/ethereum/retesteth/wiki/RPC-Methods#debug_accountrange
32+
asio::awaitable<void> DebugRpcApi::handle_debug_account_range(const nlohmann::json& request, nlohmann::json& reply) {
33+
auto tx = co_await database_->begin();
34+
35+
try {
36+
ethdb::kv::TransactionDatabase tx_database{*tx};
37+
38+
reply = make_json_error(request["id"], 500, "not yet implemented");
39+
} catch (const std::exception& e) {
40+
SILKRPC_ERROR << "exception: " << e.what() << "\n";
41+
reply = make_json_error(request["id"], 100, e.what());
42+
} catch (...) {
43+
SILKRPC_ERROR << "unexpected exception\n";
44+
reply = make_json_error(request["id"], 100, "unexpected exception");
45+
}
46+
47+
co_await tx->close(); // RAII not (yet) available with coroutines
48+
co_return;
49+
}
50+
51+
// https://github.com/ethereum/retesteth/wiki/RPC-Methods#debug_getmodifiedaccountsbynumber
52+
asio::awaitable<void> DebugRpcApi::handle_debug_get_modified_accounts_by_number(const nlohmann::json& request, nlohmann::json& reply) {
53+
auto tx = co_await database_->begin();
54+
55+
try {
56+
ethdb::kv::TransactionDatabase tx_database{*tx};
57+
58+
reply = make_json_error(request["id"], 500, "not yet implemented");
59+
} catch (const std::exception& e) {
60+
SILKRPC_ERROR << "exception: " << e.what() << "\n";
61+
reply = make_json_error(request["id"], 100, e.what());
62+
} catch (...) {
63+
SILKRPC_ERROR << "unexpected exception\n";
64+
reply = make_json_error(request["id"], 100, "unexpected exception");
65+
}
66+
67+
co_await tx->close(); // RAII not (yet) available with coroutines
68+
co_return;
69+
}
70+
71+
// https://github.com/ethereum/retesteth/wiki/RPC-Methods#debug_getmodifiedaccountsbyhash
72+
asio::awaitable<void> DebugRpcApi::handle_debug_get_modified_accounts_by_hash(const nlohmann::json& request, nlohmann::json& reply) {
73+
auto tx = co_await database_->begin();
74+
75+
try {
76+
ethdb::kv::TransactionDatabase tx_database{*tx};
77+
78+
reply = make_json_error(request["id"], 500, "not yet implemented");
79+
} catch (const std::exception& e) {
80+
SILKRPC_ERROR << "exception: " << e.what() << "\n";
81+
reply = make_json_error(request["id"], 100, e.what());
82+
} catch (...) {
83+
SILKRPC_ERROR << "unexpected exception\n";
84+
reply = make_json_error(request["id"], 100, "unexpected exception");
85+
}
86+
87+
co_await tx->close(); // RAII not (yet) available with coroutines
88+
co_return;
89+
}
90+
91+
// https://github.com/ethereum/retesteth/wiki/RPC-Methods#debug_storagerangeat
92+
asio::awaitable<void> DebugRpcApi::handle_debug_storage_range_at(const nlohmann::json& request, nlohmann::json& reply) {
93+
auto tx = co_await database_->begin();
94+
95+
try {
96+
ethdb::kv::TransactionDatabase tx_database{*tx};
97+
98+
reply = make_json_error(request["id"], 500, "not yet implemented");
99+
} catch (const std::exception& e) {
100+
SILKRPC_ERROR << "exception: " << e.what() << "\n";
101+
reply = make_json_error(request["id"], 100, e.what());
102+
} catch (...) {
103+
SILKRPC_ERROR << "unexpected exception\n";
104+
reply = make_json_error(request["id"], 100, "unexpected exception");
105+
}
106+
107+
co_await tx->close(); // RAII not (yet) available with coroutines
108+
co_return;
109+
}
110+
111+
// https://github.com/ethereum/retesteth/wiki/RPC-Methods#debug_tracetransaction
112+
asio::awaitable<void> DebugRpcApi::handle_debug_trace_transaction(const nlohmann::json& request, nlohmann::json& reply) {
113+
auto tx = co_await database_->begin();
114+
115+
try {
116+
ethdb::kv::TransactionDatabase tx_database{*tx};
117+
118+
reply = make_json_error(request["id"], 500, "not yet implemented");
119+
} catch (const std::exception& e) {
120+
SILKRPC_ERROR << "exception: " << e.what() << "\n";
121+
reply = make_json_error(request["id"], 100, e.what());
122+
} catch (...) {
123+
SILKRPC_ERROR << "unexpected exception\n";
124+
reply = make_json_error(request["id"], 100, "unexpected exception");
125+
}
126+
127+
co_await tx->close(); // RAII not (yet) available with coroutines
128+
co_return;
129+
}
130+
131+
// https://github.com/ethereum/retesteth/wiki/RPC-Methods#debug_tracecall
132+
asio::awaitable<void> DebugRpcApi::handle_debug_trace_call(const nlohmann::json& request, nlohmann::json& reply) {
133+
auto tx = co_await database_->begin();
134+
135+
try {
136+
ethdb::kv::TransactionDatabase tx_database{*tx};
137+
138+
reply = make_json_error(request["id"], 500, "not yet implemented");
139+
} catch (const std::exception& e) {
140+
SILKRPC_ERROR << "exception: " << e.what() << "\n";
141+
reply = make_json_error(request["id"], 100, e.what());
142+
} catch (...) {
143+
SILKRPC_ERROR << "unexpected exception\n";
144+
reply = make_json_error(request["id"], 100, "unexpected exception");
145+
}
146+
147+
co_await tx->close(); // RAII not (yet) available with coroutines
148+
co_return;
149+
}
150+
151+
} // namespace silkrpc::commands

silkrpc/commands/debug_api.hpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright 2020 The Silkrpc Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#ifndef SILKRPC_COMMANDS_DEBUG_API_HPP_
18+
#define SILKRPC_COMMANDS_DEBUG_API_HPP_
19+
20+
#include <memory>
21+
22+
#include <silkrpc/config.hpp> // NOLINT(build/include_order)
23+
24+
#include <asio/awaitable.hpp>
25+
#include <nlohmann/json.hpp>
26+
27+
#include <silkrpc/core/rawdb/accessors.hpp>
28+
#include <silkrpc/json/types.hpp>
29+
#include <silkrpc/ethdb/kv/database.hpp>
30+
31+
namespace silkrpc::http { class RequestHandler; }
32+
33+
namespace silkrpc::commands {
34+
35+
class DebugRpcApi {
36+
public:
37+
explicit DebugRpcApi(std::unique_ptr<ethdb::kv::Database>& database) : database_(database) {}
38+
virtual ~DebugRpcApi() {}
39+
40+
DebugRpcApi(const DebugRpcApi&) = delete;
41+
DebugRpcApi& operator=(const DebugRpcApi&) = delete;
42+
43+
protected:
44+
asio::awaitable<void> handle_debug_account_range(const nlohmann::json& request, nlohmann::json& reply);
45+
asio::awaitable<void> handle_debug_get_modified_accounts_by_number(const nlohmann::json& request, nlohmann::json& reply);
46+
asio::awaitable<void> handle_debug_get_modified_accounts_by_hash(const nlohmann::json& request, nlohmann::json& reply);
47+
asio::awaitable<void> handle_debug_storage_range_at(const nlohmann::json& request, nlohmann::json& reply);
48+
asio::awaitable<void> handle_debug_trace_transaction(const nlohmann::json& request, nlohmann::json& reply);
49+
asio::awaitable<void> handle_debug_trace_call(const nlohmann::json& request, nlohmann::json& reply);
50+
51+
private:
52+
std::unique_ptr<ethdb::kv::Database>& database_;
53+
54+
friend class silkrpc::http::RequestHandler;
55+
};
56+
57+
} // namespace silkrpc::commands
58+
59+
#endif // SILKRPC_COMMANDS_DEBUG_API_HPP_

0 commit comments

Comments
 (0)