Skip to content

Commit

Permalink
Merge pull request #346 from Toktar/task-2292-update-state
Browse files Browse the repository at this point in the history
INDY-2292: change State restoring logiс
  • Loading branch information
anikitinDSR authored Nov 19, 2019
2 parents cb007fb + 2404339 commit ea83b4b
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 2 deletions.
2 changes: 1 addition & 1 deletion devops/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ifeq ($(SRC_DIR_NAME),sovtoken)
# pypi: indy-plenum
# apt: indy-plenum (stable component)

FPM_P_DEPENDS := indy-node(=1.12.0~dev1132)
FPM_P_DEPENDS := indy-node(=1.12.0~dev1135)
FPM_ARGS := --no-python-dependencies $(FPM_ARGS)
endif

Expand Down
2 changes: 1 addition & 1 deletion sovtoken/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
'*.css', '*.ico', '*.png', 'LICENSE', 'LEGAL', 'sovtoken']},
include_package_data=True,

install_requires=['indy-node==1.12.0.dev1132'],
install_requires=['indy-node==1.12.0.dev1135'],

setup_requires=['pytest-runner'],
extras_require={
Expand Down
4 changes: 4 additions & 0 deletions sovtokenfees/sovtokenfees/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from sovtokenfees.req_handlers.write_handlers.auth_rule_fee_handler import AuthRuleFeeHandler
from sovtokenfees.req_handlers.write_handlers.fee_txn_handler import FeeTxnCatchupHandler
from sovtokenfees.req_handlers.write_handlers.set_fees_handler import SetFeesHandler
from sovtokenfees.req_handlers.write_handlers.set_fees_handler_0_9_3 import SetFeesHandler093
from sovtokenfees.req_handlers.write_handlers.xfer_fee_handler import XferFeeHandler
from sovtokenfees.req_handlers.fees_utils import BatchFeesTracker
from sovtokenfees.req_handlers.write_handlers.domain_fee_handler import DomainFeeHandler
Expand Down Expand Up @@ -53,6 +54,9 @@ def integrate_plugin_in_node(node):
def register_req_handlers(node, fees_tracker):
node.write_manager.register_req_handler(SetFeesHandler(node.db_manager,
node.write_req_validator))
node.write_manager.register_req_handler_with_version(SetFeesHandler093(node.db_manager,
node.write_req_validator),
"0.9.3")

if XFER_PUBLIC not in node.write_manager.request_handlers:
raise ImportError('sovtoken plugin should be loaded, request '
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from sovtokenfees.constants import SET_FEES, FEES
from sovtokenfees.req_handlers.fees_utils import FeesStaticHelper
from sovtokenfees.req_handlers.write_handlers.set_fees_handler import SetFeesHandler
from plenum.common.txn_util import get_payload_data


class SetFeesHandler093(SetFeesHandler):
fees_state_key = 'fees'

def update_state(self, txn, prev_result, request, is_committed=False):
payload = get_payload_data(txn)
fees_from_req = payload.get(FEES)
current_fees = FeesStaticHelper.get_fee_from_state(self.state)
current_fees = current_fees if current_fees else {}
current_fees.update(fees_from_req)
self._set_to_state(self.fees_state_key, current_fees)
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import shutil
from datetime import datetime, timedelta

import dateutil
import pytest

from indy_common.config_helper import NodeConfigHelper
from indy_node.test.upgrade.helper import sdk_ensure_upgrade_sent
from plenum.common.constants import TXN_TYPE, DATA, VERSION, CURRENT_PROTOCOL_VERSION
from indy_common.constants import NODE_UPGRADE, ACTION, COMPLETE, AUTH_RULE, START
from indy_node.test.helper import sdk_send_and_check_auth_rule_request, TestNode
from plenum.common.request import Request
from plenum.common.types import f
from plenum.test.node_catchup.helper import waitNodeDataEquality

from plenum.test.helper import assertEquality
from plenum.test.test_node import checkNodesConnected, ensure_node_disconnected
from sovtokenfees.constants import SET_FEES
from stp_core.loop.eventually import eventually


@pytest.fixture(scope="module")
def tconf(tconf):
old_version_matching = tconf.INDY_VERSION_MATCHING
tconf.INDY_VERSION_MATCHING = {"1.1.24": "0.9.3"}
yield tconf
tconf.INDY_VERSION_MATCHING = old_version_matching


@pytest.fixture(scope='module')
def valid_upgrade(nodeSetWithIntegratedTokenPlugin, tconf):
schedule = {}
unow = datetime.utcnow().replace(tzinfo=dateutil.tz.tzutc())
startAt = unow + timedelta(seconds=30000000)
acceptableDiff = tconf.MinSepBetweenNodeUpgrades + 1
for n in nodeSetWithIntegratedTokenPlugin[0].poolManager.nodeIds:
schedule[n] = datetime.isoformat(startAt)
startAt = startAt + timedelta(seconds=acceptableDiff + 3)

return dict(name='upgrade', version="10000.10.10",
action=START, schedule=schedule, timeout=1,
package=None,
sha256='db34a72a90d026dae49c3b3f0436c8d3963476c77468ad955845a1ccf7b03f55')


def send_node_upgrades(nodes, version, looper, count=None):
if count is None:
count = len(nodes)
last_ordered = nodes[0].master_last_ordered_3PC[1]
for node in nodes[:count]:
op = {
TXN_TYPE: NODE_UPGRADE,
DATA: {
ACTION: COMPLETE,
VERSION: version
}
}
op[f.SIG.nm] = node.wallet.signMsg(op[DATA])

request = node.wallet.signRequest(
Request(operation=op, protocolVersion=CURRENT_PROTOCOL_VERSION))

node.startedProcessingReq(request.key, node.nodestack.name)
node.send(request)
looper.run(eventually(lambda: assertEquality(node.master_last_ordered_3PC[1],
last_ordered + 1)))
last_ordered += 1


def test_state_recovery_with_fees(looper, tconf, tdir,
sdk_pool_handle,
sdk_wallet_trustee,
allPluginsPath,
do_post_node_creation,
nodeSetWithIntegratedTokenPlugin,
helpers,
valid_upgrade,
monkeypatch):
version1 = "1.1.24"
version2 = "1.1.88"
node_set = nodeSetWithIntegratedTokenPlugin
# send POOL_UPGRADE to write in a ledger
last_ordered = node_set[0].master_last_ordered_3PC[1]
sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee,
valid_upgrade)
looper.run(eventually(lambda: assertEquality(node_set[0].master_last_ordered_3PC[1],
last_ordered + 1)))

send_node_upgrades(node_set, version1, looper)
for n in node_set:
handler = n.write_manager.request_handlers.get(SET_FEES)[0]
handler_for_0_9_3 = n.write_manager._request_handlers_with_version.get((SET_FEES, "0.9.3"))[0]
monkeypatch.setattr(handler, 'update_state',
handler_for_0_9_3.update_state)
helpers.general.do_set_fees({"A": 2}, fill_auth_map=False)
send_node_upgrades(node_set, version2, looper)
monkeypatch.undo()
helpers.general.do_set_fees({"B": 2}, fill_auth_map=False)

node_to_stop = node_set[-1]
state_db_pathes = [state._kv.db_path
for state in node_to_stop.states.values()]
node_to_stop.cleanupOnStopping = False
node_to_stop.stop()
looper.removeProdable(node_to_stop)
ensure_node_disconnected(looper, node_to_stop, node_set[:-1])

for path in state_db_pathes:
shutil.rmtree(path)
config_helper = NodeConfigHelper(node_to_stop.name, tconf, chroot=tdir)
restarted_node = TestNode(
node_to_stop.name,
config_helper=config_helper,
config=tconf,
pluginPaths=allPluginsPath,
ha=node_to_stop.nodestack.ha,
cliha=node_to_stop.clientstack.ha)
do_post_node_creation(restarted_node)

looper.add(restarted_node)
node_set[-1] = restarted_node

looper.run(checkNodesConnected(node_set))
waitNodeDataEquality(looper, restarted_node, *node_set[:-1], exclude_from_check=['check_last_ordered_3pc_backup'])

0 comments on commit ea83b4b

Please sign in to comment.