1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

updated block header

1. Updated block header, proofs now contain more data
   Notice, that old proofs may become invalid in the future
2. Fixed message routing
3. Fixed block creator id in block header
4. Support for full proofs in tonlib
5. Support for partial state download
6. Some other bugfixes
This commit is contained in:
ton 2019-09-18 21:46:32 +04:00
parent bce33f588a
commit 13140ddf29
73 changed files with 2084 additions and 304 deletions

View file

@ -27,6 +27,8 @@
*/
#include "lite-client.h"
#include "lite-client-common.h"
#include "adnl/adnl-ext-client.h"
#include "tl-utils/lite-utils.hpp"
#include "auto/tl/ton_api_json.h"
@ -2102,78 +2104,17 @@ bool TestNode::get_block_proof(ton::BlockIdExt from, ton::BlockIdExt to, int mod
});
}
td::Result<std::unique_ptr<block::BlockProofChain>> TestNode::deserialize_proof_chain(td::BufferSlice pchain) {
TRY_RESULT(f, ton::fetch_tl_object<ton::lite_api::liteServer_partialBlockProof>(std::move(pchain), true));
// deserialize proof chain
auto chain = std::make_unique<block::BlockProofChain>(ton::create_block_id(f->from_), ton::create_block_id(f->to_));
chain->complete = f->complete_;
for (auto& s : f->steps_) {
bool ok = false;
td::BufferSlice dest_proof, proof, state_proof;
ton::lite_api::downcast_call(
*s,
td::overloaded(
[&](ton::lite_api::liteServer_blockLinkBack& s) {
auto& link = chain->new_link(ton::create_block_id(s.from_), ton::create_block_id(s.to_), s.to_key_block_);
link.is_fwd = false;
// dest_proof:bytes state_proof:bytes proof:bytes
dest_proof = std::move(s.dest_proof_);
state_proof = std::move(s.state_proof_);
proof = std::move(s.proof_);
ok = true;
},
[&](ton::lite_api::liteServer_blockLinkForward& s) {
auto& link = chain->new_link(ton::create_block_id(s.from_), ton::create_block_id(s.to_), s.to_key_block_);
link.is_fwd = true;
// dest_proof:bytes config_proof:bytes signatures:liteServer.SignatureSet
dest_proof = std::move(s.dest_proof_);
proof = std::move(s.config_proof_);
link.cc_seqno = s.signatures_->catchain_seqno_;
link.validator_set_hash = s.signatures_->validator_set_hash_;
for (auto& sig : s.signatures_->signatures_) {
link.signatures.emplace_back(std::move(sig->node_id_short_), std::move(sig->signature_));
}
ok = true;
},
[&](auto& obj) {}));
if (!ok) {
return td::Status::Error("unknown constructor of liteServer.BlockLink");
}
auto& link = chain->last_link();
if (!dest_proof.empty()) {
auto d_res = vm::std_boc_deserialize(std::move(dest_proof));
if (d_res.is_error()) {
return td::Status::Error("cannot deserialize dest_proof in a block proof link: "s +
d_res.move_as_error().to_string());
}
link.dest_proof = d_res.move_as_ok();
}
auto d_res = vm::std_boc_deserialize(std::move(proof));
if (d_res.is_error()) {
return td::Status::Error("cannot deserialize proof in a block proof link: "s + d_res.move_as_error().to_string());
}
link.proof = d_res.move_as_ok();
if (!link.is_fwd) {
d_res = vm::std_boc_deserialize(std::move(state_proof));
if (d_res.is_error()) {
return td::Status::Error("cannot deserialize state_proof in a block proof link: "s +
d_res.move_as_error().to_string());
}
link.state_proof = d_res.move_as_ok();
}
LOG(DEBUG) << "deserialized a " << (link.is_fwd ? "forward" : "backward") << " BlkProofLink from "
<< link.from.to_str() << " to " << link.to.to_str() << " with " << link.signatures.size()
<< " signatures";
}
LOG(DEBUG) << "deserialized a BlkProofChain of " << chain->link_count() << " links";
return std::move(chain);
}
void TestNode::got_block_proof(ton::BlockIdExt from, ton::BlockIdExt to, int mode, td::BufferSlice pchain) {
LOG(INFO) << "got block proof from " << from.to_str() << " to "
<< ((mode & 1) ? to.to_str() : "last masterchain block") << " with mode=" << mode << " (" << pchain.size()
<< " bytes)";
auto res = deserialize_proof_chain(std::move(pchain));
auto r_f = ton::fetch_tl_object<ton::lite_api::liteServer_partialBlockProof>(std::move(pchain), true);
if (r_f.is_error()) {
LOG(ERROR) << "cannot deserialize liteServer.partialBlockProof: " << r_f.move_as_error();
return;
}
auto f = r_f.move_as_ok();
auto res = liteclient::deserialize_proof_chain(std::move(f));
if (res.is_error()) {
LOG(ERROR) << "cannot deserialize liteServer.partialBlockProof: " << res.move_as_error();
return;