mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
func: bugfix
- bugfix in func - vertseqno support in validator/collator/topsharddescr
This commit is contained in:
parent
29deff15c3
commit
f67f5d879b
10 changed files with 78 additions and 20 deletions
|
@ -129,6 +129,7 @@ class Collator final : public td::actor::Actor {
|
|||
ton::UnixTime prev_state_utime_;
|
||||
int global_id_{0};
|
||||
ton::BlockSeqno min_ref_mc_seqno_{~0U};
|
||||
ton::BlockSeqno vert_seqno_{~0U}, prev_vert_seqno_{~0U};
|
||||
ton::BlockIdExt prev_key_block_;
|
||||
ton::LogicalTime prev_key_block_lt_;
|
||||
bool accept_msgs_{true};
|
||||
|
|
|
@ -518,6 +518,8 @@ bool Collator::unpack_last_mc_state() {
|
|||
prev_key_block_seqno_ = 0;
|
||||
}
|
||||
LOG(DEBUG) << "previous key block is " << prev_key_block_.to_str() << " (exists=" << prev_key_block_exists_ << ")";
|
||||
vert_seqno_ = config_->get_vert_seqno();
|
||||
LOG(DEBUG) << "vertical seqno (vert_seqno) is " << vert_seqno_;
|
||||
auto limits = config_->get_block_limits(is_masterchain());
|
||||
if (limits.is_error()) {
|
||||
return fatal_error(limits.move_as_error());
|
||||
|
@ -686,6 +688,12 @@ bool Collator::unpack_one_last_state(block::ShardState& ss, BlockIdExt blkid, Re
|
|||
if (res.is_error()) {
|
||||
return fatal_error(std::move(res));
|
||||
}
|
||||
if (ss.vert_seqno_ > vert_seqno_) {
|
||||
return fatal_error(
|
||||
PSTRING() << "cannot create new block with vertical seqno " << vert_seqno_
|
||||
<< " prescribed by the current masterchain configuration because the previous state of shard "
|
||||
<< ss.id_.to_str() << " has larger vertical seqno " << ss.vert_seqno_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -712,8 +720,8 @@ bool Collator::split_last_state(block::ShardState& ss) {
|
|||
|
||||
// SETS: account_dict, shard_libraries_, mc_state_extra
|
||||
// total_balance_ = old_total_balance_, total_validator_fees_
|
||||
// SETS: overload_history, underload_history
|
||||
// SETS: prev_state_utime_, prev_state_lt_
|
||||
// SETS: overload_history_, underload_history_
|
||||
// SETS: prev_state_utime_, prev_state_lt_, prev_vert_seqno_
|
||||
// SETS: out_msg_queue, processed_upto_, ihr_pending
|
||||
bool Collator::import_shard_state_data(block::ShardState& ss) {
|
||||
account_dict = std::move(ss.account_dict_);
|
||||
|
@ -723,6 +731,7 @@ bool Collator::import_shard_state_data(block::ShardState& ss) {
|
|||
underload_history_ = ss.underload_history_;
|
||||
prev_state_utime_ = ss.utime_;
|
||||
prev_state_lt_ = ss.lt_;
|
||||
prev_vert_seqno_ = ss.vert_seqno_;
|
||||
total_balance_ = old_total_balance_ = std::move(ss.total_balance_);
|
||||
value_flow_.from_prev_blk = old_total_balance_;
|
||||
total_validator_fees_ = std::move(ss.total_validator_fees_);
|
||||
|
@ -3426,7 +3435,7 @@ bool Collator::create_shard_state() {
|
|||
&& global_id_ // { global_id != 0 }
|
||||
&& block::ShardId{shard}.serialize(cb) // shard_id:ShardIdent
|
||||
&& cb.store_long_bool(new_block_seqno, 32) // seq_no:uint32
|
||||
&& cb.store_long_bool(0, 32) // vert_seq_no:#
|
||||
&& cb.store_long_bool(vert_seqno_, 32) // vert_seq_no:#
|
||||
&& cb.store_long_bool(now_, 32) // gen_utime:uint32
|
||||
&& cb.store_long_bool(max_lt, 64) // gen_lt:uint64
|
||||
&& update_processed_upto() // insert new ProcessedUpto
|
||||
|
@ -3561,9 +3570,9 @@ bool Collator::create_block_info(Ref<vm::Cell>& block_info) {
|
|||
&& cb.store_bool_bool(want_split_) // want_split:Bool
|
||||
&& cb.store_bool_bool(want_merge_) // want_merge:Bool
|
||||
&& cb.store_bool_bool(is_key_block_) // key_block:Bool
|
||||
&& cb.store_long_bool(0, 9) // flags:(## 9)
|
||||
&& cb.store_long_bool(0, 9) // vert_seqno_incr:(## 1) flags:(## 8)
|
||||
&& cb.store_long_bool(new_block_seqno, 32) // seq_no:#
|
||||
&& cb.store_long_bool(0, 32) // vert_seq_no:#
|
||||
&& cb.store_long_bool(vert_seqno_, 32) // vert_seq_no:#
|
||||
&& block::ShardId{shard}.serialize(cb) // shard:ShardIdent
|
||||
&& cb.store_long_bool(now_, 32) // gen_utime:uint32
|
||||
&& cb.store_long_bool(start_lt, 64) // start_lt:uint64
|
||||
|
|
|
@ -100,6 +100,7 @@ td::Status ShardTopBlockDescrQ::unpack_one_proof(BlockIdExt& cur_id, Ref<vm::Cel
|
|||
after_merge_ = info.after_merge;
|
||||
before_split_ = info.before_split;
|
||||
gen_utime_ = first_gen_utime_ = info.gen_utime;
|
||||
vert_seqno_ = info.vert_seq_no;
|
||||
} else {
|
||||
auto nx_mc_seqno = chain_mc_blk_ids_.back().id.seqno;
|
||||
if (nx_mc_seqno < mc_blkid.id.seqno) {
|
||||
|
@ -122,6 +123,11 @@ td::Status ShardTopBlockDescrQ::unpack_one_proof(BlockIdExt& cur_id, Ref<vm::Cel
|
|||
<< cur_id.to_str() << " and " << chain_blk_ids_.back().to_str());
|
||||
}
|
||||
first_gen_utime_ = info.gen_utime;
|
||||
if (vert_seqno_ != BlockSeqno(info.vert_seq_no)) {
|
||||
return td::Status::Error(-666, PSTRING() << "intermediate link for block " << cur_id.to_str()
|
||||
<< " has vertical seqno " << info.vert_seq_no
|
||||
<< " distinct from the final value in chain " << vert_seqno_);
|
||||
}
|
||||
}
|
||||
chain_mc_blk_ids_.push_back(mc_blkid);
|
||||
chain_blk_ids_.push_back(cur_id);
|
||||
|
@ -281,7 +287,7 @@ td::Result<int> ShardTopBlockDescrQ::validate_internal(BlockIdExt last_mc_block_
|
|||
BlockSeqno delta = chain_mc_blk_ids_[0].id.seqno - last_mc_block_id.id.seqno;
|
||||
// too new
|
||||
if ((mode & Mode::fail_new) || (delta > 8 && (mode & Mode::fail_too_new))) {
|
||||
return td::Status::Error(-666, std::string{"ShardTopBlockDescr for "} + block_id_.to_str() +
|
||||
return td::Status::Error(-666, "ShardTopBlockDescr for "s + block_id_.to_str() +
|
||||
" is too new for us: it refers to masterchain block " +
|
||||
chain_mc_blk_ids_[0].id.to_str() + " but we know only " +
|
||||
last_mc_block_id.to_str());
|
||||
|
@ -289,6 +295,18 @@ td::Result<int> ShardTopBlockDescrQ::validate_internal(BlockIdExt last_mc_block_
|
|||
return -1; // valid, but too new
|
||||
}
|
||||
auto config = state->get_config();
|
||||
if (config->get_vert_seqno() != vert_seqno_) {
|
||||
if (vert_seqno_ < config->get_vert_seqno()) {
|
||||
return td::Status::Error(-666, PSTRING() << "ShardTopBlockDescr for " << block_id_.to_str()
|
||||
<< " is too old: it has vertical seqno " << vert_seqno_
|
||||
<< " but we already know about " << config->get_vert_seqno());
|
||||
}
|
||||
if (mode & Mode::fail_new) {
|
||||
return td::Status::Error(-666, PSTRING() << "ShardTopBlockDescr for " << block_id_.to_str()
|
||||
<< " is too new for us: it has vertical seqno " << vert_seqno_
|
||||
<< " but we know only about " << config->get_vert_seqno());
|
||||
}
|
||||
}
|
||||
BlockSeqno next_mc_seqno = ~BlockSeqno(0);
|
||||
for (const auto& mcid : chain_mc_blk_ids_) {
|
||||
if (mcid.id.seqno > next_mc_seqno) {
|
||||
|
|
|
@ -89,6 +89,9 @@ class ShardTopBlockDescrQ final : public ShardTopBlockDescrQBase {
|
|||
Ref<vm::Cell> get_root() const {
|
||||
return root_;
|
||||
}
|
||||
BlockSeqno get_vert_seqno() const {
|
||||
return vert_seqno_;
|
||||
}
|
||||
ShardTopBlockDescrQ(td::BufferSlice data, bool is_fake = false)
|
||||
: ShardTopBlockDescrQBase(std::move(data)), is_fake_(is_fake) {
|
||||
}
|
||||
|
@ -123,6 +126,7 @@ class ShardTopBlockDescrQ final : public ShardTopBlockDescrQBase {
|
|||
UnixTime gen_utime_{0};
|
||||
CatchainSeqno catchain_seqno_{0};
|
||||
td::uint32 validator_set_hash_{0};
|
||||
BlockSeqno vert_seqno_{~0U};
|
||||
td::uint32 sig_count_;
|
||||
ValidatorWeight sig_weight_;
|
||||
Ref<vm::Cell> sig_root_;
|
||||
|
|
|
@ -378,7 +378,7 @@ bool ValidateQuery::init_parse() {
|
|||
block::gen::ExtBlkRef::Record mcref; // _ ExtBlkRef = BlkMasterInfo;
|
||||
ShardIdFull shard;
|
||||
if (!(tlb::unpack_cell(block_root_, blk) && tlb::unpack_cell(blk.info, info) && !info.version &&
|
||||
block::tlb::t_ShardIdent.unpack(info.shard.write(), shard) && !info.vert_seq_no &&
|
||||
block::tlb::t_ShardIdent.unpack(info.shard.write(), shard) &&
|
||||
block::gen::BlkPrevInfo{info.after_merge}.validate_ref(info.prev_ref) &&
|
||||
(!info.not_master || tlb::unpack_cell(info.master_ref, mcref)) && tlb::unpack_cell(blk.extra, extra))) {
|
||||
return reject_query("cannot unpack block header");
|
||||
|
@ -393,6 +393,7 @@ bool ValidateQuery::init_parse() {
|
|||
return fatal_error("invalid Merkle update in block");
|
||||
}
|
||||
global_id_ = blk.global_id;
|
||||
vert_seqno_ = info.vert_seq_no;
|
||||
prev_state_hash_ = upd_cs.prefetch_ref(0)->get_hash(0).bits();
|
||||
state_hash_ = upd_cs.prefetch_ref(1)->get_hash(0).bits();
|
||||
start_lt_ = info.start_lt;
|
||||
|
@ -428,6 +429,9 @@ bool ValidateQuery::init_parse() {
|
|||
if (is_key_block_ && !shard.is_masterchain()) {
|
||||
return reject_query("a non-masterchain block cannot be a key block");
|
||||
}
|
||||
if (info.vert_seqno_incr) {
|
||||
return reject_query("new blocks cannot have vert_seqno_incr set");
|
||||
}
|
||||
if (info.after_merge != after_merge_) {
|
||||
return reject_query("after_merge value mismatch in block header");
|
||||
}
|
||||
|
@ -683,7 +687,13 @@ bool ValidateQuery::try_unpack_mc_state() {
|
|||
CHECK(!mc_seqno_ || new_shard_conf_->get_mc_hash().not_null());
|
||||
}
|
||||
if (global_id_ != config_->get_global_blockchain_id()) {
|
||||
return reject_query("blockchain global id mismatch");
|
||||
return reject_query(PSTRING() << "blockchain global id mismatch: new block has " << global_id_
|
||||
<< " while the masterchain configuration expects "
|
||||
<< config_->get_global_blockchain_id());
|
||||
}
|
||||
if (vert_seqno_ != config_->get_vert_seqno()) {
|
||||
return reject_query(PSTRING() << "vertical seqno mismatch: new block has " << vert_seqno_
|
||||
<< " while the masterchain configuration expects " << config_->get_vert_seqno());
|
||||
}
|
||||
prev_key_block_exists_ = config_->get_last_key_block(prev_key_block_, prev_key_block_lt_);
|
||||
if (prev_key_block_exists_) {
|
||||
|
@ -1102,6 +1112,10 @@ bool ValidateQuery::unpack_one_prev_state(block::ShardState& ss, BlockIdExt blki
|
|||
if (res.is_error()) {
|
||||
return fatal_error(std::move(res));
|
||||
}
|
||||
if (ss.vert_seqno_ > vert_seqno_) {
|
||||
return reject_query(PSTRING() << "one of previous states " << ss.id_.to_str() << " has vertical seqno "
|
||||
<< ss.vert_seqno_ << " larger than that of the new block " << vert_seqno_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1148,6 +1162,10 @@ bool ValidateQuery::unpack_next_state() {
|
|||
return reject_query("new state refers to masterchain block "s + ns_.mc_blk_ref_.to_str() + " different from " +
|
||||
mc_blkid_.to_str() + " indicated in block header");
|
||||
}
|
||||
if (ns_.vert_seqno_ != vert_seqno_) {
|
||||
return reject_query(PSTRING() << "new state has vertical seqno " << ns_.vert_seqno_ << " different from "
|
||||
<< vert_seqno_ << " declared in the new block header");
|
||||
}
|
||||
// ...
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -176,6 +176,7 @@ class ValidateQuery : public td::actor::Actor {
|
|||
ton::LogicalTime max_shard_lt_{0};
|
||||
|
||||
int global_id_{0};
|
||||
ton::BlockSeqno vert_seqno_{~0U};
|
||||
bool ihr_enabled_{false};
|
||||
bool create_stats_enabled_{false};
|
||||
ton::BlockSeqno prev_key_block_seqno_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue