6
6
#ifndef KAGOME_RUNTIME_DISPATCH_INFO_HPP
7
7
#define KAGOME_RUNTIME_DISPATCH_INFO_HPP
8
8
9
+ #include < scale/scale.hpp>
10
+ #include " common/unused.hpp"
11
+ #include " scale/big_fixed_integers.hpp"
12
+
9
13
namespace kagome ::primitives {
10
14
11
- /* * Information related to a dispatchable's class, weight, and fee that can be
15
+ // obsolete weight format used in TransactionPayment API versions less than 2
16
+ using OldWeight = scale::Compact<uint64_t >;
17
+
18
+ struct Weight {
19
+ SCALE_TIE (2 );
20
+ Weight () = default ;
21
+
22
+ explicit Weight (OldWeight w) : ref_time{w}, proof_size{0 } {}
23
+
24
+ Weight (uint64_t ref_time, uint64_t proof_size)
25
+ : ref_time{ref_time}, proof_size{proof_size} {}
26
+
27
+ // The weight of computational time used based on some reference hardware.
28
+ scale::Compact<uint64_t > ref_time;
29
+ // The weight of storage space used by proof of validity.
30
+ scale::Compact<uint64_t > proof_size;
31
+ };
32
+
33
+ // for some reason encoded as variant in substrate, thus custom encode/decode
34
+ // operators
35
+ enum class DispatchClass : uint8_t {
36
+ Normal,
37
+ Operational,
38
+ /* A mandatory dispatch. These kinds of dispatch are always included
39
+ * regardless of their weight, therefore it is critical that they are
40
+ * separately validated to ensure that a malicious validator cannot craft
41
+ * a valid but impossibly heavy block. Usually this just means ensuring
42
+ * that the extrinsic can only be included once and that it is always very
43
+ * light.
44
+ *
45
+ * Do *NOT* use it for extrinsics that can be heavy.
46
+ *
47
+ * The only real use case for this is inherent extrinsics that are
48
+ * required to execute in a block for the block to be valid, and it solves
49
+ * the issue in the case that the block initialization is sufficiently
50
+ * heavy to mean that those inherents do not fit into the block.
51
+ * Essentially, we assume that in these exceptional circumstances, it is
52
+ * better to allow an overweight block to be created than to not allow any
53
+ * block at all to be created.
54
+ */
55
+ Mandatory
56
+ };
57
+
58
+ template <typename Stream,
59
+ typename = std::enable_if_t <Stream::is_decoder_stream>>
60
+ Stream &operator >>(Stream &stream, DispatchClass &dispatch_class) {
61
+ std::ignore = stream.nextByte ();
62
+ uint8_t dispatch_class_byte;
63
+ stream >> dispatch_class_byte;
64
+ dispatch_class = static_cast <DispatchClass>(dispatch_class_byte);
65
+ return stream;
66
+ }
67
+
68
+ template <typename Stream,
69
+ typename = std::enable_if_t <Stream::is_decoder_stream>>
70
+ Stream &operator <<(Stream &stream, DispatchClass dispatch_class) {
71
+ return stream << uint8_t {0 } << dispatch_class;
72
+ }
73
+
74
+ struct Balance : public scale ::Fixed <scale::uint128_t > {};
75
+
76
+ /* * Information related to a dispatchable class, weight, and fee that can be
12
77
* queried from the runtime.
13
78
*/
79
+ template <typename Weight>
14
80
struct RuntimeDispatchInfo {
15
- using Weight = uint64_t ;
16
- using Balance = uint32_t ;
81
+ SCALE_TIE (3 )
17
82
18
83
Weight weight;
19
-
20
- enum class DispatchClass {
21
- Normal,
22
- Operational,
23
- /* A mandatory dispatch. These kinds of dispatch are always included
24
- * regardless of their weight, therefore it is critical that they are
25
- * separately validated to ensure that a malicious validator cannot craft
26
- * a valid but impossibly heavy block. Usually this just means ensuring
27
- * that the extrinsic can only be included once and that it is always very
28
- * light.
29
- *
30
- * Do *NOT* use it for extrinsics that can be heavy.
31
- *
32
- * The only real use case for this is inherent extrinsics that are
33
- * required to execute in a block for the block to be valid, and it solves
34
- * the issue in the case that the block initialization is sufficiently
35
- * heavy to mean that those inherents do not fit into the block.
36
- * Essentially, we assume that in these exceptional circumstances, it is
37
- * better to allow an overweight block to be created than to not allow any
38
- * block at all to be created.
39
- */
40
- Mandatory
41
- } dispatch_class;
84
+ DispatchClass dispatch_class;
42
85
43
86
/* * The inclusion fee of this dispatch. This does not include a tip or
44
87
* anything else that depends on the signature (i.e. depends on a
@@ -47,22 +90,6 @@ namespace kagome::primitives {
47
90
Balance partial_fee;
48
91
};
49
92
50
- template <class Stream ,
51
- typename = std::enable_if_t <Stream::is_encoder_stream>>
52
- Stream &operator <<(Stream &s, const RuntimeDispatchInfo &v) {
53
- return s << v.weight << v.dispatch_class << v.partial_fee ;
54
- }
55
-
56
- template <class Stream ,
57
- typename = std::enable_if_t <Stream::is_decoder_stream>>
58
- Stream &operator >>(Stream &s, RuntimeDispatchInfo &v) {
59
- uint8_t dispatch_class;
60
- s >> v.weight >> dispatch_class >> v.partial_fee ;
61
- v.dispatch_class =
62
- static_cast <RuntimeDispatchInfo::DispatchClass>(dispatch_class);
63
- return s;
64
- }
65
-
66
93
} // namespace kagome::primitives
67
94
68
95
#endif // KAGOME_RUNTIME_DISPATCH_INFO_HPP
0 commit comments