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

Commit 6b78a50

Browse files
NikVolfgavofyork
authored andcommitted
Improve auto-docs a little. (#4032)
1 parent 438c0c8 commit 6b78a50

File tree

1 file changed

+52
-13
lines changed

1 file changed

+52
-13
lines changed

core/client/src/backend.rs

+52-13
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,21 @@ impl NewBlockState {
8585
}
8686
}
8787

88-
/// Block insertion operation. Keeps hold if the inserted block state and data.
88+
/// Block insertion operation.
89+
///
90+
/// Keeps hold if the inserted block state and data.
8991
pub trait BlockImportOperation<Block, H> where
9092
Block: BlockT,
9193
H: Hasher<Out=Block::Hash>,
9294
{
9395
/// Associated state backend type.
9496
type State: StateBackend<H>;
9597

96-
/// Returns pending state. Returns None for backends with locally-unavailable state data.
98+
/// Returns pending state.
99+
///
100+
/// Returns None for backends with locally-unavailable state data.
97101
fn state(&self) -> error::Result<Option<&Self::State>>;
102+
98103
/// Append block data to the transaction.
99104
fn set_block_data(
100105
&mut self,
@@ -106,21 +111,29 @@ pub trait BlockImportOperation<Block, H> where
106111

107112
/// Update cached data.
108113
fn update_cache(&mut self, cache: HashMap<well_known_cache_keys::Id, Vec<u8>>);
114+
109115
/// Inject storage data into the database.
110116
fn update_db_storage(&mut self, update: <Self::State as StateBackend<H>>::Transaction) -> error::Result<()>;
117+
111118
/// Inject storage data into the database replacing any existing data.
112119
fn reset_storage(&mut self, top: StorageOverlay, children: ChildrenStorageOverlay) -> error::Result<H::Out>;
120+
113121
/// Set storage changes.
114122
fn update_storage(
115123
&mut self,
116124
update: StorageCollection,
117125
child_update: ChildStorageCollection,
118126
) -> error::Result<()>;
127+
119128
/// Inject changes trie data into the database.
120129
fn update_changes_trie(&mut self, update: ChangesTrieTransaction<H, NumberFor<Block>>) -> error::Result<()>;
121-
/// Insert auxiliary keys. Values are `None` if should be deleted.
130+
131+
/// Insert auxiliary keys.
132+
///
133+
/// Values are `None` if should be deleted.
122134
fn insert_aux<I>(&mut self, ops: I) -> error::Result<()>
123135
where I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>;
136+
124137
/// Mark a block as finalized.
125138
fn mark_finalized(&mut self, id: BlockId<Block>, justification: Option<Justification>) -> error::Result<()>;
126139
/// Mark a block as new head. If both block import and set head are specified, set head overrides block import's best block rule.
@@ -129,8 +142,9 @@ pub trait BlockImportOperation<Block, H> where
129142

130143
/// Finalize Facilities
131144
pub trait Finalizer<Block: BlockT, H: Hasher<Out=Block::Hash>, B: Backend<Block, H>> {
132-
/// Mark all blocks up to given as finalized in operation. If a
133-
/// justification is provided it is stored with the given finalized
145+
/// Mark all blocks up to given as finalized in operation.
146+
///
147+
/// If `justification` is provided it is stored with the given finalized
134148
/// block (any other finalized blocks are left unjustified).
135149
///
136150
/// If the block being finalized is on a different fork from the current
@@ -146,7 +160,9 @@ pub trait Finalizer<Block: BlockT, H: Hasher<Out=Block::Hash>, B: Backend<Block,
146160
) -> error::Result<()>;
147161

148162

149-
/// Finalize a block. This will implicitly finalize all blocks up to it and
163+
/// Finalize a block.
164+
///
165+
/// This will implicitly finalize all blocks up to it and
150166
/// fire finality notifications.
151167
///
152168
/// If the block being finalized is on a different fork from the current
@@ -168,19 +184,24 @@ pub trait Finalizer<Block: BlockT, H: Hasher<Out=Block::Hash>, B: Backend<Block,
168184

169185
/// Provides access to an auxiliary database.
170186
pub trait AuxStore {
171-
/// Insert auxiliary data into key-value store. Deletions occur after insertions.
187+
/// Insert auxiliary data into key-value store.
188+
///
189+
/// Deletions occur after insertions.
172190
fn insert_aux<
173191
'a,
174192
'b: 'a,
175193
'c: 'a,
176194
I: IntoIterator<Item=&'a(&'c [u8], &'c [u8])>,
177195
D: IntoIterator<Item=&'a &'b [u8]>,
178196
>(&self, insert: I, delete: D) -> error::Result<()>;
197+
179198
/// Query auxiliary data from key-value store.
180199
fn get_aux(&self, key: &[u8]) -> error::Result<Option<Vec<u8>>>;
181200
}
182201

183-
/// Client backend. Manages the data layer.
202+
/// Client backend.
203+
///
204+
/// Manages the data layer.
184205
///
185206
/// Note on state pruning: while an object from `state_at` is alive, the state
186207
/// should not be pruned. The backend should internally reference-count
@@ -204,35 +225,49 @@ pub trait Backend<Block, H>: AuxStore + Send + Sync where
204225
type OffchainStorage: OffchainStorage;
205226

206227
/// Begin a new block insertion transaction with given parent block id.
228+
///
207229
/// When constructing the genesis, this is called with all-zero hash.
208230
fn begin_operation(&self) -> error::Result<Self::BlockImportOperation>;
231+
209232
/// Note an operation to contain state transition.
210233
fn begin_state_operation(&self, operation: &mut Self::BlockImportOperation, block: BlockId<Block>) -> error::Result<()>;
234+
211235
/// Commit block insertion.
212236
fn commit_operation(&self, transaction: Self::BlockImportOperation) -> error::Result<()>;
213-
/// Finalize block with given Id. This should only be called if the parent of the given
214-
/// block has been finalized.
237+
238+
/// Finalize block with given Id.
239+
///
240+
/// This should only be called if the parent of the given block has been finalized.
215241
fn finalize_block(&self, block: BlockId<Block>, justification: Option<Justification>) -> error::Result<()>;
242+
216243
/// Returns reference to blockchain backend.
217244
fn blockchain(&self) -> &Self::Blockchain;
245+
218246
/// Returns the used state cache, if existent.
219247
fn used_state_cache_size(&self) -> Option<usize>;
248+
220249
/// Returns reference to changes trie storage.
221250
fn changes_trie_storage(&self) -> Option<&Self::ChangesTrieStorage>;
251+
222252
/// Returns a handle to offchain storage.
223253
fn offchain_storage(&self) -> Option<Self::OffchainStorage>;
254+
224255
/// Returns true if state for given block is available.
225256
fn have_state_at(&self, hash: &Block::Hash, _number: NumberFor<Block>) -> bool {
226257
self.state_at(BlockId::Hash(hash.clone())).is_ok()
227258
}
259+
228260
/// Returns state backend with post-state of given block.
229261
fn state_at(&self, block: BlockId<Block>) -> error::Result<Self::State>;
262+
230263
/// Destroy state and save any useful data, such as cache.
231264
fn destroy_state(&self, _state: Self::State) -> error::Result<()> {
232265
Ok(())
233266
}
234-
/// Attempts to revert the chain by `n` blocks. Returns the number of blocks that were
235-
/// successfully reverted.
267+
268+
/// Attempts to revert the chain by `n` blocks.
269+
///
270+
/// Returns the number of blocks that were successfully reverted.
236271
fn revert(&self, n: NumberFor<Block>) -> error::Result<NumberFor<Block>>;
237272

238273
/// Insert auxiliary data into key-value store.
@@ -252,6 +287,7 @@ pub trait Backend<Block, H>: AuxStore + Send + Sync where
252287
}
253288

254289
/// Gain access to the import lock around this backend.
290+
///
255291
/// _Note_ Backend isn't expected to acquire the lock by itself ever. Rather
256292
/// the using components should acquire and hold the lock whenever they do
257293
/// something that the import of a block would interfere with, e.g. importing
@@ -306,7 +342,10 @@ where
306342
{
307343
/// Returns true if the state for given block is available locally.
308344
fn is_local_state_available(&self, block: &BlockId<Block>) -> bool;
309-
/// Returns reference to blockchain backend that either resolves blockchain data
345+
346+
/// Returns reference to blockchain backend.
347+
///
348+
/// Returned backend either resolves blockchain data
310349
/// locally, or prepares request to fetch that data from remote node.
311350
fn remote_blockchain(&self) -> Arc<dyn RemoteBlockchain<Block>>;
312351
}

0 commit comments

Comments
 (0)