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

initial commit

This commit is contained in:
initial commit 2019-09-07 14:03:22 +04:00 committed by vvaltman
commit c2da007f40
1610 changed files with 398047 additions and 0 deletions

View file

@ -0,0 +1,105 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "ton/ton-types.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/actor.h"
namespace ton {
namespace validator {
class ValidatorManagerInterface;
struct BlockHandleInterface {
public:
virtual BlockIdExt id() const = 0;
virtual bool received() const = 0;
virtual bool moved_to_storage() const = 0;
virtual bool deleted() const = 0;
virtual bool inited_next_left() const = 0;
virtual bool inited_next_right() const = 0;
virtual bool inited_next() const = 0;
virtual bool inited_prev_left() const = 0;
virtual bool inited_prev_right() const = 0;
virtual bool inited_prev() const = 0;
virtual bool inited_logical_time() const = 0;
virtual bool inited_unix_time() const = 0;
virtual bool inited_proof() const = 0;
virtual bool inited_proof_link() const = 0;
virtual bool inited_signatures() const = 0;
virtual bool inited_split_after() const = 0;
virtual bool inited_merge_before() const = 0;
virtual bool inited_is_key_block() const = 0;
virtual bool split_after() const = 0;
virtual bool merge_before() const = 0;
virtual bool is_key_block() const = 0;
virtual bool inited_state_root_hash() const = 0;
virtual bool received_state() const = 0;
virtual bool inited_state_boc() const = 0;
virtual bool deleted_state_boc() const = 0;
virtual bool need_flush() const = 0;
virtual bool is_zero() const = 0;
virtual bool is_archived() const = 0;
virtual bool is_applied() const = 0;
virtual std::vector<BlockIdExt> prev() const = 0;
virtual BlockIdExt one_prev(bool left) const = 0;
virtual std::vector<BlockIdExt> next() const = 0;
virtual BlockIdExt one_next(bool left) const = 0;
virtual RootHash state() const = 0;
virtual td::uint32 version() const = 0;
virtual bool processed() const = 0;
virtual void set_processed() = 0;
virtual void flush(td::actor::ActorId<ValidatorManagerInterface> manager, std::shared_ptr<BlockHandleInterface> self,
td::Promise<td::Unit> promise) = 0;
virtual void flushed_upto(td::uint32 version) = 0;
virtual void set_logical_time(LogicalTime lt) = 0;
virtual void set_unix_time(UnixTime ts) = 0;
virtual LogicalTime logical_time() const = 0;
virtual UnixTime unix_time() const = 0;
virtual void set_proof() = 0;
virtual void set_proof_link() = 0;
virtual void set_signatures() = 0;
virtual void set_next(BlockIdExt next) = 0;
virtual void set_prev(BlockIdExt prev) = 0;
virtual void set_received() = 0;
virtual void set_moved_to_storage() = 0;
virtual void set_deleted() = 0;
virtual void set_split(bool value) = 0;
virtual void set_merge(bool value) = 0;
virtual void set_is_key_block(bool value) = 0;
virtual void set_state_root_hash(RootHash hash) = 0;
virtual void set_state_boc() = 0;
virtual void set_deleted_state_boc() = 0;
virtual void set_archived() = 0;
virtual void set_applied() = 0;
virtual td::BufferSlice serialize() const = 0;
virtual ~BlockHandleInterface() = default;
};
using BlockHandle = std::shared_ptr<BlockHandleInterface>;
} // namespace validator
} // namespace ton

View file

@ -0,0 +1,39 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "vm/cells.h"
#include "ton/ton-types.h"
namespace ton {
namespace validator {
class BlockData : public td::CntObject {
public:
virtual ~BlockData() = default;
virtual td::BufferSlice data() const = 0;
virtual FileHash file_hash() const = 0;
virtual BlockIdExt block_id() const = 0;
virtual td::Ref<vm::Cell> root_cell() const = 0;
};
} // namespace validator
} // namespace ton

View file

@ -0,0 +1,41 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "ton/ton-types.h"
#include "crypto/common/refcnt.hpp"
#include "validator-set.h"
#include "crypto/block/mc-config.h"
namespace ton {
namespace validator {
using McShardHash = block::McShardHashI;
class ConfigHolder : public td::CntObject {
public:
virtual ~ConfigHolder() = default;
virtual td::Ref<ValidatorSet> get_total_validator_set(int next) const = 0; // next = -1 -> prev, next = 0 -> cur
};
} // namespace validator
} // namespace ton

98
validator/interfaces/db.h Normal file
View file

@ -0,0 +1,98 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "ton/ton-types.h"
#include "validator/interfaces/block-handle.h"
#include "validator/interfaces/validator-manager.h"
namespace ton {
namespace validator {
class Db : public td::actor::Actor {
public:
virtual ~Db() = default;
virtual void store_block_data(BlockHandle handle, td::Ref<BlockData> data, td::Promise<td::Unit> promise) = 0;
virtual void get_block_data(BlockHandle handle, td::Promise<td::Ref<BlockData>> promise) = 0;
virtual void store_block_signatures(BlockHandle handle, td::Ref<BlockSignatureSet> data,
td::Promise<td::Unit> promise) = 0;
virtual void get_block_signatures(BlockHandle handle, td::Promise<td::Ref<BlockSignatureSet>> promise) = 0;
virtual void store_block_proof(BlockHandle handle, td::Ref<Proof> proof, td::Promise<td::Unit> promise) = 0;
virtual void get_block_proof(BlockHandle handle, td::Promise<td::Ref<Proof>> promise) = 0;
virtual void store_block_proof_link(BlockHandle handle, td::Ref<ProofLink> proof, td::Promise<td::Unit> promise) = 0;
virtual void get_block_proof_link(BlockHandle handle, td::Promise<td::Ref<ProofLink>> promise) = 0;
virtual void store_block_candidate(BlockCandidate candidate, td::Promise<td::Unit> promise) = 0;
virtual void get_block_candidate(ton::PublicKey source, BlockIdExt id, FileHash collated_data_file_hash,
td::Promise<BlockCandidate> promise) = 0;
virtual void store_block_state(BlockHandle handle, td::Ref<ShardState> state,
td::Promise<td::Ref<ShardState>> promise) = 0;
virtual void get_block_state(BlockHandle handle, td::Promise<td::Ref<ShardState>> promise) = 0;
virtual void store_persistent_state_file(BlockIdExt block_id, BlockIdExt masterchain_block_id, td::BufferSlice state,
td::Promise<td::Unit> promise) = 0;
virtual void get_persistent_state_file(BlockIdExt block_id, BlockIdExt masterchain_block_id,
td::Promise<td::BufferSlice> promise) = 0;
virtual void check_persistent_state_file_exists(BlockIdExt block_id, BlockIdExt masterchain_block_id,
td::Promise<bool> promise) = 0;
virtual void store_zero_state_file(BlockIdExt block_id, td::BufferSlice state, td::Promise<td::Unit> promise) = 0;
virtual void get_zero_state_file(BlockIdExt block_id, td::Promise<td::BufferSlice> promise) = 0;
virtual void check_zero_state_file_exists(BlockIdExt block_id, td::Promise<bool> promise) = 0;
virtual void try_get_static_file(FileHash file_hash, td::Promise<td::BufferSlice> promise) = 0;
//virtual void store_zero_state(ZeroStateIdExt id, td::Ref<ShardState> state, td::Promise<td::Unit> promise) = 0;
//virtual void get_zero_state(ZeroStateIdExt id, td::Promise<td::Ref<ShardState>> promise) = 0;
virtual void store_block_handle(BlockHandle handle, td::Promise<td::Unit> promise) = 0;
virtual void get_block_handle(BlockIdExt id, td::Promise<BlockHandle> promise) = 0;
virtual void apply_block(BlockHandle handle, td::Promise<td::Unit> promise) = 0;
virtual void get_block_by_lt(AccountIdPrefixFull account, LogicalTime lt, td::Promise<BlockIdExt> promise) = 0;
virtual void get_block_by_unix_time(AccountIdPrefixFull account, UnixTime ts, td::Promise<BlockIdExt> promise) = 0;
virtual void get_block_by_seqno(AccountIdPrefixFull account, BlockSeqno seqno, td::Promise<BlockIdExt> promise) = 0;
virtual void update_init_masterchain_block(BlockIdExt block, td::Promise<td::Unit> promise) = 0;
virtual void get_init_masterchain_block(td::Promise<BlockIdExt> promise) = 0;
virtual void update_gc_masterchain_block(BlockIdExt block, td::Promise<td::Unit> promise) = 0;
virtual void get_gc_masterchain_block(td::Promise<BlockIdExt> promise) = 0;
virtual void update_shard_client_state(BlockIdExt masterchain_block_id, td::Promise<td::Unit> promise) = 0;
virtual void get_shard_client_state(td::Promise<BlockIdExt> promise) = 0;
virtual void update_destroyed_validator_sessions(std::vector<ValidatorSessionId> sessions,
td::Promise<td::Unit> promise) = 0;
virtual void get_destroyed_validator_sessions(td::Promise<std::vector<ValidatorSessionId>> promise) = 0;
virtual void update_async_serializer_state(AsyncSerializerState state, td::Promise<td::Unit> promise) = 0;
virtual void get_async_serializer_state(td::Promise<AsyncSerializerState> promise) = 0;
virtual void archive(BlockIdExt block_id, td::Promise<td::Unit> promise) = 0;
};
} // namespace validator
} // namespace ton

View file

@ -0,0 +1,42 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "crypto/common/refcnt.hpp"
#include "ton/ton-types.h"
#include "crypto/vm/cells.h"
namespace ton {
namespace validator {
class ExtMessage : public td::CntObject {
public:
using Hash = Bits256;
virtual ~ExtMessage() = default;
virtual AccountIdPrefixFull shard() const = 0;
virtual td::BufferSlice serialize() const = 0;
virtual td::Ref<vm::Cell> root_cell() const = 0;
virtual Hash hash() const = 0;
};
} // namespace validator
} // namespace ton

View file

@ -0,0 +1,42 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "crypto/common/refcnt.hpp"
#include "ton/ton-types.h"
#include "crypto/vm/cells.h"
namespace ton {
namespace validator {
class IhrMessage : public td::CntObject {
public:
using Hash = Bits256;
virtual ~IhrMessage() = default;
virtual AccountIdPrefixFull shard() const = 0;
virtual td::BufferSlice serialize() const = 0;
virtual td::Ref<vm::Cell> root_cell() const = 0;
virtual Hash hash() const = 0;
};
} // namespace validator
} // namespace ton

View file

@ -0,0 +1,41 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "ton/ton-types.h"
#include "crypto/common/refcnt.hpp"
#include "crypto/vm/cells.h"
namespace ton {
namespace validator {
class MessageQueue : public td::CntObject {
public:
virtual ~MessageQueue() = default;
virtual ShardIdFull get_shard() const = 0;
virtual BlockSeqno get_seqno() const = 0;
virtual BlockIdExt get_block_id() const = 0;
virtual RootHash root_hash() const = 0;
virtual td::Ref<vm::Cell> root_cell() const = 0;
};
} // namespace validator
} // namespace ton

View file

@ -0,0 +1,45 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "ton/ton-types.h"
#include "config.h"
namespace ton {
namespace validator {
class ProofLink : public td::CntObject {
public:
virtual ~ProofLink() = default;
virtual BlockIdExt block_id() const = 0;
virtual td::BufferSlice data() const = 0;
virtual td::Result<BlockSeqno> prev_key_mc_seqno() const = 0;
virtual td::Result<td::Ref<ConfigHolder>> get_key_block_config() const = 0;
};
class Proof : virtual public ProofLink {
public:
virtual ~Proof() = default;
virtual td::Result<td::Ref<ProofLink>> export_as_proof_link() const = 0;
};
} // namespace validator
} // namespace ton

View file

@ -0,0 +1,55 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "ton/ton-types.h"
#include "shard.h"
#include "interfaces/block-handle.h"
namespace ton {
namespace validator {
class ShardTopBlockDescription : public td::CntObject {
public:
virtual ~ShardTopBlockDescription() = default;
virtual ShardIdFull shard() const = 0;
virtual BlockIdExt block_id() const = 0;
virtual bool before_split() const = 0;
virtual bool after_split() const = 0;
virtual bool after_merge() const = 0;
virtual CatchainSeqno catchain_seqno() const = 0;
virtual UnixTime generated_at() const = 0;
// if method returns false this shard block description is discarded
// if it returns true it will be supplied to collator
//
// it may be invalid if:
// a. a block with a greater or equal seqno is in the masterchain
// b. this validator set is not valid anymore
// c. this shard is not valid anymore
virtual bool may_be_valid(BlockHandle last_masterchain_block_handle,
td::Ref<MasterchainState> last_masterchain_block_state) const = 0;
virtual td::BufferSlice serialize() const = 0;
};
} // namespace validator
} // namespace ton

View file

@ -0,0 +1,89 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "ton/ton-shard.h"
#include "ton/ton-types.h"
#include "validator-set.h"
#include "config.h"
#include "block.h"
#include "message-queue.h"
#include "vm/cells.h"
#include "proof.h"
namespace ton {
namespace validator {
class ShardState : public td::CntObject {
public:
virtual ~ShardState() = default;
virtual bool disable_boc() const = 0;
virtual UnixTime get_unix_time() const = 0;
virtual LogicalTime get_logical_time() const = 0;
virtual ShardIdFull get_shard() const = 0;
virtual BlockSeqno get_seqno() const = 0;
virtual BlockIdExt get_block_id() const = 0;
virtual RootHash root_hash() const = 0;
virtual td::Ref<vm::Cell> root_cell() const = 0;
virtual td::Status validate_deep() const = 0;
virtual bool before_split() const = 0;
virtual td::Result<td::Ref<MessageQueue>> message_queue() const = 0;
virtual td::Status apply_block(BlockIdExt id, td::Ref<BlockData> block) = 0;
virtual td::Result<td::Ref<ShardState>> merge_with(const ShardState& with) const = 0;
virtual td::Result<std::pair<td::Ref<ShardState>, td::Ref<ShardState>>> split() const = 0;
virtual td::Result<td::BufferSlice> serialize() const = 0;
};
class MasterchainState : virtual public ShardState {
public:
virtual ~MasterchainState() = default;
virtual td::Ref<ValidatorSet> get_validator_set(ShardIdFull shard) const = 0;
virtual td::Ref<ValidatorSet> get_next_validator_set(ShardIdFull shard) const = 0;
virtual td::Ref<ValidatorSet> get_total_validator_set(int next) const = 0; // next = -1 -> prev, next = 0 -> cur
virtual bool rotated_all_shards() const = 0;
virtual std::vector<td::Ref<McShardHash>> get_shards() const = 0;
virtual td::Ref<McShardHash> get_shard_from_config(ShardIdFull shard) const = 0;
virtual bool workchain_is_active(WorkchainId workchain_id) const = 0;
virtual td::uint32 min_split_depth(WorkchainId workchain_id) const = 0;
virtual td::uint32 soft_min_split_depth(WorkchainId workchain_id) const = 0;
virtual BlockSeqno min_ref_masterchain_seqno() const = 0;
virtual bool ancestor_is_valid(BlockIdExt id) const = 0;
virtual ValidatorSessionConfig get_consensus_config() const = 0;
virtual BlockIdExt last_key_block_id() const = 0;
virtual BlockIdExt next_key_block_id(BlockSeqno seqno) const = 0;
virtual BlockIdExt prev_key_block_id(BlockSeqno seqno) const = 0;
virtual bool get_old_mc_block_id(ton::BlockSeqno seqno, ton::BlockIdExt& blkid,
ton::LogicalTime* end_lt = nullptr) const = 0;
virtual bool check_old_mc_block_id(const ton::BlockIdExt& blkid, bool strict = false) const = 0;
virtual td::Status prepare() {
return td::Status::OK();
}
};
} // namespace validator
} // namespace ton

View file

@ -0,0 +1,51 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "crypto/common/refcnt.hpp"
#include "ton/ton-types.h"
namespace ton {
namespace validator {
class BlockSignatureSet : public td::CntObject {
public:
const auto &signatures() const {
return signatures_;
}
auto &signatures() {
return signatures_;
}
std::size_t size() const {
return signatures_.size();
}
virtual td::BufferSlice serialize() const = 0;
BlockSignatureSet(std::vector<BlockSignature> signatures) : signatures_(std::move(signatures)) {
}
protected:
std::vector<BlockSignature> signatures_;
};
} // namespace validator
} // namespace ton

View file

@ -0,0 +1,42 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "ton/ton-types.h"
#include "auto/tl/ton_api.h"
#include "keys/keys.hpp"
namespace ton {
namespace validator {
class ValidatorFullId : public PublicKey {
public:
NodeIdShort short_id() const;
operator Ed25519_PublicKey() const;
ValidatorFullId(PublicKey id) : PublicKey{std::move(id)} {
}
ValidatorFullId(const Ed25519_PublicKey& key) : PublicKey{pubkeys::Ed25519{key.as_bits256()}} {
}
};
} // namespace validator
} // namespace ton

View file

@ -0,0 +1,168 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "shard.h"
#include "block.h"
#include "proof.h"
#include "external-message.h"
#include "ihr-message.h"
#include "shard-block.h"
#include "message-queue.h"
#include "validator/validator.h"
namespace ton {
namespace validator {
constexpr int VERBOSITY_NAME(VALIDATOR_WARNING) = verbosity_WARNING;
constexpr int VERBOSITY_NAME(VALIDATOR_NOTICE) = verbosity_INFO;
constexpr int VERBOSITY_NAME(VALIDATOR_INFO) = verbosity_DEBUG;
constexpr int VERBOSITY_NAME(VALIDATOR_DEBUG) = verbosity_DEBUG;
constexpr int VERBOSITY_NAME(VALIDATOR_EXTRA_DEBUG) = verbosity_DEBUG + 1;
struct CandidateReject {
std::string reason;
td::BufferSlice proof;
};
struct AsyncSerializerState {
BlockIdExt last_block_id;
BlockIdExt last_written_block_id;
UnixTime last_written_block_ts;
};
using ValidateCandidateResult = td::Variant<UnixTime, CandidateReject>;
class ValidatorManager : public ValidatorManagerInterface {
public:
virtual void set_block_state(BlockHandle handle, td::Ref<ShardState> state,
td::Promise<td::Ref<ShardState>> promise) = 0;
virtual void store_persistent_state_file(BlockIdExt block_id, BlockIdExt masterchain_block_id, td::BufferSlice state,
td::Promise<td::Unit> promise) = 0;
virtual void store_zero_state_file(BlockIdExt block_id, td::BufferSlice state, td::Promise<td::Unit> promise) = 0;
virtual void wait_block_state(BlockHandle handle, td::uint32 priority, td::Timestamp timeout,
td::Promise<td::Ref<ShardState>> promise) = 0;
virtual void wait_block_state_short(BlockIdExt block_id, td::uint32 priority, td::Timestamp timeout,
td::Promise<td::Ref<ShardState>> promise) = 0;
virtual void set_block_data(BlockHandle handle, td::Ref<BlockData> data, td::Promise<td::Unit> promise) = 0;
virtual void wait_block_data(BlockHandle handle, td::uint32 priority, td::Timestamp,
td::Promise<td::Ref<BlockData>> promise) = 0;
virtual void wait_block_data_short(BlockIdExt block_id, td::uint32 priority, td::Timestamp,
td::Promise<td::Ref<BlockData>> promise) = 0;
virtual void set_block_proof(BlockHandle handle, td::Ref<Proof> proof, td::Promise<td::Unit> promise) = 0;
virtual void wait_block_proof(BlockHandle handle, td::Timestamp timeout, td::Promise<td::Ref<Proof>> promise) = 0;
virtual void wait_block_proof_short(BlockIdExt id, td::Timestamp timeout, td::Promise<td::Ref<Proof>> promise) = 0;
virtual void set_block_proof_link(BlockHandle handle, td::Ref<ProofLink> proof, td::Promise<td::Unit> promise) = 0;
virtual void wait_block_proof_link(BlockHandle handle, td::Timestamp timeout,
td::Promise<td::Ref<ProofLink>> promise) = 0;
virtual void wait_block_proof_link_short(BlockIdExt id, td::Timestamp timeout,
td::Promise<td::Ref<ProofLink>> promise) = 0;
virtual void set_block_signatures(BlockHandle handle, td::Ref<BlockSignatureSet> signatures,
td::Promise<td::Unit> promise) = 0;
virtual void wait_block_signatures(BlockHandle handle, td::Timestamp timeout,
td::Promise<td::Ref<BlockSignatureSet>> promise) = 0;
virtual void wait_block_signatures_short(BlockIdExt id, td::Timestamp timeout,
td::Promise<td::Ref<BlockSignatureSet>> promise) = 0;
virtual void set_block_candidate(BlockIdExt id, BlockCandidate candidate, td::Promise<td::Unit> promise) = 0;
virtual void wait_block_state_merge(BlockIdExt left_id, BlockIdExt right_id, td::uint32 priority,
td::Timestamp timeout, td::Promise<td::Ref<ShardState>> promise) = 0;
virtual void wait_prev_block_state(BlockHandle handle, td::uint32 priority, td::Timestamp timeout,
td::Promise<td::Ref<ShardState>> promise) = 0;
virtual void wait_block_message_queue(BlockHandle handle, td::uint32 priority, td::Timestamp timeout,
td::Promise<td::Ref<MessageQueue>> promise) = 0;
virtual void wait_block_message_queue_short(BlockIdExt id, td::uint32 priority, td::Timestamp timeout,
td::Promise<td::Ref<MessageQueue>> promise) = 0;
virtual void get_external_messages(ShardIdFull shard, td::Promise<std::vector<td::Ref<ExtMessage>>> promise) = 0;
virtual void get_ihr_messages(ShardIdFull shard, td::Promise<std::vector<td::Ref<IhrMessage>>> promise) = 0;
virtual void get_shard_blocks(BlockIdExt masterchain_block_id,
td::Promise<std::vector<td::Ref<ShardTopBlockDescription>>> promise) = 0;
virtual void complete_external_messages(std::vector<ExtMessage::Hash> to_delay,
std::vector<ExtMessage::Hash> to_delete) = 0;
virtual void complete_ihr_messages(std::vector<IhrMessage::Hash> to_delay,
std::vector<IhrMessage::Hash> to_delete) = 0;
//virtual void set_first_block(ZeroStateIdExt state, BlockIdExt block, td::Promise<td::Unit> promise) = 0;
virtual void set_next_block(BlockIdExt prev, BlockIdExt next, td::Promise<td::Unit> promise) = 0;
virtual void new_block(BlockHandle handle, td::Ref<ShardState> state, td::Promise<td::Unit> promise) = 0;
virtual void send_get_block_request(BlockIdExt id, td::uint32 priority, td::Promise<ReceivedBlock> promise) = 0;
virtual void send_get_zero_state_request(BlockIdExt id, td::uint32 priority,
td::Promise<td::BufferSlice> promise) = 0;
virtual void send_get_persistent_state_request(BlockIdExt id, BlockIdExt masterchain_block_id, td::uint32 priority,
td::Promise<td::BufferSlice> promise) = 0;
virtual void send_get_block_proof_request(BlockIdExt block_id, td::uint32 priority,
td::Promise<td::BufferSlice> promise) = 0;
virtual void send_get_block_proof_link_request(BlockIdExt block_id, td::uint32 priority,
td::Promise<td::BufferSlice> promise) = 0;
virtual void send_get_next_key_blocks_request(BlockIdExt block_id, td::uint32 priority,
td::Promise<std::vector<BlockIdExt>> promise) = 0;
virtual void send_external_message(td::Ref<ExtMessage> message) = 0;
virtual void send_ihr_message(td::Ref<IhrMessage> message) = 0;
virtual void send_top_shard_block_description(td::Ref<ShardTopBlockDescription> desc) = 0;
virtual void send_block_broadcast(BlockBroadcast broadcast) = 0;
virtual void update_shard_client_state(BlockIdExt masterchain_block_id, td::Promise<td::Unit> promise) = 0;
virtual void get_shard_client_state(td::Promise<BlockIdExt> promise) = 0;
virtual void subscribe_to_shard(ShardIdFull shard) = 0;
virtual void update_async_serializer_state(AsyncSerializerState state, td::Promise<td::Unit> promise) = 0;
virtual void get_async_serializer_state(td::Promise<AsyncSerializerState> promise) = 0;
virtual void try_get_static_file(FileHash file_hash, td::Promise<td::BufferSlice> promise) = 0;
virtual void allow_block_data_gc(BlockIdExt block_id, bool is_archive, td::Promise<bool> promise) = 0;
virtual void allow_block_state_gc(BlockIdExt block_id, td::Promise<bool> promise) = 0;
virtual void allow_zero_state_file_gc(BlockIdExt block_id, td::Promise<bool> promise) = 0;
virtual void allow_persistent_state_file_gc(BlockIdExt block_id, BlockIdExt masterchain_block_id,
td::Promise<bool> promise) = 0;
virtual void allow_block_signatures_gc(BlockIdExt block_id, td::Promise<bool> promise) = 0;
virtual void allow_block_proof_gc(BlockIdExt block_id, bool is_archive, td::Promise<bool> promise) = 0;
virtual void allow_block_proof_link_gc(BlockIdExt block_id, bool is_archive, td::Promise<bool> promise) = 0;
virtual void allow_block_candidate_gc(BlockIdExt block_id, td::Promise<bool> promise) = 0;
virtual void allow_block_info_gc(BlockIdExt block_id, td::Promise<bool> promise) = 0;
virtual void check_is_hardfork(BlockIdExt block_id, td::Promise<bool> promise) = 0;
virtual void get_vertical_height(BlockSeqno seqno, td::Promise<td::uint32> promise) = 0;
virtual void update_last_known_key_block(BlockHandle handle, bool send_request) = 0;
virtual void update_gc_block_handle(BlockHandle handle, td::Promise<td::Unit> promise) = 0;
static bool is_persistent_state(UnixTime ts, UnixTime prev_ts) {
return ts / 1024 != prev_ts / 1024;
}
static UnixTime persistent_state_ttl(UnixTime ts) {
auto x = ts / 1024;
CHECK(x > 0);
auto b = td::count_trailing_zeroes32(x);
return ts + (2048 << b);
}
};
} // namespace validator
} // namespace ton

View file

@ -0,0 +1,46 @@
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "validator-full-id.h"
#include "signature-set.h"
#include "ton/ton-types.h"
#include "adnl/adnl-node-id.hpp"
namespace ton {
namespace validator {
class ValidatorSet : public td::CntObject {
public:
virtual ~ValidatorSet() = default;
virtual bool is_validator(NodeIdShort id) const = 0;
virtual CatchainSeqno get_catchain_seqno() const = 0;
virtual td::uint32 get_validator_set_hash() const = 0;
virtual ShardId get_validator_set_from() const = 0;
virtual std::vector<ValidatorDescr> export_vector() const = 0;
virtual td::Result<ValidatorWeight> check_signatures(RootHash root_hash, FileHash file_hash,
td::Ref<BlockSignatureSet> signatures) const = 0;
virtual td::Result<ValidatorWeight> check_approve_signatures(RootHash root_hash, FileHash file_hash,
td::Ref<BlockSignatureSet> signatures) const = 0;
};
} // namespace validator
} // namespace ton