Skip to content

Commit 53696fc

Browse files
authored
Merge pull request #6178 from oasisprotocol/kostko/fix/rt-verifier-sync
runtime: Support HEIGHT_LATEST in Verifier::sync implementations
2 parents f7978e8 + 2ef12ad commit 53696fc

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

.changelog/6178.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
runtime: Support HEIGHT_LATEST in `Verifier::sync` implementations

runtime/src/consensus/tendermint/verifier/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ impl Verifier {
155155
}
156156

157157
fn sync(&self, cache: &mut Cache, instance: &mut Instance, height: u64) -> Result<(), Error> {
158-
if height < cache.last_verified_height || height < cache.latest_known_height().unwrap_or(0)
158+
if height != HEIGHT_LATEST
159+
&& (height < cache.last_verified_height
160+
|| height < cache.latest_known_height().unwrap_or(0))
159161
{
160162
// Ignore requests for earlier heights.
161163
return Ok(());

runtime/src/consensus/tendermint/verifier/noop.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ impl NopVerifier {
6464
#[async_trait]
6565
impl verifier::Verifier for NopVerifier {
6666
async fn sync(&self, height: u64) -> Result<(), Error> {
67+
let height = self.fetch_light_block(height).await?.height; // Ensure height is valid.
68+
6769
let mut inner = self.inner.lock().unwrap();
6870
inner.latest_height = Some(height);
6971

runtime/src/transaction/tree.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,42 @@ impl Tree {
208208
self.tree
209209
.commit_both(self.io_root.namespace, self.io_root.version)
210210
}
211+
212+
/// Fetch the input artifact for the given transaction hash.
213+
pub fn get_input(&self, tx_hash: Hash) -> Result<Option<Vec<u8>>> {
214+
let raw = self.tree.get(
215+
&TxnKeyFormat {
216+
tx_hash,
217+
kind: ArtifactKind::Input,
218+
}
219+
.encode(),
220+
)?;
221+
match raw {
222+
Some(raw) => {
223+
let ia: InputArtifacts = cbor::from_slice(&raw)?;
224+
Ok(Some(ia.input))
225+
}
226+
None => Ok(None),
227+
}
228+
}
229+
230+
/// Fetch the output artifact for the given transaction hash.
231+
pub fn get_output(&self, tx_hash: Hash) -> Result<Option<Vec<u8>>> {
232+
let raw = self.tree.get(
233+
&TxnKeyFormat {
234+
tx_hash,
235+
kind: ArtifactKind::Output,
236+
}
237+
.encode(),
238+
)?;
239+
match raw {
240+
Some(raw) => {
241+
let oa: OutputArtifacts = cbor::from_slice(&raw)?;
242+
Ok(Some(oa.output))
243+
}
244+
None => Ok(None),
245+
}
246+
}
211247
}
212248

213249
#[cfg(test)]
@@ -228,6 +264,7 @@ mod test {
228264

229265
let input = b"this goes in".to_vec();
230266
let tx_hash = Hash::digest_bytes(&input);
267+
let orig_tx_hash = tx_hash;
231268
tree.add_input(input, 0).unwrap();
232269
tree.add_output(
233270
tx_hash,
@@ -258,5 +295,16 @@ mod test {
258295
format!("{:?}", root_hash),
259296
"8399ffa753987b00ec6ab251337c6b88e40812662ed345468fcbf1dbdd16321c",
260297
);
298+
299+
// Accessors.
300+
let dec_input = tree.get_input(orig_tx_hash).unwrap();
301+
assert_eq!(dec_input, Some(b"this goes in".to_vec()));
302+
let dec_output = tree.get_output(orig_tx_hash).unwrap();
303+
assert_eq!(dec_output, Some(b"and this comes out".to_vec()));
304+
305+
let dec_input = tree.get_input(Hash::empty_hash()).unwrap();
306+
assert!(dec_input.is_none());
307+
let dec_output = tree.get_output(Hash::empty_hash()).unwrap();
308+
assert!(dec_output.is_none());
261309
}
262310
}

0 commit comments

Comments
 (0)