spacejam_service/
lib.rs

1#![doc = include_str!("../README.md")]
2#![warn(missing_docs)]
3#![cfg_attr(not(feature = "std"), no_std)]
4#[cfg(not(feature = "std"))]
5extern crate alloc;
6
7#[cfg(feature = "std")]
8pub(crate) use std::{collections::BTreeMap, string::String, vec::Vec};
9
10#[cfg(not(feature = "std"))]
11pub(crate) use alloc::{collections::BTreeMap, string::String, vec::Vec};
12
13pub use params::Parameters;
14
15pub mod api;
16pub mod params;
17pub mod service;
18pub mod vm;
19
20/// (B_I) The balance per item
21pub const BALANCE_PER_ITEM: u64 = 10;
22
23/// (B_L) The balance per octet
24pub const BALANCE_PER_OCTET: u64 = 1;
25
26/// (B_S) The balance per service
27pub const BALANCE_PER_SERVICE: u64 = 100;
28
29/// (C) The count of cores
30pub const CORES_COUNT: usize = 2;
31
32/// (G_A) The gas allocated to invoke a work report's Accumulation logic
33pub const GAS_ACC: u64 = 10_000_000;
34
35/// (G_T) The total gas allocated across for all accumulation
36///
37/// should be no smaller than G_A * C + ∑ privileges
38pub const GAS_ALL_ACC: u64 = 20_000_000;
39
40/// (W_G) The size of a segment
41pub const SEGMENT_SIZE: usize = 4104;
42
43/// The gas type
44pub type Gas = u64;
45
46/// The service id type
47pub type ServiceId = u32;
48
49/// The opaque hash type
50pub type OpaqueHash = [u8; 32];
51
52/// The time slot type
53pub type TimeSlot = u32;
54
55/// The type for a state root
56pub type StateRoot = OpaqueHash;
57
58/// The type for a beefy root
59pub type BeefyRoot = OpaqueHash;
60
61/// The type for a work package hash
62pub type WorkPackageHash = OpaqueHash;
63
64/// The type for a work report hash
65pub type WorkReportHash = OpaqueHash;
66
67/// The type for an exports root
68pub type ExportsRoot = OpaqueHash;
69
70/// The type for an erasure root
71pub type ErasureRoot = OpaqueHash;
72
73/// The type for an entropy buffer
74pub type EntropyBuffer = [OpaqueHash; 4];
75
76/// The type for a validator metadata
77pub type ValidatorMetadata = [u8; 128];
78
79/// The type for a bandersnatch public key
80pub type BandersnatchPublic = [u8; 32];
81
82/// The type for an ed25519 public key
83pub type Ed25519Public = [u8; 32];
84
85/// The type for a bls public key
86pub type BlsPublic = [u8; 144];
87
88#[cfg(feature = "blake2")]
89/// Compute the BLAKE2b 256-bit hash of a given input.
90pub fn blake2b(input: &[u8]) -> [u8; 32] {
91    use blake2::{Blake2b, Digest, digest::consts::U32};
92
93    let mut hasher = Blake2b::<U32>::new();
94    hasher.update(input);
95    hasher.finalize().into()
96}