mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Use candidates from DB in wait block data
This commit is contained in:
parent
d4da0ace74
commit
70322f58c1
17 changed files with 140 additions and 30 deletions
|
@ -213,6 +213,28 @@ std::string CandidateShort::filename_short() const {
|
|||
return PSTRING() << "candidate_" << block_id.workchain << "_" << s << "_" << block_id.seqno << "_" << hash().to_hex();
|
||||
}
|
||||
|
||||
CandidateRefShort CandidateRef::shortref() const {
|
||||
return CandidateRefShort{block_id.id, hash()};
|
||||
}
|
||||
|
||||
std::string CandidateRef::filename() const {
|
||||
return PSTRING() << "candidateref_" << block_id.to_str();
|
||||
}
|
||||
|
||||
std::string CandidateRef::filename_short() const {
|
||||
char s[33];
|
||||
sprintf(s, "%llx", static_cast<long long>(block_id.id.shard));
|
||||
return PSTRING() << "candidateref_" << block_id.id.workchain << "_" << s << "_" << block_id.id.seqno << "_"
|
||||
<< hash().to_hex();
|
||||
}
|
||||
|
||||
std::string CandidateRefShort::filename_short() const {
|
||||
char s[33];
|
||||
sprintf(s, "%llx", static_cast<long long>(block_id.shard));
|
||||
return PSTRING() << "candidateref_" << block_id.workchain << "_" << s << "_" << block_id.seqno << "_"
|
||||
<< hash().to_hex();
|
||||
}
|
||||
|
||||
BlockInfoShort BlockInfo::shortref() const {
|
||||
return BlockInfoShort{block_id.id, hash()};
|
||||
}
|
||||
|
@ -259,6 +281,9 @@ FileReference::FileReference(tl_object_ptr<ton_api::db_filedb_Key> key) {
|
|||
ref_ = fileref::Candidate{PublicKey{key.id_->source_}, create_block_id(key.id_->id_),
|
||||
key.id_->collated_data_file_hash_};
|
||||
},
|
||||
[&](const ton_api::db_filedb_key_candidateRef& key) {
|
||||
ref_ = fileref::CandidateRef{create_block_id(key.id_)};
|
||||
},
|
||||
[&](const ton_api::db_filedb_key_blockInfo& key) {
|
||||
ref_ = fileref::BlockInfo{create_block_id(key.block_id_)};
|
||||
}));
|
||||
|
|
|
@ -278,6 +278,38 @@ class Candidate {
|
|||
FileHash collated_data_file_hash;
|
||||
};
|
||||
|
||||
class CandidateRefShort {
|
||||
public:
|
||||
FileHash hash() const {
|
||||
return hashv;
|
||||
}
|
||||
ShardIdFull shard() const {
|
||||
return block_id.shard_full();
|
||||
}
|
||||
std::string filename_short() const;
|
||||
|
||||
BlockId block_id;
|
||||
FileHash hashv;
|
||||
};
|
||||
|
||||
class CandidateRef {
|
||||
public:
|
||||
tl_object_ptr<ton_api::db_filedb_Key> tl() const {
|
||||
return create_tl_object<ton_api::db_filedb_key_candidateRef>(create_tl_block_id(block_id));
|
||||
}
|
||||
FileHash hash() const {
|
||||
return create_hash_tl_object<ton_api::db_filedb_key_candidateRef>(create_tl_block_id(block_id));
|
||||
}
|
||||
ShardIdFull shard() const {
|
||||
return block_id.shard_full();
|
||||
}
|
||||
CandidateRefShort shortref() const;
|
||||
std::string filename() const;
|
||||
std::string filename_short() const;
|
||||
|
||||
BlockIdExt block_id;
|
||||
};
|
||||
|
||||
class BlockInfoShort {
|
||||
public:
|
||||
FileHash hash() const {
|
||||
|
@ -316,7 +348,7 @@ class FileReferenceShort {
|
|||
private:
|
||||
td::Variant<fileref::Empty, fileref::BlockShort, fileref::ZeroStateShort, fileref::PersistentStateShort,
|
||||
fileref::ProofShort, fileref::ProofShort, fileref::ProofLinkShort, fileref::SignaturesShort,
|
||||
fileref::CandidateShort, fileref::BlockInfoShort>
|
||||
fileref::CandidateShort, fileref::CandidateRefShort, fileref::BlockInfoShort>
|
||||
ref_;
|
||||
|
||||
public:
|
||||
|
@ -340,7 +372,8 @@ class FileReferenceShort {
|
|||
class FileReference {
|
||||
private:
|
||||
td::Variant<fileref::Empty, fileref::Block, fileref::ZeroState, fileref::PersistentState, fileref::Proof,
|
||||
fileref::Proof, fileref::ProofLink, fileref::Signatures, fileref::Candidate, fileref::BlockInfo>
|
||||
fileref::Proof, fileref::ProofLink, fileref::Signatures, fileref::Candidate, fileref::CandidateRef,
|
||||
fileref::BlockInfo>
|
||||
ref_;
|
||||
|
||||
public:
|
||||
|
|
|
@ -177,21 +177,21 @@ void RootDb::get_block_proof_link(ConstBlockHandle handle, td::Promise<td::Ref<P
|
|||
}
|
||||
|
||||
void RootDb::store_block_candidate(BlockCandidate candidate, td::Promise<td::Unit> promise) {
|
||||
auto source = PublicKey{pubkeys::Ed25519{candidate.pubkey.as_bits256()}};
|
||||
auto obj = create_serialize_tl_object<ton_api::db_candidate>(
|
||||
PublicKey{pubkeys::Ed25519{candidate.pubkey.as_bits256()}}.tl(), create_tl_block_id(candidate.id),
|
||||
std::move(candidate.data), std::move(candidate.collated_data));
|
||||
|
||||
auto P = td::PromiseCreator::lambda([promise = std::move(promise)](td::Result<td::Unit> R) mutable {
|
||||
if (R.is_error()) {
|
||||
promise.set_error(R.move_as_error());
|
||||
} else {
|
||||
promise.set_value(td::Unit());
|
||||
}
|
||||
});
|
||||
source.tl(), create_tl_block_id(candidate.id), std::move(candidate.data), std::move(candidate.collated_data));
|
||||
auto P = td::PromiseCreator::lambda(
|
||||
[archive_db = archive_db_.get(), promise = std::move(promise), block_id = candidate.id, source,
|
||||
collated_file_hash = candidate.collated_file_hash](td::Result<td::Unit> R) mutable {
|
||||
TRY_RESULT_PROMISE(promise, _, std::move(R));
|
||||
td::actor::send_closure(archive_db, &ArchiveManager::add_temp_file_short, fileref::CandidateRef{block_id},
|
||||
create_serialize_tl_object<ton_api::db_candidate_id>(
|
||||
source.tl(), create_tl_block_id(block_id), collated_file_hash),
|
||||
std::move(promise));
|
||||
});
|
||||
td::actor::send_closure(archive_db_, &ArchiveManager::add_temp_file_short,
|
||||
fileref::Candidate{PublicKey{pubkeys::Ed25519{candidate.pubkey.as_bits256()}}, candidate.id,
|
||||
candidate.collated_file_hash},
|
||||
std::move(obj), std::move(P));
|
||||
fileref::Candidate{source, candidate.id, candidate.collated_file_hash}, std::move(obj),
|
||||
std::move(P));
|
||||
}
|
||||
|
||||
void RootDb::get_block_candidate(PublicKey source, BlockIdExt id, FileHash collated_data_file_hash,
|
||||
|
@ -215,6 +215,17 @@ void RootDb::get_block_candidate(PublicKey source, BlockIdExt id, FileHash colla
|
|||
fileref::Candidate{source, id, collated_data_file_hash}, std::move(P));
|
||||
}
|
||||
|
||||
void RootDb::get_block_candidate_by_block_id(BlockIdExt id, td::Promise<BlockCandidate> promise) {
|
||||
td::actor::send_closure(
|
||||
archive_db_, &ArchiveManager::get_temp_file_short, fileref::CandidateRef{id},
|
||||
[SelfId = actor_id(this), promise = std::move(promise)](td::Result<td::BufferSlice> R) mutable {
|
||||
TRY_RESULT_PROMISE(promise, data, std::move(R));
|
||||
TRY_RESULT_PROMISE(promise, f, fetch_tl_object<ton_api::db_candidate_id>(data, true));
|
||||
td::actor::send_closure(SelfId, &RootDb::get_block_candidate, PublicKey{f->source_}, create_block_id(f->id_),
|
||||
f->collated_data_file_hash_, std::move(promise));
|
||||
});
|
||||
}
|
||||
|
||||
void RootDb::store_block_state(BlockHandle handle, td::Ref<ShardState> state,
|
||||
td::Promise<td::Ref<ShardState>> promise) {
|
||||
if (handle->moved_to_archive()) {
|
||||
|
|
|
@ -58,6 +58,7 @@ class RootDb : public Db {
|
|||
void store_block_candidate(BlockCandidate candidate, td::Promise<td::Unit> promise) override;
|
||||
void get_block_candidate(PublicKey source, BlockIdExt id, FileHash collated_data_file_hash,
|
||||
td::Promise<BlockCandidate> promise) override;
|
||||
void get_block_candidate_by_block_id(BlockIdExt id, td::Promise<BlockCandidate> promise) override;
|
||||
|
||||
void store_block_state(BlockHandle handle, td::Ref<ShardState> state,
|
||||
td::Promise<td::Ref<ShardState>> promise) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue