id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
248,100 | hyperledger/indy-plenum | plenum/server/node.py | Node.sendToReplica | def sendToReplica(self, msg, frm):
"""
Send the message to the intended replica.
:param msg: the message to send
:param frm: the name of the node which sent this `msg`
"""
# TODO: discard or stash messages here instead of doing
# this in msgHas* methods!!!
... | python | def sendToReplica(self, msg, frm):
# TODO: discard or stash messages here instead of doing
# this in msgHas* methods!!!
if self.msgHasAcceptableInstId(msg, frm):
self.replicas.pass_message((msg, frm), msg.instId) | [
"def",
"sendToReplica",
"(",
"self",
",",
"msg",
",",
"frm",
")",
":",
"# TODO: discard or stash messages here instead of doing",
"# this in msgHas* methods!!!",
"if",
"self",
".",
"msgHasAcceptableInstId",
"(",
"msg",
",",
"frm",
")",
":",
"self",
".",
"replicas",
... | Send the message to the intended replica.
:param msg: the message to send
:param frm: the name of the node which sent this `msg` | [
"Send",
"the",
"message",
"to",
"the",
"intended",
"replica",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L1831-L1841 |
248,101 | hyperledger/indy-plenum | plenum/server/node.py | Node.sendToViewChanger | def sendToViewChanger(self, msg, frm):
"""
Send the message to the intended view changer.
:param msg: the message to send
:param frm: the name of the node which sent this `msg`
"""
if (isinstance(msg, InstanceChange) or
self.msgHasAcceptableViewNo(msg, fr... | python | def sendToViewChanger(self, msg, frm):
if (isinstance(msg, InstanceChange) or
self.msgHasAcceptableViewNo(msg, frm)):
logger.debug("{} sending message to view changer: {}".
format(self, (msg, frm)))
self.msgsToViewChanger.append((msg, frm)) | [
"def",
"sendToViewChanger",
"(",
"self",
",",
"msg",
",",
"frm",
")",
":",
"if",
"(",
"isinstance",
"(",
"msg",
",",
"InstanceChange",
")",
"or",
"self",
".",
"msgHasAcceptableViewNo",
"(",
"msg",
",",
"frm",
")",
")",
":",
"logger",
".",
"debug",
"(",... | Send the message to the intended view changer.
:param msg: the message to send
:param frm: the name of the node which sent this `msg` | [
"Send",
"the",
"message",
"to",
"the",
"intended",
"view",
"changer",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L1843-L1854 |
248,102 | hyperledger/indy-plenum | plenum/server/node.py | Node.send_to_observer | def send_to_observer(self, msg, frm):
"""
Send the message to the observer.
:param msg: the message to send
:param frm: the name of the node which sent this `msg`
"""
logger.debug("{} sending message to observer: {}".
format(self, (msg, frm)))
... | python | def send_to_observer(self, msg, frm):
logger.debug("{} sending message to observer: {}".
format(self, (msg, frm)))
self._observer.append_input(msg, frm) | [
"def",
"send_to_observer",
"(",
"self",
",",
"msg",
",",
"frm",
")",
":",
"logger",
".",
"debug",
"(",
"\"{} sending message to observer: {}\"",
".",
"format",
"(",
"self",
",",
"(",
"msg",
",",
"frm",
")",
")",
")",
"self",
".",
"_observer",
".",
"appen... | Send the message to the observer.
:param msg: the message to send
:param frm: the name of the node which sent this `msg` | [
"Send",
"the",
"message",
"to",
"the",
"observer",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L1856-L1865 |
248,103 | hyperledger/indy-plenum | plenum/server/node.py | Node.handleOneNodeMsg | def handleOneNodeMsg(self, wrappedMsg):
"""
Validate and process one message from a node.
:param wrappedMsg: Tuple of message and the name of the node that sent
the message
"""
try:
vmsg = self.validateNodeMsg(wrappedMsg)
if vmsg:
... | python | def handleOneNodeMsg(self, wrappedMsg):
try:
vmsg = self.validateNodeMsg(wrappedMsg)
if vmsg:
logger.trace("{} msg validated {}".format(self, wrappedMsg),
extra={"tags": ["node-msg-validation"]})
self.unpackNodeMsg(*vmsg)
... | [
"def",
"handleOneNodeMsg",
"(",
"self",
",",
"wrappedMsg",
")",
":",
"try",
":",
"vmsg",
"=",
"self",
".",
"validateNodeMsg",
"(",
"wrappedMsg",
")",
"if",
"vmsg",
":",
"logger",
".",
"trace",
"(",
"\"{} msg validated {}\"",
".",
"format",
"(",
"self",
","... | Validate and process one message from a node.
:param wrappedMsg: Tuple of message and the name of the node that sent
the message | [
"Validate",
"and",
"process",
"one",
"message",
"from",
"a",
"node",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L1867-L1887 |
248,104 | hyperledger/indy-plenum | plenum/server/node.py | Node.validateNodeMsg | def validateNodeMsg(self, wrappedMsg):
"""
Validate another node's message sent to this node.
:param wrappedMsg: Tuple of message and the name of the node that sent
the message
:return: Tuple of message from node and name of the node
"""
msg, frm = wrappedMsg
... | python | def validateNodeMsg(self, wrappedMsg):
msg, frm = wrappedMsg
if self.isNodeBlacklisted(frm):
self.discard(str(msg)[:256], "received from blacklisted node {}".format(frm), logger.display)
return None
with self.metrics.measure_time(MetricsName.INT_VALIDATE_NODE_MSG_TIME):
... | [
"def",
"validateNodeMsg",
"(",
"self",
",",
"wrappedMsg",
")",
":",
"msg",
",",
"frm",
"=",
"wrappedMsg",
"if",
"self",
".",
"isNodeBlacklisted",
"(",
"frm",
")",
":",
"self",
".",
"discard",
"(",
"str",
"(",
"msg",
")",
"[",
":",
"256",
"]",
",",
... | Validate another node's message sent to this node.
:param wrappedMsg: Tuple of message and the name of the node that sent
the message
:return: Tuple of message from node and name of the node | [
"Validate",
"another",
"node",
"s",
"message",
"sent",
"to",
"this",
"node",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L1890-L1916 |
248,105 | hyperledger/indy-plenum | plenum/server/node.py | Node.unpackNodeMsg | def unpackNodeMsg(self, msg, frm) -> None:
"""
If the message is a batch message validate each message in the batch,
otherwise add the message to the node's inbox.
:param msg: a node message
:param frm: the name of the node that sent this `msg`
"""
# TODO: why do... | python | def unpackNodeMsg(self, msg, frm) -> None:
# TODO: why do we unpack batches here? Batching is a feature of
# a transport, it should be encapsulated.
if isinstance(msg, Batch):
logger.trace("{} processing a batch {}".format(self, msg))
with self.metrics.measure_time(Metri... | [
"def",
"unpackNodeMsg",
"(",
"self",
",",
"msg",
",",
"frm",
")",
"->",
"None",
":",
"# TODO: why do we unpack batches here? Batching is a feature of",
"# a transport, it should be encapsulated.",
"if",
"isinstance",
"(",
"msg",
",",
"Batch",
")",
":",
"logger",
".",
... | If the message is a batch message validate each message in the batch,
otherwise add the message to the node's inbox.
:param msg: a node message
:param frm: the name of the node that sent this `msg` | [
"If",
"the",
"message",
"is",
"a",
"batch",
"message",
"validate",
"each",
"message",
"in",
"the",
"batch",
"otherwise",
"add",
"the",
"message",
"to",
"the",
"node",
"s",
"inbox",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L1918-L1940 |
248,106 | hyperledger/indy-plenum | plenum/server/node.py | Node.postToNodeInBox | def postToNodeInBox(self, msg, frm):
"""
Append the message to the node inbox
:param msg: a node message
:param frm: the name of the node that sent this `msg`
"""
logger.trace("{} appending to nodeInbox {}".format(self, msg))
self.nodeInBox.append((msg, frm)) | python | def postToNodeInBox(self, msg, frm):
logger.trace("{} appending to nodeInbox {}".format(self, msg))
self.nodeInBox.append((msg, frm)) | [
"def",
"postToNodeInBox",
"(",
"self",
",",
"msg",
",",
"frm",
")",
":",
"logger",
".",
"trace",
"(",
"\"{} appending to nodeInbox {}\"",
".",
"format",
"(",
"self",
",",
"msg",
")",
")",
"self",
".",
"nodeInBox",
".",
"append",
"(",
"(",
"msg",
",",
"... | Append the message to the node inbox
:param msg: a node message
:param frm: the name of the node that sent this `msg` | [
"Append",
"the",
"message",
"to",
"the",
"node",
"inbox"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L1942-L1950 |
248,107 | hyperledger/indy-plenum | plenum/server/node.py | Node.processNodeInBox | async def processNodeInBox(self):
"""
Process the messages in the node inbox asynchronously.
"""
while self.nodeInBox:
m = self.nodeInBox.popleft()
await self.process_one_node_message(m) | python | async def processNodeInBox(self):
while self.nodeInBox:
m = self.nodeInBox.popleft()
await self.process_one_node_message(m) | [
"async",
"def",
"processNodeInBox",
"(",
"self",
")",
":",
"while",
"self",
".",
"nodeInBox",
":",
"m",
"=",
"self",
".",
"nodeInBox",
".",
"popleft",
"(",
")",
"await",
"self",
".",
"process_one_node_message",
"(",
"m",
")"
] | Process the messages in the node inbox asynchronously. | [
"Process",
"the",
"messages",
"in",
"the",
"node",
"inbox",
"asynchronously",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L1953-L1959 |
248,108 | hyperledger/indy-plenum | plenum/server/node.py | Node.handleOneClientMsg | def handleOneClientMsg(self, wrappedMsg):
"""
Validate and process a client message
:param wrappedMsg: a message from a client
"""
try:
vmsg = self.validateClientMsg(wrappedMsg)
if vmsg:
self.unpackClientMsg(*vmsg)
except BlowUp:
... | python | def handleOneClientMsg(self, wrappedMsg):
try:
vmsg = self.validateClientMsg(wrappedMsg)
if vmsg:
self.unpackClientMsg(*vmsg)
except BlowUp:
raise
except Exception as ex:
msg, frm = wrappedMsg
friendly = friendlyEx(ex)
... | [
"def",
"handleOneClientMsg",
"(",
"self",
",",
"wrappedMsg",
")",
":",
"try",
":",
"vmsg",
"=",
"self",
".",
"validateClientMsg",
"(",
"wrappedMsg",
")",
"if",
"vmsg",
":",
"self",
".",
"unpackClientMsg",
"(",
"*",
"vmsg",
")",
"except",
"BlowUp",
":",
"... | Validate and process a client message
:param wrappedMsg: a message from a client | [
"Validate",
"and",
"process",
"a",
"client",
"message"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L1968-L1986 |
248,109 | hyperledger/indy-plenum | plenum/server/node.py | Node.processClientInBox | async def processClientInBox(self):
"""
Process the messages in the node's clientInBox asynchronously.
All messages in the inBox have already been validated, including
signature check.
"""
while self.clientInBox:
m = self.clientInBox.popleft()
req,... | python | async def processClientInBox(self):
while self.clientInBox:
m = self.clientInBox.popleft()
req, frm = m
logger.debug("{} processing {} request {}".
format(self.clientstack.name, frm, req),
extra={"cli": True,
... | [
"async",
"def",
"processClientInBox",
"(",
"self",
")",
":",
"while",
"self",
".",
"clientInBox",
":",
"m",
"=",
"self",
".",
"clientInBox",
".",
"popleft",
"(",
")",
"req",
",",
"frm",
"=",
"m",
"logger",
".",
"debug",
"(",
"\"{} processing {} request {}\... | Process the messages in the node's clientInBox asynchronously.
All messages in the inBox have already been validated, including
signature check. | [
"Process",
"the",
"messages",
"in",
"the",
"node",
"s",
"clientInBox",
"asynchronously",
".",
"All",
"messages",
"in",
"the",
"inBox",
"have",
"already",
"been",
"validated",
"including",
"signature",
"check",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L2120-L2137 |
248,110 | hyperledger/indy-plenum | plenum/server/node.py | Node.is_catchup_needed_during_view_change | def is_catchup_needed_during_view_change(self) -> bool:
"""
Check if received a quorum of view change done messages and if yes
check if caught up till the
Check if all requests ordered till last prepared certificate
Check if last catchup resulted in no txns
"""
if... | python | def is_catchup_needed_during_view_change(self) -> bool:
if self.caught_up_for_current_view():
logger.info('{} is caught up for the current view {}'.format(self, self.viewNo))
return False
logger.info('{} is not caught up for the current view {}'.format(self, self.viewNo))
... | [
"def",
"is_catchup_needed_during_view_change",
"(",
"self",
")",
"->",
"bool",
":",
"if",
"self",
".",
"caught_up_for_current_view",
"(",
")",
":",
"logger",
".",
"info",
"(",
"'{} is caught up for the current view {}'",
".",
"format",
"(",
"self",
",",
"self",
".... | Check if received a quorum of view change done messages and if yes
check if caught up till the
Check if all requests ordered till last prepared certificate
Check if last catchup resulted in no txns | [
"Check",
"if",
"received",
"a",
"quorum",
"of",
"view",
"change",
"done",
"messages",
"and",
"if",
"yes",
"check",
"if",
"caught",
"up",
"till",
"the",
"Check",
"if",
"all",
"requests",
"ordered",
"till",
"last",
"prepared",
"certificate",
"Check",
"if",
"... | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L2275-L2298 |
248,111 | hyperledger/indy-plenum | plenum/server/node.py | Node.doDynamicValidation | def doDynamicValidation(self, request: Request):
"""
State based validation
"""
self.execute_hook(NodeHooks.PRE_DYNAMIC_VALIDATION, request=request)
# Digest validation
ledger_id, seq_no = self.seqNoDB.get_by_payload_digest(request.payload_digest)
if ledger_id is... | python | def doDynamicValidation(self, request: Request):
self.execute_hook(NodeHooks.PRE_DYNAMIC_VALIDATION, request=request)
# Digest validation
ledger_id, seq_no = self.seqNoDB.get_by_payload_digest(request.payload_digest)
if ledger_id is not None and seq_no is not None:
raise Sus... | [
"def",
"doDynamicValidation",
"(",
"self",
",",
"request",
":",
"Request",
")",
":",
"self",
".",
"execute_hook",
"(",
"NodeHooks",
".",
"PRE_DYNAMIC_VALIDATION",
",",
"request",
"=",
"request",
")",
"# Digest validation",
"ledger_id",
",",
"seq_no",
"=",
"self"... | State based validation | [
"State",
"based",
"validation"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L2401-L2421 |
248,112 | hyperledger/indy-plenum | plenum/server/node.py | Node.applyReq | def applyReq(self, request: Request, cons_time: int):
"""
Apply request to appropriate ledger and state. `cons_time` is the
UTC epoch at which consensus was reached.
"""
self.execute_hook(NodeHooks.PRE_REQUEST_APPLICATION, request=request,
cons_time=cons... | python | def applyReq(self, request: Request, cons_time: int):
self.execute_hook(NodeHooks.PRE_REQUEST_APPLICATION, request=request,
cons_time=cons_time)
req_handler = self.get_req_handler(txn_type=request.operation[TXN_TYPE])
seq_no, txn = req_handler.apply(request, cons_time)
... | [
"def",
"applyReq",
"(",
"self",
",",
"request",
":",
"Request",
",",
"cons_time",
":",
"int",
")",
":",
"self",
".",
"execute_hook",
"(",
"NodeHooks",
".",
"PRE_REQUEST_APPLICATION",
",",
"request",
"=",
"request",
",",
"cons_time",
"=",
"cons_time",
")",
... | Apply request to appropriate ledger and state. `cons_time` is the
UTC epoch at which consensus was reached. | [
"Apply",
"request",
"to",
"appropriate",
"ledger",
"and",
"state",
".",
"cons_time",
"is",
"the",
"UTC",
"epoch",
"at",
"which",
"consensus",
"was",
"reached",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L2423-L2435 |
248,113 | hyperledger/indy-plenum | plenum/server/node.py | Node.processRequest | def processRequest(self, request: Request, frm: str):
"""
Handle a REQUEST from the client.
If the request has already been executed, the node re-sends the reply to
the client. Otherwise, the node acknowledges the client request, adds it
to its list of client requests, and sends ... | python | def processRequest(self, request: Request, frm: str):
logger.debug("{} received client request: {} from {}".
format(self.name, request, frm))
self.nodeRequestSpikeMonitorData['accum'] += 1
# TODO: What if client sends requests with same request id quickly so
# befor... | [
"def",
"processRequest",
"(",
"self",
",",
"request",
":",
"Request",
",",
"frm",
":",
"str",
")",
":",
"logger",
".",
"debug",
"(",
"\"{} received client request: {} from {}\"",
".",
"format",
"(",
"self",
".",
"name",
",",
"request",
",",
"frm",
")",
")"... | Handle a REQUEST from the client.
If the request has already been executed, the node re-sends the reply to
the client. Otherwise, the node acknowledges the client request, adds it
to its list of client requests, and sends a PROPAGATE to the
remaining nodes.
:param request: the R... | [
"Handle",
"a",
"REQUEST",
"from",
"the",
"client",
".",
"If",
"the",
"request",
"has",
"already",
"been",
"executed",
"the",
"node",
"re",
"-",
"sends",
"the",
"reply",
"to",
"the",
"client",
".",
"Otherwise",
"the",
"node",
"acknowledges",
"the",
"client"... | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L2464-L2528 |
248,114 | hyperledger/indy-plenum | plenum/server/node.py | Node.processPropagate | def processPropagate(self, msg: Propagate, frm):
"""
Process one propagateRequest sent to this node asynchronously
- If this propagateRequest hasn't been seen by this node, then broadcast
it to all nodes after verifying the the signature.
- Add the client to blacklist if its sig... | python | def processPropagate(self, msg: Propagate, frm):
logger.debug("{} received propagated request: {}".
format(self.name, msg))
request = TxnUtilConfig.client_request_class(**msg.request)
clientName = msg.senderClient
if not self.isProcessingReq(request.key):
... | [
"def",
"processPropagate",
"(",
"self",
",",
"msg",
":",
"Propagate",
",",
"frm",
")",
":",
"logger",
".",
"debug",
"(",
"\"{} received propagated request: {}\"",
".",
"format",
"(",
"self",
".",
"name",
",",
"msg",
")",
")",
"request",
"=",
"TxnUtilConfig",... | Process one propagateRequest sent to this node asynchronously
- If this propagateRequest hasn't been seen by this node, then broadcast
it to all nodes after verifying the the signature.
- Add the client to blacklist if its signature is invalid
:param msg: the propagateRequest
:... | [
"Process",
"one",
"propagateRequest",
"sent",
"to",
"this",
"node",
"asynchronously"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L2569-L2610 |
248,115 | hyperledger/indy-plenum | plenum/server/node.py | Node.handle_get_txn_req | def handle_get_txn_req(self, request: Request, frm: str):
"""
Handle GET_TXN request
"""
ledger_id = request.operation.get(f.LEDGER_ID.nm, DOMAIN_LEDGER_ID)
if ledger_id not in self.ledger_to_req_handler:
self.send_nack_to_client((request.identifier, request.reqId),
... | python | def handle_get_txn_req(self, request: Request, frm: str):
ledger_id = request.operation.get(f.LEDGER_ID.nm, DOMAIN_LEDGER_ID)
if ledger_id not in self.ledger_to_req_handler:
self.send_nack_to_client((request.identifier, request.reqId),
'Invalid ledger id ... | [
"def",
"handle_get_txn_req",
"(",
"self",
",",
"request",
":",
"Request",
",",
"frm",
":",
"str",
")",
":",
"ledger_id",
"=",
"request",
".",
"operation",
".",
"get",
"(",
"f",
".",
"LEDGER_ID",
".",
"nm",
",",
"DOMAIN_LEDGER_ID",
")",
"if",
"ledger_id",... | Handle GET_TXN request | [
"Handle",
"GET_TXN",
"request"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L2634-L2670 |
248,116 | hyperledger/indy-plenum | plenum/server/node.py | Node.processOrdered | def processOrdered(self, ordered: Ordered):
"""
Execute ordered request
:param ordered: an ordered request
:return: whether executed
"""
if ordered.instId not in self.instances.ids:
logger.warning('{} got ordered request for instance {} which '
... | python | def processOrdered(self, ordered: Ordered):
if ordered.instId not in self.instances.ids:
logger.warning('{} got ordered request for instance {} which '
'does not exist'.format(self, ordered.instId))
return False
if ordered.instId != self.instances.mast... | [
"def",
"processOrdered",
"(",
"self",
",",
"ordered",
":",
"Ordered",
")",
":",
"if",
"ordered",
".",
"instId",
"not",
"in",
"self",
".",
"instances",
".",
"ids",
":",
"logger",
".",
"warning",
"(",
"'{} got ordered request for instance {} which '",
"'does not e... | Execute ordered request
:param ordered: an ordered request
:return: whether executed | [
"Execute",
"ordered",
"request"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L2673-L2735 |
248,117 | hyperledger/indy-plenum | plenum/server/node.py | Node.force_process_ordered | def force_process_ordered(self):
"""
Take any messages from replica that have been ordered and process
them, this should be done rarely, like before catchup starts
so a more current LedgerStatus can be sent.
can be called either
1. when node is participating, this happens... | python | def force_process_ordered(self):
for instance_id, messages in self.replicas.take_ordereds_out_of_turn():
num_processed = 0
for message in messages:
self.try_processing_ordered(message)
num_processed += 1
logger.info('{} processed {} Ordered bat... | [
"def",
"force_process_ordered",
"(",
"self",
")",
":",
"for",
"instance_id",
",",
"messages",
"in",
"self",
".",
"replicas",
".",
"take_ordereds_out_of_turn",
"(",
")",
":",
"num_processed",
"=",
"0",
"for",
"message",
"in",
"messages",
":",
"self",
".",
"tr... | Take any messages from replica that have been ordered and process
them, this should be done rarely, like before catchup starts
so a more current LedgerStatus can be sent.
can be called either
1. when node is participating, this happens just before catchup starts
so the node can h... | [
"Take",
"any",
"messages",
"from",
"replica",
"that",
"have",
"been",
"ordered",
"and",
"process",
"them",
"this",
"should",
"be",
"done",
"rarely",
"like",
"before",
"catchup",
"starts",
"so",
"a",
"more",
"current",
"LedgerStatus",
"can",
"be",
"sent",
"."... | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L2737-L2758 |
248,118 | hyperledger/indy-plenum | plenum/server/node.py | Node.processEscalatedException | def processEscalatedException(self, ex):
"""
Process an exception escalated from a Replica
"""
if isinstance(ex, SuspiciousNode):
self.reportSuspiciousNodeEx(ex)
else:
raise RuntimeError("unhandled replica-escalated exception") from ex | python | def processEscalatedException(self, ex):
if isinstance(ex, SuspiciousNode):
self.reportSuspiciousNodeEx(ex)
else:
raise RuntimeError("unhandled replica-escalated exception") from ex | [
"def",
"processEscalatedException",
"(",
"self",
",",
"ex",
")",
":",
"if",
"isinstance",
"(",
"ex",
",",
"SuspiciousNode",
")",
":",
"self",
".",
"reportSuspiciousNodeEx",
"(",
"ex",
")",
"else",
":",
"raise",
"RuntimeError",
"(",
"\"unhandled replica-escalated... | Process an exception escalated from a Replica | [
"Process",
"an",
"exception",
"escalated",
"from",
"a",
"Replica"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L2766-L2773 |
248,119 | hyperledger/indy-plenum | plenum/server/node.py | Node.lost_master_primary | def lost_master_primary(self):
"""
Schedule an primary connection check which in turn can send a view
change message
"""
self.primaries_disconnection_times[self.master_replica.instId] = time.perf_counter()
self._schedule_view_change() | python | def lost_master_primary(self):
self.primaries_disconnection_times[self.master_replica.instId] = time.perf_counter()
self._schedule_view_change() | [
"def",
"lost_master_primary",
"(",
"self",
")",
":",
"self",
".",
"primaries_disconnection_times",
"[",
"self",
".",
"master_replica",
".",
"instId",
"]",
"=",
"time",
".",
"perf_counter",
"(",
")",
"self",
".",
"_schedule_view_change",
"(",
")"
] | Schedule an primary connection check which in turn can send a view
change message | [
"Schedule",
"an",
"primary",
"connection",
"check",
"which",
"in",
"turn",
"can",
"send",
"a",
"view",
"change",
"message"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L3134-L3140 |
248,120 | hyperledger/indy-plenum | plenum/server/node.py | Node.executeBatch | def executeBatch(self, three_pc_batch: ThreePcBatch,
valid_reqs_keys: List, invalid_reqs_keys: List,
audit_txn_root) -> None:
"""
Execute the REQUEST sent to this Node
:param view_no: the view number (See glossary)
:param pp_time: the time at wh... | python | def executeBatch(self, three_pc_batch: ThreePcBatch,
valid_reqs_keys: List, invalid_reqs_keys: List,
audit_txn_root) -> None:
# We need hashes in apply and str in commit
three_pc_batch.txn_root = Ledger.hashToStr(three_pc_batch.txn_root)
three_pc_batch.s... | [
"def",
"executeBatch",
"(",
"self",
",",
"three_pc_batch",
":",
"ThreePcBatch",
",",
"valid_reqs_keys",
":",
"List",
",",
"invalid_reqs_keys",
":",
"List",
",",
"audit_txn_root",
")",
"->",
"None",
":",
"# We need hashes in apply and str in commit",
"three_pc_batch",
... | Execute the REQUEST sent to this Node
:param view_no: the view number (See glossary)
:param pp_time: the time at which PRE-PREPARE was sent
:param valid_reqs: list of valid client requests keys
:param valid_reqs: list of invalid client requests keys | [
"Execute",
"the",
"REQUEST",
"sent",
"to",
"this",
"Node"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L3251-L3346 |
248,121 | hyperledger/indy-plenum | plenum/server/node.py | Node.addNewRole | def addNewRole(self, txn):
"""
Adds a new client or steward to this node based on transaction type.
"""
# If the client authenticator is a simple authenticator then add verkey.
# For a custom authenticator, handle appropriately.
# NOTE: The following code should not be u... | python | def addNewRole(self, txn):
# If the client authenticator is a simple authenticator then add verkey.
# For a custom authenticator, handle appropriately.
# NOTE: The following code should not be used in production
if isinstance(self.clientAuthNr.core_authenticator, SimpleAuthNr):
... | [
"def",
"addNewRole",
"(",
"self",
",",
"txn",
")",
":",
"# If the client authenticator is a simple authenticator then add verkey.",
"# For a custom authenticator, handle appropriately.",
"# NOTE: The following code should not be used in production",
"if",
"isinstance",
"(",
"self",
".... | Adds a new client or steward to this node based on transaction type. | [
"Adds",
"a",
"new",
"client",
"or",
"steward",
"to",
"this",
"node",
"based",
"on",
"transaction",
"type",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L3441-L3461 |
248,122 | hyperledger/indy-plenum | plenum/server/node.py | Node.ensureKeysAreSetup | def ensureKeysAreSetup(self):
"""
Check whether the keys are setup in the local STP keep.
Raises KeysNotFoundException if not found.
"""
if not areKeysSetup(self.name, self.keys_dir):
raise REx(REx.reason.format(self.name) + self.keygenScript) | python | def ensureKeysAreSetup(self):
if not areKeysSetup(self.name, self.keys_dir):
raise REx(REx.reason.format(self.name) + self.keygenScript) | [
"def",
"ensureKeysAreSetup",
"(",
"self",
")",
":",
"if",
"not",
"areKeysSetup",
"(",
"self",
".",
"name",
",",
"self",
".",
"keys_dir",
")",
":",
"raise",
"REx",
"(",
"REx",
".",
"reason",
".",
"format",
"(",
"self",
".",
"name",
")",
"+",
"self",
... | Check whether the keys are setup in the local STP keep.
Raises KeysNotFoundException if not found. | [
"Check",
"whether",
"the",
"keys",
"are",
"setup",
"in",
"the",
"local",
"STP",
"keep",
".",
"Raises",
"KeysNotFoundException",
"if",
"not",
"found",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L3478-L3484 |
248,123 | hyperledger/indy-plenum | plenum/server/node.py | Node.reportSuspiciousNodeEx | def reportSuspiciousNodeEx(self, ex: SuspiciousNode):
"""
Report suspicion on a node on the basis of an exception
"""
self.reportSuspiciousNode(ex.node, ex.reason, ex.code, ex.offendingMsg) | python | def reportSuspiciousNodeEx(self, ex: SuspiciousNode):
self.reportSuspiciousNode(ex.node, ex.reason, ex.code, ex.offendingMsg) | [
"def",
"reportSuspiciousNodeEx",
"(",
"self",
",",
"ex",
":",
"SuspiciousNode",
")",
":",
"self",
".",
"reportSuspiciousNode",
"(",
"ex",
".",
"node",
",",
"ex",
".",
"reason",
",",
"ex",
".",
"code",
",",
"ex",
".",
"offendingMsg",
")"
] | Report suspicion on a node on the basis of an exception | [
"Report",
"suspicion",
"on",
"a",
"node",
"on",
"the",
"basis",
"of",
"an",
"exception"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L3492-L3496 |
248,124 | hyperledger/indy-plenum | plenum/server/node.py | Node.reportSuspiciousNode | def reportSuspiciousNode(self,
nodeName: str,
reason=None,
code: int = None,
offendingMsg=None):
"""
Report suspicion on a node and add it to this node's blacklist.
:param nodeNam... | python | def reportSuspiciousNode(self,
nodeName: str,
reason=None,
code: int = None,
offendingMsg=None):
logger.warning("{} raised suspicion on node {} for {}; suspicion code "
"is ... | [
"def",
"reportSuspiciousNode",
"(",
"self",
",",
"nodeName",
":",
"str",
",",
"reason",
"=",
"None",
",",
"code",
":",
"int",
"=",
"None",
",",
"offendingMsg",
"=",
"None",
")",
":",
"logger",
".",
"warning",
"(",
"\"{} raised suspicion on node {} for {}; susp... | Report suspicion on a node and add it to this node's blacklist.
:param nodeName: name of the node to report suspicion on
:param reason: the reason for suspicion | [
"Report",
"suspicion",
"on",
"a",
"node",
"and",
"add",
"it",
"to",
"this",
"node",
"s",
"blacklist",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L3498-L3543 |
248,125 | hyperledger/indy-plenum | plenum/server/node.py | Node.reportSuspiciousClient | def reportSuspiciousClient(self, clientName: str, reason):
"""
Report suspicion on a client and add it to this node's blacklist.
:param clientName: name of the client to report suspicion on
:param reason: the reason for suspicion
"""
logger.warning("{} raised suspicion o... | python | def reportSuspiciousClient(self, clientName: str, reason):
logger.warning("{} raised suspicion on client {} for {}"
.format(self, clientName, reason))
self.blacklistClient(clientName) | [
"def",
"reportSuspiciousClient",
"(",
"self",
",",
"clientName",
":",
"str",
",",
"reason",
")",
":",
"logger",
".",
"warning",
"(",
"\"{} raised suspicion on client {} for {}\"",
".",
"format",
"(",
"self",
",",
"clientName",
",",
"reason",
")",
")",
"self",
... | Report suspicion on a client and add it to this node's blacklist.
:param clientName: name of the client to report suspicion on
:param reason: the reason for suspicion | [
"Report",
"suspicion",
"on",
"a",
"client",
"and",
"add",
"it",
"to",
"this",
"node",
"s",
"blacklist",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L3545-L3554 |
248,126 | hyperledger/indy-plenum | plenum/server/node.py | Node.blacklistClient | def blacklistClient(self, clientName: str,
reason: str = None, code: int = None):
"""
Add the client specified by `clientName` to this node's blacklist
"""
msg = "{} blacklisting client {}".format(self, clientName)
if reason:
msg += " for reaso... | python | def blacklistClient(self, clientName: str,
reason: str = None, code: int = None):
msg = "{} blacklisting client {}".format(self, clientName)
if reason:
msg += " for reason {}".format(reason)
logger.display(msg)
self.clientBlacklister.blacklist(clientNa... | [
"def",
"blacklistClient",
"(",
"self",
",",
"clientName",
":",
"str",
",",
"reason",
":",
"str",
"=",
"None",
",",
"code",
":",
"int",
"=",
"None",
")",
":",
"msg",
"=",
"\"{} blacklisting client {}\"",
".",
"format",
"(",
"self",
",",
"clientName",
")",... | Add the client specified by `clientName` to this node's blacklist | [
"Add",
"the",
"client",
"specified",
"by",
"clientName",
"to",
"this",
"node",
"s",
"blacklist"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L3565-L3574 |
248,127 | hyperledger/indy-plenum | plenum/server/node.py | Node.blacklistNode | def blacklistNode(self, nodeName: str, reason: str = None, code: int = None):
"""
Add the node specified by `nodeName` to this node's blacklist
"""
msg = "{} blacklisting node {}".format(self, nodeName)
if reason:
msg += " for reason {}".format(reason)
if code... | python | def blacklistNode(self, nodeName: str, reason: str = None, code: int = None):
msg = "{} blacklisting node {}".format(self, nodeName)
if reason:
msg += " for reason {}".format(reason)
if code:
msg += " for code {}".format(code)
logger.display(msg)
self.node... | [
"def",
"blacklistNode",
"(",
"self",
",",
"nodeName",
":",
"str",
",",
"reason",
":",
"str",
"=",
"None",
",",
"code",
":",
"int",
"=",
"None",
")",
":",
"msg",
"=",
"\"{} blacklisting node {}\"",
".",
"format",
"(",
"self",
",",
"nodeName",
")",
"if",... | Add the node specified by `nodeName` to this node's blacklist | [
"Add",
"the",
"node",
"specified",
"by",
"nodeName",
"to",
"this",
"node",
"s",
"blacklist"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L3585-L3595 |
248,128 | hyperledger/indy-plenum | plenum/server/node.py | Node.logstats | def logstats(self):
"""
Print the node's current statistics to log.
"""
lines = [
"node {} current stats".format(self),
"--------------------------------------------------------",
"node inbox size : {}".format(len(self.nodeInBox)),
... | python | def logstats(self):
lines = [
"node {} current stats".format(self),
"--------------------------------------------------------",
"node inbox size : {}".format(len(self.nodeInBox)),
"client inbox size : {}".format(len(self.clientInBox)),
"a... | [
"def",
"logstats",
"(",
"self",
")",
":",
"lines",
"=",
"[",
"\"node {} current stats\"",
".",
"format",
"(",
"self",
")",
",",
"\"--------------------------------------------------------\"",
",",
"\"node inbox size : {}\"",
".",
"format",
"(",
"len",
"(",
"se... | Print the node's current statistics to log. | [
"Print",
"the",
"node",
"s",
"current",
"statistics",
"to",
"log",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L3685-L3711 |
248,129 | hyperledger/indy-plenum | plenum/server/node.py | Node.logNodeInfo | def logNodeInfo(self):
"""
Print the node's info to log for the REST backend to read.
"""
self.nodeInfo['data'] = self.collectNodeInfo()
with closing(open(os.path.join(self.ledger_dir, 'node_info'), 'w')) \
as logNodeInfoFile:
logNodeInfoFile.write(js... | python | def logNodeInfo(self):
self.nodeInfo['data'] = self.collectNodeInfo()
with closing(open(os.path.join(self.ledger_dir, 'node_info'), 'w')) \
as logNodeInfoFile:
logNodeInfoFile.write(json.dumps(self.nodeInfo['data'])) | [
"def",
"logNodeInfo",
"(",
"self",
")",
":",
"self",
".",
"nodeInfo",
"[",
"'data'",
"]",
"=",
"self",
".",
"collectNodeInfo",
"(",
")",
"with",
"closing",
"(",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"ledger_dir",
",",
"'node_... | Print the node's info to log for the REST backend to read. | [
"Print",
"the",
"node",
"s",
"info",
"to",
"log",
"for",
"the",
"REST",
"backend",
"to",
"read",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/node.py#L3738-L3746 |
248,130 | hyperledger/indy-plenum | plenum/common/perf_util.py | get_collection_sizes | def get_collection_sizes(obj, collections: Optional[Tuple]=None,
get_only_non_empty=False):
"""
Iterates over `collections` of the gives object and gives its byte size
and number of items in collection
"""
from pympler import asizeof
collections = collections or (list, d... | python | def get_collection_sizes(obj, collections: Optional[Tuple]=None,
get_only_non_empty=False):
from pympler import asizeof
collections = collections or (list, dict, set, deque, abc.Sized)
if not isinstance(collections, tuple):
collections = tuple(collections)
result = []
... | [
"def",
"get_collection_sizes",
"(",
"obj",
",",
"collections",
":",
"Optional",
"[",
"Tuple",
"]",
"=",
"None",
",",
"get_only_non_empty",
"=",
"False",
")",
":",
"from",
"pympler",
"import",
"asizeof",
"collections",
"=",
"collections",
"or",
"(",
"list",
"... | Iterates over `collections` of the gives object and gives its byte size
and number of items in collection | [
"Iterates",
"over",
"collections",
"of",
"the",
"gives",
"object",
"and",
"gives",
"its",
"byte",
"size",
"and",
"number",
"of",
"items",
"in",
"collection"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/common/perf_util.py#L52-L70 |
248,131 | hyperledger/indy-plenum | ledger/error.py | returns_true_or_raises | def returns_true_or_raises(f):
"""A safety net.
Decorator for functions that are only allowed to return True or raise
an exception.
Args:
f: A function whose only expected return value is True.
Returns:
A wrapped functions whose guaranteed only return value is True.
"""
@f... | python | def returns_true_or_raises(f):
@functools.wraps(f)
def wrapped(*args, **kwargs):
ret = f(*args, **kwargs)
if ret is not True:
raise RuntimeError("Unexpected return value %r" % ret)
return True
return wrapped | [
"def",
"returns_true_or_raises",
"(",
"f",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"f",
")",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"ret",
"=",
"f",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"if",
"r... | A safety net.
Decorator for functions that are only allowed to return True or raise
an exception.
Args:
f: A function whose only expected return value is True.
Returns:
A wrapped functions whose guaranteed only return value is True. | [
"A",
"safety",
"net",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/ledger/error.py#L126-L144 |
248,132 | hyperledger/indy-plenum | plenum/server/instances.py | Instances.backupIds | def backupIds(self) -> Sequence[int]:
"""
Return the list of replicas that don't belong to the master protocol
instance
"""
return [id for id in self.started.keys() if id != 0] | python | def backupIds(self) -> Sequence[int]:
return [id for id in self.started.keys() if id != 0] | [
"def",
"backupIds",
"(",
"self",
")",
"->",
"Sequence",
"[",
"int",
"]",
":",
"return",
"[",
"id",
"for",
"id",
"in",
"self",
".",
"started",
".",
"keys",
"(",
")",
"if",
"id",
"!=",
"0",
"]"
] | Return the list of replicas that don't belong to the master protocol
instance | [
"Return",
"the",
"list",
"of",
"replicas",
"that",
"don",
"t",
"belong",
"to",
"the",
"master",
"protocol",
"instance"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/instances.py#L37-L42 |
248,133 | hyperledger/indy-plenum | plenum/server/view_change/view_changer.py | ViewChanger._hasViewChangeQuorum | def _hasViewChangeQuorum(self):
# This method should just be present for master instance.
"""
Checks whether n-f nodes completed view change and whether one
of them is the next primary
"""
num_of_ready_nodes = len(self._view_change_done)
diff = self.quorum - num_o... | python | def _hasViewChangeQuorum(self):
# This method should just be present for master instance.
num_of_ready_nodes = len(self._view_change_done)
diff = self.quorum - num_of_ready_nodes
if diff > 0:
logger.info('{} needs {} ViewChangeDone messages'.format(self, diff))
re... | [
"def",
"_hasViewChangeQuorum",
"(",
"self",
")",
":",
"# This method should just be present for master instance.",
"num_of_ready_nodes",
"=",
"len",
"(",
"self",
".",
"_view_change_done",
")",
"diff",
"=",
"self",
".",
"quorum",
"-",
"num_of_ready_nodes",
"if",
"diff",
... | Checks whether n-f nodes completed view change and whether one
of them is the next primary | [
"Checks",
"whether",
"n",
"-",
"f",
"nodes",
"completed",
"view",
"change",
"and",
"whether",
"one",
"of",
"them",
"is",
"the",
"next",
"primary"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/view_change/view_changer.py#L234-L248 |
248,134 | hyperledger/indy-plenum | plenum/server/view_change/view_changer.py | ViewChanger.process_instance_change_msg | def process_instance_change_msg(self, instChg: InstanceChange, frm: str) -> None:
"""
Validate and process an instance change request.
:param instChg: the instance change request
:param frm: the name of the node that sent this `msg`
"""
if frm not in self.provider.connec... | python | def process_instance_change_msg(self, instChg: InstanceChange, frm: str) -> None:
if frm not in self.provider.connected_nodes():
self.provider.discard(
instChg,
"received instance change request: {} from {} "
"which is not in connected list: {}".format... | [
"def",
"process_instance_change_msg",
"(",
"self",
",",
"instChg",
":",
"InstanceChange",
",",
"frm",
":",
"str",
")",
"->",
"None",
":",
"if",
"frm",
"not",
"in",
"self",
".",
"provider",
".",
"connected_nodes",
"(",
")",
":",
"self",
".",
"provider",
"... | Validate and process an instance change request.
:param instChg: the instance change request
:param frm: the name of the node that sent this `msg` | [
"Validate",
"and",
"process",
"an",
"instance",
"change",
"request",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/view_change/view_changer.py#L373-L416 |
248,135 | hyperledger/indy-plenum | plenum/server/view_change/view_changer.py | ViewChanger.process_vchd_msg | def process_vchd_msg(self, msg: ViewChangeDone, sender: str) -> bool:
"""
Processes ViewChangeDone messages. Once n-f messages have been
received, decides on a primary for specific replica.
:param msg: ViewChangeDone message
:param sender: the name of the node from which this me... | python | def process_vchd_msg(self, msg: ViewChangeDone, sender: str) -> bool:
logger.info("{}'s primary selector started processing of ViewChangeDone msg from {} : {}".
format(self.name, sender, msg))
view_no = msg.viewNo
if self.view_no != view_no:
self.provider.discard(... | [
"def",
"process_vchd_msg",
"(",
"self",
",",
"msg",
":",
"ViewChangeDone",
",",
"sender",
":",
"str",
")",
"->",
"bool",
":",
"logger",
".",
"info",
"(",
"\"{}'s primary selector started processing of ViewChangeDone msg from {} : {}\"",
".",
"format",
"(",
"self",
"... | Processes ViewChangeDone messages. Once n-f messages have been
received, decides on a primary for specific replica.
:param msg: ViewChangeDone message
:param sender: the name of the node from which this message was sent | [
"Processes",
"ViewChangeDone",
"messages",
".",
"Once",
"n",
"-",
"f",
"messages",
"have",
"been",
"received",
"decides",
"on",
"a",
"primary",
"for",
"specific",
"replica",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/view_change/view_changer.py#L418-L452 |
248,136 | hyperledger/indy-plenum | plenum/server/view_change/view_changer.py | ViewChanger.sendInstanceChange | def sendInstanceChange(self, view_no: int,
suspicion=Suspicions.PRIMARY_DEGRADED):
"""
Broadcast an instance change request to all the remaining nodes
:param view_no: the view number when the instance change is requested
"""
# If not found any sent in... | python | def sendInstanceChange(self, view_no: int,
suspicion=Suspicions.PRIMARY_DEGRADED):
# If not found any sent instance change messages in last
# `ViewChangeWindowSize` seconds or the last sent instance change
# message was sent long enough ago then instance change message... | [
"def",
"sendInstanceChange",
"(",
"self",
",",
"view_no",
":",
"int",
",",
"suspicion",
"=",
"Suspicions",
".",
"PRIMARY_DEGRADED",
")",
":",
"# If not found any sent instance change messages in last",
"# `ViewChangeWindowSize` seconds or the last sent instance change",
"# messag... | Broadcast an instance change request to all the remaining nodes
:param view_no: the view number when the instance change is requested | [
"Broadcast",
"an",
"instance",
"change",
"request",
"to",
"all",
"the",
"remaining",
"nodes"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/view_change/view_changer.py#L475-L505 |
248,137 | hyperledger/indy-plenum | plenum/server/view_change/view_changer.py | ViewChanger._canViewChange | def _canViewChange(self, proposedViewNo: int) -> (bool, str):
"""
Return whether there's quorum for view change for the proposed view
number and its view is less than or equal to the proposed view
"""
msg = None
quorum = self.quorums.view_change.value
if not self.... | python | def _canViewChange(self, proposedViewNo: int) -> (bool, str):
msg = None
quorum = self.quorums.view_change.value
if not self.instance_changes.has_quorum(proposedViewNo, quorum):
msg = '{} has no quorum for view {}'.format(self, proposedViewNo)
elif not proposedViewNo > self.v... | [
"def",
"_canViewChange",
"(",
"self",
",",
"proposedViewNo",
":",
"int",
")",
"->",
"(",
"bool",
",",
"str",
")",
":",
"msg",
"=",
"None",
"quorum",
"=",
"self",
".",
"quorums",
".",
"view_change",
".",
"value",
"if",
"not",
"self",
".",
"instance_chan... | Return whether there's quorum for view change for the proposed view
number and its view is less than or equal to the proposed view | [
"Return",
"whether",
"there",
"s",
"quorum",
"for",
"view",
"change",
"for",
"the",
"proposed",
"view",
"number",
"and",
"its",
"view",
"is",
"less",
"than",
"or",
"equal",
"to",
"the",
"proposed",
"view"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/view_change/view_changer.py#L548-L561 |
248,138 | hyperledger/indy-plenum | plenum/server/view_change/view_changer.py | ViewChanger.start_view_change | def start_view_change(self, proposed_view_no: int, continue_vc=False):
"""
Trigger the view change process.
:param proposed_view_no: the new view number after view change.
"""
# TODO: consider moving this to pool manager
# TODO: view change is a special case, which can h... | python | def start_view_change(self, proposed_view_no: int, continue_vc=False):
# TODO: consider moving this to pool manager
# TODO: view change is a special case, which can have different
# implementations - we need to make this logic pluggable
if self.pre_vc_strategy and (not continue_vc):
... | [
"def",
"start_view_change",
"(",
"self",
",",
"proposed_view_no",
":",
"int",
",",
"continue_vc",
"=",
"False",
")",
":",
"# TODO: consider moving this to pool manager",
"# TODO: view change is a special case, which can have different",
"# implementations - we need to make this logic... | Trigger the view change process.
:param proposed_view_no: the new view number after view change. | [
"Trigger",
"the",
"view",
"change",
"process",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/view_change/view_changer.py#L563-L591 |
248,139 | hyperledger/indy-plenum | plenum/server/view_change/view_changer.py | ViewChanger._verify_primary | def _verify_primary(self, new_primary, ledger_info):
"""
This method is called when sufficient number of ViewChangeDone
received and makes steps to switch to the new primary
"""
expected_primary = self.provider.next_primary_name()
if new_primary != expected_primary:
... | python | def _verify_primary(self, new_primary, ledger_info):
expected_primary = self.provider.next_primary_name()
if new_primary != expected_primary:
logger.error("{}{} expected next primary to be {}, but majority "
"declared {} instead for view {}"
... | [
"def",
"_verify_primary",
"(",
"self",
",",
"new_primary",
",",
"ledger_info",
")",
":",
"expected_primary",
"=",
"self",
".",
"provider",
".",
"next_primary_name",
"(",
")",
"if",
"new_primary",
"!=",
"expected_primary",
":",
"logger",
".",
"error",
"(",
"\"{... | This method is called when sufficient number of ViewChangeDone
received and makes steps to switch to the new primary | [
"This",
"method",
"is",
"called",
"when",
"sufficient",
"number",
"of",
"ViewChangeDone",
"received",
"and",
"makes",
"steps",
"to",
"switch",
"to",
"the",
"new",
"primary"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/view_change/view_changer.py#L691-L705 |
248,140 | hyperledger/indy-plenum | plenum/server/view_change/view_changer.py | ViewChanger._send_view_change_done_message | def _send_view_change_done_message(self):
"""
Sends ViewChangeDone message to other protocol participants
"""
new_primary_name = self.provider.next_primary_name()
ledger_summary = self.provider.ledger_summary()
message = ViewChangeDone(self.view_no,
... | python | def _send_view_change_done_message(self):
new_primary_name = self.provider.next_primary_name()
ledger_summary = self.provider.ledger_summary()
message = ViewChangeDone(self.view_no,
new_primary_name,
ledger_summary)
logge... | [
"def",
"_send_view_change_done_message",
"(",
"self",
")",
":",
"new_primary_name",
"=",
"self",
".",
"provider",
".",
"next_primary_name",
"(",
")",
"ledger_summary",
"=",
"self",
".",
"provider",
".",
"ledger_summary",
"(",
")",
"message",
"=",
"ViewChangeDone",... | Sends ViewChangeDone message to other protocol participants | [
"Sends",
"ViewChangeDone",
"message",
"to",
"other",
"protocol",
"participants"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/view_change/view_changer.py#L708-L721 |
248,141 | hyperledger/indy-plenum | plenum/server/view_change/view_changer.py | ViewChanger.get_msgs_for_lagged_nodes | def get_msgs_for_lagged_nodes(self) -> List[ViewChangeDone]:
# Should not return a list, only done for compatibility with interface
"""
Returns the last accepted `ViewChangeDone` message.
If no view change has happened returns ViewChangeDone
with view no 0 to a newly joined node
... | python | def get_msgs_for_lagged_nodes(self) -> List[ViewChangeDone]:
# Should not return a list, only done for compatibility with interface
# TODO: Consider a case where more than one node joins immediately,
# then one of the node might not have an accepted
# ViewChangeDone message
messa... | [
"def",
"get_msgs_for_lagged_nodes",
"(",
"self",
")",
"->",
"List",
"[",
"ViewChangeDone",
"]",
":",
"# Should not return a list, only done for compatibility with interface",
"# TODO: Consider a case where more than one node joins immediately,",
"# then one of the node might not have an ac... | Returns the last accepted `ViewChangeDone` message.
If no view change has happened returns ViewChangeDone
with view no 0 to a newly joined node | [
"Returns",
"the",
"last",
"accepted",
"ViewChangeDone",
"message",
".",
"If",
"no",
"view",
"change",
"has",
"happened",
"returns",
"ViewChangeDone",
"with",
"view",
"no",
"0",
"to",
"a",
"newly",
"joined",
"node"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/view_change/view_changer.py#L724-L744 |
248,142 | hyperledger/indy-plenum | plenum/common/messages/fields.py | FieldBase.validate | def validate(self, val):
"""
Performs basic validation of field value and then passes it for
specific validation.
:param val: field value to validate
:return: error message or None
"""
if self.nullable and val is None:
return
type_er = self._... | python | def validate(self, val):
if self.nullable and val is None:
return
type_er = self.__type_check(val)
if type_er:
return type_er
spec_err = self._specific_validation(val)
if spec_err:
return spec_err | [
"def",
"validate",
"(",
"self",
",",
"val",
")",
":",
"if",
"self",
".",
"nullable",
"and",
"val",
"is",
"None",
":",
"return",
"type_er",
"=",
"self",
".",
"__type_check",
"(",
"val",
")",
"if",
"type_er",
":",
"return",
"type_er",
"spec_err",
"=",
... | Performs basic validation of field value and then passes it for
specific validation.
:param val: field value to validate
:return: error message or None | [
"Performs",
"basic",
"validation",
"of",
"field",
"value",
"and",
"then",
"passes",
"it",
"for",
"specific",
"validation",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/common/messages/fields.py#L51-L68 |
248,143 | hyperledger/indy-plenum | plenum/common/signer_did.py | DidSigner.sign | def sign(self, msg: Dict) -> Dict:
"""
Return a signature for the given message.
"""
ser = serialize_msg_for_signing(msg, topLevelKeysToIgnore=[f.SIG.nm])
bsig = self.naclSigner.signature(ser)
sig = base58.b58encode(bsig).decode("utf-8")
return sig | python | def sign(self, msg: Dict) -> Dict:
ser = serialize_msg_for_signing(msg, topLevelKeysToIgnore=[f.SIG.nm])
bsig = self.naclSigner.signature(ser)
sig = base58.b58encode(bsig).decode("utf-8")
return sig | [
"def",
"sign",
"(",
"self",
",",
"msg",
":",
"Dict",
")",
"->",
"Dict",
":",
"ser",
"=",
"serialize_msg_for_signing",
"(",
"msg",
",",
"topLevelKeysToIgnore",
"=",
"[",
"f",
".",
"SIG",
".",
"nm",
"]",
")",
"bsig",
"=",
"self",
".",
"naclSigner",
"."... | Return a signature for the given message. | [
"Return",
"a",
"signature",
"for",
"the",
"given",
"message",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/common/signer_did.py#L122-L129 |
248,144 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.lastPrePrepareSeqNo | def lastPrePrepareSeqNo(self, n):
"""
This will _lastPrePrepareSeqNo to values greater than its previous
values else it will not. To forcefully override as in case of `revert`,
directly set `self._lastPrePrepareSeqNo`
"""
if n > self._lastPrePrepareSeqNo:
self... | python | def lastPrePrepareSeqNo(self, n):
if n > self._lastPrePrepareSeqNo:
self._lastPrePrepareSeqNo = n
else:
self.logger.debug(
'{} cannot set lastPrePrepareSeqNo to {} as its '
'already {}'.format(
self, n, self._lastPrePrepareSeqNo... | [
"def",
"lastPrePrepareSeqNo",
"(",
"self",
",",
"n",
")",
":",
"if",
"n",
">",
"self",
".",
"_lastPrePrepareSeqNo",
":",
"self",
".",
"_lastPrePrepareSeqNo",
"=",
"n",
"else",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'{} cannot set lastPrePrepareSeqNo t... | This will _lastPrePrepareSeqNo to values greater than its previous
values else it will not. To forcefully override as in case of `revert`,
directly set `self._lastPrePrepareSeqNo` | [
"This",
"will",
"_lastPrePrepareSeqNo",
"to",
"values",
"greater",
"than",
"its",
"previous",
"values",
"else",
"it",
"will",
"not",
".",
"To",
"forcefully",
"override",
"as",
"in",
"case",
"of",
"revert",
"directly",
"set",
"self",
".",
"_lastPrePrepareSeqNo"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L515-L527 |
248,145 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.primaryName | def primaryName(self, value: Optional[str]) -> None:
"""
Set the value of isPrimary.
:param value: the value to set isPrimary to
"""
if value is not None:
self.warned_no_primary = False
self.primaryNames[self.viewNo] = value
self.compact_primary_names... | python | def primaryName(self, value: Optional[str]) -> None:
if value is not None:
self.warned_no_primary = False
self.primaryNames[self.viewNo] = value
self.compact_primary_names()
if value != self._primaryName:
self._primaryName = value
self.logger.info("{} ... | [
"def",
"primaryName",
"(",
"self",
",",
"value",
":",
"Optional",
"[",
"str",
"]",
")",
"->",
"None",
":",
"if",
"value",
"is",
"not",
"None",
":",
"self",
".",
"warned_no_primary",
"=",
"False",
"self",
".",
"primaryNames",
"[",
"self",
".",
"viewNo",... | Set the value of isPrimary.
:param value: the value to set isPrimary to | [
"Set",
"the",
"value",
"of",
"isPrimary",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L598-L618 |
248,146 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.get_lowest_probable_prepared_certificate_in_view | def get_lowest_probable_prepared_certificate_in_view(
self, view_no) -> Optional[int]:
"""
Return lowest pp_seq_no of the view for which can be prepared but
choose from unprocessed PRE-PREPAREs and PREPAREs.
"""
# TODO: Naive implementation, dont need to iterate over ... | python | def get_lowest_probable_prepared_certificate_in_view(
self, view_no) -> Optional[int]:
# TODO: Naive implementation, dont need to iterate over the complete
# data structures, fix this later
seq_no_pp = SortedList() # pp_seq_no of PRE-PREPAREs
# pp_seq_no of PREPAREs with cou... | [
"def",
"get_lowest_probable_prepared_certificate_in_view",
"(",
"self",
",",
"view_no",
")",
"->",
"Optional",
"[",
"int",
"]",
":",
"# TODO: Naive implementation, dont need to iterate over the complete",
"# data structures, fix this later",
"seq_no_pp",
"=",
"SortedList",
"(",
... | Return lowest pp_seq_no of the view for which can be prepared but
choose from unprocessed PRE-PREPAREs and PREPAREs. | [
"Return",
"lowest",
"pp_seq_no",
"of",
"the",
"view",
"for",
"which",
"can",
"be",
"prepared",
"but",
"choose",
"from",
"unprocessed",
"PRE",
"-",
"PREPAREs",
"and",
"PREPAREs",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L692-L717 |
248,147 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.is_primary_in_view | def is_primary_in_view(self, viewNo: int) -> Optional[bool]:
"""
Return whether this replica was primary in the given view
"""
if viewNo not in self.primaryNames:
return False
return self.primaryNames[viewNo] == self.name | python | def is_primary_in_view(self, viewNo: int) -> Optional[bool]:
if viewNo not in self.primaryNames:
return False
return self.primaryNames[viewNo] == self.name | [
"def",
"is_primary_in_view",
"(",
"self",
",",
"viewNo",
":",
"int",
")",
"->",
"Optional",
"[",
"bool",
"]",
":",
"if",
"viewNo",
"not",
"in",
"self",
".",
"primaryNames",
":",
"return",
"False",
"return",
"self",
".",
"primaryNames",
"[",
"viewNo",
"]"... | Return whether this replica was primary in the given view | [
"Return",
"whether",
"this",
"replica",
"was",
"primary",
"in",
"the",
"given",
"view"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L747-L753 |
248,148 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.processReqDuringBatch | def processReqDuringBatch(
self,
req: Request,
cons_time: int):
"""
This method will do dynamic validation and apply requests.
If there is any errors during validation it would be raised
"""
if self.isMaster:
self.node.doDynamicVali... | python | def processReqDuringBatch(
self,
req: Request,
cons_time: int):
if self.isMaster:
self.node.doDynamicValidation(req)
self.node.applyReq(req, cons_time) | [
"def",
"processReqDuringBatch",
"(",
"self",
",",
"req",
":",
"Request",
",",
"cons_time",
":",
"int",
")",
":",
"if",
"self",
".",
"isMaster",
":",
"self",
".",
"node",
".",
"doDynamicValidation",
"(",
"req",
")",
"self",
".",
"node",
".",
"applyReq",
... | This method will do dynamic validation and apply requests.
If there is any errors during validation it would be raised | [
"This",
"method",
"will",
"do",
"dynamic",
"validation",
"and",
"apply",
"requests",
".",
"If",
"there",
"is",
"any",
"errors",
"during",
"validation",
"it",
"would",
"be",
"raised"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L902-L912 |
248,149 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.serviceQueues | def serviceQueues(self, limit=None):
"""
Process `limit` number of messages in the inBox.
:param limit: the maximum number of messages to process
:return: the number of messages successfully processed
"""
# TODO should handle SuspiciousNode here
r = self.dequeue_... | python | def serviceQueues(self, limit=None):
# TODO should handle SuspiciousNode here
r = self.dequeue_pre_prepares()
r += self.inBoxRouter.handleAllSync(self.inBox, limit)
r += self.send_3pc_batch()
r += self._serviceActions()
return r | [
"def",
"serviceQueues",
"(",
"self",
",",
"limit",
"=",
"None",
")",
":",
"# TODO should handle SuspiciousNode here",
"r",
"=",
"self",
".",
"dequeue_pre_prepares",
"(",
")",
"r",
"+=",
"self",
".",
"inBoxRouter",
".",
"handleAllSync",
"(",
"self",
".",
"inBox... | Process `limit` number of messages in the inBox.
:param limit: the maximum number of messages to process
:return: the number of messages successfully processed | [
"Process",
"limit",
"number",
"of",
"messages",
"in",
"the",
"inBox",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1043-L1055 |
248,150 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.tryPrepare | def tryPrepare(self, pp: PrePrepare):
"""
Try to send the Prepare message if the PrePrepare message is ready to
be passed into the Prepare phase.
"""
rv, msg = self.canPrepare(pp)
if rv:
self.doPrepare(pp)
else:
self.logger.debug("{} cannot... | python | def tryPrepare(self, pp: PrePrepare):
rv, msg = self.canPrepare(pp)
if rv:
self.doPrepare(pp)
else:
self.logger.debug("{} cannot send PREPARE since {}".format(self, msg)) | [
"def",
"tryPrepare",
"(",
"self",
",",
"pp",
":",
"PrePrepare",
")",
":",
"rv",
",",
"msg",
"=",
"self",
".",
"canPrepare",
"(",
"pp",
")",
"if",
"rv",
":",
"self",
".",
"doPrepare",
"(",
"pp",
")",
"else",
":",
"self",
".",
"logger",
".",
"debug... | Try to send the Prepare message if the PrePrepare message is ready to
be passed into the Prepare phase. | [
"Try",
"to",
"send",
"the",
"Prepare",
"message",
"if",
"the",
"PrePrepare",
"message",
"is",
"ready",
"to",
"be",
"passed",
"into",
"the",
"Prepare",
"phase",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1293-L1302 |
248,151 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.processPrepare | def processPrepare(self, prepare: Prepare, sender: str) -> None:
"""
Validate and process the PREPARE specified.
If validation is successful, create a COMMIT and broadcast it.
:param prepare: a PREPARE msg
:param sender: name of the node that sent the PREPARE
"""
... | python | def processPrepare(self, prepare: Prepare, sender: str) -> None:
key = (prepare.viewNo, prepare.ppSeqNo)
self.logger.debug("{} received PREPARE{} from {}".format(self, key, sender))
# TODO move this try/except up higher
try:
if self.validatePrepare(prepare, sender):
... | [
"def",
"processPrepare",
"(",
"self",
",",
"prepare",
":",
"Prepare",
",",
"sender",
":",
"str",
")",
"->",
"None",
":",
"key",
"=",
"(",
"prepare",
".",
"viewNo",
",",
"prepare",
".",
"ppSeqNo",
")",
"self",
".",
"logger",
".",
"debug",
"(",
"\"{} r... | Validate and process the PREPARE specified.
If validation is successful, create a COMMIT and broadcast it.
:param prepare: a PREPARE msg
:param sender: name of the node that sent the PREPARE | [
"Validate",
"and",
"process",
"the",
"PREPARE",
"specified",
".",
"If",
"validation",
"is",
"successful",
"create",
"a",
"COMMIT",
"and",
"broadcast",
"it",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1306-L1329 |
248,152 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.processCommit | def processCommit(self, commit: Commit, sender: str) -> None:
"""
Validate and process the COMMIT specified.
If validation is successful, return the message to the node.
:param commit: an incoming COMMIT message
:param sender: name of the node that sent the COMMIT
"""
... | python | def processCommit(self, commit: Commit, sender: str) -> None:
self.logger.debug("{} received COMMIT{} from {}".format(
self, (commit.viewNo, commit.ppSeqNo), sender))
if self.validateCommit(commit, sender):
self.stats.inc(TPCStat.CommitRcvd)
self.addToCommits(commit,... | [
"def",
"processCommit",
"(",
"self",
",",
"commit",
":",
"Commit",
",",
"sender",
":",
"str",
")",
"->",
"None",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"\"{} received COMMIT{} from {}\"",
".",
"format",
"(",
"self",
",",
"(",
"commit",
".",
"view... | Validate and process the COMMIT specified.
If validation is successful, return the message to the node.
:param commit: an incoming COMMIT message
:param sender: name of the node that sent the COMMIT | [
"Validate",
"and",
"process",
"the",
"COMMIT",
"specified",
".",
"If",
"validation",
"is",
"successful",
"return",
"the",
"message",
"to",
"the",
"node",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1333-L1348 |
248,153 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.tryCommit | def tryCommit(self, prepare: Prepare):
"""
Try to commit if the Prepare message is ready to be passed into the
commit phase.
"""
rv, reason = self.canCommit(prepare)
if rv:
self.doCommit(prepare)
else:
self.logger.debug("{} cannot send COMM... | python | def tryCommit(self, prepare: Prepare):
rv, reason = self.canCommit(prepare)
if rv:
self.doCommit(prepare)
else:
self.logger.debug("{} cannot send COMMIT since {}".format(self, reason)) | [
"def",
"tryCommit",
"(",
"self",
",",
"prepare",
":",
"Prepare",
")",
":",
"rv",
",",
"reason",
"=",
"self",
".",
"canCommit",
"(",
"prepare",
")",
"if",
"rv",
":",
"self",
".",
"doCommit",
"(",
"prepare",
")",
"else",
":",
"self",
".",
"logger",
"... | Try to commit if the Prepare message is ready to be passed into the
commit phase. | [
"Try",
"to",
"commit",
"if",
"the",
"Prepare",
"message",
"is",
"ready",
"to",
"be",
"passed",
"into",
"the",
"commit",
"phase",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1350-L1359 |
248,154 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.tryOrder | def tryOrder(self, commit: Commit):
"""
Try to order if the Commit message is ready to be ordered.
"""
canOrder, reason = self.canOrder(commit)
if canOrder:
self.logger.trace("{} returning request to node".format(self))
self.doOrder(commit)
else:
... | python | def tryOrder(self, commit: Commit):
canOrder, reason = self.canOrder(commit)
if canOrder:
self.logger.trace("{} returning request to node".format(self))
self.doOrder(commit)
else:
self.logger.debug("{} cannot return request to node: {}".format(self, reason))
... | [
"def",
"tryOrder",
"(",
"self",
",",
"commit",
":",
"Commit",
")",
":",
"canOrder",
",",
"reason",
"=",
"self",
".",
"canOrder",
"(",
"commit",
")",
"if",
"canOrder",
":",
"self",
".",
"logger",
".",
"trace",
"(",
"\"{} returning request to node\"",
".",
... | Try to order if the Commit message is ready to be ordered. | [
"Try",
"to",
"order",
"if",
"the",
"Commit",
"message",
"is",
"ready",
"to",
"be",
"ordered",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1361-L1371 |
248,155 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.nonFinalisedReqs | def nonFinalisedReqs(self, reqKeys: List[Tuple[str, int]]):
"""
Check if there are any requests which are not finalised, i.e for
which there are not enough PROPAGATEs
"""
return {key for key in reqKeys if not self.requests.is_finalised(key)} | python | def nonFinalisedReqs(self, reqKeys: List[Tuple[str, int]]):
return {key for key in reqKeys if not self.requests.is_finalised(key)} | [
"def",
"nonFinalisedReqs",
"(",
"self",
",",
"reqKeys",
":",
"List",
"[",
"Tuple",
"[",
"str",
",",
"int",
"]",
"]",
")",
":",
"return",
"{",
"key",
"for",
"key",
"in",
"reqKeys",
"if",
"not",
"self",
".",
"requests",
".",
"is_finalised",
"(",
"key",... | Check if there are any requests which are not finalised, i.e for
which there are not enough PROPAGATEs | [
"Check",
"if",
"there",
"are",
"any",
"requests",
"which",
"are",
"not",
"finalised",
"i",
".",
"e",
"for",
"which",
"there",
"are",
"not",
"enough",
"PROPAGATEs"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1428-L1433 |
248,156 | hyperledger/indy-plenum | plenum/server/replica.py | Replica._can_process_pre_prepare | def _can_process_pre_prepare(self, pre_prepare: PrePrepare, sender: str) -> Optional[int]:
"""
Decide whether this replica is eligible to process a PRE-PREPARE.
:param pre_prepare: a PRE-PREPARE msg to process
:param sender: the name of the node that sent the PRE-PREPARE msg
"""... | python | def _can_process_pre_prepare(self, pre_prepare: PrePrepare, sender: str) -> Optional[int]:
# TODO: Check whether it is rejecting PRE-PREPARE from previous view
# PRE-PREPARE should not be sent from non primary
if not self.isMsgFromPrimary(pre_prepare, sender):
return PP_CHECK_NOT_FR... | [
"def",
"_can_process_pre_prepare",
"(",
"self",
",",
"pre_prepare",
":",
"PrePrepare",
",",
"sender",
":",
"str",
")",
"->",
"Optional",
"[",
"int",
"]",
":",
"# TODO: Check whether it is rejecting PRE-PREPARE from previous view",
"# PRE-PREPARE should not be sent from non pr... | Decide whether this replica is eligible to process a PRE-PREPARE.
:param pre_prepare: a PRE-PREPARE msg to process
:param sender: the name of the node that sent the PRE-PREPARE msg | [
"Decide",
"whether",
"this",
"replica",
"is",
"eligible",
"to",
"process",
"a",
"PRE",
"-",
"PREPARE",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1539-L1579 |
248,157 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.addToPrePrepares | def addToPrePrepares(self, pp: PrePrepare) -> None:
"""
Add the specified PRE-PREPARE to this replica's list of received
PRE-PREPAREs and try sending PREPARE
:param pp: the PRE-PREPARE to add to the list
"""
key = (pp.viewNo, pp.ppSeqNo)
self.prePrepares[key] = p... | python | def addToPrePrepares(self, pp: PrePrepare) -> None:
key = (pp.viewNo, pp.ppSeqNo)
self.prePrepares[key] = pp
self.lastPrePrepareSeqNo = pp.ppSeqNo
self.last_accepted_pre_prepare_time = pp.ppTime
self.dequeue_prepares(*key)
self.dequeue_commits(*key)
self.stats.inc... | [
"def",
"addToPrePrepares",
"(",
"self",
",",
"pp",
":",
"PrePrepare",
")",
"->",
"None",
":",
"key",
"=",
"(",
"pp",
".",
"viewNo",
",",
"pp",
".",
"ppSeqNo",
")",
"self",
".",
"prePrepares",
"[",
"key",
"]",
"=",
"pp",
"self",
".",
"lastPrePrepareSe... | Add the specified PRE-PREPARE to this replica's list of received
PRE-PREPAREs and try sending PREPARE
:param pp: the PRE-PREPARE to add to the list | [
"Add",
"the",
"specified",
"PRE",
"-",
"PREPARE",
"to",
"this",
"replica",
"s",
"list",
"of",
"received",
"PRE",
"-",
"PREPAREs",
"and",
"try",
"sending",
"PREPARE"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1581-L1595 |
248,158 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.canPrepare | def canPrepare(self, ppReq) -> (bool, str):
"""
Return whether the batch of requests in the PRE-PREPARE can
proceed to the PREPARE step.
:param ppReq: any object with identifier and requestId attributes
"""
if self.has_sent_prepare(ppReq):
return False, 'has ... | python | def canPrepare(self, ppReq) -> (bool, str):
if self.has_sent_prepare(ppReq):
return False, 'has already sent PREPARE for {}'.format(ppReq)
return True, '' | [
"def",
"canPrepare",
"(",
"self",
",",
"ppReq",
")",
"->",
"(",
"bool",
",",
"str",
")",
":",
"if",
"self",
".",
"has_sent_prepare",
"(",
"ppReq",
")",
":",
"return",
"False",
",",
"'has already sent PREPARE for {}'",
".",
"format",
"(",
"ppReq",
")",
"r... | Return whether the batch of requests in the PRE-PREPARE can
proceed to the PREPARE step.
:param ppReq: any object with identifier and requestId attributes | [
"Return",
"whether",
"the",
"batch",
"of",
"requests",
"in",
"the",
"PRE",
"-",
"PREPARE",
"can",
"proceed",
"to",
"the",
"PREPARE",
"step",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1600-L1609 |
248,159 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.validatePrepare | def validatePrepare(self, prepare: Prepare, sender: str) -> bool:
"""
Return whether the PREPARE specified is valid.
:param prepare: the PREPARE to validate
:param sender: the name of the node that sent the PREPARE
:return: True if PREPARE is valid, False otherwise
"""
... | python | def validatePrepare(self, prepare: Prepare, sender: str) -> bool:
key = (prepare.viewNo, prepare.ppSeqNo)
primaryStatus = self.isPrimaryForMsg(prepare)
ppReq = self.getPrePrepare(*key)
# If a non primary replica and receiving a PREPARE request before a
# PRE-PREPARE request, th... | [
"def",
"validatePrepare",
"(",
"self",
",",
"prepare",
":",
"Prepare",
",",
"sender",
":",
"str",
")",
"->",
"bool",
":",
"key",
"=",
"(",
"prepare",
".",
"viewNo",
",",
"prepare",
".",
"ppSeqNo",
")",
"primaryStatus",
"=",
"self",
".",
"isPrimaryForMsg"... | Return whether the PREPARE specified is valid.
:param prepare: the PREPARE to validate
:param sender: the name of the node that sent the PREPARE
:return: True if PREPARE is valid, False otherwise | [
"Return",
"whether",
"the",
"PREPARE",
"specified",
"is",
"valid",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1611-L1682 |
248,160 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.addToPrepares | def addToPrepares(self, prepare: Prepare, sender: str):
"""
Add the specified PREPARE to this replica's list of received
PREPAREs and try sending COMMIT
:param prepare: the PREPARE to add to the list
"""
# BLS multi-sig:
self._bls_bft_replica.process_prepare(prep... | python | def addToPrepares(self, prepare: Prepare, sender: str):
# BLS multi-sig:
self._bls_bft_replica.process_prepare(prepare, sender)
self.prepares.addVote(prepare, sender)
self.dequeue_commits(prepare.viewNo, prepare.ppSeqNo)
self.tryCommit(prepare) | [
"def",
"addToPrepares",
"(",
"self",
",",
"prepare",
":",
"Prepare",
",",
"sender",
":",
"str",
")",
":",
"# BLS multi-sig:",
"self",
".",
"_bls_bft_replica",
".",
"process_prepare",
"(",
"prepare",
",",
"sender",
")",
"self",
".",
"prepares",
".",
"addVote"... | Add the specified PREPARE to this replica's list of received
PREPAREs and try sending COMMIT
:param prepare: the PREPARE to add to the list | [
"Add",
"the",
"specified",
"PREPARE",
"to",
"this",
"replica",
"s",
"list",
"of",
"received",
"PREPAREs",
"and",
"try",
"sending",
"COMMIT"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1684-L1696 |
248,161 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.canCommit | def canCommit(self, prepare: Prepare) -> (bool, str):
"""
Return whether the specified PREPARE can proceed to the Commit
step.
Decision criteria:
- If this replica has got just n-f-1 PREPARE requests then commit request.
- If less than n-f-1 PREPARE requests then probab... | python | def canCommit(self, prepare: Prepare) -> (bool, str):
quorum = self.quorums.prepare.value
if not self.prepares.hasQuorum(prepare, quorum):
return False, 'does not have prepare quorum for {}'.format(prepare)
if self.hasCommitted(prepare):
return False, 'has already sent CO... | [
"def",
"canCommit",
"(",
"self",
",",
"prepare",
":",
"Prepare",
")",
"->",
"(",
"bool",
",",
"str",
")",
":",
"quorum",
"=",
"self",
".",
"quorums",
".",
"prepare",
".",
"value",
"if",
"not",
"self",
".",
"prepares",
".",
"hasQuorum",
"(",
"prepare"... | Return whether the specified PREPARE can proceed to the Commit
step.
Decision criteria:
- If this replica has got just n-f-1 PREPARE requests then commit request.
- If less than n-f-1 PREPARE requests then probably there's no consensus on
the request; don't commit
-... | [
"Return",
"whether",
"the",
"specified",
"PREPARE",
"can",
"proceed",
"to",
"the",
"Commit",
"step",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1740-L1759 |
248,162 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.validateCommit | def validateCommit(self, commit: Commit, sender: str) -> bool:
"""
Return whether the COMMIT specified is valid.
:param commit: the COMMIT to validate
:return: True if `request` is valid, False otherwise
"""
key = (commit.viewNo, commit.ppSeqNo)
if not self.has_p... | python | def validateCommit(self, commit: Commit, sender: str) -> bool:
key = (commit.viewNo, commit.ppSeqNo)
if not self.has_prepared(key):
self.enqueue_commit(commit, sender)
return False
if self.commits.hasCommitFrom(commit, sender):
raise SuspiciousNode(sender, Su... | [
"def",
"validateCommit",
"(",
"self",
",",
"commit",
":",
"Commit",
",",
"sender",
":",
"str",
")",
"->",
"bool",
":",
"key",
"=",
"(",
"commit",
".",
"viewNo",
",",
"commit",
".",
"ppSeqNo",
")",
"if",
"not",
"self",
".",
"has_prepared",
"(",
"key",... | Return whether the COMMIT specified is valid.
:param commit: the COMMIT to validate
:return: True if `request` is valid, False otherwise | [
"Return",
"whether",
"the",
"COMMIT",
"specified",
"is",
"valid",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1761-L1790 |
248,163 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.addToCommits | def addToCommits(self, commit: Commit, sender: str):
"""
Add the specified COMMIT to this replica's list of received
commit requests.
:param commit: the COMMIT to add to the list
:param sender: the name of the node that sent the COMMIT
"""
# BLS multi-sig:
... | python | def addToCommits(self, commit: Commit, sender: str):
# BLS multi-sig:
self._bls_bft_replica.process_commit(commit, sender)
self.commits.addVote(commit, sender)
self.tryOrder(commit) | [
"def",
"addToCommits",
"(",
"self",
",",
"commit",
":",
"Commit",
",",
"sender",
":",
"str",
")",
":",
"# BLS multi-sig:",
"self",
".",
"_bls_bft_replica",
".",
"process_commit",
"(",
"commit",
",",
"sender",
")",
"self",
".",
"commits",
".",
"addVote",
"(... | Add the specified COMMIT to this replica's list of received
commit requests.
:param commit: the COMMIT to add to the list
:param sender: the name of the node that sent the COMMIT | [
"Add",
"the",
"specified",
"COMMIT",
"to",
"this",
"replica",
"s",
"list",
"of",
"received",
"commit",
"requests",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1792-L1804 |
248,164 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.canOrder | def canOrder(self, commit: Commit) -> Tuple[bool, Optional[str]]:
"""
Return whether the specified commitRequest can be returned to the node.
Decision criteria:
- If have got just n-f Commit requests then return request to node
- If less than n-f of commit requests then probabl... | python | def canOrder(self, commit: Commit) -> Tuple[bool, Optional[str]]:
quorum = self.quorums.commit.value
if not self.commits.hasQuorum(commit, quorum):
return False, "no quorum ({}): {} commits where f is {}". \
format(quorum, commit, self.f)
key = (commit.viewNo, commit... | [
"def",
"canOrder",
"(",
"self",
",",
"commit",
":",
"Commit",
")",
"->",
"Tuple",
"[",
"bool",
",",
"Optional",
"[",
"str",
"]",
"]",
":",
"quorum",
"=",
"self",
".",
"quorums",
".",
"commit",
".",
"value",
"if",
"not",
"self",
".",
"commits",
".",... | Return whether the specified commitRequest can be returned to the node.
Decision criteria:
- If have got just n-f Commit requests then return request to node
- If less than n-f of commit requests then probably don't have
consensus on the request; don't return request to node
... | [
"Return",
"whether",
"the",
"specified",
"commitRequest",
"can",
"be",
"returned",
"to",
"the",
"node",
"."
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1806-L1839 |
248,165 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.all_prev_ordered | def all_prev_ordered(self, commit: Commit):
"""
Return True if all previous COMMITs have been ordered
"""
# TODO: This method does a lot of work, choose correct data
# structures to make it efficient.
viewNo, ppSeqNo = commit.viewNo, commit.ppSeqNo
if self.last_... | python | def all_prev_ordered(self, commit: Commit):
# TODO: This method does a lot of work, choose correct data
# structures to make it efficient.
viewNo, ppSeqNo = commit.viewNo, commit.ppSeqNo
if self.last_ordered_3pc == (viewNo, ppSeqNo - 1):
# Last ordered was in same view as t... | [
"def",
"all_prev_ordered",
"(",
"self",
",",
"commit",
":",
"Commit",
")",
":",
"# TODO: This method does a lot of work, choose correct data",
"# structures to make it efficient.",
"viewNo",
",",
"ppSeqNo",
"=",
"commit",
".",
"viewNo",
",",
"commit",
".",
"ppSeqNo",
"i... | Return True if all previous COMMITs have been ordered | [
"Return",
"True",
"if",
"all",
"previous",
"COMMITs",
"have",
"been",
"ordered"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L1841-L1869 |
248,166 | hyperledger/indy-plenum | plenum/server/replica.py | Replica.process_checkpoint | def process_checkpoint(self, msg: Checkpoint, sender: str) -> bool:
"""
Process checkpoint messages
:return: whether processed (True) or stashed (False)
"""
self.logger.info('{} processing checkpoint {} from {}'.format(self, msg, sender))
result, reason = self.validator.... | python | def process_checkpoint(self, msg: Checkpoint, sender: str) -> bool:
self.logger.info('{} processing checkpoint {} from {}'.format(self, msg, sender))
result, reason = self.validator.validate_checkpoint_msg(msg)
if result == DISCARD:
self.discard(msg, "{} discard message {} from {} "
... | [
"def",
"process_checkpoint",
"(",
"self",
",",
"msg",
":",
"Checkpoint",
",",
"sender",
":",
"str",
")",
"->",
"bool",
":",
"self",
".",
"logger",
".",
"info",
"(",
"'{} processing checkpoint {} from {}'",
".",
"format",
"(",
"self",
",",
"msg",
",",
"send... | Process checkpoint messages
:return: whether processed (True) or stashed (False) | [
"Process",
"checkpoint",
"messages"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L2050-L2069 |
248,167 | hyperledger/indy-plenum | plenum/server/replica.py | Replica._process_stashed_pre_prepare_for_time_if_possible | def _process_stashed_pre_prepare_for_time_if_possible(
self, key: Tuple[int, int]):
"""
Check if any PRE-PREPAREs that were stashed since their time was not
acceptable, can now be accepted since enough PREPAREs are received
"""
self.logger.debug('{} going to process s... | python | def _process_stashed_pre_prepare_for_time_if_possible(
self, key: Tuple[int, int]):
self.logger.debug('{} going to process stashed PRE-PREPAREs with '
'incorrect times'.format(self))
q = self.quorums.f
if len(self.preparesWaitingForPrePrepare[key]) > q:
... | [
"def",
"_process_stashed_pre_prepare_for_time_if_possible",
"(",
"self",
",",
"key",
":",
"Tuple",
"[",
"int",
",",
"int",
"]",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'{} going to process stashed PRE-PREPAREs with '",
"'incorrect times'",
".",
"format",
... | Check if any PRE-PREPAREs that were stashed since their time was not
acceptable, can now be accepted since enough PREPAREs are received | [
"Check",
"if",
"any",
"PRE",
"-",
"PREPAREs",
"that",
"were",
"stashed",
"since",
"their",
"time",
"was",
"not",
"acceptable",
"can",
"now",
"be",
"accepted",
"since",
"enough",
"PREPAREs",
"are",
"received"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L2742-L2768 |
248,168 | hyperledger/indy-plenum | plenum/server/replica.py | Replica._remove_till_caught_up_3pc | def _remove_till_caught_up_3pc(self, last_caught_up_3PC):
"""
Remove any 3 phase messages till the last ordered key and also remove
any corresponding request keys
"""
outdated_pre_prepares = {}
for key, pp in self.prePrepares.items():
if compare_3PC_keys(key, ... | python | def _remove_till_caught_up_3pc(self, last_caught_up_3PC):
outdated_pre_prepares = {}
for key, pp in self.prePrepares.items():
if compare_3PC_keys(key, last_caught_up_3PC) >= 0:
outdated_pre_prepares[key] = pp
for key, pp in self.sentPrePrepares.items():
if... | [
"def",
"_remove_till_caught_up_3pc",
"(",
"self",
",",
"last_caught_up_3PC",
")",
":",
"outdated_pre_prepares",
"=",
"{",
"}",
"for",
"key",
",",
"pp",
"in",
"self",
".",
"prePrepares",
".",
"items",
"(",
")",
":",
"if",
"compare_3PC_keys",
"(",
"key",
",",
... | Remove any 3 phase messages till the last ordered key and also remove
any corresponding request keys | [
"Remove",
"any",
"3",
"phase",
"messages",
"till",
"the",
"last",
"ordered",
"key",
"and",
"also",
"remove",
"any",
"corresponding",
"request",
"keys"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L2843-L2865 |
248,169 | hyperledger/indy-plenum | plenum/server/replica.py | Replica._remove_ordered_from_queue | def _remove_ordered_from_queue(self, last_caught_up_3PC=None):
"""
Remove any Ordered that the replica might be sending to node which is
less than or equal to `last_caught_up_3PC` if `last_caught_up_3PC` is
passed else remove all ordered, needed in catchup
"""
to_remove =... | python | def _remove_ordered_from_queue(self, last_caught_up_3PC=None):
to_remove = []
for i, msg in enumerate(self.outBox):
if isinstance(msg, Ordered) and \
(not last_caught_up_3PC or
compare_3PC_keys((msg.viewNo, msg.ppSeqNo), last_caught_up_3PC) >= 0):
... | [
"def",
"_remove_ordered_from_queue",
"(",
"self",
",",
"last_caught_up_3PC",
"=",
"None",
")",
":",
"to_remove",
"=",
"[",
"]",
"for",
"i",
",",
"msg",
"in",
"enumerate",
"(",
"self",
".",
"outBox",
")",
":",
"if",
"isinstance",
"(",
"msg",
",",
"Ordered... | Remove any Ordered that the replica might be sending to node which is
less than or equal to `last_caught_up_3PC` if `last_caught_up_3PC` is
passed else remove all ordered, needed in catchup | [
"Remove",
"any",
"Ordered",
"that",
"the",
"replica",
"might",
"be",
"sending",
"to",
"node",
"which",
"is",
"less",
"than",
"or",
"equal",
"to",
"last_caught_up_3PC",
"if",
"last_caught_up_3PC",
"is",
"passed",
"else",
"remove",
"all",
"ordered",
"needed",
"i... | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L2867-L2888 |
248,170 | hyperledger/indy-plenum | plenum/server/replica.py | Replica._remove_stashed_checkpoints | def _remove_stashed_checkpoints(self, till_3pc_key=None):
"""
Remove stashed received checkpoints up to `till_3pc_key` if provided,
otherwise remove all stashed received checkpoints
"""
if till_3pc_key is None:
self.stashedRecvdCheckpoints.clear()
self.log... | python | def _remove_stashed_checkpoints(self, till_3pc_key=None):
if till_3pc_key is None:
self.stashedRecvdCheckpoints.clear()
self.logger.info('{} removing all stashed checkpoints'.format(self))
return
for view_no in list(self.stashedRecvdCheckpoints.keys()):
... | [
"def",
"_remove_stashed_checkpoints",
"(",
"self",
",",
"till_3pc_key",
"=",
"None",
")",
":",
"if",
"till_3pc_key",
"is",
"None",
":",
"self",
".",
"stashedRecvdCheckpoints",
".",
"clear",
"(",
")",
"self",
".",
"logger",
".",
"info",
"(",
"'{} removing all s... | Remove stashed received checkpoints up to `till_3pc_key` if provided,
otherwise remove all stashed received checkpoints | [
"Remove",
"stashed",
"received",
"checkpoints",
"up",
"to",
"till_3pc_key",
"if",
"provided",
"otherwise",
"remove",
"all",
"stashed",
"received",
"checkpoints"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/plenum/server/replica.py#L2890-L2914 |
248,171 | hyperledger/indy-plenum | stp_core/network/util.py | checkPortAvailable | def checkPortAvailable(ha):
"""Checks whether the given port is available"""
# Not sure why OS would allow binding to one type and not other.
# Checking for port available for TCP and UDP.
sockTypes = (socket.SOCK_DGRAM, socket.SOCK_STREAM)
for typ in sockTypes:
sock = socket.socket(socket.A... | python | def checkPortAvailable(ha):
# Not sure why OS would allow binding to one type and not other.
# Checking for port available for TCP and UDP.
sockTypes = (socket.SOCK_DGRAM, socket.SOCK_STREAM)
for typ in sockTypes:
sock = socket.socket(socket.AF_INET, typ)
try:
sock.setsockopt... | [
"def",
"checkPortAvailable",
"(",
"ha",
")",
":",
"# Not sure why OS would allow binding to one type and not other.",
"# Checking for port available for TCP and UDP.",
"sockTypes",
"=",
"(",
"socket",
".",
"SOCK_DGRAM",
",",
"socket",
".",
"SOCK_STREAM",
")",
"for",
"typ",
... | Checks whether the given port is available | [
"Checks",
"whether",
"the",
"given",
"port",
"is",
"available"
] | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/stp_core/network/util.py#L19-L44 |
248,172 | hyperledger/indy-plenum | stp_core/network/util.py | evenCompare | def evenCompare(a: str, b: str) -> bool:
"""
A deterministic but more evenly distributed comparator than simple alphabetical.
Useful when comparing consecutive strings and an even distribution is needed.
Provides an even chance of returning true as often as false
"""
ab = a.encode('utf-8')
b... | python | def evenCompare(a: str, b: str) -> bool:
ab = a.encode('utf-8')
bb = b.encode('utf-8')
ac = crypto_hash_sha256(ab)
bc = crypto_hash_sha256(bb)
return ac < bc | [
"def",
"evenCompare",
"(",
"a",
":",
"str",
",",
"b",
":",
"str",
")",
"->",
"bool",
":",
"ab",
"=",
"a",
".",
"encode",
"(",
"'utf-8'",
")",
"bb",
"=",
"b",
".",
"encode",
"(",
"'utf-8'",
")",
"ac",
"=",
"crypto_hash_sha256",
"(",
"ab",
")",
"... | A deterministic but more evenly distributed comparator than simple alphabetical.
Useful when comparing consecutive strings and an even distribution is needed.
Provides an even chance of returning true as often as false | [
"A",
"deterministic",
"but",
"more",
"evenly",
"distributed",
"comparator",
"than",
"simple",
"alphabetical",
".",
"Useful",
"when",
"comparing",
"consecutive",
"strings",
"and",
"an",
"even",
"distribution",
"is",
"needed",
".",
"Provides",
"an",
"even",
"chance"... | dcd144e238af7f17a869ffc9412f13dc488b7020 | https://github.com/hyperledger/indy-plenum/blob/dcd144e238af7f17a869ffc9412f13dc488b7020/stp_core/network/util.py#L47-L57 |
248,173 | kylejusticemagnuson/pyti | pyti/keltner_bands.py | center_band | def center_band(close_data, high_data, low_data, period):
"""
Center Band.
Formula:
CB = SMA(TP)
"""
tp = typical_price(close_data, high_data, low_data)
cb = sma(tp, period)
return cb | python | def center_band(close_data, high_data, low_data, period):
tp = typical_price(close_data, high_data, low_data)
cb = sma(tp, period)
return cb | [
"def",
"center_band",
"(",
"close_data",
",",
"high_data",
",",
"low_data",
",",
"period",
")",
":",
"tp",
"=",
"typical_price",
"(",
"close_data",
",",
"high_data",
",",
"low_data",
")",
"cb",
"=",
"sma",
"(",
"tp",
",",
"period",
")",
"return",
"cb"
] | Center Band.
Formula:
CB = SMA(TP) | [
"Center",
"Band",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/keltner_bands.py#L23-L32 |
248,174 | kylejusticemagnuson/pyti | pyti/simple_moving_average.py | simple_moving_average | def simple_moving_average(data, period):
"""
Simple Moving Average.
Formula:
SUM(data / N)
"""
catch_errors.check_for_period_error(data, period)
# Mean of Empty Slice RuntimeWarning doesn't affect output so it is
# supressed
with warnings.catch_warnings():
warnings.simplefil... | python | def simple_moving_average(data, period):
catch_errors.check_for_period_error(data, period)
# Mean of Empty Slice RuntimeWarning doesn't affect output so it is
# supressed
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=RuntimeWarning)
sma = [np.mean(data[idx-(per... | [
"def",
"simple_moving_average",
"(",
"data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"# Mean of Empty Slice RuntimeWarning doesn't affect output so it is",
"# supressed",
"with",
"warnings",
".",
"catch_warnin... | Simple Moving Average.
Formula:
SUM(data / N) | [
"Simple",
"Moving",
"Average",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/simple_moving_average.py#L9-L23 |
248,175 | kylejusticemagnuson/pyti | pyti/average_true_range_percent.py | average_true_range_percent | def average_true_range_percent(close_data, period):
"""
Average True Range Percent.
Formula:
ATRP = (ATR / CLOSE) * 100
"""
catch_errors.check_for_period_error(close_data, period)
atrp = (atr(close_data, period) / np.array(close_data)) * 100
return atrp | python | def average_true_range_percent(close_data, period):
catch_errors.check_for_period_error(close_data, period)
atrp = (atr(close_data, period) / np.array(close_data)) * 100
return atrp | [
"def",
"average_true_range_percent",
"(",
"close_data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"close_data",
",",
"period",
")",
"atrp",
"=",
"(",
"atr",
"(",
"close_data",
",",
"period",
")",
"/",
"np",
".",
"array",
"(... | Average True Range Percent.
Formula:
ATRP = (ATR / CLOSE) * 100 | [
"Average",
"True",
"Range",
"Percent",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/average_true_range_percent.py#L9-L18 |
248,176 | kylejusticemagnuson/pyti | pyti/on_balance_volume.py | on_balance_volume | def on_balance_volume(close_data, volume):
"""
On Balance Volume.
Formula:
start = 1
if CLOSEt > CLOSEt-1
obv = obvt-1 + volumet
elif CLOSEt < CLOSEt-1
obv = obvt-1 - volumet
elif CLOSEt == CLOSTt-1
obv = obvt-1
"""
catch_errors.check_for_input_len_diff(close... | python | def on_balance_volume(close_data, volume):
catch_errors.check_for_input_len_diff(close_data, volume)
obv = np.zeros(len(volume))
obv[0] = 1
for idx in range(1, len(obv)):
if close_data[idx] > close_data[idx-1]:
obv[idx] = obv[idx-1] + volume[idx]
elif close_data[idx] < close_... | [
"def",
"on_balance_volume",
"(",
"close_data",
",",
"volume",
")",
":",
"catch_errors",
".",
"check_for_input_len_diff",
"(",
"close_data",
",",
"volume",
")",
"obv",
"=",
"np",
".",
"zeros",
"(",
"len",
"(",
"volume",
")",
")",
"obv",
"[",
"0",
"]",
"="... | On Balance Volume.
Formula:
start = 1
if CLOSEt > CLOSEt-1
obv = obvt-1 + volumet
elif CLOSEt < CLOSEt-1
obv = obvt-1 - volumet
elif CLOSEt == CLOSTt-1
obv = obvt-1 | [
"On",
"Balance",
"Volume",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/on_balance_volume.py#L7-L30 |
248,177 | kylejusticemagnuson/pyti | pyti/rate_of_change.py | rate_of_change | def rate_of_change(data, period):
"""
Rate of Change.
Formula:
(Close - Close n periods ago) / (Close n periods ago) * 100
"""
catch_errors.check_for_period_error(data, period)
rocs = [((data[idx] - data[idx - (period - 1)]) /
data[idx - (period - 1)]) * 100 for idx in range(perio... | python | def rate_of_change(data, period):
catch_errors.check_for_period_error(data, period)
rocs = [((data[idx] - data[idx - (period - 1)]) /
data[idx - (period - 1)]) * 100 for idx in range(period - 1, len(data))]
rocs = fill_for_noncomputable_vals(data, rocs)
return rocs | [
"def",
"rate_of_change",
"(",
"data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"rocs",
"=",
"[",
"(",
"(",
"data",
"[",
"idx",
"]",
"-",
"data",
"[",
"idx",
"-",
"(",
"period",
"-",
"1",... | Rate of Change.
Formula:
(Close - Close n periods ago) / (Close n periods ago) * 100 | [
"Rate",
"of",
"Change",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/rate_of_change.py#L7-L19 |
248,178 | kylejusticemagnuson/pyti | pyti/average_true_range.py | average_true_range | def average_true_range(close_data, period):
"""
Average True Range.
Formula:
ATRt = ATRt-1 * (n - 1) + TRt / n
"""
tr = true_range(close_data, period)
atr = smoothed_moving_average(tr, period)
atr[0:period-1] = tr[0:period-1]
return atr | python | def average_true_range(close_data, period):
tr = true_range(close_data, period)
atr = smoothed_moving_average(tr, period)
atr[0:period-1] = tr[0:period-1]
return atr | [
"def",
"average_true_range",
"(",
"close_data",
",",
"period",
")",
":",
"tr",
"=",
"true_range",
"(",
"close_data",
",",
"period",
")",
"atr",
"=",
"smoothed_moving_average",
"(",
"tr",
",",
"period",
")",
"atr",
"[",
"0",
":",
"period",
"-",
"1",
"]",
... | Average True Range.
Formula:
ATRt = ATRt-1 * (n - 1) + TRt / n | [
"Average",
"True",
"Range",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/average_true_range.py#L8-L18 |
248,179 | kylejusticemagnuson/pyti | pyti/relative_strength_index.py | relative_strength_index | def relative_strength_index(data, period):
"""
Relative Strength Index.
Formula:
RSI = 100 - (100 / 1 + (prevGain/prevLoss))
"""
catch_errors.check_for_period_error(data, period)
period = int(period)
changes = [data_tup[1] - data_tup[0] for data_tup in zip(data[::1], data[1::1])]
... | python | def relative_strength_index(data, period):
catch_errors.check_for_period_error(data, period)
period = int(period)
changes = [data_tup[1] - data_tup[0] for data_tup in zip(data[::1], data[1::1])]
filtered_gain = [val < 0 for val in changes]
gains = [0 if filtered_gain[idx] is True else changes[idx]... | [
"def",
"relative_strength_index",
"(",
"data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"period",
"=",
"int",
"(",
"period",
")",
"changes",
"=",
"[",
"data_tup",
"[",
"1",
"]",
"-",
"data_tup... | Relative Strength Index.
Formula:
RSI = 100 - (100 / 1 + (prevGain/prevLoss)) | [
"Relative",
"Strength",
"Index",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/relative_strength_index.py#L9-L51 |
248,180 | kylejusticemagnuson/pyti | pyti/vertical_horizontal_filter.py | vertical_horizontal_filter | def vertical_horizontal_filter(data, period):
"""
Vertical Horizontal Filter.
Formula:
ABS(pHIGH - pLOW) / SUM(ABS(Pi - Pi-1))
"""
catch_errors.check_for_period_error(data, period)
vhf = [abs(np.max(data[idx+1-period:idx+1]) -
np.min(data[idx+1-period:idx+1])) /
sum([ab... | python | def vertical_horizontal_filter(data, period):
catch_errors.check_for_period_error(data, period)
vhf = [abs(np.max(data[idx+1-period:idx+1]) -
np.min(data[idx+1-period:idx+1])) /
sum([abs(data[idx+1-period:idx+1][i] - data[idx+1-period:idx+1][i-1]) for i in range(0, len(data[idx+1-period:idx... | [
"def",
"vertical_horizontal_filter",
"(",
"data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"vhf",
"=",
"[",
"abs",
"(",
"np",
".",
"max",
"(",
"data",
"[",
"idx",
"+",
"1",
"-",
"period",
... | Vertical Horizontal Filter.
Formula:
ABS(pHIGH - pLOW) / SUM(ABS(Pi - Pi-1)) | [
"Vertical",
"Horizontal",
"Filter",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/vertical_horizontal_filter.py#L8-L22 |
248,181 | kylejusticemagnuson/pyti | pyti/ultimate_oscillator.py | buying_pressure | def buying_pressure(close_data, low_data):
"""
Buying Pressure.
Formula:
BP = current close - min()
"""
catch_errors.check_for_input_len_diff(close_data, low_data)
bp = [close_data[idx] - np.min([low_data[idx], close_data[idx-1]]) for idx in range(1, len(close_data))]
bp = fill_for_nonc... | python | def buying_pressure(close_data, low_data):
catch_errors.check_for_input_len_diff(close_data, low_data)
bp = [close_data[idx] - np.min([low_data[idx], close_data[idx-1]]) for idx in range(1, len(close_data))]
bp = fill_for_noncomputable_vals(close_data, bp)
return bp | [
"def",
"buying_pressure",
"(",
"close_data",
",",
"low_data",
")",
":",
"catch_errors",
".",
"check_for_input_len_diff",
"(",
"close_data",
",",
"low_data",
")",
"bp",
"=",
"[",
"close_data",
"[",
"idx",
"]",
"-",
"np",
".",
"min",
"(",
"[",
"low_data",
"[... | Buying Pressure.
Formula:
BP = current close - min() | [
"Buying",
"Pressure",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/ultimate_oscillator.py#L9-L19 |
248,182 | kylejusticemagnuson/pyti | pyti/ultimate_oscillator.py | ultimate_oscillator | def ultimate_oscillator(close_data, low_data):
"""
Ultimate Oscillator.
Formula:
UO = 100 * ((4 * AVG7) + (2 * AVG14) + AVG28) / (4 + 2 + 1)
"""
a7 = 4 * average_7(close_data, low_data)
a14 = 2 * average_14(close_data, low_data)
a28 = average_28(close_data, low_data)
uo = 100 * ((a7... | python | def ultimate_oscillator(close_data, low_data):
a7 = 4 * average_7(close_data, low_data)
a14 = 2 * average_14(close_data, low_data)
a28 = average_28(close_data, low_data)
uo = 100 * ((a7 + a14 + a28) / 7)
return uo | [
"def",
"ultimate_oscillator",
"(",
"close_data",
",",
"low_data",
")",
":",
"a7",
"=",
"4",
"*",
"average_7",
"(",
"close_data",
",",
"low_data",
")",
"a14",
"=",
"2",
"*",
"average_14",
"(",
"close_data",
",",
"low_data",
")",
"a28",
"=",
"average_28",
... | Ultimate Oscillator.
Formula:
UO = 100 * ((4 * AVG7) + (2 * AVG14) + AVG28) / (4 + 2 + 1) | [
"Ultimate",
"Oscillator",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/ultimate_oscillator.py#L62-L73 |
248,183 | kylejusticemagnuson/pyti | pyti/aroon.py | aroon_up | def aroon_up(data, period):
"""
Aroon Up.
Formula:
AROONUP = (((PERIOD) - (PERIODS since PERIOD high)) / (PERIOD)) * 100
"""
catch_errors.check_for_period_error(data, period)
period = int(period)
a_up = [((period -
list(reversed(data[idx+1-period:idx+1])).index(np.max(data[... | python | def aroon_up(data, period):
catch_errors.check_for_period_error(data, period)
period = int(period)
a_up = [((period -
list(reversed(data[idx+1-period:idx+1])).index(np.max(data[idx+1-period:idx+1]))) /
float(period)) * 100 for idx in range(period-1, len(data))]
a_up = fill_for_n... | [
"def",
"aroon_up",
"(",
"data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"period",
"=",
"int",
"(",
"period",
")",
"a_up",
"=",
"[",
"(",
"(",
"period",
"-",
"list",
"(",
"reversed",
"(",
... | Aroon Up.
Formula:
AROONUP = (((PERIOD) - (PERIODS since PERIOD high)) / (PERIOD)) * 100 | [
"Aroon",
"Up",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/aroon.py#L8-L22 |
248,184 | kylejusticemagnuson/pyti | pyti/aroon.py | aroon_down | def aroon_down(data, period):
"""
Aroon Down.
Formula:
AROONDWN = (((PERIOD) - (PERIODS SINCE PERIOD LOW)) / (PERIOD)) * 100
"""
catch_errors.check_for_period_error(data, period)
period = int(period)
a_down = [((period -
list(reversed(data[idx+1-period:idx+1])).index(np.min... | python | def aroon_down(data, period):
catch_errors.check_for_period_error(data, period)
period = int(period)
a_down = [((period -
list(reversed(data[idx+1-period:idx+1])).index(np.min(data[idx+1-period:idx+1]))) /
float(period)) * 100 for idx in range(period-1, len(data))]
a_down = fill... | [
"def",
"aroon_down",
"(",
"data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"period",
"=",
"int",
"(",
"period",
")",
"a_down",
"=",
"[",
"(",
"(",
"period",
"-",
"list",
"(",
"reversed",
"... | Aroon Down.
Formula:
AROONDWN = (((PERIOD) - (PERIODS SINCE PERIOD LOW)) / (PERIOD)) * 100 | [
"Aroon",
"Down",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/aroon.py#L25-L39 |
248,185 | kylejusticemagnuson/pyti | pyti/price_channels.py | upper_price_channel | def upper_price_channel(data, period, upper_percent):
"""
Upper Price Channel.
Formula:
upc = EMA(t) * (1 + upper_percent / 100)
"""
catch_errors.check_for_period_error(data, period)
emas = ema(data, period)
upper_channel = [val * (1+float(upper_percent)/100) for val in emas]
retur... | python | def upper_price_channel(data, period, upper_percent):
catch_errors.check_for_period_error(data, period)
emas = ema(data, period)
upper_channel = [val * (1+float(upper_percent)/100) for val in emas]
return upper_channel | [
"def",
"upper_price_channel",
"(",
"data",
",",
"period",
",",
"upper_percent",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"emas",
"=",
"ema",
"(",
"data",
",",
"period",
")",
"upper_channel",
"=",
"[",
"val",
... | Upper Price Channel.
Formula:
upc = EMA(t) * (1 + upper_percent / 100) | [
"Upper",
"Price",
"Channel",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/price_channels.py#L8-L19 |
248,186 | kylejusticemagnuson/pyti | pyti/price_channels.py | lower_price_channel | def lower_price_channel(data, period, lower_percent):
"""
Lower Price Channel.
Formula:
lpc = EMA(t) * (1 - lower_percent / 100)
"""
catch_errors.check_for_period_error(data, period)
emas = ema(data, period)
lower_channel = [val * (1-float(lower_percent)/100) for val in emas]
retur... | python | def lower_price_channel(data, period, lower_percent):
catch_errors.check_for_period_error(data, period)
emas = ema(data, period)
lower_channel = [val * (1-float(lower_percent)/100) for val in emas]
return lower_channel | [
"def",
"lower_price_channel",
"(",
"data",
",",
"period",
",",
"lower_percent",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"emas",
"=",
"ema",
"(",
"data",
",",
"period",
")",
"lower_channel",
"=",
"[",
"val",
... | Lower Price Channel.
Formula:
lpc = EMA(t) * (1 - lower_percent / 100) | [
"Lower",
"Price",
"Channel",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/price_channels.py#L22-L33 |
248,187 | kylejusticemagnuson/pyti | pyti/exponential_moving_average.py | exponential_moving_average | def exponential_moving_average(data, period):
"""
Exponential Moving Average.
Formula:
p0 + (1 - w) * p1 + (1 - w)^2 * p2 + (1 + w)^3 * p3 +...
/ 1 + (1 - w) + (1 - w)^2 + (1 - w)^3 +...
where: w = 2 / (N + 1)
"""
catch_errors.check_for_period_error(data, period)
emas... | python | def exponential_moving_average(data, period):
catch_errors.check_for_period_error(data, period)
emas = [exponential_moving_average_helper(
data[idx - period + 1:idx + 1], period) for idx in range(period - 1, len(data))]
emas = fill_for_noncomputable_vals(data, emas)
return emas | [
"def",
"exponential_moving_average",
"(",
"data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"emas",
"=",
"[",
"exponential_moving_average_helper",
"(",
"data",
"[",
"idx",
"-",
"period",
"+",
"1",
... | Exponential Moving Average.
Formula:
p0 + (1 - w) * p1 + (1 - w)^2 * p2 + (1 + w)^3 * p3 +...
/ 1 + (1 - w) + (1 - w)^2 + (1 - w)^3 +...
where: w = 2 / (N + 1) | [
"Exponential",
"Moving",
"Average",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/exponential_moving_average.py#L7-L21 |
248,188 | kylejusticemagnuson/pyti | pyti/commodity_channel_index.py | commodity_channel_index | def commodity_channel_index(close_data, high_data, low_data, period):
"""
Commodity Channel Index.
Formula:
CCI = (TP - SMA(TP)) / (0.015 * Mean Deviation)
"""
catch_errors.check_for_input_len_diff(close_data, high_data, low_data)
catch_errors.check_for_period_error(close_data, period)
... | python | def commodity_channel_index(close_data, high_data, low_data, period):
catch_errors.check_for_input_len_diff(close_data, high_data, low_data)
catch_errors.check_for_period_error(close_data, period)
tp = typical_price(close_data, high_data, low_data)
cci = ((tp - sma(tp, period)) /
(0.015 * np.... | [
"def",
"commodity_channel_index",
"(",
"close_data",
",",
"high_data",
",",
"low_data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_input_len_diff",
"(",
"close_data",
",",
"high_data",
",",
"low_data",
")",
"catch_errors",
".",
"check_for_period_error",
... | Commodity Channel Index.
Formula:
CCI = (TP - SMA(TP)) / (0.015 * Mean Deviation) | [
"Commodity",
"Channel",
"Index",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/commodity_channel_index.py#L10-L22 |
248,189 | kylejusticemagnuson/pyti | pyti/williams_percent_r.py | williams_percent_r | def williams_percent_r(close_data):
"""
Williams %R.
Formula:
wr = (HighestHigh - close / HighestHigh - LowestLow) * -100
"""
highest_high = np.max(close_data)
lowest_low = np.min(close_data)
wr = [((highest_high - close) / (highest_high - lowest_low)) * -100 for close in close_data]
... | python | def williams_percent_r(close_data):
highest_high = np.max(close_data)
lowest_low = np.min(close_data)
wr = [((highest_high - close) / (highest_high - lowest_low)) * -100 for close in close_data]
return wr | [
"def",
"williams_percent_r",
"(",
"close_data",
")",
":",
"highest_high",
"=",
"np",
".",
"max",
"(",
"close_data",
")",
"lowest_low",
"=",
"np",
".",
"min",
"(",
"close_data",
")",
"wr",
"=",
"[",
"(",
"(",
"highest_high",
"-",
"close",
")",
"/",
"(",... | Williams %R.
Formula:
wr = (HighestHigh - close / HighestHigh - LowestLow) * -100 | [
"Williams",
"%R",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/williams_percent_r.py#L5-L15 |
248,190 | kylejusticemagnuson/pyti | pyti/moving_average_convergence_divergence.py | moving_average_convergence_divergence | def moving_average_convergence_divergence(data, short_period, long_period):
"""
Moving Average Convergence Divergence.
Formula:
EMA(DATA, P1) - EMA(DATA, P2)
"""
catch_errors.check_for_period_error(data, short_period)
catch_errors.check_for_period_error(data, long_period)
macd = ema(da... | python | def moving_average_convergence_divergence(data, short_period, long_period):
catch_errors.check_for_period_error(data, short_period)
catch_errors.check_for_period_error(data, long_period)
macd = ema(data, short_period) - ema(data, long_period)
return macd | [
"def",
"moving_average_convergence_divergence",
"(",
"data",
",",
"short_period",
",",
"long_period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"short_period",
")",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"long... | Moving Average Convergence Divergence.
Formula:
EMA(DATA, P1) - EMA(DATA, P2) | [
"Moving",
"Average",
"Convergence",
"Divergence",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/moving_average_convergence_divergence.py#L8-L19 |
248,191 | kylejusticemagnuson/pyti | pyti/money_flow_index.py | money_flow_index | def money_flow_index(close_data, high_data, low_data, volume, period):
"""
Money Flow Index.
Formula:
MFI = 100 - (100 / (1 + PMF / NMF))
"""
catch_errors.check_for_input_len_diff(
close_data, high_data, low_data, volume
)
catch_errors.check_for_period_error(close_data, peri... | python | def money_flow_index(close_data, high_data, low_data, volume, period):
catch_errors.check_for_input_len_diff(
close_data, high_data, low_data, volume
)
catch_errors.check_for_period_error(close_data, period)
mf = money_flow(close_data, high_data, low_data, volume)
tp = typical_price(clo... | [
"def",
"money_flow_index",
"(",
"close_data",
",",
"high_data",
",",
"low_data",
",",
"volume",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_input_len_diff",
"(",
"close_data",
",",
"high_data",
",",
"low_data",
",",
"volume",
")",
"catch_errors",
".... | Money Flow Index.
Formula:
MFI = 100 - (100 / (1 + PMF / NMF)) | [
"Money",
"Flow",
"Index",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/money_flow_index.py#L11-L43 |
248,192 | kylejusticemagnuson/pyti | pyti/typical_price.py | typical_price | def typical_price(close_data, high_data, low_data):
"""
Typical Price.
Formula:
TPt = (HIGHt + LOWt + CLOSEt) / 3
"""
catch_errors.check_for_input_len_diff(close_data, high_data, low_data)
tp = [(high_data[idx] + low_data[idx] + close_data[idx]) / 3 for idx in range(0, len(close_data))]
... | python | def typical_price(close_data, high_data, low_data):
catch_errors.check_for_input_len_diff(close_data, high_data, low_data)
tp = [(high_data[idx] + low_data[idx] + close_data[idx]) / 3 for idx in range(0, len(close_data))]
return np.array(tp) | [
"def",
"typical_price",
"(",
"close_data",
",",
"high_data",
",",
"low_data",
")",
":",
"catch_errors",
".",
"check_for_input_len_diff",
"(",
"close_data",
",",
"high_data",
",",
"low_data",
")",
"tp",
"=",
"[",
"(",
"high_data",
"[",
"idx",
"]",
"+",
"low_d... | Typical Price.
Formula:
TPt = (HIGHt + LOWt + CLOSEt) / 3 | [
"Typical",
"Price",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/typical_price.py#L7-L16 |
248,193 | kylejusticemagnuson/pyti | pyti/true_range.py | true_range | def true_range(close_data, period):
"""
True Range.
Formula:
TRt = MAX(abs(Ht - Lt), abs(Ht - Ct-1), abs(Lt - Ct-1))
"""
catch_errors.check_for_period_error(close_data, period)
tr = [np.max([np.max(close_data[idx+1-period:idx+1]) -
np.min(close_data[idx+1-period:idx+1]),
... | python | def true_range(close_data, period):
catch_errors.check_for_period_error(close_data, period)
tr = [np.max([np.max(close_data[idx+1-period:idx+1]) -
np.min(close_data[idx+1-period:idx+1]),
abs(np.max(close_data[idx+1-period:idx+1]) -
close_data[idx-1]),
... | [
"def",
"true_range",
"(",
"close_data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"close_data",
",",
"period",
")",
"tr",
"=",
"[",
"np",
".",
"max",
"(",
"[",
"np",
".",
"max",
"(",
"close_data",
"[",
"idx",
"+",
"1"... | True Range.
Formula:
TRt = MAX(abs(Ht - Lt), abs(Ht - Ct-1), abs(Lt - Ct-1)) | [
"True",
"Range",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/true_range.py#L8-L24 |
248,194 | kylejusticemagnuson/pyti | pyti/double_smoothed_stochastic.py | double_smoothed_stochastic | def double_smoothed_stochastic(data, period):
"""
Double Smoothed Stochastic.
Formula:
dss = 100 * EMA(Close - Lowest Low) / EMA(Highest High - Lowest Low)
"""
catch_errors.check_for_period_error(data, period)
lows = [data[idx] - np.min(data[idx+1-period:idx+1]) for idx in range(period-1, ... | python | def double_smoothed_stochastic(data, period):
catch_errors.check_for_period_error(data, period)
lows = [data[idx] - np.min(data[idx+1-period:idx+1]) for idx in range(period-1, len(data))]
sm_lows = ema(ema(lows, period), period)
highs = [np.max(data[idx+1-period:idx+1]) - np.min(data[idx+1-period:idx+1]... | [
"def",
"double_smoothed_stochastic",
"(",
"data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"lows",
"=",
"[",
"data",
"[",
"idx",
"]",
"-",
"np",
".",
"min",
"(",
"data",
"[",
"idx",
"+",
"... | Double Smoothed Stochastic.
Formula:
dss = 100 * EMA(Close - Lowest Low) / EMA(Highest High - Lowest Low) | [
"Double",
"Smoothed",
"Stochastic",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/double_smoothed_stochastic.py#L11-L26 |
248,195 | kylejusticemagnuson/pyti | pyti/volume_adjusted_moving_average.py | volume_adjusted_moving_average | def volume_adjusted_moving_average(close_data, volume, period):
"""
Volume Adjusted Moving Average.
Formula:
VAMA = SUM(CLOSE * VolumeRatio) / period
"""
catch_errors.check_for_input_len_diff(close_data, volume)
catch_errors.check_for_period_error(close_data, period)
avg_vol = np.mean(... | python | def volume_adjusted_moving_average(close_data, volume, period):
catch_errors.check_for_input_len_diff(close_data, volume)
catch_errors.check_for_period_error(close_data, period)
avg_vol = np.mean(volume)
vol_incr = avg_vol * 0.67
vol_ratio = [val / vol_incr for val in volume]
close_vol = np.arr... | [
"def",
"volume_adjusted_moving_average",
"(",
"close_data",
",",
"volume",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_input_len_diff",
"(",
"close_data",
",",
"volume",
")",
"catch_errors",
".",
"check_for_period_error",
"(",
"close_data",
",",
"period",... | Volume Adjusted Moving Average.
Formula:
VAMA = SUM(CLOSE * VolumeRatio) / period | [
"Volume",
"Adjusted",
"Moving",
"Average",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/volume_adjusted_moving_average.py#L8-L24 |
248,196 | kylejusticemagnuson/pyti | pyti/double_exponential_moving_average.py | double_exponential_moving_average | def double_exponential_moving_average(data, period):
"""
Double Exponential Moving Average.
Formula:
DEMA = 2*EMA - EMA(EMA)
"""
catch_errors.check_for_period_error(data, period)
dema = (2 * ema(data, period)) - ema(ema(data, period), period)
return dema | python | def double_exponential_moving_average(data, period):
catch_errors.check_for_period_error(data, period)
dema = (2 * ema(data, period)) - ema(ema(data, period), period)
return dema | [
"def",
"double_exponential_moving_average",
"(",
"data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"dema",
"=",
"(",
"2",
"*",
"ema",
"(",
"data",
",",
"period",
")",
")",
"-",
"ema",
"(",
"e... | Double Exponential Moving Average.
Formula:
DEMA = 2*EMA - EMA(EMA) | [
"Double",
"Exponential",
"Moving",
"Average",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/double_exponential_moving_average.py#L8-L18 |
248,197 | kylejusticemagnuson/pyti | pyti/triangular_moving_average.py | triangular_moving_average | def triangular_moving_average(data, period):
"""
Triangular Moving Average.
Formula:
TMA = SMA(SMA())
"""
catch_errors.check_for_period_error(data, period)
tma = sma(sma(data, period), period)
return tma | python | def triangular_moving_average(data, period):
catch_errors.check_for_period_error(data, period)
tma = sma(sma(data, period), period)
return tma | [
"def",
"triangular_moving_average",
"(",
"data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"tma",
"=",
"sma",
"(",
"sma",
"(",
"data",
",",
"period",
")",
",",
"period",
")",
"return",
"tma"
] | Triangular Moving Average.
Formula:
TMA = SMA(SMA()) | [
"Triangular",
"Moving",
"Average",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/triangular_moving_average.py#L8-L18 |
248,198 | kylejusticemagnuson/pyti | pyti/weighted_moving_average.py | weighted_moving_average | def weighted_moving_average(data, period):
"""
Weighted Moving Average.
Formula:
(P1 + 2 P2 + 3 P3 + ... + n Pn) / K
where K = (1+2+...+n) = n(n+1)/2 and Pn is the most recent price
"""
catch_errors.check_for_period_error(data, period)
k = (period * (period + 1)) / 2.0
wmas = []
... | python | def weighted_moving_average(data, period):
catch_errors.check_for_period_error(data, period)
k = (period * (period + 1)) / 2.0
wmas = []
for idx in range(0, len(data)-period+1):
product = [data[idx + period_idx] * (period_idx + 1) for period_idx in range(0, period)]
wma = sum(product) /... | [
"def",
"weighted_moving_average",
"(",
"data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"k",
"=",
"(",
"period",
"*",
"(",
"period",
"+",
"1",
")",
")",
"/",
"2.0",
"wmas",
"=",
"[",
"]",
... | Weighted Moving Average.
Formula:
(P1 + 2 P2 + 3 P3 + ... + n Pn) / K
where K = (1+2+...+n) = n(n+1)/2 and Pn is the most recent price | [
"Weighted",
"Moving",
"Average",
"."
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/weighted_moving_average.py#L7-L25 |
248,199 | kylejusticemagnuson/pyti | pyti/ichimoku_cloud.py | conversion_base_line_helper | def conversion_base_line_helper(data, period):
"""
The only real difference between TenkanSen and KijunSen is the period value
"""
catch_errors.check_for_period_error(data, period)
cblh = [(np.max(data[idx+1-period:idx+1]) +
np.min(data[idx+1-period:idx+1])) / 2 for idx in range(period-1... | python | def conversion_base_line_helper(data, period):
catch_errors.check_for_period_error(data, period)
cblh = [(np.max(data[idx+1-period:idx+1]) +
np.min(data[idx+1-period:idx+1])) / 2 for idx in range(period-1, len(data))]
cblh = fill_for_noncomputable_vals(data, cblh)
return cblh | [
"def",
"conversion_base_line_helper",
"(",
"data",
",",
"period",
")",
":",
"catch_errors",
".",
"check_for_period_error",
"(",
"data",
",",
"period",
")",
"cblh",
"=",
"[",
"(",
"np",
".",
"max",
"(",
"data",
"[",
"idx",
"+",
"1",
"-",
"period",
":",
... | The only real difference between TenkanSen and KijunSen is the period value | [
"The",
"only",
"real",
"difference",
"between",
"TenkanSen",
"and",
"KijunSen",
"is",
"the",
"period",
"value"
] | 2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2 | https://github.com/kylejusticemagnuson/pyti/blob/2f78430dfd60a0d20f4e7fc0cb4588c03107c4b2/pyti/ichimoku_cloud.py#L8-L17 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.