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 #54 from icon-project/feature/LC-88
Browse files Browse the repository at this point in the history
[LC-88] remove unusing configurations
  • Loading branch information
June Park authored Jan 18, 2019
2 parents a660506 + 8c4b5da commit d050c01
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 114 deletions.
2 changes: 0 additions & 2 deletions conf/loopchain_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"0x2": 1,
"0x3": 1
},
"store_valid_transaction_only": true,
"send_tx_type": 2,
"load_cert": false,
"consensus_cert_use": false,
"tx_cert_use": false,
Expand Down
2 changes: 0 additions & 2 deletions loopchain/baseservice/broadcast_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@ def __handler_create_tx(self, create_tx_param):
# logging.debug(f"Broadcast create_tx....")
try:
tx_item = TxItem.create_tx_item(create_tx_param, self.__channel)
# util.logger.spam(f"broadcast_process:__handler_create_tx "
# f"send_tx_type({create_tx_param.meta[Transaction.SEND_TX_TYPE_KEY]})")
except Exception as e:
logging.warning(f"tx in channel({self.__channel})")
logging.warning(f"__handler_create_tx: meta({create_tx_param})")
Expand Down
19 changes: 1 addition & 18 deletions loopchain/blockchain/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ def __init__(self, blockchain_db=None, channel_name=None):
self.__last_block = None
# last unconfirmed block that the leader broadcast.
self.last_unconfirmed_block = None
self.__save_tx_by_address_strategy = None
self.__channel_name = channel_name
self.__peer_id = ChannelProperty().peer_id
self.__set_send_tx_type(conf.CHANNEL_OPTION[channel_name]["send_tx_type"])

# block db has [ block_hash - block | block_height - block_hash | BlockChain.LAST_BLOCK_KEY - block_hash ]
self.__confirmed_block_db = blockchain_db
Expand Down Expand Up @@ -91,12 +89,6 @@ def __init__(self, blockchain_db=None, channel_name=None):
for tx_version, tx_hash_version in channel_option.get("hash_versions", {}).items():
self.__tx_versioner.hash_generator_versions[tx_version] = tx_hash_version

def __set_send_tx_type(self, send_tx_type):
if send_tx_type == conf.SendTxType.icx:
self.__save_tx_by_address_strategy = self.__save_tx_by_address
else:
self.__save_tx_by_address_strategy = self.__save_tx_by_address_pass

def close_blockchain_db(self):
del self.__confirmed_block_db
self.__confirmed_block_db = None
Expand All @@ -111,12 +103,6 @@ def total_tx(self):

@property
def last_block(self) -> Block:
try:
logging.debug(f"ENGINE-303 blockchain last_block: "
f"{self.__last_block.header.height}, "
f"{self.__last_block.header.hash.hex()}")
except:
pass
return self.__last_block

@property
Expand Down Expand Up @@ -407,7 +393,7 @@ def __add_tx_to_block_db(self, block, invoke_results):
# util.logger.spam(f"pop tx from queue:{tx_hash}")

if block.header.height > 0:
self.__save_tx_by_address_strategy(tx)
self.__save_tx_by_address(tx)

self.__save_invoke_result_block_height(block.header.height)

Expand Down Expand Up @@ -443,9 +429,6 @@ def __save_tx_by_address(self, tx: 'Transaction'):
address = tx.from_address.hex_hx()
return self.add_tx_to_list_by_address(address, tx.hash.hex())

def __save_tx_by_address_pass(self, tx):
return True

@staticmethod
def __get_tx_list_key(address, index):
return conf.TX_LIST_ADDRESS_PREFIX + (address + str(index)).encode(encoding=conf.HASH_KEY_ENCODING)
Expand Down
14 changes: 4 additions & 10 deletions loopchain/channel/channel_inner_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,11 @@ async def get_status(self):
block_manager = self._channel_service.block_manager
status_data["made_block_count"] = block_manager.made_block_count
unconfirmed_block_height = None
if block_manager.get_blockchain().last_block is not None:
block_height = block_manager.get_blockchain().last_block.header.height
if block_manager.get_blockchain().last_unconfirmed_block:
unconfirmed_block_height = block_manager.get_blockchain().last_unconfirmed_block.header.height
logging.debug("getstatus block hash(block_manager.get_blockchain().last_block.block_hash): "
+ str(block_manager.get_blockchain().last_block.header.hash.hex()))
logging.debug("getstatus block hash(block_manager.get_blockchain().block_height): "
+ str(block_manager.get_blockchain().block_height))
logging.debug("getstatus block height: " + str(block_height))
# Score와 상관없이 TransactionTx는 블럭매니저가 관리 합니다.
last_block = block_manager.get_blockchain().last_block
if last_block:
block_height = last_block.header.height
total_tx = block_manager.get_total_tx()
logging.debug(f"last_block height({block_height}), hash({last_block.header.hash})")

status_data["status"] = block_manager.service_status
status_data["state"] = self._channel_service.state_machine.state
Expand Down
40 changes: 9 additions & 31 deletions loopchain/channel/channel_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,7 @@ async def subscribe_network(self):

def __init_peer_auth(self):
try:
channel_authorization = IcxAuthorization if util.channel_use_icx(ChannelProperty().name) \
else PeerAuthorization

self.__peer_auth = channel_authorization(ChannelProperty().name)
self.__peer_auth = IcxAuthorization(ChannelProperty().name)

except Exception as e:
logging.exception(f"peer auth init fail cause : {e}")
Expand Down Expand Up @@ -354,17 +351,10 @@ async def __run_score_container(self):
)
self.__score_container = CommonSubprocess(process_args)

if util.channel_use_icx(ChannelProperty().name):
await StubCollection().create_icon_score_stub(ChannelProperty().name)
await StubCollection().icon_score_stubs[ChannelProperty().name].connect()
await StubCollection().icon_score_stubs[ChannelProperty().name].async_task().hello()
return None
else:
await StubCollection().create_score_stub(ChannelProperty().name, ChannelProperty().score_package)
await StubCollection().score_stubs[ChannelProperty().name].connect()
await StubCollection().score_stubs[ChannelProperty().name].async_task().hello()

return await self.__load_score()
await StubCollection().create_icon_score_stub(ChannelProperty().name)
await StubCollection().icon_score_stubs[ChannelProperty().name].connect()
await StubCollection().icon_score_stubs[ChannelProperty().name].async_task().hello()
return None

async def __load_score(self):
channel_name = ChannelProperty().name
Expand Down Expand Up @@ -826,22 +816,10 @@ def score_write_precommit_state(self, block: Block):
return True

def score_remove_precommit_state(self, block: Block):
if not util.channel_use_icx(ChannelProperty().name):
request = {
"blockHeight": block.height,
"blockHash": block.block_hash,
}
request = convert_params(request, ParamType.remove_precommit_state)

stub = StubCollection().icon_score_stubs[ChannelProperty().name]
stub.sync_task().remove_precommit_state(request)

return True
else:
invoke_fail_info = json.dumps({"block_height": block.height, "block_hash": block.block_hash})
stub = StubCollection().score_stubs[ChannelProperty().name]
stub.sync_task().remove_precommit_state(invoke_fail_info)
return True
invoke_fail_info = json.dumps({"block_height": block.height, "block_hash": block.block_hash})
stub = StubCollection().score_stubs[ChannelProperty().name]
stub.sync_task().remove_precommit_state(invoke_fail_info)
return True

def get_object_has_queue_by_consensus(self):
if conf.CONSENSUS_ALGORITHM == conf.ConsensusAlgorithm.lft:
Expand Down
2 changes: 1 addition & 1 deletion loopchain/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def start_as_score(args):
amqp_target = args.amqp_target or conf.AMQP_TARGET
amqp_key = args.amqp_key or conf.AMQP_KEY

if util.channel_use_icx(channel) and conf.USE_EXTERNAL_SCORE:
if conf.USE_EXTERNAL_SCORE:
if conf.EXTERNAL_SCORE_RUN_IN_LAUNCHER:
from iconservice.icon_service import IconService
from iconservice.icon_config import default_icon_config
Expand Down
9 changes: 1 addition & 8 deletions loopchain/peer/block_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def __init__(self, name: str, channel_manager, peer_id, channel_name, level_db_i

self.__channel_service: ChannelService = channel_manager
self.__channel_name = channel_name
self.__pre_validate_strategy = None
self.__set_send_tx_type(conf.CHANNEL_OPTION[channel_name]["send_tx_type"])
self.__pre_validate_strategy = self.__pre_validate
self.__peer_id = peer_id
self.__level_db = None
self.__level_db_path = ""
Expand Down Expand Up @@ -73,12 +72,6 @@ def __init__(self, name: str, channel_manager, peer_id, channel_name, level_db_i
self.name = name
self.__service_status = status_code.Service.online

def __set_send_tx_type(self, send_tx_type):
if send_tx_type == conf.SendTxType.icx:
self.__pre_validate_strategy = self.__pre_validate
else:
self.__pre_validate_strategy = self.__pre_validate_pass

@property
def channel_name(self):
return self.__channel_name
Expand Down
7 changes: 2 additions & 5 deletions loopchain/peer/peer_outer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def Request(self, request, context):

def __status_update(self, channel, future):
# update peer outer status cache by channel
util.logger.spam(f"peer_outer_service:__status_update channel({channel}) result({future.result()})")
util.logger.spam(f"status_update channel({channel}) result({future.result()})")
self.__status_cache_update_time[channel] = datetime.datetime.now()
self.peer_service.status_cache[channel] = future.result()

Expand Down Expand Up @@ -252,10 +252,7 @@ def GetStatus(self, request, context):
stubs = {
"peer": StubCollection().peer_stub,
"channel": StubCollection().channel_stubs.get(channel_name),
"score":
StubCollection().icon_score_stubs.get(channel_name)
if util.channel_use_icx(channel_name) else
StubCollection().score_stubs.get(channel_name)
"score": StubCollection().icon_score_stubs.get(channel_name)
}

mq_status_data = {}
Expand Down
24 changes: 3 additions & 21 deletions loopchain/peer/peer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ def __get_channel_infos(self):
channels = json.loads(response.channel_infos)
else:
response = self.stub_to_radiostation.call_in_times(method_name="GetChannelInfos")
channels = {channel: value for channel, value in response["channel_infos"].items()
if util.channel_use_icx(channel)}
channels = {channel: value for channel, value in response["channel_infos"].items()}

return channels

Expand Down Expand Up @@ -235,21 +234,7 @@ def __run_rest_services(self, port):
def __make_peer_id(self):
"""네트워크에서 Peer 를 식별하기 위한 UUID를 level db 에 생성한다.
"""
if util.channel_use_icx(conf.LOOPCHAIN_DEFAULT_CHANNEL):
self.__peer_id = IcxAuthorization(conf.LOOPCHAIN_DEFAULT_CHANNEL).address
else:
try:
uuid_bytes = bytes(self.__level_db.Get(conf.LEVEL_DB_KEY_FOR_PEER_ID))
peer_id = uuid.UUID(bytes=uuid_bytes)
except KeyError: # It's first Run
peer_id = None

if peer_id is None:
peer_id = uuid.uuid1()
logging.info("make new peer_id: " + str(peer_id))
self.__level_db.Put(conf.LEVEL_DB_KEY_FOR_PEER_ID, peer_id.bytes)

self.__peer_id = str(peer_id)
self.__peer_id = IcxAuthorization(conf.LOOPCHAIN_DEFAULT_CHANNEL).address

logger_preset = loggers.get_preset()
logger_preset.peer_id = self.peer_id
Expand Down Expand Up @@ -407,7 +392,4 @@ async def ready_tasks(self):
for channel_name, channel_info in self.__channel_infos.items():
await StubCollection().create_channel_stub(channel_name)

if util.channel_use_icx(channel_name):
await StubCollection().create_icon_score_stub(channel_name)
else:
await StubCollection().create_score_stub(channel_name, channel_info['score_package'])
await StubCollection().create_icon_score_stub(channel_name)
5 changes: 1 addition & 4 deletions loopchain/rest_server/peer_service_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ def get_last_block_hash(self, channel: str) -> str:
def get_block(self, channel: str, block_hash: str= "", block_height: int=-1):
block_data_filter = "prev_block_hash, height, block_hash, merkle_tree_root_hash," \
" time_stamp, peer_id, signature"
if conf.CHANNEL_OPTION[channel]['send_tx_type'] == conf.SendTxType.icx:
tx_data_filter = "icx_origin_data"
else:
tx_data_filter = "tx_hash, timestamp, data_string, peer_id"
tx_data_filter = "icx_origin_data"

response = self.call("GetBlock",
loopchain_pb2.GetBlockRequest(
Expand Down
4 changes: 0 additions & 4 deletions loopchain/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,6 @@ def get_private_ip():
return get_private_ip3()


def channel_use_icx(channel):
return conf.CHANNEL_OPTION[channel]['send_tx_type'] == conf.SendTxType.icx


def dict_to_binary(the_dict):
return str.encode(json.dumps(the_dict))

Expand Down
5 changes: 1 addition & 4 deletions loopchain/utils/json_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ async def get_block_by_params(block_height=None, block_hash="", with_commit_stat
channel_name = conf.LOOPCHAIN_DEFAULT_CHANNEL
block_data_filter = "prev_block_hash, height, block_hash, merkle_tree_root_hash," \
" time_stamp, peer_id, signature"
if conf.CHANNEL_OPTION[channel_name]['send_tx_type'] == conf.SendTxType.icx:
tx_data_filter = "icx_origin_data"
else:
tx_data_filter = "tx_hash, timestamp, data_string, peer_id"
tx_data_filter = "icx_origin_data"
channel_stub = StubCollection().channel_stubs[channel_name]
response_code, block_hash, block_data_json, tx_data_json_list = \
await channel_stub.async_task().get_block(
Expand Down
4 changes: 0 additions & 4 deletions testcase/unittest/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ def test_save_and_restore_user_configure(self):
conf.DISABLE_V1_API = False
conf.CHANNEL_OPTION = {
conf.LOOPCHAIN_DEFAULT_CHANNEL: {
"store_valid_transaction_only": True,
"send_tx_type": conf.SendTxType.icx,
"load_cert": False,
"consensus_cert_use": False,
"tx_cert_use": False,
Expand All @@ -96,8 +94,6 @@ def test_save_and_restore_user_configure(self):
"private_password": b'test'
},
conf.LOOPCHAIN_TEST_CHANNEL: {
"store_valid_transaction_only": False,
"send_tx_type": conf.SendTxType.pickle,
"load_cert": False,
"consensus_cert_use": False,
"tx_cert_use": False,
Expand Down

0 comments on commit d050c01

Please sign in to comment.