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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//! The rows a cache hit needs, published into the store.
//!
//! # Why this exists, and what D43 got wrong
//!
//! D43 says the SQLite index "is rebuildable from the store, which it can
//! be because everything in it derives from content hashes". Held against
//! `cache.rs`, that is **false**. A step's key is a hash of its
//! ingredients — code, parameters, input hashes, tool versions — and no
//! object in the store carries any of them, so a bag of objects cannot say
//! which key produced which. `remotes` is keyed by a locator, which is not
//! a hash of anything either.
//!
//! The consequence is the whole of this module. A clean machine pointed at
//! a shared bucket computes exactly the right step key, finds the output
//! sitting in the bucket under exactly the right name, and still has no
//! way to know they belong together. So the rows are published too: each
//! one an object, named for the key it answers to.
//!
//! # These are claims, and that is the one thing to be clear about
//!
//! An object's name is the hash of its contents, so an object's name is a
//! claim that can be checked, and [`BlobStore::checked_get`] checks it. A
//! row is different. It says "key K produced object O", and nothing short
//! of running the step can check that. A row is therefore **the one object
//! class whose name is not the hash of its contents**, and it gets the
//! verification it can have rather than the one it cannot:
//!
//! - the body restates the table and the key, and a body that restates the
//! wrong ones is refused, so a row cannot be served in answer to a
//! question it was not written for;
//! - the object it points at is still verified byte for byte on the way in
//! ([`super::tiered`]), so a shared store can never hand over corrupt
//! data.
//!
//! What remains is that **a shared store is as trustworthy as write access
//! to it**. Someone who can write your bucket can claim that step K
//! produced some other intact object, and you would believe them. That is
//! the same trust boundary a Nix binary cache has — Nix answers it with
//! signatures, which v0.2 does not have — and it is written down here,
//! in the architecture page and in D43 rather than left to be discovered.
//!
//! The practical reading: point Ligase at a bucket your lab writes, not at
//! one the internet writes.
use crateContentHash;
use ;
/// Separates a row's name from every other hash in the engine.
const DOMAIN: &str = "ligase.published-row";
/// The format of a row's body.
///
/// A row written by another version is *ignored* rather than read, exactly
/// as a cache entry from another key format is: it describes something
/// that was put together differently, and the cost of ignoring it is one
/// recomputation.
const ROW_VERSION: u32 = 1;
/// Step entries: which key produced which output.
pub const STEPS: &str = "steps";
/// Pinned remotes: which locator resolved to which objects.
pub const REMOTES: &str = "remotes";
/// Where a row lives in the store.
///
/// Not the hash of the row's contents — the hash of the *question* it
/// answers, because the question is all a cold machine has. The `.row`
/// suffix keeps the two classes apart in any listing, and the domain
/// string keeps a row from ever colliding with an object.
/// Publish a row, so a machine with an empty index can learn it.
///
/// Write-once like every other object: a row already published is left
/// alone. That is right rather than merely convenient — a step key fixes
/// its ingredients, so two rows under one key would have to agree.
///
/// # Errors
///
/// If the row cannot be written.
/// Read a row back, refusing one that answers a different question.
///
/// `None` for a row that is not there, and for one written by a version
/// this build does not read.
///
/// # Errors
///
/// [`StoreError::Impostor`] if the row restates a table or key other than
/// the one it was found under — which means the store holds a row someone
/// wrote by hand or by accident, and serving it would be worse than
/// recomputing. Or an I/O failure.
/// Tabs, newlines and backslashes, so no field can shift a column.