-
Notifications
You must be signed in to change notification settings - Fork 36
/
chain.hpp
63 lines (51 loc) · 1.81 KB
/
chain.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <optional>
#include <vector>
#include <outcome/outcome.hpp>
#include "consensus/grandpa/common.hpp"
#include "consensus/grandpa/structs.hpp"
namespace kagome::consensus::grandpa {
class VoterSet;
}
namespace kagome::consensus::grandpa {
/**
* Chain context necessary for implementation of the finality gadget.
*/
struct Chain {
virtual ~Chain() = default;
/**
* @brief Checks if {@param block} exists locally
* @return true iff block exists
*/
virtual bool hasBlock(const primitives::BlockHash &block) const = 0;
/**
* @brief Get the ancestry of a {@param block} up to the {@param base} hash.
* Should be in reverse order from block's parent.
* @return If the block is not a descendant of base, returns an error.
*/
virtual outcome::result<std::vector<primitives::BlockHash>> getAncestry(
const primitives::BlockHash &base,
const primitives::BlockHash &block) const = 0;
/**
* @brief Check if block is ancestor for second one
* @param base is potential ancestor
* @param block is testee block
* @return true, if \param base is ancestor for \param block
*/
virtual bool hasAncestry(const primitives::BlockHash &base,
const primitives::BlockHash &block) const = 0;
/**
* @returns the hash of the best block whose chain contains the given
* block hash, even if that block is {@param base} itself. If base is
* unknown, return None.
*/
virtual outcome::result<primitives::BlockInfo> bestChainContaining(
const primitives::BlockHash &base,
std::optional<VoterSetId> voter_set_id) const = 0;
};
} // namespace kagome::consensus::grandpa