Skip to content

Commit 4fa6e55

Browse files
authored
Merge pull request #94 from hyperledger/master
Master
2 parents ff3b654 + 199d930 commit 4fa6e55

File tree

70 files changed

+1254
-762
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1254
-762
lines changed

Jenkinsfile.ci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test(options=[:]) {
8989

9090
try {
9191
if (options.useRunner) {
92-
sh "PYTHONASYNCIODEBUG='0' $options.python runner.py --pytest \"$options.python -m pytest\" --dir $options.testDir --output \"$options.resFile\" --test-only-slice \"$options.testOnlySlice\""
92+
sh "RUSTPYTHONASYNCIODEBUG='0' $options.python runner.py --pytest \"$options.python -m pytest\" --dir $options.testDir --output \"$options.resFile\" --test-only-slice \"$options.testOnlySlice\""
9393
} else {
9494
sh "$options.python -m pytest --junitxml=$options.resFile $options.testDir"
9595
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2016 Sovrin Foundation
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

ci/code-validation.dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ RUN apt-get update -y && apt-get install -y \
1111
python3-pip \
1212
python-setuptools \
1313
python3-nacl
14-
RUN pip3 install -U \
15-
pip \
14+
RUN pip3 install -U \
1615
setuptools \
1716
pep8 \
1817
pep8-naming \

ci/ubuntu.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ RUN echo "To invalidate cache"
99

1010
RUN apt-get update -y && apt-get install -y \
1111
python3-nacl \
12-
libindy-crypto=0.2.0 \
13-
libindy=1.3.1~403 \
12+
libindy-crypto=0.4.0 \
13+
libindy=1.3.1~469 \
1414
# rocksdb python wrapper
1515
libbz2-dev \
1616
zlib1g-dev \

plenum/cli/cli.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -927,14 +927,10 @@ def newNode(self, nodeName: str):
927927
nodes = []
928928
for name in names:
929929
try:
930-
nodeRegistry = None if self.nodeRegLoadedFromFile \
931-
else self.nodeRegistry
932-
933930
config_helper = PNodeConfigHelper(name, self.config, chroot=self.nodes_chroot)
934931
learnKeysFromOthers(config_helper.keys_dir, name,
935932
self.nodes.values())
936933
node = self.NodeClass(name,
937-
nodeRegistry=nodeRegistry,
938934
config_helper=config_helper,
939935
pluginPaths=self.pluginPaths,
940936
config=self.config)

plenum/common/ledger.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ def discardTxns(self, count: int):
8181
self.uncommittedTree = self.treeWithAppliedTxns(
8282
self.uncommittedTxns)
8383
self.uncommittedRootHash = self.uncommittedTree.root_hash
84-
logger.debug('Discarding {} txns and root hash {} and new root hash '
85-
'is {}. {} are still uncommitted'.
86-
format(count, old_hash, self.uncommittedRootHash,
87-
len(self.uncommittedTxns)))
84+
logger.info('Discarding {} txns and root hash {} and new root hash '
85+
'is {}. {} are still uncommitted'.
86+
format(count, old_hash, self.uncommittedRootHash,
87+
len(self.uncommittedTxns)))
8888

8989
def treeWithAppliedTxns(self, txns: List, currentTree=None):
9090
"""

plenum/common/ledger_manager.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def request_CPs_if_needed(self, ledgerId):
100100

101101
quorum = Quorums(self.owner.totalNodes)
102102
groupedProofs, null_proofs_count = self._groupConsistencyProofs(proofs)
103-
if quorum.same_consistency_proof.is_reached(null_proofs_count):
103+
if quorum.same_consistency_proof.is_reached(null_proofs_count)\
104+
or len(groupedProofs) == 0:
104105
return
105106
result = self._latestReliableProof(groupedProofs, ledgerInfo.ledger)
106107
if not result:
@@ -723,6 +724,7 @@ def canStartCatchUpProcess(self, ledgerId: int):
723724
# from other nodes, see `request_CPs_if_needed`
724725

725726
ledgerInfo.consistencyProofsTimer = time.perf_counter()
727+
# TODO: find appropriate moment to unschedule this event!
726728
self._schedule(partial(self.request_CPs_if_needed, ledgerId),
727729
self.config.ConsistencyProofsTimeout * (
728730
self.owner.totalNodes - 1))
@@ -1017,7 +1019,7 @@ def _buildConsistencyProof(self, ledgerId, seqNoStart, seqNoEnd):
10171019
.format(self, seqNoEnd, ledgerSize))
10181020
return
10191021
if seqNoEnd < seqNoStart:
1020-
self.error(
1022+
logger.error(
10211023
'{} cannot build consistency proof since end {} is '
10221024
'lesser than start {}'.format(
10231025
self, seqNoEnd, seqNoStart))
@@ -1090,8 +1092,8 @@ def appendToLedger(self, ledgerId: int, txn: Any) -> Dict:
10901092
return ledgerInfo.ledger.append(txn)
10911093

10921094
def stashLedgerStatus(self, ledgerId: int, status, frm: str):
1093-
logger.debug("{} stashing ledger status {} from {}".
1094-
format(self, status, frm))
1095+
logger.info("{} stashing ledger status {} from {}".
1096+
format(self, status, frm))
10951097
ledgerInfo = self.getLedgerInfoByType(ledgerId)
10961098
ledgerInfo.stashedLedgerStatuses.append((status, frm))
10971099

plenum/common/messages/fields.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,28 @@ def _specific_validation(self, val):
194194
class IterableField(FieldBase):
195195
_base_types = (list, tuple)
196196

197-
def __init__(self, inner_field_type: FieldValidator, **kwargs):
197+
def __init__(self, inner_field_type: FieldValidator, min_length=None,
198+
max_length=None, **kwargs):
198199
assert inner_field_type
199200
assert isinstance(inner_field_type, FieldValidator)
201+
for m in (min_length, max_length):
202+
if m is not None:
203+
assert isinstance(m, int)
204+
assert m > 0
200205

201206
self.inner_field_type = inner_field_type
207+
self.min_length = min_length
208+
self.max_length = max_length
202209
super().__init__(**kwargs)
203210

204211
def _specific_validation(self, val):
212+
if self.min_length is not None:
213+
if len(val) < self.min_length:
214+
return 'length should be at least {}'.format(self.min_length)
215+
if self.max_length is not None:
216+
if len(val) > self.max_length:
217+
return 'length should be at most {}'.format(self.max_length)
218+
205219
for v in val:
206220
check_er = self.inner_field_type.validate(v)
207221
if check_er:

plenum/common/messages/node_messages.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from typing import TypeVar, NamedTuple
22

3-
from plenum.common.constants import NOMINATE, BATCH, REELECTION, PRIMARY, BLACKLIST, REQACK, REQNACK, REJECT, \
4-
POOL_LEDGER_TXNS, ORDERED, PROPAGATE, PREPREPARE, PREPARE, COMMIT, CHECKPOINT, THREE_PC_STATE, CHECKPOINT_STATE, \
5-
REPLY, INSTANCE_CHANGE, LEDGER_STATUS, CONSISTENCY_PROOF, CATCHUP_REQ, CATCHUP_REP, VIEW_CHANGE_DONE, CURRENT_STATE, \
3+
from plenum.common.constants import NOMINATE, BATCH, REELECTION, PRIMARY, \
4+
BLACKLIST, REQACK, REQNACK, REJECT, \
5+
POOL_LEDGER_TXNS, ORDERED, PROPAGATE, PREPREPARE, PREPARE, COMMIT, \
6+
CHECKPOINT, THREE_PC_STATE, CHECKPOINT_STATE, \
7+
REPLY, INSTANCE_CHANGE, LEDGER_STATUS, CONSISTENCY_PROOF, CATCHUP_REQ, \
8+
CATCHUP_REP, VIEW_CHANGE_DONE, CURRENT_STATE, \
69
MESSAGE_REQUEST, MESSAGE_RESPONSE, OBSERVED_DATA, BATCH_COMMITTED
710
from plenum.common.messages.client_request import ClientMessageValidator
811
from plenum.common.messages.fields import NonNegativeNumberField, IterableField, \

plenum/common/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class f: # provides a namespace for reusable field constants
4545
ELECTION_DATA = Field('electionData', Any)
4646
TXN_ID = Field('txnId', str)
4747
REASON = Field('reason', Any)
48+
IS_SUCCESS = Field('isSuccess', Any)
4849
SENDER_CLIENT = Field('senderClient', str)
4950
PP_TIME = Field("ppTime", float)
5051
REQ_IDR = Field("reqIdr", List[Tuple[str, int]])

plenum/config.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686

8787
# Monitoring configuration
8888
PerfCheckFreq = 10
89+
UnorderedCheckFreq = 60
8990

9091
# Temporarily reducing DELTA till the calculations for extra work are not
9192
# incorporated
@@ -100,17 +101,19 @@
100101
LatencyGraphDuration = 240
101102
notifierEventTriggeringConfig = {
102103
'clusterThroughputSpike': {
103-
'coefficient': 3,
104-
'minCnt': 100,
104+
'borders_coeff': 10,
105+
'min_cnt': 15,
105106
'freq': 60,
106-
'minActivityThreshold': 2,
107+
'min_activity_threshold': 10,
108+
'use_weighted_borders_coeff': True,
107109
'enabled': True
108110
},
109111
'nodeRequestSpike': {
110-
'coefficient': 3,
111-
'minCnt': 100,
112+
'borders_coeff': 10,
113+
'min_cnt': 15,
112114
'freq': 60,
113-
'minActivityThreshold': 2,
115+
'min_activity_threshold': 10,
116+
'use_weighted_borders_coeff': True,
114117
'enabled': True
115118
}
116119
}
@@ -149,10 +152,11 @@
149152

150153

151154
# Log configuration
152-
logRotationWhen = 'D'
155+
logRotationWhen = 'W6'
153156
logRotationInterval = 1
154-
logRotationBackupCount = 10
157+
logRotationBackupCount = 50
155158
logRotationMaxBytes = 100 * 1024 * 1024
159+
logRotationCompress = True
156160
logFormat = '{asctime:s} | {levelname:8s} | {filename:20s} ({lineno: >4}) | {funcName:s} | {message:s}'
157161
logFormatStyle = '{'
158162
logLevel = logging.NOTSET

plenum/server/action_req_handler.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from plenum.common.request import Request
2+
from plenum.server.req_handler import RequestHandler
3+
4+
5+
class ActionReqHandler(RequestHandler):
6+
def __init__(self):
7+
super().__init__()
8+
9+
def doStaticValidation(self, request: Request):
10+
pass
11+
12+
def validate(self, req: Request):
13+
pass
14+
15+
def apply(self, req: Request, cons_time: int):
16+
pass

plenum/server/client_authn.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
InsufficientSignatures, InsufficientCorrectSignatures
1515
from plenum.common.types import f
1616
from plenum.common.verifier import DidVerifier, Verifier
17+
from plenum.server.action_req_handler import ActionReqHandler
1718
from plenum.server.domain_req_handler import DomainRequestHandler
1819
from plenum.server.pool_req_handler import PoolRequestHandler
1920
from stp_core.common.log import getlogger
@@ -179,13 +180,18 @@ class CoreAuthMixin:
179180
).union(
180181
DomainRequestHandler.query_types
181182
)
183+
action_types = ActionReqHandler.operation_types
182184

183185
def is_query(self, typ):
184186
return typ in self.query_types
185187

186188
def is_write(self, typ):
187189
return typ in self.write_types
188190

191+
@classmethod
192+
def is_action(cls, typ):
193+
return typ in cls.action_types
194+
189195
@staticmethod
190196
def _extract_signature(msg):
191197
if f.SIG.nm not in msg:

plenum/server/config_req_handler.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
from plenum.server.req_handler import RequestHandler
1+
from plenum.common.request import Request
2+
from plenum.server.ledger_req_handler import LedgerRequestHandler
23

34

4-
class ConfigReqHandler(RequestHandler):
5+
class ConfigReqHandler(LedgerRequestHandler):
56
def __init__(self, ledger, state):
67
super().__init__(ledger, state)
8+
9+
def doStaticValidation(self, request: Request):
10+
pass
11+
12+
def get_query_response(self, request):
13+
pass
14+
15+
def validate(self, req: Request):
16+
pass
17+
18+
def apply(self, req: Request, cons_time: int):
19+
pass

plenum/server/domain_req_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
from plenum.common.txn_util import reqToTxn
1212
from plenum.common.types import f
1313
from plenum.persistence.util import txnsWithSeqNo
14+
from plenum.server.ledger_req_handler import LedgerRequestHandler
1415
from plenum.server.req_handler import RequestHandler
1516
from stp_core.common.log import getlogger
1617

1718
logger = getlogger()
1819

1920

20-
class DomainRequestHandler(RequestHandler):
21+
class DomainRequestHandler(LedgerRequestHandler):
2122
stateSerializer = domain_state_serializer
2223
write_types = {NYM, }
2324

plenum/server/ledger_req_handler.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from abc import ABCMeta, abstractmethod
2+
from typing import List
3+
4+
import base58
5+
6+
from plenum.common.ledger import Ledger
7+
from plenum.common.request import Request
8+
from plenum.persistence.util import txnsWithSeqNo
9+
from plenum.server.req_handler import RequestHandler
10+
from stp_core.common.log import getlogger
11+
12+
from state.state import State
13+
14+
logger = getlogger()
15+
16+
17+
class LedgerRequestHandler(RequestHandler, metaclass=ABCMeta):
18+
"""
19+
Base class for request handlers
20+
Declares methods for validation, application of requests and
21+
state control
22+
"""
23+
24+
query_types = set()
25+
write_types = set()
26+
27+
def __init__(self, ledger: Ledger, state: State):
28+
self.state = state
29+
self.ledger = ledger
30+
31+
def updateState(self, txns, isCommitted=False):
32+
"""
33+
Updates current state with a number of committed or
34+
not committed transactions
35+
"""
36+
37+
def commit(self, txnCount, stateRoot, txnRoot, ppTime) -> List:
38+
"""
39+
:param txnCount: The number of requests to commit (The actual requests
40+
are picked up from the uncommitted list from the ledger)
41+
:param stateRoot: The state trie root after the txns are committed
42+
:param txnRoot: The txn merkle root after the txns are committed
43+
44+
:return: list of committed transactions
45+
"""
46+
47+
(seqNoStart, seqNoEnd), committedTxns = \
48+
self.ledger.commitTxns(txnCount)
49+
stateRoot = base58.b58decode(stateRoot.encode())
50+
# Probably the following assertion fail should trigger catchup
51+
assert self.ledger.root_hash == txnRoot, '{} {}'.format(
52+
self.ledger.root_hash, txnRoot)
53+
self.state.commit(rootHash=stateRoot)
54+
return txnsWithSeqNo(seqNoStart, seqNoEnd, committedTxns)
55+
56+
def onBatchCreated(self, state_root):
57+
pass
58+
59+
def onBatchRejected(self):
60+
pass
61+
62+
@abstractmethod
63+
def doStaticValidation(self, request: Request):
64+
pass
65+
66+
def is_query(self, txn_type):
67+
return txn_type in self.query_types
68+
69+
def get_query_response(self, request):
70+
raise NotImplementedError
71+
72+
@staticmethod
73+
def transform_txn_for_ledger(txn):
74+
return txn
75+
76+
@property
77+
def operation_types(self) -> set:
78+
return self.write_types.union(self.query_types)

0 commit comments

Comments
 (0)