@@ -85,16 +85,21 @@ impl NewBlockState {
85
85
}
86
86
}
87
87
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.
89
91
pub trait BlockImportOperation < Block , H > where
90
92
Block : BlockT ,
91
93
H : Hasher < Out =Block :: Hash > ,
92
94
{
93
95
/// Associated state backend type.
94
96
type State : StateBackend < H > ;
95
97
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.
97
101
fn state ( & self ) -> error:: Result < Option < & Self :: State > > ;
102
+
98
103
/// Append block data to the transaction.
99
104
fn set_block_data (
100
105
& mut self ,
@@ -106,21 +111,29 @@ pub trait BlockImportOperation<Block, H> where
106
111
107
112
/// Update cached data.
108
113
fn update_cache ( & mut self , cache : HashMap < well_known_cache_keys:: Id , Vec < u8 > > ) ;
114
+
109
115
/// Inject storage data into the database.
110
116
fn update_db_storage ( & mut self , update : <Self :: State as StateBackend < H > >:: Transaction ) -> error:: Result < ( ) > ;
117
+
111
118
/// Inject storage data into the database replacing any existing data.
112
119
fn reset_storage ( & mut self , top : StorageOverlay , children : ChildrenStorageOverlay ) -> error:: Result < H :: Out > ;
120
+
113
121
/// Set storage changes.
114
122
fn update_storage (
115
123
& mut self ,
116
124
update : StorageCollection ,
117
125
child_update : ChildStorageCollection ,
118
126
) -> error:: Result < ( ) > ;
127
+
119
128
/// Inject changes trie data into the database.
120
129
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.
122
134
fn insert_aux < I > ( & mut self , ops : I ) -> error:: Result < ( ) >
123
135
where I : IntoIterator < Item =( Vec < u8 > , Option < Vec < u8 > > ) > ;
136
+
124
137
/// Mark a block as finalized.
125
138
fn mark_finalized ( & mut self , id : BlockId < Block > , justification : Option < Justification > ) -> error:: Result < ( ) > ;
126
139
/// 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
129
142
130
143
/// Finalize Facilities
131
144
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
134
148
/// block (any other finalized blocks are left unjustified).
135
149
///
136
150
/// 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,
146
160
) -> error:: Result < ( ) > ;
147
161
148
162
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
150
166
/// fire finality notifications.
151
167
///
152
168
/// 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,
168
184
169
185
/// Provides access to an auxiliary database.
170
186
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.
172
190
fn insert_aux <
173
191
' a ,
174
192
' b : ' a ,
175
193
' c : ' a ,
176
194
I : IntoIterator < Item =& ' a ( & ' c [ u8 ] , & ' c [ u8 ] ) > ,
177
195
D : IntoIterator < Item =& ' a & ' b [ u8 ] > ,
178
196
> ( & self , insert : I , delete : D ) -> error:: Result < ( ) > ;
197
+
179
198
/// Query auxiliary data from key-value store.
180
199
fn get_aux ( & self , key : & [ u8 ] ) -> error:: Result < Option < Vec < u8 > > > ;
181
200
}
182
201
183
- /// Client backend. Manages the data layer.
202
+ /// Client backend.
203
+ ///
204
+ /// Manages the data layer.
184
205
///
185
206
/// Note on state pruning: while an object from `state_at` is alive, the state
186
207
/// should not be pruned. The backend should internally reference-count
@@ -204,35 +225,49 @@ pub trait Backend<Block, H>: AuxStore + Send + Sync where
204
225
type OffchainStorage : OffchainStorage ;
205
226
206
227
/// Begin a new block insertion transaction with given parent block id.
228
+ ///
207
229
/// When constructing the genesis, this is called with all-zero hash.
208
230
fn begin_operation ( & self ) -> error:: Result < Self :: BlockImportOperation > ;
231
+
209
232
/// Note an operation to contain state transition.
210
233
fn begin_state_operation ( & self , operation : & mut Self :: BlockImportOperation , block : BlockId < Block > ) -> error:: Result < ( ) > ;
234
+
211
235
/// Commit block insertion.
212
236
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.
215
241
fn finalize_block ( & self , block : BlockId < Block > , justification : Option < Justification > ) -> error:: Result < ( ) > ;
242
+
216
243
/// Returns reference to blockchain backend.
217
244
fn blockchain ( & self ) -> & Self :: Blockchain ;
245
+
218
246
/// Returns the used state cache, if existent.
219
247
fn used_state_cache_size ( & self ) -> Option < usize > ;
248
+
220
249
/// Returns reference to changes trie storage.
221
250
fn changes_trie_storage ( & self ) -> Option < & Self :: ChangesTrieStorage > ;
251
+
222
252
/// Returns a handle to offchain storage.
223
253
fn offchain_storage ( & self ) -> Option < Self :: OffchainStorage > ;
254
+
224
255
/// Returns true if state for given block is available.
225
256
fn have_state_at ( & self , hash : & Block :: Hash , _number : NumberFor < Block > ) -> bool {
226
257
self . state_at ( BlockId :: Hash ( hash. clone ( ) ) ) . is_ok ( )
227
258
}
259
+
228
260
/// Returns state backend with post-state of given block.
229
261
fn state_at ( & self , block : BlockId < Block > ) -> error:: Result < Self :: State > ;
262
+
230
263
/// Destroy state and save any useful data, such as cache.
231
264
fn destroy_state ( & self , _state : Self :: State ) -> error:: Result < ( ) > {
232
265
Ok ( ( ) )
233
266
}
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.
236
271
fn revert ( & self , n : NumberFor < Block > ) -> error:: Result < NumberFor < Block > > ;
237
272
238
273
/// Insert auxiliary data into key-value store.
@@ -252,6 +287,7 @@ pub trait Backend<Block, H>: AuxStore + Send + Sync where
252
287
}
253
288
254
289
/// Gain access to the import lock around this backend.
290
+ ///
255
291
/// _Note_ Backend isn't expected to acquire the lock by itself ever. Rather
256
292
/// the using components should acquire and hold the lock whenever they do
257
293
/// something that the import of a block would interfere with, e.g. importing
@@ -306,7 +342,10 @@ where
306
342
{
307
343
/// Returns true if the state for given block is available locally.
308
344
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
310
349
/// locally, or prepares request to fetch that data from remote node.
311
350
fn remote_blockchain ( & self ) -> Arc < dyn RemoteBlockchain < Block > > ;
312
351
}
0 commit comments