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

Commit

Permalink
Merge pull request #563 from icon-project/release/1.8.9
Browse files Browse the repository at this point in the history
Release/1.8.9
  • Loading branch information
cow-hs committed Mar 8, 2021
2 parents 38c571c + 8038776 commit 6569500
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 22 deletions.
2 changes: 1 addition & 1 deletion iconservice/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.8.4'
__version__ = '1.8.9'
43 changes: 34 additions & 9 deletions iconservice/icon_inner_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ def _close():
async def invoke(self, request: dict) -> dict:
Logger.debug(tag=_TAG, msg=f'invoke() start')

self._check_icon_service_ready()
try:
self._check_icon_service_ready()
except ServiceNotReadyException as e:
return MakeResponse.make_error_response(e.code, str(e))

if self._is_thread_flag_on(EnableThreadFlag.INVOKE):
loop = asyncio.get_event_loop()
Expand Down Expand Up @@ -214,7 +217,11 @@ def _invoke(self, request: dict):

@message_queue_task
async def query(self, request: dict) -> dict:
self._check_icon_service_ready()
try:
self._check_icon_service_ready()
except ServiceNotReadyException as e:
return MakeResponse.make_error_response(e.code, str(e))

return await self._get_query_response(request)

async def _get_query_response(self, request: dict) -> dict:
Expand Down Expand Up @@ -264,7 +271,10 @@ def _query(self, request: dict, method: str):
async def call(self, request: dict):
Logger.info(tag=_TAG, msg=f'call() start: {request}')

self._check_icon_service_ready()
try:
self._check_icon_service_ready()
except ServiceNotReadyException as e:
return MakeResponse.make_error_response(e.code, str(e))

if self._is_thread_flag_on(EnableThreadFlag.QUERY):
loop = asyncio.get_event_loop()
Expand Down Expand Up @@ -296,7 +306,10 @@ def _call(self, request: dict):

@message_queue_task
async def write_precommit_state(self, request: dict):
self._check_icon_service_ready()
try:
self._check_icon_service_ready()
except ServiceNotReadyException as e:
return MakeResponse.make_error_response(e.code, str(e))

if self._is_thread_flag_on(EnableThreadFlag.INVOKE):
loop = asyncio.get_event_loop()
Expand Down Expand Up @@ -341,8 +354,10 @@ def _write_precommit_state(self, request: dict) -> dict:
async def remove_precommit_state(self, request: dict):
Logger.info(tag=_TAG, msg=f'remove_precommit_state() start')

self._check_icon_service_ready()

try:
self._check_icon_service_ready()
except ServiceNotReadyException as e:
return MakeResponse.make_error_response(e.code, str(e))

"""
Unused API
Expand All @@ -359,7 +374,10 @@ async def rollback(self, request: dict):

Logger.info(tag=_TAG, msg=f"rollback() start")

self._check_icon_service_ready()
try:
self._check_icon_service_ready()
except ServiceNotReadyException as e:
return MakeResponse.make_error_response(e.code, str(e))

if self._is_thread_flag_on(EnableThreadFlag.INVOKE):
loop = asyncio.get_event_loop()
Expand Down Expand Up @@ -398,7 +416,10 @@ def _rollback(self, request: dict) -> dict:

@message_queue_task
async def validate_transaction(self, request: dict):
self._check_icon_service_ready()
try:
self._check_icon_service_ready()
except ServiceNotReadyException as e:
return MakeResponse.make_error_response(e.code, str(e))

if self._is_thread_flag_on(EnableThreadFlag.VALIDATE):
loop = asyncio.get_event_loop()
Expand Down Expand Up @@ -428,7 +449,11 @@ def _validate_transaction(self, request: dict):

@message_queue_task
async def change_block_hash(self, _params):
self._check_icon_service_ready()
try:
self._check_icon_service_ready()
except ServiceNotReadyException as e:
return MakeResponse.make_error_response(e.code, str(e))

return ExceptionCode.OK


Expand Down
31 changes: 31 additions & 0 deletions iconservice/icon_service_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,25 @@ def invoke(self,
if context.is_revision_changed(Revision.FIX_BALANCE_BUG.value):
self._run_unstake_patcher(context)

if tx_request["params"].get("dataType") == "call":
data = tx_request["params"].get("data")
if data:
method: str = data.get("method", "EMPTY_METHOD")
else:
method: str = "NOT_SCORE_CALL"
else:
method: str = "NOT_CALL_DATA_TYPE"

Logger.info(
tag=_TAG,
msg=f"TX_END: "
f"BH={tx_result.block_height} "
f"txIndex={tx_result.tx_index} "
f"to={tx_result.to} "
f"method={method} "
f"duration={one_tx_timer.duration}"
)

Logger.debug(tag=_TAG, msg=f"INVOKE txResult: {tx_result}")

if self._check_end_block_height_of_calc(context):
Expand Down Expand Up @@ -1083,7 +1094,27 @@ def query(self, method: str, params: dict) -> Any:
context.traces = []
context.set_step_counter(step_limit=step_limit)

one_tx_timer = Timer()
one_tx_timer.start()

ret = self._call(context, method, params)

if method == 'icx_call':
score_addr = params.get("to", "INVALID_TO_ADDR")
data = params.get("data")
if data:
score_method: str = data.get("method", "EMPTY_METHOD")
else:
score_method: str = "NOT_SCORE_CALL"

Logger.info(
tag=_TAG,
msg=f"QUERY_END: "
f"to={score_addr} "
f"method={score_method} "
f"duration={one_tx_timer.duration}"
)

return ret

def validate_transaction(self, request: dict, origin_request: dict) -> None:
Expand Down
8 changes: 4 additions & 4 deletions iconservice/iiss/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
from .reward_calc.ipc.message import CalculateDoneNotification, ReadyNotification
from .reward_calc.ipc.reward_calc_proxy import RewardCalcProxy
from ..base.ComponentBase import EngineBase
from ..base.address import Address
from ..base.address import SYSTEM_SCORE_ADDRESS
from ..base.address import Address, SYSTEM_SCORE_ADDRESS
from ..base.block import Block
from ..base.exception import (
InvalidParamsException, InvalidRequestException, OutOfBalanceException, FatalException,
InternalServiceErrorException
Expand All @@ -51,7 +51,6 @@
from ..iiss.storage import RewardRate
from ..icx import IcxStorage
from ..prep.data import Term
from ..base.block import Block

_TAG = IISS_LOG_TAG

Expand Down Expand Up @@ -717,7 +716,8 @@ def handle_query_iscore(self, context: 'IconScoreContext', address: 'Address') -
raise InvalidParamsException(f"Invalid address: {address}")

tx_hash = context.tx.hash if isinstance(context.tx, Transaction) else None
iscore, block_height = self._reward_calc_proxy.query_iscore(address, tx_hash)
block = context.block if isinstance(context.block, Block) else None
iscore, block_height = self._reward_calc_proxy.query_iscore(address, block, tx_hash)

data = {
"iscore": iscore,
Expand Down
11 changes: 7 additions & 4 deletions iconservice/iiss/reward_calc/ipc/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,22 +333,25 @@ class QueryRequest(Request):
"""queryIScore
"""

def __init__(self, address: 'Address', tx_hash: Optional[bytes]):
def __init__(self, address: 'Address', block_height: int, block_hash: Optional[bytes], tx_hash: Optional[bytes]):
super().__init__(MessageType.QUERY)

self.address = address
self.block_height = block_height
self.block_hash = block_hash
self.tx_hash = tx_hash

def __str__(self) -> str:
return (
f"{self.msg_type.name}"
f"({self.msg_id}, {self.address}, {bytes_to_hex(self.tx_hash)})"
f"{self.msg_type.name}, "
f"({self.msg_id}, {self.address}, {self.block_height}, {bytes_to_hex(self.block_hash)}, "
f"{bytes_to_hex(self.tx_hash)})"
)

def _to_list(self) -> tuple:
return self.msg_type, \
self.msg_id, \
(self.address.to_bytes_including_prefix(), self.tx_hash)
(self.address.to_bytes_including_prefix(), self.block_height, self.block_hash, self.tx_hash)


class QueryResponse(Response):
Expand Down
15 changes: 11 additions & 4 deletions iconservice/iiss/reward_calc/ipc/reward_calc_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .message_queue import MessageQueue
from .server import IPCServer
from ....base.address import Address
from ....base.block import Block
from ....base.exception import TimeoutException
from ....icon_constant import RCStatus
from ....utils import bytes_to_hex
Expand Down Expand Up @@ -310,7 +311,7 @@ async def _commit_claim(self, success: bool, address: 'Address',

return future.result()

def query_iscore(self, address: 'Address', tx_hash: Optional[bytes]) -> Tuple[int, int]:
def query_iscore(self, address: 'Address', block: Optional[Block], tx_hash: Optional[bytes]) -> Tuple[int, int]:
"""Returns the I-Score of a given address
It should be called on query thread
Expand All @@ -325,7 +326,7 @@ def query_iscore(self, address: 'Address', tx_hash: Optional[bytes]) -> Tuple[in
Logger.debug(tag=_TAG, msg="query_iscore() start")

future: concurrent.futures.Future = asyncio.run_coroutine_threadsafe(
self._query_iscore(address, tx_hash), self._loop)
self._query_iscore(address, block, tx_hash), self._loop)

try:
response: 'QueryResponse' = future.result(self._ipc_timeout)
Expand All @@ -337,15 +338,21 @@ def query_iscore(self, address: 'Address', tx_hash: Optional[bytes]) -> Tuple[in

return response.iscore, response.block_height

async def _query_iscore(self, address: 'Address', tx_hash: Optional[bytes]) -> 'QueryResponse':
async def _query_iscore(self, address: 'Address', block: Optional[Block],
tx_hash: Optional[bytes]) -> 'QueryResponse':
"""
:param address:
:return: [iscore(int), block_height(int)]
"""
Logger.debug(tag=_TAG, msg="_query_iscore() start")

request = QueryRequest(address, tx_hash)
request = QueryRequest(
address,
block.height if block is not None else 0,
block.hash if block is not None else None,
tx_hash,
)

future: asyncio.Future = self._message_queue.put(request)
await future
Expand Down

0 comments on commit 6569500

Please sign in to comment.