diff --git a/src/app/include/CrustStatus.h b/src/app/include/CrustStatus.h index ea039c76..556a147e 100644 --- a/src/app/include/CrustStatus.h +++ b/src/app/include/CrustStatus.h @@ -13,6 +13,7 @@ typedef enum _crust_status_t CRUST_BLOCK_HEIGHT_EXPIRED = CRUST_MK_ERROR(0x2000), CRUST_FIRST_WORK_REPORT_AFTER_REPORT = CRUST_MK_ERROR(0x2001), CRUST_WORK_REPORT_NOT_VALIDATED = CRUST_MK_ERROR(0x2002), + CRUST_NO_KARST = CRUST_MK_ERROR(0x2003), // Failed CRUST_MALLOC_FAILED = CRUST_MK_ERROR(0x4000), CRUST_SEAL_DATA_FAILED = CRUST_MK_ERROR(0x4001), diff --git a/src/app/process/WorkReport.cpp b/src/app/process/WorkReport.cpp index 38b7e6d8..f3ac9954 100644 --- a/src/app/process/WorkReport.cpp +++ b/src/app/process/WorkReport.cpp @@ -107,6 +107,10 @@ void work_report_loop(void) { p_log->info("Can't generate work report for the first time after restart\n"); } + else if (crust_status == CRUST_NO_KARST) + { + p_log->info("Can't generate work report. You have meaningful files, please start karst\n"); + } else { p_log->err("Get signed validation report failed! Error code: %x\n", crust_status); diff --git a/src/enclave/include/CrustStatus.h b/src/enclave/include/CrustStatus.h index ea039c76..556a147e 100644 --- a/src/enclave/include/CrustStatus.h +++ b/src/enclave/include/CrustStatus.h @@ -13,6 +13,7 @@ typedef enum _crust_status_t CRUST_BLOCK_HEIGHT_EXPIRED = CRUST_MK_ERROR(0x2000), CRUST_FIRST_WORK_REPORT_AFTER_REPORT = CRUST_MK_ERROR(0x2001), CRUST_WORK_REPORT_NOT_VALIDATED = CRUST_MK_ERROR(0x2002), + CRUST_NO_KARST = CRUST_MK_ERROR(0x2003), // Failed CRUST_MALLOC_FAILED = CRUST_MK_ERROR(0x4000), CRUST_SEAL_DATA_FAILED = CRUST_MK_ERROR(0x4001), diff --git a/src/enclave/report/Report.cpp b/src/enclave/report/Report.cpp index b51b4892..c38231fc 100644 --- a/src/enclave/report/Report.cpp +++ b/src/enclave/report/Report.cpp @@ -73,14 +73,23 @@ crust_status_t get_signed_work_report(const char *block_hash, size_t block_heigh } id_set_report_slot((block_height - 1)/ERA_LENGTH + 1); + + Workload *wl = Workload::get_instance(); // The first report after restart will not be processed if (id_just_after_restart()) { id_set_just_after_restart(false); + wl->set_report_flag(true); return CRUST_FIRST_WORK_REPORT_AFTER_REPORT; } - Workload *wl = Workload::get_instance(); + // Have files and no karst + if (!wl->get_report_flag()) + { + wl->set_report_flag(true); + return CRUST_NO_KARST; + } + ecc_key_pair id_key_pair = id_get_key_pair(); crust_status_t crust_status = CRUST_SUCCESS; sgx_status_t sgx_status; @@ -125,27 +134,24 @@ crust_status_t get_signed_work_report(const char *block_hash, size_t block_heigh // ----- Get files info ----- // std::string old_files = "["; - if (wl->get_report_flag()) + sgx_thread_mutex_lock(&g_checked_files_mutex); + for (uint32_t i = 0; i < wl->checked_files.size(); i++) { - sgx_thread_mutex_lock(&g_checked_files_mutex); - for (uint32_t i = 0; i < wl->checked_files.size(); i++) + if (wl->checked_files[i][FILE_STATUS].ToString().compare(FILE_STATUS_VALID) != 0) + { + continue; + } + + old_files.append("{\"").append(FILE_HASH).append("\":") + .append("\"").append(wl->checked_files[i][FILE_OLD_HASH].ToString()).append("\","); + old_files.append("\"").append(FILE_SIZE).append("\":") + .append(std::to_string(wl->checked_files[i][FILE_OLD_SIZE].ToInt())).append("}"); + if (i != wl->checked_files.size() - 1) { - if (wl->checked_files[i][FILE_STATUS].ToString().compare(FILE_STATUS_VALID) != 0) - { - continue; - } - - old_files.append("{\"").append(FILE_HASH).append("\":") - .append("\"").append(wl->checked_files[i][FILE_OLD_HASH].ToString()).append("\","); - old_files.append("\"").append(FILE_SIZE).append("\":") - .append(std::to_string(wl->checked_files[i][FILE_OLD_SIZE].ToInt())).append("}"); - if (i != wl->checked_files.size() - 1) - { - old_files.append(","); - } + old_files.append(","); } - sgx_thread_mutex_unlock(&g_checked_files_mutex); } + sgx_thread_mutex_unlock(&g_checked_files_mutex); old_files.append("]"); // ----- Create signature data ----- // diff --git a/src/enclave/validator/Validator.cpp b/src/enclave/validator/Validator.cpp index 42ab51ab..3a3357ea 100644 --- a/src/enclave/validator/Validator.cpp +++ b/src/enclave/validator/Validator.cpp @@ -239,7 +239,10 @@ void validate_meaningful_file() ocall_validate_init(&crust_status); if (CRUST_SUCCESS != crust_status) { - wl->set_report_flag(false); + if(wl->checked_files.size() != 0) + { + wl->set_report_flag(false); + } ocall_validate_close(); sgx_thread_mutex_unlock(&g_checked_files_mutex); return; diff --git a/src/enclave/workload/Workload.cpp b/src/enclave/workload/Workload.cpp index dd71225e..b4e230e0 100644 --- a/src/enclave/workload/Workload.cpp +++ b/src/enclave/workload/Workload.cpp @@ -5,6 +5,7 @@ sgx_thread_mutex_t g_srd_mutex = SGX_THREAD_MUTEX_INITIALIZER; sgx_thread_mutex_t g_checked_files_mutex = SGX_THREAD_MUTEX_INITIALIZER; sgx_thread_mutex_t g_new_files_mutex = SGX_THREAD_MUTEX_INITIALIZER; sgx_thread_mutex_t g_order_files_mutex = SGX_THREAD_MUTEX_INITIALIZER; +sgx_thread_mutex_t g_report_flag_mutex = SGX_THREAD_MUTEX_INITIALIZER; Workload *Workload::workload = NULL; @@ -320,7 +321,9 @@ void Workload::add_order_file(std::pair file) */ void Workload::set_report_flag(bool flag) { + sgx_thread_mutex_lock(&g_report_flag_mutex); this->report_files = flag; + sgx_thread_mutex_unlock(&g_report_flag_mutex); } /** @@ -329,7 +332,10 @@ void Workload::set_report_flag(bool flag) */ bool Workload::get_report_flag() { - return this->report_files; + sgx_thread_mutex_lock(&g_report_flag_mutex); + bool flag = this->report_files; + sgx_thread_mutex_unlock(&g_report_flag_mutex); + return flag; } /**