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 #480 from icon-project/release/1.7.0
Browse files Browse the repository at this point in the history
Release/1.7.0
  • Loading branch information
goldworm-icon authored Jul 29, 2020
2 parents 2778d9c + ebcdc14 commit 1a64edb
Show file tree
Hide file tree
Showing 92 changed files with 2,941 additions and 526 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: python
python:
- "3.6"
- "3.7"

branches:
Expand Down
10 changes: 5 additions & 5 deletions docs/api-references/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import os
import sys

# from recommonmark.parser import CommonMarkParser
# -- Path setup --------------------------------------------------------------
from recommonmark.transform import AutoStructify

Expand All @@ -22,11 +21,12 @@
copyright = '2019, ICON Foundation'
author = 'ICON Foundation'

version = os.environ.get('VERSION')
if version is None:
with open(os.path.join('../..', 'VERSION')) as version_file:
version = version_file.read().strip()
about = {}
path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../../iconservice/__version__.py')
with open(path, 'r', encoding='utf-8') as f:
exec(f.read(), about)

version = about["__version__"]
release = ''


Expand Down
2 changes: 2 additions & 0 deletions iconservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
from abc import ABCMeta, abstractmethod, ABC
from functools import wraps
from inspect import isfunction
from typing import List, Union, Optional, Dict

from iconcommons.logger import Logger
from typing_extensions import TypedDict

from .base.address import Address, AddressPrefix, SYSTEM_SCORE_ADDRESS, ZERO_SCORE_ADDRESS
from .base.exception import IconScoreException
Expand Down
2 changes: 1 addition & 1 deletion iconservice/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.7.0rc2'
__version__ = '1.7.0'
35 changes: 30 additions & 5 deletions iconservice/deploy/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from typing import TYPE_CHECKING

from iconcommons import Logger

from .icon_score_deployer import IconScoreDeployer
from .utils import remove_path, get_score_path
from ..base.ComponentBase import EngineBase
Expand All @@ -33,6 +34,9 @@
from ..iconscore.icon_score_context_util import IconScoreContextUtil
from ..iconscore.icon_score_mapper_object import IconScoreInfo
from ..iconscore.icon_score_step import StepType, get_deploy_content_size
from ..iconscore.typing.conversion import convert_score_parameters
from ..iconscore.typing.element import check_score_flag
from ..iconscore.typing.element import normalize_signature
from ..iconscore.utils import get_score_deploy_path
from ..utils import is_builtin_score

Expand Down Expand Up @@ -203,16 +207,24 @@ def _on_deploy(self,

score_info: 'IconScoreInfo' =\
self._create_score_info(context, score_address, next_tx_hash)

if context.revision >= Revision.STRICT_SCORE_DECORATOR_CHECK.value:
check_score_flag(score_info.score_class)

# score_info.get_score() returns a cached or created score instance
# according to context.revision.
score: 'IconScoreBase' = score_info.get_score(context.revision)
ScoreApiGenerator.check_on_deploy(context, score)

# check_on_deploy will be done by normalize_signature()
# since Revision.THREE
if context.revision < Revision.THREE.value:
ScoreApiGenerator.check_on_deploy(context, score)

# owner is set in IconScoreBase.__init__()
context.msg = Message(sender=score.owner)
context.tx = None

self._initialize_score(tx_params.deploy_type, score, params)
self._initialize_score(context, tx_params.deploy_type, score, params)
new_tx_score_mapper[score_address] = score_info
except BaseException as e:
Logger.warning(f'Failed to deploy a SCORE: {score_address}', ICON_DEPLOY_LOG_TAG)
Expand All @@ -222,7 +234,8 @@ def _on_deploy(self,
context.tx = backup_tx
self._update_new_score_mapper(context.new_icon_score_mapper, new_tx_score_mapper)

def _update_new_score_mapper(self, block_mapper: 'IconScoreMapper', tx_mapper: dict):
@classmethod
def _update_new_score_mapper(cls, block_mapper: 'IconScoreMapper', tx_mapper: dict):
for address, score_info in tx_mapper.items():
block_mapper[address] = score_info

Expand Down Expand Up @@ -302,7 +315,10 @@ def _write_score_to_score_deploy_path(context: 'IconScoreContext',
IconScoreDeployer.deploy_legacy(score_deploy_path, content)

@staticmethod
def _initialize_score(deploy_type: DeployType, score: 'IconScoreBase', params: dict):
def _initialize_score(
context: 'IconScoreContext',
deploy_type: DeployType,
score: 'IconScoreBase', params: dict):
"""Call on_install() or on_update() of a SCORE
only once when installing or updating it
:param deploy_type: DeployType.INSTALL or DeployType.UPDATE
Expand All @@ -316,5 +332,14 @@ def _initialize_score(deploy_type: DeployType, score: 'IconScoreBase', params: d
else:
raise InvalidParamsException(f'Invalid deployType: {deploy_type}')

TypeConverter.adjust_params_to_method(on_init, params)
if context.revision < Revision.THREE.value:
TypeConverter.adjust_params_to_method(on_init, params)
else:
signatures = [None, None]
# Do not allow **kwargs, *args used in on_install() and on_update() of score
signatures[DeployType.INSTALL.value] = normalize_signature(score.on_install)
signatures[DeployType.UPDATE.value] = normalize_signature(score.on_update)

params = convert_score_parameters(params, signatures[deploy_type.value])

on_init(**params)
2 changes: 2 additions & 0 deletions iconservice/icon_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class Revision(Enum):
PREVENT_DUPLICATED_ENDPOINT = 9
SET_IREP_VIA_NETWORK_PROPOSAL = 9
MULTIPLE_UNSTAKE = 9
FIX_COIN_PART_BYTES_ENCODING = 9
STRICT_SCORE_DECORATOR_CHECK = 9

LATEST = 9

Expand Down
3 changes: 2 additions & 1 deletion iconservice/icon_service_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from iconservice.icon_config import default_icon_config
from iconservice.icon_constant import ICON_SCORE_QUEUE_NAME_FORMAT, ICON_SERVICE_PROCTITLE_FORMAT, ConfigKey
from .__version__ import __version__

if TYPE_CHECKING:
from .icon_inner_service import IconScoreInnerStub
Expand All @@ -43,7 +44,7 @@ class ExitCode(IntEnum):
def main():
parser = argparse.ArgumentParser(prog='icon_service_cli.py', usage=f"""
==========================
iconservice
iconservice {__version__}
==========================
iconservice commands:
start : iconservice start
Expand Down
9 changes: 7 additions & 2 deletions iconservice/icon_service_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

import os
import shutil
from copy import deepcopy
from enum import IntEnum
from typing import TYPE_CHECKING, List, Any, Optional, Tuple, Dict, Union
Expand Down Expand Up @@ -444,6 +445,8 @@ def invoke(self,
tx_timer.start()

for index, tx_request in enumerate(tx_requests):
Logger.debug(_TAG, f"INVOKE tx: {tx_request}")

# Adjust the number of transactions in a block to make sure that
# a leader can broadcast a block candidate to validators in a specific period.
if is_block_editable and not self._continue_to_invoke(tx_request, tx_timer):
Expand Down Expand Up @@ -473,6 +476,8 @@ def invoke(self,
if context.revision >= Revision.IISS.value:
context.block_batch.block.cumulative_fee += tx_result.step_price * tx_result.step_used

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

if self._check_end_block_height_of_calc(context):
context.revision_changed_flag |= RevisionChangedFlag.IISS_CALC
if check_decentralization_condition(context):
Expand Down Expand Up @@ -1951,11 +1956,11 @@ class DBType(IntEnum):
pass
elif items[DBType.STANDBY][1]:
# Rename standby_rc_db to iiss_rc_db
os.rename(items[DBType.STANDBY][0], items[DBType.IISS][0])
shutil.move(items[DBType.STANDBY][0], items[DBType.IISS][0])
elif items[DBType.CURRENT][1]:
# Rename current_db to iiss_rc_db
path: str = items[DBType.CURRENT][0]
os.rename(path, items[DBType.IISS][0])
shutil.move(path, items[DBType.IISS][0])
else:
raise DatabaseException("IISS-related DB not found")

Expand Down
27 changes: 16 additions & 11 deletions iconservice/iconscore/icon_score_api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
from inspect import signature, Signature, Parameter, isclass, getmembers, isfunction
from typing import Any, Optional, TYPE_CHECKING

from .icon_score_constant import ConstBitFlag, CONST_BIT_FLAG, CONST_INDEXED_ARGS_COUNT, BaseType, \
from .icon_score_constant import ScoreFlag, CONST_INDEXED_ARGS_COUNT, BaseType, \
STR_FALLBACK, STR_ON_INSTALL, STR_ON_UPDATE
from .typing.element import get_score_flag, is_any_score_flag_on
from ..base.address import Address
from ..base.exception import IllegalFormatException, InvalidParamsException
from ..base.type_converter import TypeConverter
Expand Down Expand Up @@ -77,12 +78,12 @@ def __check_on_deploy_function(context: 'IconScoreContext', sig_info: 'Signature
@staticmethod
def __generate_functions(src: list, score_funcs: list) -> None:
for func in score_funcs:
const_bit_flag = getattr(func, CONST_BIT_FLAG, 0)
is_readonly = const_bit_flag & ConstBitFlag.ReadOnly == ConstBitFlag.ReadOnly
is_payable = const_bit_flag & ConstBitFlag.Payable == ConstBitFlag.Payable
score_flag = get_score_flag(func)
is_readonly = bool(score_flag & ScoreFlag.READONLY)
is_payable = bool(score_flag & ScoreFlag.PAYABLE)

try:
if const_bit_flag & ConstBitFlag.External:
if score_flag & ScoreFlag.EXTERNAL:
src.append(ScoreApiGenerator.__generate_normal_function(
func.__name__, is_readonly, is_payable, signature(func)))
elif func.__name__ == ScoreApiGenerator.__API_TYPE_FALLBACK:
Expand Down Expand Up @@ -130,12 +131,16 @@ def __generate_fallback_function(func_name: str, is_payable: bool, sig_info: 'Si

@staticmethod
def __generate_events(src: list, score_funcs: list) -> None:
event_funcs = {func.__name__: signature(func) for func in score_funcs
if getattr(func, CONST_BIT_FLAG, 0) & ConstBitFlag.EventLog}

indexed_args_counts = {func.__name__: getattr(func, CONST_INDEXED_ARGS_COUNT, 0)
for func in score_funcs
if getattr(func, CONST_INDEXED_ARGS_COUNT, 0)}
event_funcs = {
func.__name__: signature(func) for func in score_funcs
if is_any_score_flag_on(func, ScoreFlag.EVENTLOG)
}

indexed_args_counts = {
func.__name__: getattr(func, CONST_INDEXED_ARGS_COUNT, 0)
for func in score_funcs
if getattr(func, CONST_INDEXED_ARGS_COUNT, 0)
}

for func_name, event in event_funcs.items():
index_args_count = indexed_args_counts.get(func_name, 0)
Expand Down
Loading

0 comments on commit 1a64edb

Please sign in to comment.