Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several small cleanups #491

Merged
merged 6 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion client/pdo/client/builder/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(self, state, prefix='') :
self.__state__ = state

if type(self.context) is not dict :
raise ValueError('invalid context reference, {}'.self.__path__)
raise ValueError('invalid context reference, {}', self.__path__)

# --------------------------------------------------
@property
Expand Down Expand Up @@ -118,6 +118,12 @@ def get_context(self, relative_path) :
return Context(self.__state__, '.'.join(new_keylist[1:]))
# return Context(self.__state__, new_keylist, new_context)

# --------------------------------------------------
def get_value(self, relative_path, value=None) :
"""return the raw, unexpanded value
"""
return self.__state__.get(self.__path__ + relative_path.split('.'), value)

# --------------------------------------------------
def __setitem__(self, relative_path, value):
return self.set(relative_path, value)
Expand Down
2 changes: 1 addition & 1 deletion client/pdo/client/commands/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def export_contract_collection(
if p not in ec :
ec[p] = {}
ec = ec[p]
ec[key] = copy.deepcopy(context.get(c))
ec[key] = copy.deepcopy(context.get_value(c))

# now find all of the contract references in the exported context
save_files = __find_contracts__(export_context)
Expand Down
48 changes: 26 additions & 22 deletions eservice/pdo/eservice/scripts/EServiceEnclaveInfoCLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys
import argparse
import json
import logging
import os
import sys
import time
from pathlib import Path

import pdo.common.config as pconfig
Expand All @@ -26,22 +28,25 @@
import pdo.eservice.pdo_helper as pdo_enclave_helper
import pdo.eservice.pdo_enclave as pdo_enclave

import logging
logger = logging.getLogger(__name__)

import time



# -----------------------------------------------------------------
# -----------------------------------------------------------------
def GetBasename(save_path, config) :
attempts = 0
while True :
"""get the BASENAME and MRENCLAVE from the enclave, write the
results to the specified file
"""

logger.debug('initialize the enclave')
try :
enclave_config = config.get('EnclaveModule')
spid = Path(os.path.join(enclave_config['sgx_key_root'], "sgx_spid.txt")).read_text().strip()
except Exception as e :
logger.critical(f'unable to read sgx_spid file {e}')
sys.exit(-1)

for _ in range(0, 10) :
try :
logger.debug('initialize the enclave')
enclave_config = config.get('EnclaveModule')
spid = Path(os.path.join(enclave_config['sgx_key_root'], "sgx_spid.txt")).read_text().strip()
info = pdo_enclave_helper.get_enclave_service_info(spid)

logger.info('save MR_ENCLAVE and MR_BASENAME to %s', save_path)
Expand All @@ -58,22 +63,21 @@ def GetBasename(save_path, config) :
logger.critical('system error in enclave; %s', se)
sys.exit(-1)

time.sleep(10)

except Exception as e :
logger.critical('failed to initialize enclave; %s', e)
sys.exit(-1)

attempts = attempts + 1
if 10 < attempts :
logger.critical('wait for enclave failed')
sys.exit(-1)

logger.info('SGX_BUSY, attempt %s', attempts)
time.sleep(10)
logger.critical('SGX continues to be busy')
sys.exit(-1)

def GetIasCertificates(config) :
# load, initialize and create signup info the enclave library
# (signup info are not relevant here)
# the creation of signup info includes getting a verification report from IAS
"""load, initialize and create signup info the enclave library

the creation of signup info includes getting a verification report
from IAS
"""
try :
enclave_config = config.get('EnclaveModule')
pdo_enclave.initialize_with_configuration(enclave_config)
Expand Down
4 changes: 2 additions & 2 deletions python/pdo/contract/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def commit_id(self):
return (self.contract_id, self.new_state_hash, self.request_number)

# -------------------------------------------------------
def commit_asynchronously(self, ledger_config=None, wait_parameter_for_ledger=30):
def commit_asynchronously(self, ledger_config) :
"""Commit includes two steps: First, replicate the change set to
all provisioned encalves. Second, commit the transaction to the
ledger. In this method, we add a job to the replication queue to
Expand Down Expand Up @@ -124,7 +124,7 @@ def commit_asynchronously(self, ledger_config=None, wait_parameter_for_ledger=30
self.commit_id)

#create the transaction request if ledger is enabled
self.transaction_request = TransactionRequest(ledger_config, self.commit_id, wait_parameter_for_ledger)
self.transaction_request = TransactionRequest(ledger_config, self.commit_id)

#submit the replication task
add_replication_task(self)
Expand Down
10 changes: 3 additions & 7 deletions python/pdo/contract/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __get(self, contractid, statehash) :

## -------------------------------------------------------
def FindDependency(self, contractid, statehash) :
logger.debug('find dependency for %s, %s', contractid, statehash)
logger.debug(f'find dependency for {contractid}:{statehash}')

with self.__lock__ :
txnid = self.__get(contractid, statehash)
Expand All @@ -79,7 +79,7 @@ def FindDependency(self, contractid, statehash) :
self.__set(contractid, statehash, txnid)
return txnid
except Exception as e :
logger.info('unable to find dependency for %s:%s; failed to retrieve the transaction', contractid, statehash)
logger.warning(f'failed to retrieve contract state for {contractid}:{statehash}; {e}')
return None

## -------------------------------------------------------
Expand Down Expand Up @@ -320,13 +320,9 @@ def __submit_update_transaction__(response, ledger_config, **extra_params):
# -----------------------------------------------------------------
class TransactionRequest(object):

def __init__(self, ledger_config, commit_id, wait_parameter_for_ledger = None):
def __init__(self, ledger_config, commit_id) :

self.ledger_config = ledger_config
# add the wait parameter to the ledger config, if there is one.
# Question: does CCF (or the submitter) use this parameter?
if wait_parameter_for_ledger:
self.ledger_config['wait'] = wait_parameter_for_ledger
self.commit_id = commit_id

self.is_completed = False
Expand Down
Loading