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

Commit

Permalink
Turn is_shutdown flag on every revision change since revision 13
Browse files Browse the repository at this point in the history
  • Loading branch information
goldworm committed Sep 28, 2021
1 parent a68533b commit d9a9887
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions iconservice/icon_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Revision(Enum):
VERIFY_ASSET_INTEGRITY = 12
USE_RLP = 12

# All revisions after Revision12 pass is_shutdown flag to loopchain
SHUTDOWN = 13

LATEST = 13
Expand Down
2 changes: 1 addition & 1 deletion iconservice/icon_service_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def invoke(self,
added_transactions,
next_preps,
context.prep_address_converter,
context.is_revision_changed(Revision.SHUTDOWN.value))
context.is_shutdown())
if context.precommitdata_log_flag:
Logger.info(tag=_TAG, msg=f"Created precommit_data: \n{precommit_data}")
self._precommit_data_manager.push(precommit_data)
Expand Down
5 changes: 5 additions & 0 deletions iconservice/iconscore/icon_score_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ def is_revision_changed(self, target_rev: int) -> bool:

return old.revision_code != new.revision_code and new.revision_code == target_rev

def is_shutdown(self):
old: 'INVContainer' = self.engine.inv.inv_container
new: 'INVContainer' = self.inv_container
return old.revision_code < new.revision_code >= Revision.SHUTDOWN.value

def get_batches(self) -> Iterable['Batch']:
"""Used to support 2-depth block invocation
It is called in ContextDatabase.get_from_batch() on estimation or invoke
Expand Down
34 changes: 19 additions & 15 deletions tests/integrate_test/iiss/decentralized/test_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,22 @@ def setUp(self):
)

def test_shutdown_revision(self):
self.set_revision(Revision.IMPROVED_PRE_VALIDATOR.value)

revision = Revision.SHUTDOWN.value
from_ = self._admin
to = GOVERNANCE_SCORE_ADDRESS
params = {"code": hex(revision), "name": f"1.1.{revision}"}

tx = self.create_score_call_tx(
from_=self._admin,
to_=to,
func_name="setRevision",
params=params,
)
block, tx_results, _, _, _, is_shutdown = self.debug_make_and_req_block([tx])
assert is_shutdown
self.set_revision(11)

results = (False, False, True, False, True, True)
revisions = (11, 12, 13, 13, 14, 15)

for revision, expected in zip(revisions, results):
to = GOVERNANCE_SCORE_ADDRESS
params = {"code": hex(revision), "name": f"1.1.{revision}"}

tx = self.create_score_call_tx(
from_=self._admin,
to_=to,
func_name="setRevision",
params=params,
)
block, tx_results, _, _, _, is_shutdown = self.debug_make_and_req_block([tx])
assert is_shutdown is expected
self.process_confirm_block_tx(tx_list=[tx])
assert self.get_revision()["code"] == revision
1 change: 1 addition & 0 deletions tests/integrate_test/samples/balanced/staking

0 comments on commit d9a9887

Please sign in to comment.