Skip to content
New issue

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

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

Already on GitHub? # to your account

Increase restart punishment to 4 eras #277

Merged
merged 4 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion src/app/process/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ int process_run()
crust_status_t crust_status = CRUST_SUCCESS;
int return_status = 1;
int check_interval = 15;
int upgrade_timeout = 2 * REPORT_BLOCK_HEIGHT_BASE * BLOCK_INTERVAL;
int upgrade_timeout = 5 * REPORT_BLOCK_HEIGHT_BASE * BLOCK_INTERVAL;
int upgrade_tryout = upgrade_timeout / check_interval;
int entry_tryout = 3;
EnclaveData *ed = EnclaveData::get_instance();
Expand Down
2 changes: 1 addition & 1 deletion src/app/process/WorkReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void work_report_loop(void)
p_log->warn("Block height expired.\n");
break;
case CRUST_FIRST_WORK_REPORT_AFTER_REPORT:
p_log->warn("Can't generate work report for the first time after restart\n");
p_log->warn("Can't generate work report for the first four times after restart\n");
break;
case CRUST_NO_KARST:
p_log->warn("Can't generate work report. You have meaningful files, please start karst\n");
Expand Down
2 changes: 1 addition & 1 deletion src/enclave/identity/Identity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ crust_status_t id_restore_metadata()
// Restore chain account id
wl->set_account_id(meta_json[ID_CHAIN_ACCOUNT_ID].ToString());

wl->set_restart_flag(true);
wl->set_restart_flag();

return CRUST_SUCCESS;
}
Expand Down
6 changes: 3 additions & 3 deletions src/enclave/report/Report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ crust_status_t gen_work_report(const char *block_hash, size_t block_height, bool

if (wl->get_restart_flag())
{
// The first report after restart will not be processed
// The first 4 report after restart will not be processed
crust_status = CRUST_FIRST_WORK_REPORT_AFTER_REPORT;
}
else if (!wl->report_has_validated_proof())
Expand All @@ -97,7 +97,7 @@ crust_status_t gen_work_report(const char *block_hash, size_t block_height, bool
if (CRUST_SUCCESS != crust_status)
{
wl->set_report_height(block_height);
wl->set_restart_flag(false);
wl->reduce_restart_flag();
wl->set_report_file_flag(true);
wl->report_reduce_validated_proof();
return crust_status;
Expand Down Expand Up @@ -408,7 +408,7 @@ crust_status_t gen_work_report(const char *block_hash, size_t block_height, bool
}

wl->set_report_height(block_height);
wl->set_restart_flag(false);
wl->reduce_restart_flag();
wl->set_report_file_flag(true);
wl->report_reduce_validated_proof();

Expand Down
27 changes: 19 additions & 8 deletions src/enclave/workload/Workload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ bool Workload::try_get_key_pair()
* @description: Get public key
* @return: Const reference to public key
*/
const sgx_ec256_public_t& Workload::get_pub_key()
const sgx_ec256_public_t &Workload::get_pub_key()
{
return this->id_key_pair.pub_key;
}
Expand All @@ -553,7 +553,7 @@ const sgx_ec256_public_t& Workload::get_pub_key()
* @description: Get private key
* @return: Const reference to private key
*/
const sgx_ec256_private_t& Workload::get_pri_key()
const sgx_ec256_private_t &Workload::get_pri_key()
{
return this->id_key_pair.pri_key;
}
Expand All @@ -573,7 +573,7 @@ void Workload::set_key_pair(ecc_key_pair id_key_pair)
* @description: Get identity key pair
* @return: Const reference to identity key pair
*/
const ecc_key_pair& Workload::get_key_pair()
const ecc_key_pair &Workload::get_key_pair()
{
return this->id_key_pair;
}
Expand All @@ -591,7 +591,7 @@ void Workload::set_mr_enclave(sgx_measurement_t mr)
* @description: Get MR enclave
* @return: Const reference to MR enclave
*/
const sgx_measurement_t& Workload::get_mr_enclave()
const sgx_measurement_t &Workload::get_mr_enclave()
{
return this->mr_enclave;
}
Expand All @@ -616,11 +616,22 @@ size_t Workload::get_report_height()

/**
* @description: Set restart flag
* @param flag -> Restart flag
*/
void Workload::set_restart_flag(bool flag)
void Workload::set_restart_flag()
{
this->restart_flag = flag;
this->restart_flag = 4;
}

/**
* @description: Reduce flag
*/
void Workload::reduce_restart_flag()
{
this->restart_flag -= 1;
if (this->restart_flag < 0)
{
this->restart_flag = 0;
}
}

/**
Expand All @@ -629,7 +640,7 @@ void Workload::set_restart_flag(bool flag)
*/
bool Workload::get_restart_flag()
{
return this->restart_flag;
return this->restart_flag > 0;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/enclave/workload/Workload.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class Workload
bool report_has_validated_proof();
void set_report_file_flag(bool flag);
bool get_report_file_flag();
void set_restart_flag(bool flag);
void set_restart_flag();
void reduce_restart_flag();
bool get_restart_flag();
void handle_report_result();
crust_status_t try_report_work(size_t block_height);
Expand Down Expand Up @@ -104,7 +105,7 @@ class Workload
bool is_set_key_pair = false; // Check if key pair has been generated
sgx_measurement_t mr_enclave; // Enclave code measurement
size_t report_height = 0; // Identity report height, Used to check current block head out-of-date
bool restart_flag = false;// Used to indicate whether it is the first report after restart
int restart_flag = 0;// Used to indicate whether it is the first report after restart

int validated_proof = 0; // Generating workreport will decrease this value, while validating will increase it
sgx_thread_mutex_t validated_mutex = SGX_THREAD_MUTEX_INITIALIZER;
Expand Down