From fcf71b1d106a4b559479178eaf1d8bbc81f3c96c Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Tue, 14 May 2024 13:35:36 -0600 Subject: [PATCH 1/6] Remove unused "wait" parameter for ledger The wait_parameter_for_ledger value is not used with CCF. This removes it. Signed-off-by: Mic Bowman --- python/pdo/contract/response.py | 4 ++-- python/pdo/contract/transaction.py | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/python/pdo/contract/response.py b/python/pdo/contract/response.py index fa79b366..3735e9de 100644 --- a/python/pdo/contract/response.py +++ b/python/pdo/contract/response.py @@ -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 @@ -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) diff --git a/python/pdo/contract/transaction.py b/python/pdo/contract/transaction.py index 2818aa6d..86f3adad 100644 --- a/python/pdo/contract/transaction.py +++ b/python/pdo/contract/transaction.py @@ -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 From ed8f07517f7f844183906eb4b5673ea883043e31 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Tue, 14 May 2024 13:48:54 -0600 Subject: [PATCH 2/6] Small update for logging message Signed-off-by: Mic Bowman --- python/pdo/contract/transaction.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/pdo/contract/transaction.py b/python/pdo/contract/transaction.py index 86f3adad..ae23f36c 100644 --- a/python/pdo/contract/transaction.py +++ b/python/pdo/contract/transaction.py @@ -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) @@ -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 ## ------------------------------------------------------- From f1856006db9354d759d5445b1fcf21d7e431a0de Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Wed, 15 May 2024 15:03:59 -0600 Subject: [PATCH 3/6] Add a method to get the raw (unexpanded) value in a context Add a get_value method to get the raw value of the context. Then this is used to get context information for the contract collections (which means that the top level contexts are not expanded when they are placed in the contract collection. Signed-off-by: Mic Bowman --- client/pdo/client/builder/context.py | 8 +++++++- client/pdo/client/commands/collection.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client/pdo/client/builder/context.py b/client/pdo/client/builder/context.py index d8cd062f..e2abe6b7 100644 --- a/client/pdo/client/builder/context.py +++ b/client/pdo/client/builder/context.py @@ -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 @@ -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) diff --git a/client/pdo/client/commands/collection.py b/client/pdo/client/commands/collection.py index 272c1d02..c6594982 100644 --- a/client/pdo/client/commands/collection.py +++ b/client/pdo/client/commands/collection.py @@ -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) From 13d9314249d9576de576aa154b6a54aedfe653ea Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Thu, 16 May 2024 17:09:40 -0600 Subject: [PATCH 4/6] Clean up loops and exits Signed-off-by: Mic Bowman --- .../scripts/EServiceEnclaveInfoCLI.py | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/eservice/pdo/eservice/scripts/EServiceEnclaveInfoCLI.py b/eservice/pdo/eservice/scripts/EServiceEnclaveInfoCLI.py index ae0f9680..89c14e65 100644 --- a/eservice/pdo/eservice/scripts/EServiceEnclaveInfoCLI.py +++ b/eservice/pdo/eservice/scripts/EServiceEnclaveInfoCLI.py @@ -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 @@ -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) @@ -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) From 4c7447a62647ecdf906d40f768b84dfcde99332c Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Fri, 24 May 2024 08:52:40 -0600 Subject: [PATCH 5/6] fix variable reference in ledgers setup Signed-off-by: Mic Bowman --- ledgers/ccf/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledgers/ccf/setup.py b/ledgers/ccf/setup.py index a2da7b75..3e3ba9f2 100644 --- a/ledgers/ccf/setup.py +++ b/ledgers/ccf/setup.py @@ -41,7 +41,7 @@ pdo_version = subprocess.check_output('bin/get_version', cwd=root_dir).decode('ascii').strip() except Exception as e : warnings.warn('Failed to get pdo version, using the default') - pdo_contracts_version = '0.0.0' + pdo_version = '0.0.0' ## ----------------------------------------------------------------- ## ----------------------------------------------------------------- From c73631623ce6401b9de85da9128240fa84730bdb Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Fri, 24 May 2024 09:01:45 -0600 Subject: [PATCH 6/6] Fix missing exception import for twisted Signed-off-by: Mic Bowman --- eservice/pdo/eservice/scripts/EServiceCLI.py | 1 + pservice/pdo/pservice/scripts/PServiceCLI.py | 8 +++----- sservice/pdo/sservice/scripts/SServiceCLI.py | 1 + 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eservice/pdo/eservice/scripts/EServiceCLI.py b/eservice/pdo/eservice/scripts/EServiceCLI.py index 4e9052f5..bdc37dde 100644 --- a/eservice/pdo/eservice/scripts/EServiceCLI.py +++ b/eservice/pdo/eservice/scripts/EServiceCLI.py @@ -44,6 +44,7 @@ from twisted.internet import reactor, defer from twisted.internet.endpoints import TCP4ServerEndpoint from twisted.web.wsgi import WSGIResource +from twisted.internet.error import ReactorNotRunning ## ---------------------------------------------------------------- def ErrorResponse(request, error_code, msg) : diff --git a/pservice/pdo/pservice/scripts/PServiceCLI.py b/pservice/pdo/pservice/scripts/PServiceCLI.py index a3cf84f3..3e97e7ea 100644 --- a/pservice/pdo/pservice/scripts/PServiceCLI.py +++ b/pservice/pdo/pservice/scripts/PServiceCLI.py @@ -35,7 +35,6 @@ import pdo.common.utility as putils import pdo.pservice.pdo_helper as pdo_enclave_helper -import pdo.pservice.pdo_enclave as pdo_enclave import logging logger = logging.getLogger(__name__) @@ -46,9 +45,7 @@ from twisted.web import server, resource, http from twisted.internet import reactor, defer from twisted.web.error import Error - -import base64 - +from twisted.internet.error import ReactorNotRunning ## XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ## XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX @@ -180,7 +177,8 @@ def _secretreq(self, minfo) : logger.debug("Expected public key: %s", opk) assert contract_info['pdo_contract_creator_pem_key'] == opk except : - logger.error('request to create secret did not come from the contract owner; %s != %s', contracttxn.OriginatorID, opk) + logger.error('request to create secret did not come from the contract owner; %s != %s', + contract_info['pdo_contract_creator_pem_key'], opk) raise Error(http.NOT_ALLOWED, 'operation not allowed for {0}'.format(opk)) # make sure the provisioning service is allowed to access contract by the checking the list of allowed provisioning services diff --git a/sservice/pdo/sservice/scripts/SServiceCLI.py b/sservice/pdo/sservice/scripts/SServiceCLI.py index cb57275d..a1caae74 100644 --- a/sservice/pdo/sservice/scripts/SServiceCLI.py +++ b/sservice/pdo/sservice/scripts/SServiceCLI.py @@ -45,6 +45,7 @@ from twisted.internet import reactor, defer, task from twisted.internet.endpoints import TCP4ServerEndpoint from twisted.web.wsgi import WSGIResource +from twisted.internet.error import ReactorNotRunning ## ---------------------------------------------------------------- def ErrorResponse(request, error_code, msg) :