Skip to content

Commit

Permalink
Enforce preflight (#21)
Browse files Browse the repository at this point in the history
* feat: sendTransaction aliased function

Signed-off-by: Wilfred Almeida <[email protected]>

* feat: grpc urls file watcher

Signed-off-by: Wilfred Almeida <[email protected]>

* refactor: file watcher to signals

Signed-off-by: Wilfred Almeida <[email protected]>

* refactor: spawn management

Signed-off-by: Wilfred Almeida <[email protected]>

* refactor: task spawn/kill management

Signed-off-by: Wilfred Almeida <[email protected]>

* refactor: PR review fixes

Signed-off-by: Wilfred Almeida <[email protected]>

* feat: enforce skipPreflight true

Signed-off-by: Wilfred Almeida <[email protected]>

---------

Signed-off-by: Wilfred Almeida <[email protected]>
  • Loading branch information
WilfredAlmeida authored Mar 25, 2024
1 parent d65cc4c commit 1d2cce4
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions server/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ impl Metadata for RpcMetadata {}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SendPriorityTransactionConfig {}
pub struct SendPriorityTransactionConfig {
skip_preflight: Option<bool>,
}

pub type SendTransactionConfig = SendPriorityTransactionConfig;

Expand Down Expand Up @@ -76,7 +78,7 @@ impl Rpc for RpcServer {
&self,
meta: Self::Metadata,
data: String,
_config: Option<SendPriorityTransactionConfig>,
config: Option<SendPriorityTransactionConfig>,
) -> BoxFuture<Result<String>> {
let auth = match meta.auth {
Ok(auth) => auth,
Expand All @@ -92,6 +94,42 @@ impl Rpc for RpcServer {
}
};

match config {
Some(config) => match config.skip_preflight {
Some(skip_preflight) => {
if !skip_preflight {
return Box::pin(async move {
Err(jsonrpc_core::error::Error {
code: jsonrpc_core::error::ErrorCode::InvalidParams,
message: "skipPreflight must be true".into(),
data: None,
})
});
}

info!("Skipping preflight checks");
}
None => {
return Box::pin(async move {
Err(jsonrpc_core::error::Error {
code: jsonrpc_core::error::ErrorCode::InvalidParams,
message: "skipPreflight is mandatory".into(),
data: None,
})
});
}
},
None => {
return Box::pin(async move {
Err(jsonrpc_core::error::Error {
code: jsonrpc_core::error::ErrorCode::InvalidParams,
message: "config options are mandatory".into(),
data: None,
})
});
}
}

info!("RPC method sendPriorityTransaction called: {:?}", auth);
metrics::SERVER_RPC_TX_ACCEPTED
.with_label_values(&[&auth.to_string(), &meta.mode.to_string()])
Expand Down Expand Up @@ -157,7 +195,6 @@ impl Rpc for RpcServer {
})
}


fn send_transaction(
&self,
meta: Self::Metadata,
Expand All @@ -167,8 +204,6 @@ impl Rpc for RpcServer {
self.send_priority_transaction(meta, data, config)
}



fn get_health(&self) -> Result<()> {
// TODO: check total connected stake?
// Would need to make the balancer an Arc?
Expand Down

0 comments on commit 1d2cce4

Please sign in to comment.