Skip to content

Commit

Permalink
Add previous public key to network identity (crustio#251)
Browse files Browse the repository at this point in the history
* Add previous public key to entry network identity

* Delete useless code
  • Loading branch information
TonyCode2012 authored Oct 29, 2020
1 parent e4cde69 commit 7fbc6be
Show file tree
Hide file tree
Showing 27 changed files with 373 additions and 209 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.PHONY: build test build_test functionality_test clean
.PHONY: build uint_test build_integration functionality_test clean

build:
@$(MAKE) -C src/ all --no-print-directory

test:
uint_test:
@$(MAKE) -C test/unit test --no-print-directory

build_test:
build_integration:
@$(MAKE) -C test/integration build --no-print-directory

functionality_test:
Expand Down
32 changes: 6 additions & 26 deletions src/app/ecalls/ECalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ std::unordered_map<std::string, int> g_task_priority_um = {
{"Ecall_verify_iasreport", 0},
{"Ecall_gen_sgx_measurement", 0},
{"Ecall_main_loop", 0},
{"Ecall_get_signed_work_report", 0},
{"Ecall_gen_and_upload_work_report", 0},
{"Ecall_confirm_file", 0},
{"Ecall_delete_file", 0},
{"Ecall_handle_report_result", 0},
{"Ecall_gen_upgrade_data", 0},
{"Ecall_restore_from_upgrade", 0},
{"Ecall_enable_upgrade", 0},
Expand All @@ -42,20 +41,20 @@ std::unordered_map<std::string, std::unordered_set<std::string>> g_block_tasks_u
{
"Ecall_seal_file",
"Ecall_unseal_file",
"Ecall_get_signed_work_report",
"Ecall_gen_and_upload_work_report",
"Ecall_confirm_file",
}
},
{
"Ecall_confirm_file",
{
"Ecall_get_signed_work_report",
"Ecall_gen_and_upload_work_report",
}
},
{
"Ecall_delete_file",
{
"Ecall_get_signed_work_report",
"Ecall_gen_and_upload_work_report",
}
},
};
Expand Down Expand Up @@ -368,15 +367,15 @@ sgx_status_t Ecall_cmp_chain_account_id(sgx_enclave_id_t eid, crust_status_t *st
* @param block_hash (in) -> block hash
* @param block_height (in) -> block height
*/
sgx_status_t Ecall_get_signed_work_report(sgx_enclave_id_t eid, crust_status_t *status, const char *block_hash, size_t block_height)
sgx_status_t Ecall_gen_and_upload_work_report(sgx_enclave_id_t eid, crust_status_t *status, const char *block_hash, size_t block_height)
{
sgx_status_t ret = SGX_SUCCESS;
if (SGX_SUCCESS != (ret = try_get_enclave(__FUNCTION__)))
{
return ret;
}

ret = ecall_get_signed_work_report(eid, status, block_hash, block_height);
ret = ecall_gen_and_upload_work_report(eid, status, block_hash, block_height);

free_enclave(__FUNCTION__);

Expand Down Expand Up @@ -665,25 +664,6 @@ sgx_status_t Ecall_disable_upgrade(sgx_enclave_id_t eid)
return ret;
}

/**
* @description: Delete file
* @param flag -> Report result
*/
sgx_status_t Ecall_handle_report_result(sgx_enclave_id_t eid)
{
sgx_status_t ret = SGX_SUCCESS;
if (SGX_SUCCESS != (ret = try_get_enclave(__FUNCTION__)))
{
return ret;
}

ret = ecall_handle_report_result(eid);

free_enclave(__FUNCTION__);

return ret;
}

/**
* @description: Get enclave id information
*/
Expand Down
4 changes: 1 addition & 3 deletions src/app/ecalls/ECalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ sgx_status_t Ecall_srd_set_change(sgx_enclave_id_t eid, long change);
sgx_status_t Ecall_main_loop(sgx_enclave_id_t eid);
sgx_status_t Ecall_restore_metadata(sgx_enclave_id_t eid, crust_status_t *status);
sgx_status_t Ecall_cmp_chain_account_id(sgx_enclave_id_t eid, crust_status_t *status, const char *account_id, size_t len);
sgx_status_t Ecall_get_signed_work_report(sgx_enclave_id_t eid, crust_status_t *status, const char *block_hash, size_t block_height);
sgx_status_t Ecall_gen_and_upload_work_report(sgx_enclave_id_t eid, crust_status_t *status, const char *block_hash, size_t block_height);

sgx_status_t Ecall_gen_key_pair(sgx_enclave_id_t eid, sgx_status_t *status, const char *account_id, size_t len);
sgx_status_t Ecall_get_quote_report(sgx_enclave_id_t eid, sgx_status_t *status, sgx_report_t *report, sgx_target_info_t *target_info);
Expand All @@ -63,8 +63,6 @@ sgx_status_t Ecall_confirm_file(sgx_enclave_id_t eid, crust_status_t *status, co

sgx_status_t Ecall_delete_file(sgx_enclave_id_t eid, crust_status_t *status, const char *hash);

sgx_status_t Ecall_handle_report_result(sgx_enclave_id_t eid);

sgx_status_t Ecall_id_get_info(sgx_enclave_id_t eid);

sgx_status_t Ecall_get_workload(sgx_enclave_id_t eid);
Expand Down
2 changes: 1 addition & 1 deletion src/app/http/ApiHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void ApiHandler::http_handler(beast::string_view /*doc_root*/,
std::make_tuple(http::status::ok, req.version())};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
res.set(http::field::content_type, "application/text");
res.body() = "No service will be provided because of upgrade complete!";
res.body() = "No service will be provided because of upgrade!";
res.result(503);
return send(std::move(res));
}
Expand Down
10 changes: 7 additions & 3 deletions src/app/ocalls/OCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ WebsocketClient *wssclient = NULL;
tbb::concurrent_unordered_map<std::string, std::string> sealed_tree_map;

extern std::mutex srd_info_mutex;
extern bool offline_chain_mode;


/**
Expand Down Expand Up @@ -675,10 +676,13 @@ crust_status_t ocall_upload_workreport(const char *work_report)
remove_char(work_str, '\n');
remove_char(work_str, ' ');
p_log->info("Sending work report:%s\n", work_str.c_str());
if (!crust::Chain::get_instance()->post_sworker_work_report(work_str))
if (!offline_chain_mode)
{
p_log->err("Send work report to crust chain failed!\n");
return CRUST_UPGRADE_SEND_WORKREPORT_FAILED;
if (!crust::Chain::get_instance()->post_sworker_work_report(work_str))
{
p_log->err("Send work report to crust chain failed!\n");
return CRUST_UPGRADE_SEND_WORKREPORT_FAILED;
}
}

p_log->info("Send work report to crust chain successfully!\n");
Expand Down
16 changes: 0 additions & 16 deletions src/app/process/Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,3 @@ void storage_add_delete(std::string hash)
}
});
}

/**
* @description: Add delete meaningful file task
* @param hash -> Meaningful file root hash
*/
void report_add_callback()
{
sgx_enclave_id_t eid = global_eid;
std::async(std::launch::async, [eid](){
sgx_status_t sgx_status = SGX_SUCCESS;
if (SGX_SUCCESS != (sgx_status = Ecall_handle_report_result(eid)))
{
p_log->err("Report result failed!Invoke SGX API failed!Error code:%lx\n", sgx_status);
}
});
}
1 change: 0 additions & 1 deletion src/app/process/Storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extern "C"

void storage_add_confirm(std::string hash);
void storage_add_delete(std::string hash);
void report_add_callback();

#if defined(__cplusplus)
}
Expand Down
35 changes: 4 additions & 31 deletions src/app/process/WorkReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,41 +121,14 @@ void work_report_loop(void)
}

// Get signed validation report
if (SGX_SUCCESS != Ecall_get_signed_work_report(global_eid, &crust_status,
if (SGX_SUCCESS != Ecall_gen_and_upload_work_report(global_eid, &crust_status,
block_header->hash.c_str(), block_header->number))
{
p_log->err("Get signed work report failed!\n");
p_log->err("Get signed work report failed!Message:Invoke SGX API failed!\n");
}
else
else if (CRUST_SUCCESS != crust_status)
{
if (CRUST_SUCCESS == crust_status)
{
// Send signed validation report to crust chain
std::string work_str = get_g_enclave_workreport();
p_log->info("Sign validation report successfully!\n%s\n", work_str.c_str());

if (!offline_chain_mode)
{
// Delete space and line break
remove_char(work_str, '\\');
remove_char(work_str, '\n');
remove_char(work_str, ' ');
if (!p_chain->post_sworker_work_report(work_str))
{
p_log->err("Send work report to crust chain failed!\n");
}
else
{
p_log->info("Send work report to crust chain successfully!\n");
report_add_callback();
}
}
else
{
report_add_callback();
}
}
else if (crust_status == CRUST_BLOCK_HEIGHT_EXPIRED)
if (crust_status == CRUST_BLOCK_HEIGHT_EXPIRED)
{
p_log->info("Block height expired.\n");
}
Expand Down
18 changes: 2 additions & 16 deletions src/enclave/Enclave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ crust_status_t ecall_cmp_chain_account_id(const char *account_id, size_t len)
* @param block_height (in) -> block height
* @return: Sign status
*/
crust_status_t ecall_get_signed_work_report(const char *block_hash, size_t block_height)
crust_status_t ecall_gen_and_upload_work_report(const char *block_hash, size_t block_height)
{
if (ENC_UPGRADE_STATUS_PROCESS == Workload::get_instance()->get_upgrade_status())
{
return CRUST_UPGRADE_WAIT_FOR_NEXT_ERA;
}

sched_add(SCHED_GET_WORKREPORT);
crust_status_t ret = get_signed_work_report(block_hash, block_height);
crust_status_t ret = gen_and_upload_work_report(block_hash, block_height, 0, false);
sched_del(SCHED_GET_WORKREPORT);

return ret;
Expand Down Expand Up @@ -303,20 +303,6 @@ crust_status_t ecall_restore_from_upgrade(const char *meta, size_t meta_len, siz
return id_restore_from_upgrade(meta, meta_len, total_size, transfer_end);
}

/**
* @description: Set work report result
* @param flag -> Report result
*/
void ecall_handle_report_result()
{
if (ENC_UPGRADE_STATUS_PROCESS == Workload::get_instance()->get_upgrade_status())
{
return;
}

Workload::get_instance()->handle_report_result();
}

/**
* @description: Get enclave id information
*/
Expand Down
3 changes: 1 addition & 2 deletions src/enclave/Enclave.edl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enclave {
public void ecall_main_loop();
public crust_status_t ecall_cmp_chain_account_id([in, size=len] const char *account_id, size_t len);

public crust_status_t ecall_get_signed_work_report([in, string] const char *block_hash, size_t block_height);
public crust_status_t ecall_gen_and_upload_work_report([in, string] const char *block_hash, size_t block_height);

public crust_status_t ecall_restore_metadata();
public sgx_status_t ecall_get_quote_report([out] sgx_report_t *report,[in] sgx_target_info_t *target_info);
Expand All @@ -32,7 +32,6 @@ enclave {
public crust_status_t ecall_unseal_file([in, count=files_num] char **files, size_t files_num, [in, string] const char *p_dir, [out, size=path_len] char *p_new_path, uint32_t path_len);
public crust_status_t ecall_confirm_file([in, string] const char *hash);
public crust_status_t ecall_delete_file([in, string] const char *hash);
public void ecall_handle_report_result();

public crust_status_t ecall_gen_upgrade_data(size_t block_height);
public crust_status_t ecall_restore_from_upgrade([in, size=meta_len] const char *meta, size_t meta_len, size_t total_size, bool transfer_end);
Expand Down
Loading

0 comments on commit 7fbc6be

Please sign in to comment.