1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-02-12 19:22:37 +00:00

too big catchain workaround

This commit is contained in:
ton 2020-04-04 17:27:19 +04:00
parent d17186896b
commit b73b057e08
4 changed files with 40 additions and 0 deletions

View file

@ -1193,6 +1193,10 @@ td::Status ValidatorEngine::load_global_config() {
validator_options_.write().add_unsafe_resync_catchain(seq);
}
if (zero_state.file_hash.to_hex() == "5E994FCF4D425C0A6CE6A792594B7173205F740A39CD56F537DEFD28B48A0F6E") {
validator_options_.write().add_unsafe_catchain_rotate(3081761, 48452, 1);
}
std::vector<ton::BlockIdExt> h;
for (auto &x : conf.validator_->hardforks_) {
auto b = ton::create_block_id(x);

View file

@ -1705,9 +1705,19 @@ void ValidatorManagerImpl::update_shards() {
std::map<ValidatorSessionId, td::actor::ActorOwn<ValidatorGroup>> new_validator_groups_;
std::map<ValidatorSessionId, td::actor::ActorOwn<ValidatorGroup>> new_next_validator_groups_;
bool force_recover = false;
{
auto val_set = last_masterchain_state_->get_validator_set(ShardIdFull{masterchainId});
auto r = opts_->check_unsafe_catchain_rotate(last_masterchain_seqno_, val_set->get_catchain_seqno());
force_recover = r > 0;
}
if (allow_validate_) {
for (auto &desc : new_shards) {
auto shard = desc.first;
if (force_recover && !desc.first.is_masterchain()) {
continue;
}
auto prev = desc.second;
for (auto &p : prev) {
CHECK(p.is_valid());
@ -1720,6 +1730,18 @@ void ValidatorManagerImpl::update_shards() {
if (!validator_id.is_zero()) {
auto val_group_id = get_validator_set_id(shard, val_set, opts_hash);
if (force_recover) {
auto r = opts_->check_unsafe_catchain_rotate(last_masterchain_seqno_, val_set->get_catchain_seqno());
if (r) {
td::uint8 b[36];
td::MutableSlice x{b, 36};
x.copy_from(val_group_id.as_slice());
x.remove_prefix(32);
CHECK(x.size() == 4);
x.copy_from(td::Slice(reinterpret_cast<const td::uint8 *>(&r), 4));
val_group_id = sha256_bits256(td::Slice(b, 36));
}
}
// DIRTY. But we don't want to create hardfork now
// TODO! DELETE IT LATER
//if (last_masterchain_seqno_ >= 2904932 && val_set->get_catchain_seqno() == 44896) {

View file

@ -94,6 +94,14 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
bool check_unsafe_resync_allowed(CatchainSeqno seqno) const override {
return unsafe_catchains_.count(seqno) > 0;
}
td::uint32 check_unsafe_catchain_rotate(BlockSeqno seqno, CatchainSeqno cc_seqno) const override {
auto it = unsafe_catchain_rotates_.find(cc_seqno);
if (it == unsafe_catchain_rotates_.end()) {
return 0;
} else {
return it->second.first <= seqno ? it->second.second : 0;
}
}
void set_zero_block_id(BlockIdExt block_id) override {
zero_block_id_ = block_id;
@ -135,6 +143,9 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
void add_unsafe_resync_catchain(CatchainSeqno seqno) override {
unsafe_catchains_.insert(seqno);
}
void add_unsafe_catchain_rotate(BlockSeqno seqno, CatchainSeqno cc_seqno, td::uint32 value) override {
unsafe_catchain_rotates_[cc_seqno] = std::make_pair(seqno, value);
}
ValidatorManagerOptionsImpl *make_copy() const override {
return new ValidatorManagerOptionsImpl(*this);
@ -171,6 +182,7 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
std::vector<BlockIdExt> hardforks_;
td::uint32 db_depth_ = 2;
std::set<CatchainSeqno> unsafe_catchains_;
std::map<CatchainSeqno, std::pair<BlockSeqno, td::uint32>> unsafe_catchain_rotates_;
};
} // namespace validator

View file

@ -69,6 +69,7 @@ struct ValidatorManagerOptions : public td::CntObject {
return 86400;
}
virtual bool check_unsafe_resync_allowed(CatchainSeqno seqno) const = 0;
virtual td::uint32 check_unsafe_catchain_rotate(BlockSeqno seqno, CatchainSeqno cc_seqno) const = 0;
virtual void set_zero_block_id(BlockIdExt block_id) = 0;
virtual void set_init_block_id(BlockIdExt block_id) = 0;
@ -83,6 +84,7 @@ struct ValidatorManagerOptions : public td::CntObject {
virtual void set_hardforks(std::vector<BlockIdExt> hardforks) = 0;
virtual void set_filedb_depth(td::uint32 value) = 0;
virtual void add_unsafe_resync_catchain(CatchainSeqno seqno) = 0;
virtual void add_unsafe_catchain_rotate(BlockSeqno seqno, CatchainSeqno cc_seqno, td::uint32 value) = 0;
static td::Ref<ValidatorManagerOptions> create(
BlockIdExt zero_block_id, BlockIdExt init_block_id,