13 const std::pair<uint8_t, uint8_t>& output_range,
17 m_client = std::make_unique<decltype(m_client)::element_type>(
18 std::move(endpoints));
26 return m_client->init();
30 -> std::optional<std::vector<bool>> {
31 auto req =
request{dtx_id, std::move(txs)};
32 auto resp = send_request(req);
33 if(!resp.has_value()) {
36 return std::get<lock_response>(resp.value());
40 const hash_t& dtx_id) ->
bool {
41 auto req =
request{dtx_id, std::move(complete_txs)};
42 auto res = send_request(req);
43 return res.has_value();
48 auto res = send_request(req);
49 return res.has_value();
52 auto client::send_request(
const request& req) -> std::optional<response> {
53 auto result_timeout = std::chrono::seconds(3);
54 constexpr auto max_result_timeout = std::chrono::seconds(10);
55 constexpr auto retry_delay = std::chrono::seconds(1);
56 auto res = std::optional<response>();
57 while(m_running && !res.has_value()) {
58 res = m_client->call(req, result_timeout);
59 if(!res.has_value()) {
60 m_log.warn(
"Shard request failed");
62 std::this_thread::sleep_for(retry_delay);
64 = std::min(max_result_timeout, result_timeout * 2);
Interface for a locking shard.
void stop() override
Shuts down the client and unblocks any existing requests waiting for a response.
auto lock_outputs(std::vector< tx > &&txs, const hash_t &dtx_id) -> std::optional< std::vector< bool > > override
Issues a lock RPC to the remote shard and returns its response.
auto init() -> bool
Initializes the RPC client.
auto discard_dtx(const hash_t &dtx_id) -> bool override
Issues a discard RPC to the remote shard and returns its response.
auto apply_outputs(std::vector< bool > &&complete_txs, const hash_t &dtx_id) -> bool override
Issues an apply RPC to the remote shard and returns its response.
Generalized logging class.
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
Empty type for discard command parameters.