refactor validity window with generic

This commit is contained in:
Sergio Chouhy
2026-03-31 13:49:12 +02:00
committed by Moudy
parent 6d690a8d25
commit 9aa7caf3bf
13 changed files with 191 additions and 215 deletions
@@ -1,19 +1,14 @@
use nssa_core::program::{
AccountPostState, BlockId, ProgramInput, ProgramOutput, Timestamp, read_nssa_inputs,
AccountPostState, BlockId, ProgramInput, ProgramOutput, ValidityWindow, read_nssa_inputs,
};
type Instruction = (
Option<BlockId>,
Option<BlockId>,
Option<Timestamp>,
Option<Timestamp>,
);
type Instruction = ValidityWindow<BlockId>;
fn main() {
let (
ProgramInput {
pre_states,
instruction: validity_window,
instruction: block_validity_window,
},
instruction_words,
) = read_nssa_inputs::<Instruction>();
@@ -29,7 +24,6 @@ fn main() {
vec![pre],
vec![AccountPostState::new(post)],
)
.try_with_validity_window(validity_window)
.unwrap()
.with_block_validity_window(block_validity_window)
.write();
}
@@ -1,21 +1,21 @@
use nssa_core::program::{
AccountPostState, ChainedCall, ProgramId, ProgramInput, ProgramOutput, ValidityWindow,
AccountPostState, BlockId, ChainedCall, ProgramId, ProgramInput, ProgramOutput, ValidityWindow,
read_nssa_inputs,
};
use risc0_zkvm::serde::to_vec;
/// A program that sets a validity window on its output and chains to another program with a
/// potentially different validity window.
/// A program that sets a block validity window on its output and chains to another program with a
/// potentially different block validity window.
///
/// Instruction: (`window`, `chained_program_id`, `chained_window`)
/// The initial output uses `window` and chains to `chained_program_id` with `chained_window`.
type Instruction = (ValidityWindow, ProgramId, ValidityWindow);
type Instruction = (ValidityWindow<BlockId>, ProgramId, ValidityWindow<BlockId>);
fn main() {
let (
ProgramInput {
pre_states,
instruction: (validity_window, chained_program_id, chained_validity_window),
instruction: (block_validity_window, chained_program_id, chained_block_validity_window),
},
instruction_words,
) = read_nssa_inputs::<Instruction>();
@@ -23,7 +23,7 @@ fn main() {
let [pre] = <[_; 1]>::try_from(pre_states.clone()).expect("Expected exactly one pre state");
let post = pre.account.clone();
let chained_instruction = to_vec(&chained_validity_window).unwrap();
let chained_instruction = to_vec(&chained_block_validity_window).unwrap();
let chained_call = ChainedCall {
program_id: chained_program_id,
instruction_data: chained_instruction,
@@ -36,7 +36,7 @@ fn main() {
vec![pre],
vec![AccountPostState::new(post)],
)
.with_validity_window(validity_window)
.with_block_validity_window(block_validity_window)
.with_chained_calls(vec![chained_call])
.write();
}