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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//! Serialized block-write path for the store state.
//!
//! A single [`WriteWorker`] task owns the mutable trees and processes incoming [`WriteRequest`]s
//! one at a time via an mpsc channel. After each successful commit it publishes a new
//! [`StateSnapshot`] snapshot via an [`ArcSwap`], making the updated trees immediately visible to
//! wait-free readers.
//!
//! The [`BlockWriter`] and [`ProofWriter`] capabilities defined here are the only handles able
//! to feed this worker and to commit proofs; the submodules hold their entry points.
use Future;
use Pin;
use Arc;
use ;
use ;
use SignedBlock;
use ProtocolConfig;
use ;
pub use WriteWorker;
use crateCOMPONENT;
use crateBlockStore;
use crateApplyBlockError;
// WRITE CAPABILITIES
// ================================================================================================
/// The store's block-write capability.
///
/// Only handle able to apply blocks; obtained exactly once from [`LoadedState::start`](crate::state::LoadedState::start) and
/// deliberately not cloneable, so granting it to a single task (the block builder in sequencer
/// mode, the block sync loop in full-node mode) statically prevents every other component from
/// writing blocks.
///
/// Exposes no read access: holders that also need to query the store receive the
/// [`Arc<State>`](crate::state::State) returned alongside this capability by
/// [`LoadedState::start`](crate::state::LoadedState::start).
/// The store's proof-write capability.
///
/// Only handle able to commit block proofs and advance the proven tip; obtained exactly once from
/// [`LoadedState::start`](crate::state::LoadedState::start) and deliberately not cloneable, so granting it to a single task (the
/// proof scheduler in sequencer mode, the proof sync loop in full-node mode) statically prevents
/// every other component from writing proofs.
///
/// Exposes no read access: the held state is only used internally to commit proofs and advance
/// the proven tip. Holders that also need to query the store receive the
/// [`Arc<State>`](crate::state::State) returned alongside this capability by
/// [`LoadedState::start`](crate::state::LoadedState::start).
// WRITER TASK
// ================================================================================================
/// Handle of the store's write worker task, returned by [`LoadedState::start`](crate::state::LoadedState::start).
///
/// Awaiting it resolves once the writer has exited and released the tree storage it owns; a join
/// error carries a writer panic. The newtype ensures [`BlockWriter::stop`] can only be given the
/// store's own writer task, and deliberately does not expose [`tokio::task::JoinHandle::abort`]:
/// aborting the writer mid-write could leave the trees lagging the committed database state,
/// voiding the guarantee that an in-flight block write always completes.
JoinHandle);
// WRITE REQUEST
// ================================================================================================
/// A request to apply a block, paired with a one-shot channel for the result.
pub