-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathchain_spec.hpp
105 lines (76 loc) · 2.9 KB
/
chain_spec.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <set>
#include <libp2p/multi/multiaddress.hpp>
#include "crypto/ed25519_types.hpp"
#include "crypto/sr25519_types.hpp"
#include "primitives/block.hpp"
#include "primitives/code_substitutes.hpp"
namespace kagome::application {
using GenesisRawData = std::vector<std::pair<common::Buffer, common::Buffer>>;
using ChildrenDefaultRawData = std::map<common::Buffer, GenesisRawData>;
/**
* Stores configuration of a kagome node and provides convenience
* methods for accessing config parameters
*/
class ChainSpec {
public:
virtual ~ChainSpec() = default;
virtual const std::string &name() const = 0;
virtual const std::string &id() const = 0;
virtual const std::string &chainType() const = 0;
/// Return ids of peer nodes of the current node
virtual const std::vector<libp2p::multi::Multiaddress> &bootNodes()
const = 0;
virtual const std::vector<std::pair<std::string, size_t>> &
telemetryEndpoints() const = 0;
virtual const std::string &protocolId() const = 0;
virtual const std::map<std::string, std::string> &properties() const = 0;
virtual std::optional<std::reference_wrapper<const std::string>>
getProperty(const std::string &property) const = 0;
virtual const std::set<primitives::BlockHash> &forkBlocks() const = 0;
virtual const std::set<primitives::BlockHash> &badBlocks() const = 0;
virtual std::optional<std::string> consensusEngine() const = 0;
/// Fetches code_substitute from json config on demand, by its BlockInfo.
/// BlockInfo is being compared with BlockIds that were loaded on initial
/// configuration and stored in set.
virtual outcome::result<common::Buffer> fetchCodeSubstituteByBlockInfo(
const primitives::BlockInfo &block_info) const = 0;
/**
* @return runtime code substitution map
*/
virtual std::shared_ptr<const primitives::CodeSubstituteBlockIds>
codeSubstitutes() const = 0;
/**
* @return top section
*/
virtual const GenesisRawData &getGenesisTopSection() const = 0;
/**
* @return childrenDefault section
*/
virtual const ChildrenDefaultRawData &getGenesisChildrenDefaultSection()
const = 0;
bool idStartsWith(std::string_view prefix) const {
return id().starts_with(prefix);
}
bool isKusama() const {
return idStartsWith("kusama") || idStartsWith("ksm");
}
bool isRococo() const {
return idStartsWith("rococo") || idStartsWith("rco");
}
bool isWococo() const {
return idStartsWith("wococo") || idStartsWith("wco");
}
bool isVersi() const {
return idStartsWith("versi") || idStartsWith("vrs");
}
virtual primitives::BlockNumber beefyMinDelta() const {
return isWococo() ? 4 : 8;
}
};
} // namespace kagome::application