• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

oasisprotocol / oasis-core / #4696

26 Mar 2024 09:36AM UTC coverage: 47.483% (-0.7%) from 48.192%
#4696

Pull #5602

kostko
go/runtime: Improve manifest validation
Pull Request #5602: Implement ROFL (Runtime OFf-chain Logic)

3 of 133 new or added lines in 9 files covered. (2.26%)

3 existing lines in 3 files now uncovered.

3452 of 7270 relevant lines covered (47.48%)

1.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/runtime/src/host.rs
1
//! Host interface.
2
use async_trait::async_trait;
3
use thiserror::Error;
4

5
use crate::{
6
    common::{crypto::signature::PublicKey, namespace::Namespace},
7
    protocol::Protocol,
8
    storage::mkvs::sync,
9
    types::{self, Body},
10
};
11

12
/// Errors.
13
#[derive(Error, Debug)]
14
pub enum Error {
15
    #[error("bad response from host")]
16
    BadResponse,
17
    #[error("{0}")]
18
    Other(#[from] types::Error),
19
}
20

21
/// Transaction submission options.
22
#[derive(Clone, Default, Debug)]
23
pub struct SubmitTxOpts {
24
    /// Target runtime identifier. If not specified, own runtime identifier is used.
25
    pub runtime_id: Option<Namespace>,
26
    /// Whether the call should wait until the transaction is included in a block.
27
    pub wait: bool,
28
    /// Whether the response should include a proof of transaction being included in a block.
29
    pub prove: bool,
30
}
31

32
/// Transaction submission result.
33
#[derive(Clone, Default, Debug)]
34
pub struct TxResult {
35
    /// Transaction output.
36
    pub output: Vec<u8>,
37
    /// Round in which the transaction was executed.
38
    pub round: u64,
39
    /// Order of the transaction in the execution batch.
40
    pub batch_order: u32,
41
    /// Optional inclusion proof.
42
    pub proof: Option<sync::Proof>,
43
}
44

45
/// Notification registration options.
46
#[derive(Clone, Default, Debug)]
47
pub struct RegisterNotifyOpts {
48
    /// Subscribe to runtime block notifications.
49
    pub runtime_block: bool,
50
    /// Subscribe to runtime event notifications.
51
    pub runtime_event: Vec<Vec<u8>>,
52
}
53

54
/// Interface to the (untrusted) host node.
55
#[async_trait]
56
pub trait Host: Send + Sync {
57
    /// Returns the identity of the host node.
58
    async fn identity(&self) -> Result<PublicKey, Error>;
59

60
    /// Submit a transaction.
61
    async fn submit_tx(&self, data: Vec<u8>, opts: SubmitTxOpts)
62
        -> Result<Option<TxResult>, Error>;
63

64
    /// Register for receiving notifications.
65
    async fn register_notify(&self, opts: RegisterNotifyOpts) -> Result<(), Error>;
66
}
67

68
#[async_trait]
69
impl Host for Protocol {
70
    async fn identity(&self) -> Result<PublicKey, Error> {
×
71
        match self.call_host_async(Body::HostIdentityRequest {}).await? {
×
72
            Body::HostIdentityResponse { node_id } => Ok(node_id),
×
73
            _ => Err(Error::BadResponse),
×
74
        }
75
    }
76

77
    async fn submit_tx(
78
        &self,
79
        data: Vec<u8>,
80
        opts: SubmitTxOpts,
81
    ) -> Result<Option<TxResult>, Error> {
NEW
82
        match self
×
NEW
83
            .call_host_async(Body::HostSubmitTxRequest {
×
NEW
84
                runtime_id: opts.runtime_id.unwrap_or_else(|| self.get_runtime_id()),
×
NEW
85
                data,
×
NEW
86
                wait: opts.wait,
×
NEW
87
                prove: opts.prove,
×
88
            })
NEW
89
            .await?
×
90
        {
NEW
91
            Body::HostSubmitTxResponse {
×
92
                output,
93
                round,
94
                batch_order,
95
                proof,
96
            } => {
NEW
97
                if opts.wait {
×
NEW
98
                    Ok(Some(TxResult {
×
NEW
99
                        output,
×
100
                        round,
101
                        batch_order,
NEW
102
                        proof,
×
103
                    }))
104
                } else {
105
                    // If we didn't wait for inclusion then there is no result.
NEW
106
                    Ok(None)
×
107
                }
108
            }
NEW
109
            _ => Err(Error::BadResponse),
×
110
        }
111
    }
112

NEW
113
    async fn register_notify(&self, opts: RegisterNotifyOpts) -> Result<(), Error> {
×
NEW
114
        match self
×
NEW
115
            .call_host_async(Body::HostRegisterNotifyRequest {
×
NEW
116
                runtime_block: opts.runtime_block,
×
117
                runtime_event: match opts.runtime_event {
NEW
118
                    tags if tags.is_empty() => None,
×
NEW
119
                    tags => Some(types::RegisterNotifyRuntimeEvent { tags }),
×
120
                },
121
            })
NEW
122
            .await?
×
123
        {
NEW
124
            Body::Empty {} => Ok(()),
×
NEW
125
            _ => Err(Error::BadResponse),
×
126
        }
127
    }
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc