-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[INDY-1029] Change timeout for getting cathup replies #499
Merged
ashcherbakov
merged 7 commits into
hyperledger:master
from
lampkin-diet:public/indy-1029
Jan 17, 2018
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cc87190
[INDY-1029] Change timeout for getting cathup replies
9c93b34
[indy-1029] Add scripts for generating and adding transactions to dom…
ca383bb
[INDY-1029] Add new timeout var into config
37f488e
[INDY-1029] Fix static validation
b8072a6
[INDY-1029] Change evaluating pool catchup timeout for tests
2e73bca
[INDY-1029] Make timeout depended from node count (for test logic)
ba3742e
[INDY-1029] Erase dublicate sdk_reqToTxn function
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import os | ||
import sys | ||
import json | ||
import argparse | ||
|
||
from stp_core.types import HA | ||
from indy_common.config_util import getConfig | ||
from plenum.server.node import Node | ||
from plenum.common.types import f, OPERATION | ||
from plenum.common.constants import TXN_TIME | ||
from indy_common.config_helper import NodeConfigHelper | ||
|
||
config = getConfig() | ||
|
||
|
||
def get_ha_cliha_node_name(path_to_env): | ||
node_name_key = 'NODE_NAME' | ||
node_port_key = 'NODE_PORT' | ||
node_clien_port_key = 'NODE_CLIENT_PORT' | ||
node_name = '' | ||
node_port = '' | ||
node_clieint_port = '' | ||
with open(path_to_env) as fenv: | ||
for line in fenv.readlines(): | ||
print(line) | ||
if line.find(node_name_key) != -1: | ||
node_name = line.split('=')[1].strip() | ||
elif line.find(node_port_key) != -1: | ||
node_port = int(line.split('=')[1].strip()) | ||
elif line.find(node_clien_port_key) != -1: | ||
node_clieint_port = int(line.split('=')[1].strip()) | ||
return node_name, node_port, node_clieint_port | ||
|
||
|
||
def sdk_reqToTxn(sdk_req, cons_time=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we duplicate it? |
||
""" | ||
Transform a client request such that it can be stored in the ledger. | ||
Also this is what will be returned to the client in the reply | ||
:param req: | ||
:param cons_time: UTC epoch at which consensus was reached | ||
:return: | ||
""" | ||
# TODO: we should not reformat transaction this way | ||
# When refactor keep in mind thought about back compatibility | ||
|
||
if isinstance(sdk_req, dict): | ||
data = sdk_req | ||
elif isinstance(sdk_req, str): | ||
data = json.loads(sdk_req) | ||
else: | ||
raise TypeError( | ||
"Expected dict or str as input, but got: {}".format(type(sdk_req))) | ||
|
||
res = { | ||
f.IDENTIFIER.nm: data[f.IDENTIFIER.nm], | ||
f.REQ_ID.nm: data[f.REQ_ID.nm], | ||
f.SIG.nm: data.get(f.SIG.nm, None), | ||
f.SIGS.nm: data.get(f.SIGS.nm, None), | ||
TXN_TIME: cons_time or data.get(TXN_TIME) | ||
} | ||
res.update(data[OPERATION]) | ||
return res | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('infpath', help="Path to previous generated txns", type=str, default='/tmp/generated_txns') | ||
parser.add_argument('--env_file', help='Path to environment file with node name and ports', default='/etc/indy/indy.env') | ||
args = parser.parse_args() | ||
path_to_txns = os.path.realpath(args.infpath) | ||
path_to_env = os.path.realpath(args.env_file) | ||
|
||
if not os.path.exists(path_to_txns): | ||
print("Path to txns file does not exist") | ||
sys.exit(1) | ||
|
||
if not os.path.exists(path_to_env): | ||
print("Path to env file does not exist") | ||
sys.exit(1) | ||
|
||
nname, nport, ncliport = get_ha_cliha_node_name(path_to_env) | ||
ha = HA("0.0.0.0", nport) | ||
cliha = HA("0.0.0.0", ncliport) | ||
config_helper = NodeConfigHelper(nname, config) | ||
|
||
node = Node(nname, nodeRegistry=None, | ||
ha=ha, | ||
cliha=cliha, | ||
config_helper=config_helper, | ||
config=config) | ||
i = 0 | ||
with open(path_to_txns) as txns: | ||
for txn in txns: | ||
node.domainLedger.add(json.loads(txn)) | ||
i += 1 | ||
if not i % 1000: | ||
print("added {} txns".format(i)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import os | ||
import json | ||
import time | ||
from contextlib import ExitStack | ||
import argparse | ||
import random | ||
from typing import Sequence | ||
from plenum.common.request import Request | ||
from plenum.common.types import f, OPERATION | ||
from plenum.common.constants import TXN_TIME, CURRENT_PROTOCOL_VERSION | ||
from plenum.common.util import randomString | ||
from plenum.common.config_util import getConfig | ||
from indy.ledger import sign_request | ||
from indy import signus, wallet | ||
from stp_core.loop.looper import Looper | ||
|
||
config = getConfig() | ||
|
||
|
||
def sdk_reqToTxn(sdk_req, cons_time=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we duplicate it? |
||
""" | ||
Transform a client request such that it can be stored in the ledger. | ||
Also this is what will be returned to the client in the reply | ||
:param req: | ||
:param cons_time: UTC epoch at which consensus was reached | ||
:return: | ||
""" | ||
|
||
if isinstance(sdk_req, dict): | ||
data = sdk_req | ||
elif isinstance(sdk_req, str): | ||
data = json.loads(sdk_req) | ||
else: | ||
raise TypeError( | ||
"Expected dict or str as input, but got: {}".format(type(sdk_req))) | ||
|
||
res = { | ||
f.IDENTIFIER.nm: data[f.IDENTIFIER.nm], | ||
f.REQ_ID.nm: data[f.REQ_ID.nm], | ||
f.SIG.nm: data.get(f.SIG.nm, None), | ||
f.SIGS.nm: data.get(f.SIGS.nm, None), | ||
TXN_TIME: cons_time or data.get(TXN_TIME) | ||
} | ||
res.update(data[OPERATION]) | ||
return res | ||
|
||
|
||
async def get_wallet_and_pool(): | ||
pool_name = 'pool' + randomString(3) | ||
wallet_name = 'wallet' + randomString(10) | ||
their_wallet_name = 'their_wallet' + randomString(10) | ||
seed_trustee1 = "000000000000000000000000Trustee1" | ||
|
||
await wallet.create_wallet(pool_name, wallet_name, None, None, None) | ||
my_wallet_handle = await wallet.open_wallet(wallet_name, None, None) | ||
|
||
await wallet.create_wallet(pool_name, their_wallet_name, None, None, None) | ||
their_wallet_handle = await wallet.open_wallet(their_wallet_name, None, None) | ||
|
||
await signus.create_and_store_my_did(my_wallet_handle, "{}") | ||
|
||
(their_did, their_verkey) = await signus.create_and_store_my_did(their_wallet_handle, | ||
json.dumps({"seed": seed_trustee1})) | ||
|
||
await signus.store_their_did(my_wallet_handle, json.dumps({'did': their_did, 'verkey': their_verkey})) | ||
|
||
return their_wallet_handle, their_did | ||
|
||
|
||
def randomOperation(): | ||
return { | ||
"type": "buy", | ||
"amount": random.randint(10, 100000) | ||
} | ||
|
||
|
||
def random_requests(count): | ||
return [randomOperation() for _ in range(count)] | ||
|
||
|
||
def sdk_gen_request(operation, protocol_version=CURRENT_PROTOCOL_VERSION, identifier=None): | ||
return Request(operation=operation, reqId=random.randint(10, 100000), | ||
protocolVersion=protocol_version, identifier=identifier) | ||
|
||
|
||
def sdk_random_request_objects(count, protocol_version, identifier=None): | ||
ops = random_requests(count) | ||
return [sdk_gen_request(op, protocol_version=protocol_version, identifier=identifier) for op in ops] | ||
|
||
|
||
def sdk_sign_request_objects(looper, sdk_wallet, reqs: Sequence): | ||
wallet_h, did = sdk_wallet | ||
reqs_str = [json.dumps(req.as_dict) for req in reqs] | ||
resp = [looper.loop.run_until_complete(sign_request(wallet_h, did, req)) for req in reqs_str] | ||
return resp | ||
|
||
|
||
def sdk_signed_random_requests(looper, sdk_wallet, count): | ||
_, did = sdk_wallet | ||
reqs_obj = sdk_random_request_objects(count, identifier=did, protocol_version=CURRENT_PROTOCOL_VERSION) | ||
return sdk_sign_request_objects(looper, sdk_wallet, reqs_obj) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('count', help="Count of generated txns", type=int) | ||
parser.add_argument('outfpath', help="Path to save generated txns", type=str, default='/tmp/generated_txns') | ||
args = parser.parse_args() | ||
path_to_save = os.path.realpath(args.outfpath) | ||
|
||
with ExitStack() as exit_stack: | ||
with Looper() as looper: | ||
sdk_wallet, did = looper.loop.run_until_complete(get_wallet_and_pool()) | ||
with open(path_to_save, 'w') as outpath: | ||
for _ in range(args.count): | ||
req = sdk_signed_random_requests(looper, (sdk_wallet, did), 1)[0] | ||
txn = sdk_reqToTxn(req, int(time.time())) | ||
outpath.write(json.dumps(txn)) | ||
outpath.write(os.linesep) | ||
looper.stopall() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it just 6 seconds?