Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 28 additions & 2 deletions src/app/chain/Chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,33 @@ std::string Chain::get_block_hash(size_t block_number)
}
else
{
p_log->err("%s\n", "return body is null");
p_log->err("%s\n", "Get block return body is null");
}

return "";
}


/**
* @description: get block hash by number
* @return: swork code on chain
*/
std::string Chain::get_swork_code()
{
std::string url = this->url + "/swork/code";
http::response<http::string_body> res = pri_chain_client->Get(url.c_str());
if ((int)res.result() == 200)
{
return res.body().substr(3, 64);
}

if (res.body().size() != 0)
{
p_log->debug("%s\n", res.body().c_str());
}
else
{
p_log->err("%s\n", "Get swork code return body is null");
}

return "";
Expand Down Expand Up @@ -141,7 +167,7 @@ bool Chain::is_syncing(void)
}
else
{
p_log->err("%s\n", "return body is null");
p_log->err("%s\n", "Is syncing return body is null");
}

return true;
Expand Down
1 change: 1 addition & 0 deletions src/app/chain/Chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Chain
static Chain *get_instance();
bool get_block_header(BlockHeader &block_header);
std::string get_block_hash(size_t block_number);
std::string get_swork_code();
bool post_sworker_identity(std::string identity);
bool post_sworker_work_report(std::string work_report);
bool is_online(void);
Expand Down
23 changes: 23 additions & 0 deletions src/app/ocalls/OCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,29 @@ crust_status_t ocall_upload_identity(const char *id)
{
return CRUST_UNEXPECTED_ERROR;
}

// Get all id information
json::JSON all_id_info = json::JSON::Load(EnclaveData::get_instance()->get_enclave_id_info());
std::string code_on_chain = crust::Chain::get_instance()->get_swork_code();
if (code_on_chain == "")
{
p_log->err("Get sworker code from chain failed! Please check the running status of the chain.");
return CRUST_UNEXPECTED_ERROR;
}

if (all_id_info["mrenclave"].ToString() != code_on_chain)
{
p_log->err("Attention!!!!! Mrenclave is '%s', code on chain is '%s'. Your sworker need to upgrade, "
"please get the latest sworker by running 'sudo docker pull crustio/crust-sworker:latest' "
"and reload your sworker by running 'sudo crust reload sworker'\n",
all_id_info["mrenclave"].ToString().c_str(), code_on_chain.c_str());
return CRUST_SWORKER_UPGRADE_NEEDED;
}
else
{
p_log->info("Mrenclave is '%s'\n", id_json["mrenclave"].ToString().c_str());
}

if (!crust::Chain::get_instance()->post_sworker_identity(sworker_identity))
{
p_log->err("Send identity to crust chain failed!\n");
Expand Down
3 changes: 3 additions & 0 deletions src/app/process/EntryNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ crust_status_t entry_network()
case CRUST_SIGN_PUBKEY_FAILED:
p_log->err("Sign public key failed!!\n");
break;
case CRUST_SWORKER_UPGRADE_NEEDED:
p_log->err("Sworker upgrade needed!!\n");
break;
default:
p_log->err("Unknown return status!\n");
}
Expand Down
8 changes: 8 additions & 0 deletions src/app/process/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,14 @@ int process_run()
}
p_log->info("Generate key pair successfully!\n");

// Get id info
if (SGX_SUCCESS != Ecall_id_get_info(global_eid))
{
p_log->err("Get id info from enclave failed!\n");
return_status = -1;
goto cleanup;
}

// Send identity to chain and send work report
if (!offline_chain_mode)
{
Expand Down
1 change: 1 addition & 0 deletions src/enclave/include/CrustStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ typedef enum _crust_status_t
CRUST_IAS_GETPUBKEY_FAILED = CRUST_MK_ERROR(0x7017),
CRUST_SIGN_PUBKEY_FAILED = CRUST_MK_ERROR(0x7018),
CRUST_GET_ACCOUNT_ID_BYTE_FAILED = CRUST_MK_ERROR(0x7019),
CRUST_SWORKER_UPGRADE_NEEDED = CRUST_MK_ERROR(0x7020),

// Storage related
CRUST_STORAGE_SER_MERKLETREE_FAILED = CRUST_MK_ERROR(0x8001),
Expand Down