Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 1a55ca9

Browse files
authored
runtime-api subsystem lru cache (#2309)
* Add memory-lru cache to runtime-api * Add cache.rs * Adds MallocSizeOf * Review nits * Add a cached requests metric * More review nits * Some more review nits
1 parent 93fcd8f commit 1a55ca9

File tree

11 files changed

+525
-39
lines changed

11 files changed

+525
-39
lines changed

Cargo.lock

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core-primitives/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master",
99
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
1010
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
1111
parity-scale-codec = { version = "1.3.6", default-features = false, features = [ "derive" ] }
12+
parity-util-mem = { version = "0.8.0", default-features = false, optional = true }
1213

1314
[features]
1415
default = [ "std" ]
@@ -17,4 +18,5 @@ std = [
1718
"sp-runtime/std",
1819
"sp-std/std",
1920
"parity-scale-codec/std",
21+
"parity-util-mem",
2022
]

core-primitives/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
2323
use sp_runtime::{generic, MultiSignature, traits::{Verify, BlakeTwo256, IdentifyAccount}};
2424
use parity_scale_codec::{Encode, Decode};
25+
#[cfg(feature = "std")]
26+
use parity_util_mem::MallocSizeOf;
2527

2628
/// The block number type used by Polkadot.
2729
/// 32-bits will allow for 136 years of blocks assuming 1 block per second.
@@ -57,6 +59,7 @@ pub type Hash = sp_core::H256;
5759
///
5860
/// This type makes it easy to enforce that a hash is a candidate hash on the type level.
5961
#[derive(Clone, Copy, Encode, Decode, Hash, Eq, PartialEq, Debug, Default)]
62+
#[cfg_attr(feature = "std", derive(MallocSizeOf))]
6063
pub struct CandidateHash(pub Hash);
6164

6265
#[cfg(feature="std")]
@@ -103,6 +106,7 @@ pub type DownwardMessage = sp_std::vec::Vec<u8>;
103106
/// A wrapped version of `DownwardMessage`. The difference is that it has attached the block number when
104107
/// the message was sent.
105108
#[derive(Encode, Decode, Clone, sp_runtime::RuntimeDebug, PartialEq)]
109+
#[cfg_attr(feature = "std", derive(MallocSizeOf))]
106110
pub struct InboundDownwardMessage<BlockNumber = crate::BlockNumber> {
107111
/// The block number at which this messages was put into the downward message queue.
108112
pub sent_at: BlockNumber,
@@ -112,6 +116,7 @@ pub struct InboundDownwardMessage<BlockNumber = crate::BlockNumber> {
112116

113117
/// An HRMP message seen from the perspective of a recipient.
114118
#[derive(Encode, Decode, Clone, sp_runtime::RuntimeDebug, PartialEq)]
119+
#[cfg_attr(feature = "std", derive(MallocSizeOf))]
115120
pub struct InboundHrmpMessage<BlockNumber = crate::BlockNumber> {
116121
/// The block number at which this message was sent.
117122
/// Specifically, it is the block number at which the candidate that sends this message was
@@ -123,6 +128,7 @@ pub struct InboundHrmpMessage<BlockNumber = crate::BlockNumber> {
123128

124129
/// An HRMP message seen from the perspective of a sender.
125130
#[derive(Encode, Decode, Clone, sp_runtime::RuntimeDebug, PartialEq, Eq, Hash)]
131+
#[cfg_attr(feature = "std", derive(MallocSizeOf))]
126132
pub struct OutboundHrmpMessage<Id> {
127133
/// The para that will get this message in its downward message queue.
128134
pub recipient: Id,

node/core/runtime-api/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ edition = "2018"
88
futures = "0.3.12"
99
tracing = "0.1.22"
1010
tracing-futures = "0.2.4"
11+
memory-lru = "0.1.0"
12+
parity-util-mem = { version = "0.8.0", default-features = false }
13+
1114
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
1215
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
1316

0 commit comments

Comments
 (0)