Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #32 from newton-blockchain/config_update
Browse files Browse the repository at this point in the history
Config update
  • Loading branch information
tolya-yanot authored Jun 18, 2021
2 parents 93d3c92 + c81f2f7 commit 4f0480b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 8 deletions.
19 changes: 19 additions & 0 deletions crypto/block/block.tlb
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,13 @@ consensus_config_new#d7 flags:(## 7) { flags = 0 } new_catchain_ids:Bool
fast_attempts:uint32 attempt_duration:uint32 catchain_max_deps:uint32
max_block_bytes:uint32 max_collated_bytes:uint32 = ConsensusConfig;

consensus_config_v3#d8 flags:(## 7) { flags = 0 } new_catchain_ids:Bool
round_candidates:(## 8) { round_candidates >= 1 }
next_candidate_delay_ms:uint32 consensus_timeout_ms:uint32
fast_attempts:uint32 attempt_duration:uint32 catchain_max_deps:uint32
max_block_bytes:uint32 max_collated_bytes:uint32
proto_version:uint16 = ConsensusConfig;

_ CatchainConfig = ConfigParam 28;
_ ConsensusConfig = ConfigParam 29;

Expand All @@ -711,6 +718,18 @@ validator_temp_key#3 adnl_addr:bits256 temp_public_key:SigPubKey seqno:# valid_u
signed_temp_key#4 key:^ValidatorTempKey signature:CryptoSignature = ValidatorSignedTempKey;
_ (HashmapE 256 ValidatorSignedTempKey) = ConfigParam 39;

misbehaviour_punishment_config_v1#01
default_flat_fine:Grams default_proportional_fine:uint32
severity_flat_mult:uint16 severity_proportional_mult:uint16
unpunishable_interval:uint16
long_interval:uint16 long_flat_mult:uint16 long_proportional_mult:uint16
medium_interval:uint16 medium_flat_mult:uint16 medium_proportional_mult:uint16
= MisbehaviourPunishmentConfig;
_ MisbehaviourPunishmentConfig = ConfigParam 40;

oracle_set_v1#_ flat_stake:Grams min_auth_num:uint16 seqno:uint32 oracles:(HashmapE 16 uint256) = ExtChainOracleSet;
_ ExtChainOracleSet = ConfigParam 71; // Ethereum oracles

//
// PROOFS
//
Expand Down
16 changes: 13 additions & 3 deletions crypto/block/mc-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ td::Status Config::visit_validator_params() const {
ton::ValidatorSessionConfig Config::get_consensus_config() const {
auto cc = get_config_param(29);
ton::ValidatorSessionConfig c;
auto set = [&c](auto& r, bool new_cc_ids) {
auto set = [&c](auto& r) {
c.catchain_idle_timeout = r.consensus_timeout_ms * 0.001;
c.catchain_max_deps = r.catchain_max_deps;
c.round_candidates = r.round_candidates;
Expand All @@ -319,13 +319,23 @@ ton::ValidatorSessionConfig Config::get_consensus_config() const {
c.max_round_attempts = r.fast_attempts;
c.max_block_size = r.max_block_bytes;
c.max_collated_data_size = r.max_collated_bytes;
c.new_catchain_ids = new_cc_ids;
return true;
};
auto set_new_cc_ids = [&c] (auto& r) {
c.new_catchain_ids = r.new_catchain_ids;
return true;
};
auto set_proto = [&c](auto& r) {
c.proto_version = r.proto_version;
return true;
};
if (cc.not_null()) {
block::gen::ConsensusConfig::Record_consensus_config_v3 r2;
block::gen::ConsensusConfig::Record_consensus_config_new r1;
block::gen::ConsensusConfig::Record_consensus_config r0;
(tlb::unpack_cell(cc, r1) && set(r1, r1.new_catchain_ids)) || (tlb::unpack_cell(cc, r0) && set(r0, false));
(tlb::unpack_cell(cc, r2) && set(r2) && set_new_cc_ids(r2) && set_proto(r2)) ||
(tlb::unpack_cell(cc, r1) && set(r1) && set_new_cc_ids(r1)) ||
(tlb::unpack_cell(cc, r0) && set(r0));
}
return c;
}
Expand Down
47 changes: 42 additions & 5 deletions lite-client/lite-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3675,7 +3675,7 @@ void TestNode::continue_check_validator_load3(std::unique_ptr<TestNode::Validato
}
}

bool compute_punishment(int interval, bool severe, td::RefInt256& fine, unsigned& fine_part) {
bool compute_punishment_default(int interval, bool severe, td::RefInt256& fine, unsigned& fine_part) {
if (interval <= 1000) {
return false; // no punishments for less than 1000 seconds
}
Expand Down Expand Up @@ -3705,10 +3705,44 @@ bool compute_punishment(int interval, bool severe, td::RefInt256& fine, unsigned
return true;
}

bool check_punishment(int interval, bool severe, td::RefInt256 fine, unsigned fine_part) {
bool compute_punishment(int interval, bool severe, td::RefInt256& fine, unsigned& fine_part, Ref<vm::Cell> punishment_params) {
if(punishment_params.is_null()) {
return compute_punishment_default(interval, severe, fine, fine_part);
}
block::gen::MisbehaviourPunishmentConfig::Record rec;
if (!tlb::unpack_cell(punishment_params, rec)) {
return false;
}

if(interval <= rec.unpunishable_interval) {
return false;
}

fine = block::tlb::t_Grams.as_integer(rec.default_flat_fine);
fine_part = rec.default_proportional_fine;

if (severe) {
fine = fine * rec.severity_flat_mult; fine >>= 8;
fine_part = fine_part * rec.severity_proportional_mult; fine_part >>= 8;
}

if (interval >= rec.long_interval) {
fine = fine * rec.long_flat_mult; fine >>= 8;
fine_part = fine_part * rec.long_proportional_mult; fine_part >>= 8;
return true;
}
if (interval >= rec.medium_interval) {
fine = fine * rec.medium_flat_mult; fine >>= 8;
fine_part = fine_part * rec.medium_proportional_mult; fine_part >>= 8;
return true;
}
return true;
}

bool check_punishment(int interval, bool severe, td::RefInt256 fine, unsigned fine_part, Ref<vm::Cell> punishment_params) {
td::RefInt256 computed_fine;
unsigned computed_fine_part;
return compute_punishment(interval, severe, computed_fine, computed_fine_part) &&
return compute_punishment(interval, severe, computed_fine, computed_fine_part, punishment_params) &&
std::llabs((long long)fine_part - (long long)computed_fine_part) <=
(std::max(fine_part, computed_fine_part) >> 3) &&
fine * 7 <= computed_fine * 8 && computed_fine * 7 <= fine * 8;
Expand Down Expand Up @@ -3736,10 +3770,13 @@ td::Status TestNode::write_val_create_proof(TestNode::ValidatorLoadInfo& info1,
if (interval <= 0) {
return td::Status::Error("non-positive time interval");
}

auto punishment_params = info2.config->get_config_param(40);

int severity = (severe ? 2 : 1);
td::RefInt256 fine = td::make_refint(101000000000);
unsigned fine_part = 0; // todo: (tolya-yanot) temporary reduction of fine // 0xffffffff / 16; // 1/16
if (!compute_punishment(interval, severe, fine, fine_part)) {
if (!compute_punishment(interval, severe, fine, fine_part, punishment_params)) {
return td::Status::Error("cannot compute adequate punishment");
}
Ref<vm::Cell> cpl_descr, complaint;
Expand Down Expand Up @@ -4053,7 +4090,7 @@ td::Status TestNode::continue_check_validator_load_proof(std::unique_ptr<Validat
if (suggested_fine.is_null()) {
return td::Status::Error("cannot parse suggested fine");
}
if (!check_punishment(interval, severe, suggested_fine, rec.suggested_fine_part)) {
if (!check_punishment(interval, severe, suggested_fine, rec.suggested_fine_part, info2->config->get_config_param(40))) {
LOG(ERROR) << "proposed punishment (fine " << td::dec_string(suggested_fine)
<< ", fine_part=" << (double)rec.suggested_fine_part / (1LL << 32) << " is too harsh";
show_vote(root->get_hash().bits(), false);
Expand Down

0 comments on commit 4f0480b

Please sign in to comment.