Updated websocket client invalid view (#1533)

This commit is contained in:
Alex 2020-08-27 15:48:07 +01:00 коммит произвёл GitHub
Родитель e42b511983
Коммит 407caf673d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 22 добавлений и 14 удалений

Просмотреть файл

@ -3,6 +3,7 @@
import contextlib
import json
import time
import sys
import os
import subprocess
import tempfile
@ -174,6 +175,13 @@ def get_curve(ca_file):
)
def unpack_seqno_or_view(data):
(value,) = struct.unpack("<q", data)
if value == -sys.maxsize - 1:
return None
return value
class CurlClient:
"""
This client uses Curl to send HTTP requests to CCF, and logs all Curl commands it runs.
@ -439,9 +447,9 @@ class WSClient:
self.ws.send_frame(frame)
out = self.ws.recv_frame().data
(status_code,) = struct.unpack("<h", out[:2])
(seqno,) = struct.unpack("<Q", out[2:10])
(view,) = struct.unpack("<Q", out[10:18])
(global_commit,) = struct.unpack("<Q", out[18:26])
seqno = unpack_seqno_or_view(out[2:10])
view = unpack_seqno_or_view(out[10:18])
global_commit = unpack_seqno_or_view(out[18:26])
payload = out[26:]
if status_code == 200:
body = json.loads(payload) if payload else None

Просмотреть файл

@ -13,9 +13,9 @@ namespace ws
static std::vector<uint8_t> serialise(
size_t code,
const std::vector<uint8_t>& body,
kv::Version seqno = 0,
kv::Consensus::View view = 0,
kv::Version global_commit = 0)
kv::Version seqno = kv::NoVersion,
kv::Consensus::View view = ccf::VIEW_UNKNOWN,
kv::Version global_commit = kv::NoVersion)
{
return make_out_frame(code, seqno, view, global_commit, body);
};

Просмотреть файл

@ -65,12 +65,12 @@ TEST_CASE("edge cases")
INFO("Unknown views");
// Impossible: view for all global txs must be known
// get_tx_status(a, N, 0, b, >=N)
CHECK_THROWS(get_tx_status(3, 10, -1, 1, 10));
CHECK_THROWS(get_tx_status(3, 10, -1, 1, 11));
CHECK_THROWS(get_tx_status(3, 10, -1, 3, 10));
CHECK_THROWS(get_tx_status(3, 10, -1, 3, 11));
CHECK_THROWS(get_tx_status(3, 10, -1, 4, 10));
CHECK_THROWS(get_tx_status(3, 10, -1, 4, 11));
CHECK_THROWS(get_tx_status(3, 10, VIEW_UNKNOWN, 1, 10));
CHECK_THROWS(get_tx_status(3, 10, VIEW_UNKNOWN, 1, 11));
CHECK_THROWS(get_tx_status(3, 10, VIEW_UNKNOWN, 3, 10));
CHECK_THROWS(get_tx_status(3, 10, VIEW_UNKNOWN, 3, 11));
CHECK_THROWS(get_tx_status(3, 10, VIEW_UNKNOWN, 4, 10));
CHECK_THROWS(get_tx_status(3, 10, VIEW_UNKNOWN, 4, 11));
}
{
INFO("seqno is known locally in an old view");

Просмотреть файл

@ -48,7 +48,7 @@ namespace ccf
{TxStatus::Committed, tx_status_to_str(TxStatus::Committed)},
{TxStatus::Invalid, tx_status_to_str(TxStatus::Invalid)}});
constexpr int64_t VIEW_UNKNOWN = -1;
constexpr int64_t VIEW_UNKNOWN = std::numeric_limits<int64_t>::min();
static TxStatus get_tx_status(
int64_t target_view,

Просмотреть файл

@ -34,7 +34,7 @@ class Checker:
result, rpc_result.body
)
assert rpc_result.seqno and rpc_result.view, rpc_result
assert rpc_result.seqno >= 0 and rpc_result.view >= 0, rpc_result
if self.client:
wait_for_commit(self.client, rpc_result.seqno, rpc_result.view)