rpc-interface: add restricted invariant comments

This commit is contained in:
hinto.janai 2024-12-17 18:23:09 -05:00
parent 04cdc72f46
commit 3763dc9693
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
3 changed files with 20 additions and 1 deletions

View file

@ -71,7 +71,12 @@ macro_rules! generate_endpoints_inner {
($variant:ident, $handler:ident, $request:expr_2021) => { ($variant:ident, $handler:ident, $request:expr_2021) => {
paste::paste! { paste::paste! {
{ {
// Check if restricted. // INVARIANT:
// The handler functions in `cuprated` depend on this line existing,
// the functions themselves do not check if they are being called
// from an (un)restricted context.
//
// This line must be here or all methods will be allowed to be called freely.
if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() { if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() {
// TODO: mimic `monerod` behavior. // TODO: mimic `monerod` behavior.
return Err(StatusCode::FORBIDDEN); return Err(StatusCode::FORBIDDEN);

View file

@ -37,6 +37,13 @@ pub(crate) async fn json_rpc<H: RpcHandler>(
// Return early if this RPC server is restricted and // Return early if this RPC server is restricted and
// the requested method is only for non-restricted RPC. // the requested method is only for non-restricted RPC.
//
// INVARIANT:
// The handler functions in `cuprated` depend on this line existing,
// the functions themselves do not check if they are being called
// from an (un)restricted context.
//
// This line must be here or all methods will be allowed to be called freely.
if request.body.is_restricted() && handler.is_restricted() { if request.body.is_restricted() && handler.is_restricted() {
let error_object = ErrorObject { let error_object = ErrorObject {
code: ErrorCode::ServerError(-1 /* TODO */), code: ErrorCode::ServerError(-1 /* TODO */),

View file

@ -75,6 +75,13 @@ macro_rules! generate_endpoints_inner {
paste::paste! { paste::paste! {
{ {
// Check if restricted. // Check if restricted.
//
// INVARIANT:
// The handler functions in `cuprated` depend on this line existing,
// the functions themselves do not check if they are being called
// from an (un)restricted context.
//
// This line must be here or all methods will be allowed to be called freely.
if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() { if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() {
// TODO: mimic `monerod` behavior. // TODO: mimic `monerod` behavior.
return Err(StatusCode::FORBIDDEN); return Err(StatusCode::FORBIDDEN);