spacejam_service/vm/accumulate.rs
1//! Primitives for the accumulate invocation
2
3use crate::{
4 BTreeMap, Gas, OpaqueHash, ServiceId, Vec, service::WorkExecResult, vm::DeferredTransfer,
5};
6use serde::{Deserialize, Serialize};
7
8/// The commitment map
9pub type CommitmentMap = BTreeMap<ServiceId, OpaqueHash>;
10
11/// The accumulate params for the accumulation
12#[derive(Serialize, Deserialize, Debug)]
13pub struct AccumulateParams {
14 /// (N_t) timeslot for the current accumulation
15 #[serde(with = "codec::compact")]
16 pub slot: u32,
17
18 /// (N_s) the service id of the caller
19 #[serde(with = "codec::compact")]
20 pub id: u32,
21
22 /// (|o|) The count of operands
23 #[serde(with = "codec::compact")]
24 pub results: u32,
25}
26
27/// An operand of the accumulation
28///
29/// NOTE: we are currently following the order of jam-types instead
30/// of graypaper.
31///
32/// defined per GP (12.13), (C.32) for the order.
33#[derive(Serialize, Deserialize, Debug, Clone)]
34pub struct Operand {
35 /// (p) The hash of the work package
36 pub package: OpaqueHash,
37
38 /// (e) The root of the segment tree which was generated by the work-package
39 /// in which the work-item which gave this result was placed.
40 pub exports_root: OpaqueHash,
41
42 /// (a) The hash of the authorizer which authorized the execution of the
43 /// work-package which generated this result.
44 pub authorizer_hash: OpaqueHash,
45
46 /// (y) The payload blob hash
47 pub payload: OpaqueHash,
48
49 /// (g) The accumulate gas
50 #[serde(with = "codec::compact")]
51 pub gas: Gas,
52
53 /// (l) The work execution result
54 pub data: WorkExecResult,
55
56 /// (t) The output of the Is-Authorized logic which authorized the execution
57 /// of the work-package which generated this result.
58 pub auth_output: Vec<u8>,
59}
60
61/// An item of the accumulation
62///
63/// reference per GP (C.33)
64#[derive(Serialize, Deserialize, Debug, Clone)]
65pub enum AccumulateItem {
66 /// The operands (12.13) + (C.32)
67 Operand(Operand),
68
69 /// The deferred transfers (12.14) + (C.31)
70 Transfer(DeferredTransfer),
71}
72
73impl From<Operand> for AccumulateItem {
74 fn from(operand: Operand) -> Self {
75 AccumulateItem::Operand(operand)
76 }
77}
78
79impl From<DeferredTransfer> for AccumulateItem {
80 fn from(transfer: DeferredTransfer) -> Self {
81 AccumulateItem::Transfer(transfer)
82 }
83}