Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Refactor icon_rc command line (#382)
Browse files Browse the repository at this point in the history
* Change default iconRcPath: "/usr/local/bin" -> ""
* Do not use "cwd" parameter in Popen()
  • Loading branch information
Chiwon Cho authored and cow-hs committed Nov 5, 2019
1 parent 1eb7a5a commit bbe9b3a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion iconservice/icon_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# and after decentralizing, is set to 43_120.
# If you want to change as TERM_PERIOD, you also must change REVISION.
# so we determined that only TERM_PERIOD changed without IISS_CALCULATE_PERIOD.
ConfigKey.ICON_RC_DIR_PATH: '/usr/local/bin/',
ConfigKey.ICON_RC_DIR_PATH: "",
ConfigKey.IISS_CALCULATE_PERIOD: IISS_DAY_BLOCK,
ConfigKey.TERM_PERIOD: TERM_PERIOD,
ConfigKey.INITIAL_IREP: 50_000 * ICX_IN_LOOP,
Expand Down
13 changes: 12 additions & 1 deletion iconservice/iiss/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,18 @@ def __init__(self):
self._reward_calc_proxy: Optional['RewardCalcProxy'] = None
self._listeners: List['EngineListener'] = []

def open(self, context: 'IconScoreContext', log_dir: str, data_path: str, socket_path: str, ipc_timeout: int, icon_rc_path: str):
def open(self, context: 'IconScoreContext',
log_dir: str, data_path: str, socket_path: str, ipc_timeout: int, icon_rc_path: str):
"""
:param context:
:param log_dir:
:param data_path:
:param socket_path:
:param ipc_timeout:
:param icon_rc_path: ex) "/usr/local/bin"
:return:
"""
self._init_reward_calc_proxy(log_dir, data_path, socket_path, ipc_timeout, icon_rc_path)

def add_listener(self, listener: 'EngineListener'):
Expand Down
32 changes: 29 additions & 3 deletions iconservice/iiss/reward_calc/ipc/reward_calc_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class RewardCalcProxy(object):
"""Communicates with Reward Calculator through UNIX Domain Socket
"""
_DEFAULT_REWARD_CALCULATOR_PATH = "icon_rc"

def __init__(self,
icon_rc_path: str,
ipc_timeout: int,
Expand Down Expand Up @@ -417,11 +419,35 @@ def start_reward_calc(self, log_dir: str, sock_path: str, iiss_db_path: str):
iscore_db_path, _ = os.path.split(iiss_db_path)
iscore_db_path = os.path.join(iscore_db_path, 'rc')
log_path = os.path.join(log_dir, 'rc.log')
reward_calculator_path: str = self._get_reward_calculator_path(self._icon_rc_path)

if self._reward_calc is None:
cmd = f'./icon_rc -client -monitor -db-count 16 -db {iscore_db_path} -iissdata {iiss_db_path}' \
f' -ipc-addr {sock_path} -log-file {log_path}'
self._reward_calc = Popen(cmd.split(" "), cwd=self._icon_rc_path)
args = [
reward_calculator_path,
"-client",
"-monitor",
"-db-count", "16",
"-db", f"{iscore_db_path}",
"-iissdata", f"{iiss_db_path}",
"-ipc-addr", f"{sock_path}",
"-log-file", f"{log_path}",
]

Logger.info(tag=_TAG, msg=f"cmd={' '.join(args)}")
self._reward_calc = Popen(args)

Logger.debug(tag=_TAG, msg="start_reward_calc() end")

def _get_reward_calculator_path(self, path: str) -> str:
command = self._DEFAULT_REWARD_CALCULATOR_PATH

if isinstance(path, str):
if os.path.isdir(path):
return os.path.join(path, command)
elif os.path.isfile(path):
return path

return command

def stop_reward_calc(self):
""" Stop reward calculator process
Expand Down

0 comments on commit bbe9b3a

Please sign in to comment.