Skip to content

Commit 645b812

Browse files
author
Nikita Khateev
committed
Merge branch 'master' of github.com:hyperledger/indy-plenum
2 parents b5cb01b + 653eb2f commit 645b812

File tree

62 files changed

+1674
-548
lines changed

Some content is hidden

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

62 files changed

+1674
-548
lines changed

docs/source/diagrams/catchup-procedure.puml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ opt last_caught_up_3PC > Master's last_ordered_3pc
239239
note right Node4
240240
<b>Clear following replica's collections:
241241
- batches <i>- up to last_caught_up_3PC,
242-
- sentPrePrepares <i>- up to last_caught_up_3PC,
242+
- sent_preprepares <i>- up to last_caught_up_3PC,
243243
- prePrepares <i>- up to last_caught_up_3PC,
244244
- prepares <i>- up to last_caught_up_3PC,
245245
- commits <i>- up to last_caught_up_3PC,
@@ -275,7 +275,7 @@ opt last_caught_up_3PC > Master's last_ordered_3pc
275275
note right Node4
276276
<b>Clear following replica's collections completely:
277277
- batches,
278-
- sentPrePrepares,
278+
- sent_preprepares,
279279
- prePrepares,
280280
- prepares,
281281
- commits,

docs/source/diagrams/checkpoints.puml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ note right of Node4
217217
<b>Garbage collection</b> removes messages up to
218218
(current view_no, stabilized checkpoint seq_no_end) from following replica's
219219
collections:
220-
- sentPrePrepares,
220+
- sent_preprepares,
221221
- prePrepares,
222222
- prepares,
223223
- commits,

plenum/common/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
PROPAGATE = "PROPAGATE"
2323

2424
PREPREPARE = "PREPREPARE"
25+
OLD_VIEW_PREPREPARE_REQ = "OLD_VIEW_PREPREPARE_REQ"
26+
OLD_VIEW_PREPREPARE_REP = "OLD_VIEW_PREPREPARE_REP"
2527
PREPARE = "PREPARE"
2628
COMMIT = "COMMIT"
2729
CHECKPOINT = "CHECKPOINT"

plenum/common/exceptions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# - review the list and remove obsolete ones
55
# - refactor hierarchy of exceptions taking into account ones
66
# from common/exceptions.py
7+
from typing import Any, Callable
78

89
from common.exceptions import LogicError
910

@@ -204,6 +205,15 @@ class MismatchedMessageReplyException(InvalidNodeMsg):
204205
pass
205206

206207

208+
class IncorrectMessageForHandlingException(InvalidNodeMsg):
209+
def __init__(self, msg: Any, reason: str, log_method: Callable, *args, **kwargs):
210+
super().__init__(*args, **kwargs)
211+
self.log_method = log_method
212+
self.msg = msg
213+
self.reason = reason
214+
self.args = args
215+
216+
207217
class MissingNodeOp(InvalidNodeMsg):
208218
pass
209219

plenum/common/messages/internal_messages.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import NamedTuple, List, Any
1+
from typing import NamedTuple, List, Any, Optional
22

33
from plenum.common.exceptions import SuspiciousNode
44

@@ -22,8 +22,7 @@
2222
('caught_up_till_3pc', tuple)])
2323

2424
CheckpointStabilized = NamedTuple('CheckpointStabilized',
25-
[('inst_id', int),
26-
('last_stable_3pc', tuple)])
25+
[('last_stable_3pc', tuple)])
2726

2827
RaisedSuspicion = NamedTuple('RaisedSuspicion',
2928
[('inst_id', int),
@@ -32,6 +31,13 @@
3231
PreSigVerification = NamedTuple('PreSigVerification',
3332
[('cmsg', Any)])
3433

34+
Missing3pcMessage = NamedTuple('Missing3pcMessage',
35+
[('msg_type', str),
36+
('three_pc_key', tuple),
37+
('inst_id', int),
38+
('dst', List[str]),
39+
('stash_data', Optional[tuple])])
40+
3541
# by default view_no for StartViewChange is None meaning that we move to the next view
3642
NeedViewChange = NamedTuple('StartViewChange',
3743
[('view_no', int)])

plenum/common/messages/node_messages.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
CATCHUP_REP, VIEW_CHANGE_DONE, CURRENT_STATE, \
99
MESSAGE_REQUEST, MESSAGE_RESPONSE, OBSERVED_DATA, BATCH_COMMITTED, OPERATION_SCHEMA_IS_STRICT, \
1010
BACKUP_INSTANCE_FAULTY, VIEW_CHANGE_START, PROPOSED_VIEW_NO, VIEW_CHANGE_CONTINUE, VIEW_CHANGE, VIEW_CHANGE_ACK, \
11-
NEW_VIEW
11+
NEW_VIEW, OLD_VIEW_PREPREPARE_REQ, OLD_VIEW_PREPREPARE_REP
1212
from plenum.common.messages.client_request import ClientMessageValidator
1313
from plenum.common.messages.fields import NonNegativeNumberField, IterableField, \
1414
SerializedValueField, SignatureField, TieAmongField, AnyValueField, TimestampField, \
@@ -159,6 +159,23 @@ def _post_process(self, input_as_dict: Dict) -> Dict:
159159
return input_as_dict
160160

161161

162+
# TODO: use generic MessageReq mechanism once it's separated into an independent service
163+
class OldViewPrePrepareRequest(MessageBase):
164+
typename = OLD_VIEW_PREPREPARE_REQ
165+
schema = (
166+
(f.INST_ID.nm, NonNegativeNumberField()),
167+
(f.BATCH_IDS.nm, IterableField(BatchIDField())),
168+
)
169+
170+
171+
class OldViewPrePrepareReply(MessageBase):
172+
typename = OLD_VIEW_PREPREPARE_REP
173+
schema = (
174+
(f.INST_ID.nm, NonNegativeNumberField()),
175+
(f.PREPREPARES.nm, IterableField(AnyField())),
176+
)
177+
178+
162179
class Prepare(MessageBase):
163180
typename = PREPARE
164181
schema = (
@@ -233,8 +250,8 @@ class ViewChange(MessageBase):
233250
schema = (
234251
(f.VIEW_NO.nm, NonNegativeNumberField()),
235252
(f.STABLE_CHECKPOINT.nm, NonNegativeNumberField()),
236-
(f.PREPARED.nm, IterableField(BatchIDField())), # list of tuples (view_no, pp_seq_no, pp_digest)
237-
(f.PREPREPARED.nm, IterableField(BatchIDField())), # list of tuples (view_no, pp_seq_no, pp_digest)
253+
(f.PREPARED.nm, IterableField(BatchIDField())), # list of tuples (view_no, pp_view_no, pp_seq_no, pp_digest)
254+
(f.PREPREPARED.nm, IterableField(BatchIDField())), # list of tuples (view_no, pp_view_no, pp_seq_no, pp_digest)
238255
(f.CHECKPOINTS.nm, IterableField(AnyField())) # list of Checkpoints TODO: should we change to tuples?
239256
)
240257

@@ -254,7 +271,7 @@ class NewView(MessageBase):
254271
(f.VIEW_NO.nm, NonNegativeNumberField()),
255272
(f.VIEW_CHANGES.nm, IterableField(ViewChangeField())), # list of tuples (node_name, view_change_digest)
256273
(f.CHECKPOINT.nm, AnyField()), # Checkpoint to be selected as stable (TODO: or tuple?)
257-
(f.BATCHES.nm, IterableField(BatchIDField())) # list of tuples (view_no, pp_seq_no, pp_digest)
274+
(f.BATCHES.nm, IterableField(BatchIDField())) # list of tuples (view_no, pp_view_no, pp_seq_no, pp_digest)
258275
# that should get into new view
259276
)
260277

plenum/common/types.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ class f: # provides a namespace for reusable field constants
9999
TAA_ACCEPTANCE_TIME = Field("time", float)
100100
# View change
101101
STABLE_CHECKPOINT = Field("stableCheckpoint", int)
102-
PREPARED = Field("prepared", List[Tuple[int, int, str]]) # view_no, pp_seq_no, pp_digest
103-
PREPREPARED = Field("preprepared", List[Tuple[int, int, str]]) # view_no, pp_seq_no, pp_digest
104-
CHECKPOINTS = Field("checkpoints", List[Any]) # Any ==Checkpoint
102+
PREPARED = Field("prepared", List[Tuple[int, int, int, str]]) # view_no, pp_view_no, pp_seq_no, pp_digest
103+
PREPREPARED = Field("preprepared", List[Tuple[int, int, int, str]]) # view_no, pp_view_no, pp_seq_no, pp_digest
104+
BATCH_IDS = Field("batch_ids", List[Tuple[int, int, int, str]]) # view_no, pp_view_no, pp_seq_no, pp_digest
105+
PREPREPARES = Field("preprepares", Any) # Any == PrePrepare
106+
CHECKPOINTS = Field("checkpoints", List[Any]) # Any == Checkpoint
105107
VIEW_CHANGES = Field("viewChanges", List[Tuple[str, str]]) # name, vc_digest
106-
CHECKPOINT = Field("checkpoint", Any) # Any ==Checkpoint
108+
CHECKPOINT = Field("checkpoint", Any) # Any == Checkpoint
107109
BATCHES = Field("batches", List[Tuple[int, int, str]]) # view_no, pp_seq_no, pp_digest
108110

109111

plenum/server/batch_handlers/three_pc_batch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from plenum.common.ledger import Ledger
22
from plenum.common.request import Request
33
from plenum.common.types import f
4+
from plenum.server.consensus.consensus_shared_data import get_original_viewno
45

56

67
class ThreePcBatch:
@@ -41,7 +42,7 @@ def from_pre_prepare(pre_prepare, state_root, txn_root, primaries, valid_digests
4142
primaries=primaries,
4243
valid_digests=valid_digests,
4344
has_audit_txn=f.AUDIT_TXN_ROOT_HASH.nm in pre_prepare and pre_prepare.auditTxnRootHash is not None,
44-
original_view_no=pre_prepare.originalViewNo if f.ORIGINAL_VIEW_NO.nm in pre_prepare else None)
45+
original_view_no=get_original_viewno(pre_prepare))
4546

4647
@staticmethod
4748
def from_ordered(ordered):

plenum/server/consensus/checkpoint_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def _mark_checkpoint_stable(self, pp_seq_no):
207207
self.set_watermarks(low_watermark=pp_seq_no)
208208

209209
self._remove_received_checkpoints(till_3pc_key=(self.view_no, pp_seq_no))
210-
self._bus.send(CheckpointStabilized(self._data.inst_id, (self.view_no, pp_seq_no))) # call OrderingService.l_gc()
210+
self._bus.send(CheckpointStabilized((self.view_no, pp_seq_no))) # call OrderingService.gc()
211211
self._logger.info("{} marked stable checkpoint {}".format(self, pp_seq_no))
212212

213213
def set_watermarks(self, low_watermark: int, high_watermark: int = None):

plenum/server/consensus/consensus_shared_data.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from sortedcontainers import SortedListWithKey
66

77
from plenum.common.startable import Mode
8+
from plenum.common.util import SortedDict
9+
from plenum.server.models import Prepares, Commits
810
from plenum.common.types import f
911
from plenum.server.propagator import Requests
1012
from plenum.server.quorums import Quorums
@@ -20,8 +22,12 @@
2022
BatchID = NamedTuple('BatchID', [('view_no', int), ('pp_view_no', int), ('pp_seq_no', int), ('pp_digest', str)])
2123

2224

25+
def get_original_viewno(pp):
26+
return pp.originalViewNo if f.ORIGINAL_VIEW_NO.nm in pp else pp.viewNo
27+
28+
2329
def preprepare_to_batch_id(pre_prepare: PrePrepare) -> BatchID:
24-
pp_view_no = pre_prepare.originalViewNo if f.ORIGINAL_VIEW_NO.nm in pre_prepare else pre_prepare.viewNo
30+
pp_view_no = get_original_viewno(pre_prepare)
2531
return BatchID(pre_prepare.viewNo, pp_view_no, pre_prepare.ppSeqNo, pre_prepare.digest)
2632

2733

@@ -74,6 +80,28 @@ def __init__(self, name: str, validators: List[str], inst_id: int, is_master: bo
7480
self.legacy_last_prepared_before_view_change = None
7581
self.prev_view_prepare_cert = None
7682

83+
# Dictionary of sent PRE-PREPARE that are stored by primary replica
84+
# which it has broadcasted to all other non primary replicas
85+
# Key of dictionary is a 2 element tuple with elements viewNo,
86+
# pre-prepare seqNo and value is the received PRE-PREPARE
87+
self.sent_preprepares = SortedDict(lambda k: (k[0], k[1]))
88+
# type: Dict[Tuple[int, int], PrePrepare]
89+
90+
# Dictionary of all Prepare requests. Key of dictionary is a 2
91+
# element tuple with elements viewNo, seqNo and value is a 2 element
92+
# tuple containing request digest and set of sender node names(sender
93+
# replica names in case of multiple protocol instances)
94+
# (viewNo, seqNo) -> ((identifier, reqId), {senders})
95+
self.prepares = Prepares()
96+
# type: Dict[Tuple[int, int], Tuple[Tuple[str, int], Set[str]]]
97+
98+
self.commits = Commits()
99+
# type: Dict[Tuple[int, int], Tuple[Tuple[str, int], Set[str]]]
100+
101+
# Tracks for which keys PRE-PREPAREs have been requested.
102+
# Cleared in `gc`
103+
self.requested_pre_prepares = {}
104+
77105
@property
78106
def name(self) -> str:
79107
return self._name

plenum/server/consensus/message_request/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)