Skip to content

Master #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plenum/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
# ROLES
STEWARD = Roles.STEWARD.value
TRUSTEE = Roles.TRUSTEE.value
STEWARD_STRING = 'STEWARD'

# TXNs
NODE = PlenumTransactions.NODE.value
Expand Down Expand Up @@ -169,6 +170,7 @@ class LedgerState(IntEnum):
POOL_LEDGER_ID = 0
DOMAIN_LEDGER_ID = 1
CONFIG_LEDGER_ID = 2
INVALID_LEDGER_ID = 5908

VALID_LEDGER_IDS = (POOL_LEDGER_ID, DOMAIN_LEDGER_ID, CONFIG_LEDGER_ID)

Expand Down Expand Up @@ -196,3 +198,6 @@ class ReplicaHooks(UniqueSet):
RECV_PPR = 5
RECV_PR = 6
RECV_CM = 7


INVALID_SEQ_NO = -23
16 changes: 16 additions & 0 deletions plenum/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,19 @@ def __init__(self, expLen, actLen, *args, **kwargs):
ex_txt = 'Message len {} exceeded allowed limit of {}'.format(
actLen, expLen)
super().__init__(ex_txt, *args, **kwargs)


class RequestNackedException(Exception):
pass


class RequestRejectedException(Exception):
pass


class CommonSdkIOException(Exception):
pass


class PoolLedgerTimeoutException(Exception):
pass
2 changes: 1 addition & 1 deletion plenum/common/messages/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class NetworkPortField(FieldBase):
_base_types = (int,)

def _specific_validation(self, val):
if val < 0 or val > 65535:
if val <= 0 or val > 65535:
return 'network port out of the range 0-65535'


Expand Down
13 changes: 8 additions & 5 deletions plenum/server/pool_req_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def authErrorWhileAddingNode(self, request):
origin)
if self.stewardHasNode(origin):
return "{} already has a node".format(origin)
if self.isNodeDataConflicting(operation.get(DATA, {})):
if self.isNodeDataConflicting(data):
return "existing data has conflicts with " \
"request data {}".format(operation.get(DATA))

Expand Down Expand Up @@ -156,14 +156,14 @@ def isNodeDataSame(self, nodeNym, newData, isCommitted=True):
nodeInfo.pop(f.IDENTIFIER.nm, None)
return nodeInfo == newData

def isNodeDataConflicting(self, data, nodeNym=None):
def isNodeDataConflicting(self, data, updatingNym=None):
# Check if node's ALIAS or IPs or ports conflicts with other nodes,
# also, the node is not allowed to change its alias.

# Check ALIAS change
nodeData = {}
if nodeNym:
nodeData = self.getNodeData(nodeNym, isCommitted=False)
if updatingNym:
nodeData = self.getNodeData(updatingNym, isCommitted=False)
if nodeData.get(ALIAS) != data.get(ALIAS):
return True
else:
Expand All @@ -177,7 +177,7 @@ def isNodeDataConflicting(self, data, nodeNym=None):
otherNodeData = self.stateSerializer.deserialize(otherNodeData)
otherNodeData.pop(f.IDENTIFIER.nm, None)
otherNodeData.pop(SERVICES, None)
if not nodeNym or otherNode != nodeNym:
if not updatingNym or otherNode != updatingNym:
# The node's ip, port and alias shuuld be unique
bag = set()
for d in (nodeData, otherNodeData):
Expand All @@ -191,6 +191,9 @@ def isNodeDataConflicting(self, data, nodeNym=None):
if (not nodeData and len(bag) != 3) or (
nodeData and len(bag) != 6):
return True
if data.get(ALIAS) == otherNodeData.get(
ALIAS) and not updatingNym:
return True

def dataErrorWhileValidatingUpdate(self, data, nodeNym):
error = self.dataErrorWhileValidating(data, skipKeys=True)
Expand Down
38 changes: 17 additions & 21 deletions plenum/test/batching_3pc/test_batch_rejection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@
from stp_core.loop.eventually import eventually
from plenum.common.constants import DOMAIN_LEDGER_ID
from plenum.common.util import updateNamedTuple
from plenum.test.helper import sendRandomRequests, \
waitForSufficientRepliesForRequests
from plenum.test.test_node import getNonPrimaryReplicas, getPrimaryReplica
from plenum.test.helper import sdk_send_random_requests, \
sdk_send_random_and_check
from plenum.test.test_node import getNonPrimaryReplicas, \
getPrimaryReplica


@pytest.fixture(scope="module")
def setup(tconf, looper, txnPoolNodeSet, client, wallet1):
def setup(tconf, looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client):
# Patch the 3phase request sending method to send incorrect digest and
pr, otherR = getPrimaryReplica(txnPoolNodeSet, instId=0), \
getNonPrimaryReplicas(txnPoolNodeSet, instId=0)

reqs = sendRandomRequests(wallet1, client, tconf.Max3PCBatchSize)
waitForSufficientRepliesForRequests(
looper,
client,
requests=reqs,
customTimeoutPerReq=tconf.Max3PCBatchWait)
getNonPrimaryReplicas(txnPoolNodeSet, instId=0)

sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
sdk_wallet_client, tconf.Max3PCBatchSize)
stateRoot = pr.stateRootHash(DOMAIN_LEDGER_ID, to_str=False)

origMethod = pr.create3PCBatch
Expand All @@ -36,7 +33,8 @@ def badMethod(self, ledgerId):
return pp

pr.create3PCBatch = types.MethodType(badMethod, pr)
sendRandomRequests(wallet1, client, tconf.Max3PCBatchSize)
sdk_send_random_requests(looper, sdk_pool_handle, sdk_wallet_client,
tconf.Max3PCBatchSize)
return pr, otherR, stateRoot


Expand Down Expand Up @@ -75,15 +73,13 @@ def testViewChangeAfterBatchRejected(viewChanged):
"""


def testMoreBatchesWillBeSentAfterViewChange(reverted, viewChanged, wallet1,
client, tconf, looper):
def testMoreBatchesWillBeSentAfterViewChange(reverted, viewChanged,
txnPoolNodeSet,
sdk_pool_handle, sdk_wallet_client,
tconf, looper):
"""
After retrying discarded batches, new batches are sent
:return:
"""
reqs = sendRandomRequests(wallet1, client, tconf.Max3PCBatchSize)
waitForSufficientRepliesForRequests(
looper,
client,
requests=reqs,
customTimeoutPerReq=tconf.Max3PCBatchWait)
sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
sdk_wallet_client, tconf.Max3PCBatchSize)
18 changes: 12 additions & 6 deletions plenum/test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from plenum.client.wallet import Wallet
from plenum.common.constants import DOMAIN_LEDGER_ID, OP_FIELD_NAME, REPLY, REQACK, REQNACK, REJECT, \
CURRENT_PROTOCOL_VERSION
from plenum.common.exceptions import RequestNackedException, RequestRejectedException, CommonSdkIOException, \
PoolLedgerTimeoutException
from plenum.common.messages.node_messages import Reply, PrePrepare, Prepare, Commit
from plenum.common.types import f
from plenum.common.util import getNoInstances, get_utc_epoch
Expand Down Expand Up @@ -1057,14 +1059,18 @@ def get_res(task, done_list):
def sdk_check_reply(req_res):
req, res = req_res
if isinstance(res, ErrorCode):
raise AssertionError("Got an error with code {} for request {}"
.format(res, req))
if res == 307:
raise PoolLedgerTimeoutException('Got PoolLedgerTimeout for request {}'
.format(req))
else:
raise CommonSdkIOException('Got an error with code {} for request {}'
.format(res, req))
if res['op'] == REQNACK:
raise AssertionError("ReqNack of id {}. Reason: {}"
.format(req['reqId'], res['reason']))
raise RequestNackedException('ReqNack of id {}. Reason: {}'
.format(req['reqId'], res['reason']))
if res['op'] == REJECT:
raise AssertionError("Reject of id {}. Reason: {}"
.format(req['reqId'], res['reason']))
raise RequestRejectedException('Reject of id {}. Reason: {}'
.format(req['reqId'], res['reason']))


def sdk_get_and_check_replies(looper, sdk_req_resp: Sequence, timeout=None):
Expand Down
4 changes: 2 additions & 2 deletions plenum/test/input_validation/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ class NetworkPortField(TestFieldBase):

@property
def negative_test_cases(self):
return -1, 65535 + 1
return 0, -1, 65535 + 1

@property
def positive_test_cases(self):
return 0, 9700, 65535
return 0 + 1, 9700, 65535


class NetworkIpAddressField(TestFieldBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_different_ledger_request_interleave(tconf, looper, txnPoolNodeSet,
sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort = \
prepare_new_node_data(tconf, tdir, next_node_name)
node_req = looper.loop.run_until_complete(
prepare_node_request(next_node_name, steward_did, clientIp,
prepare_node_request(steward_did, next_node_name, clientIp,
clientPort, nodeIp, nodePort, bls_key,
sigseed))

Expand Down
3 changes: 1 addition & 2 deletions plenum/test/pool_transactions/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def sdk_node_theta_added(looper,
new_node_name,
tdir,
tconf,
allPluginsPath,
nodeClass=testNodeClass)
allPluginsPath)
txnPoolNodeSet.append(new_node)
looper.run(checkNodesConnected(txnPoolNodeSet))
sdk_pool_refresh(looper, sdk_pool_handle)
Expand Down
Loading