Skip to content

Commit

Permalink
feat: add config for grpc server methods (#5886)
Browse files Browse the repository at this point in the history
Description
---
Added configuration options for the base node's gRPC methods whereby
each method can be enabled or disabled with the startup-config settings.

Closing #5858

Some BloomRPC screenshots:


![image](https://github.com/tari-project/tari/assets/39146854/356cbe44-d3ff-46c8-9215-57e9f24da815)


![image](https://github.com/tari-project/tari/assets/39146854/8bf225b8-1b00-439b-96be-93c8040bf8d4)


Motivation and Context
---
See #5858

How Has This Been Tested?
---
- Pass existing unit tests
- Added unit test `fn it_deserializes_enums`
- Pass cucumber tests on CI
- Manual gRPC queries to the base node (with BloomRPC)

What process can a PR reviewer use to test or verify this change?
---
- Code walkthrough
- Manual gRPC queries to the base node

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
  • Loading branch information
hansieodendaal authored Nov 1, 2023
1 parent 4ca664e commit a3d7cf7
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions applications/minotari_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ ignored = [
# We need to specify extra features for log4rs even though it is not used directly in this crate
"log4rs"
]

[dev-dependencies]
toml = { version = "0.5" }
92 changes: 92 additions & 0 deletions applications/minotari_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ pub struct BaseNodeConfig {
pub grpc_enabled: bool,
/// GRPC address of base node
pub grpc_address: Option<Multiaddr>,
/// GRPC server config - which methods are active and which not
pub grpc_server_deny_methods: Vec<GrpcMethod>,
/// A path to the file that stores the base node identity and secret key
pub identity_file: PathBuf,
/// Spin up and use a built-in Tor instance. This only works on macos/linux - requires that the wallet was built
Expand Down Expand Up @@ -143,6 +145,16 @@ impl Default for BaseNodeConfig {
network: Network::default(),
grpc_enabled: true,
grpc_address: None,
grpc_server_deny_methods: vec![
// These gRPC server methods share sensitive information, thus disabled by default
GrpcMethod::GetVersion,
GrpcMethod::CheckForUpdates,
GrpcMethod::GetSyncInfo,
GrpcMethod::GetSyncProgress,
GrpcMethod::GetTipInfo,
GrpcMethod::Identify,
GrpcMethod::GetNetworkStatus,
],
identity_file: PathBuf::from("config/base_node_id.json"),
use_libtor: false,
tor_identity_file: PathBuf::from("config/base_node_tor_id.json"),
Expand Down Expand Up @@ -195,3 +207,83 @@ impl BaseNodeConfig {
pub enum DatabaseType {
Lmdb,
}

/// A list of all the GRPC methods that can be enabled/disabled
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum GrpcMethod {
ListHeaders,
GetHeaderByHash,
GetBlocks,
GetBlockTiming,
GetConstants,
GetBlockSize,
GetBlockFees,
GetVersion,
CheckForUpdates,
GetTokensInCirculation,
GetNetworkDifficulty,
GetNewBlockTemplate,
GetNewBlock,
GetNewBlockBlob,
SubmitBlock,
SubmitBlockBlob,
SubmitTransaction,
GetSyncInfo,
GetSyncProgress,
GetTipInfo,
SearchKernels,
SearchUtxos,
FetchMatchingUtxos,
GetPeers,
GetMempoolTransactions,
TransactionState,
Identify,
GetNetworkStatus,
ListConnectedPeers,
GetMempoolStats,
GetActiveValidatorNodes,
GetShardKey,
GetTemplateRegistrations,
GetSideChainUtxos,
}

#[cfg(test)]
mod tests {
use serde::{Deserialize, Serialize};

use crate::config::GrpcMethod;

#[derive(Clone, Serialize, Deserialize, Debug)]
#[allow(clippy::struct_excessive_bools)]
struct TestConfig {
name: String,
inner_config: TestInnerConfig,
}

#[derive(Clone, Serialize, Deserialize, Debug)]
#[allow(clippy::struct_excessive_bools)]
struct TestInnerConfig {
deny_methods: Vec<GrpcMethod>,
}

#[test]
fn it_deserializes_enums() {
let config_str = r#"name = "blockchain champion"
inner_config.deny_methods = [
"list_headers",
"get_constants",
# "get_blocks"
"identify",
# "get_shard_key"
]"#;
let config = toml::from_str::<TestConfig>(config_str).unwrap();

// Enums in the config
assert!(config.inner_config.deny_methods.contains(&GrpcMethod::ListHeaders));
assert!(config.inner_config.deny_methods.contains(&GrpcMethod::GetConstants));
assert!(!config.inner_config.deny_methods.contains(&GrpcMethod::GetBlocks)); // commented out in the config
assert!(config.inner_config.deny_methods.contains(&GrpcMethod::Identify));
assert!(!config.inner_config.deny_methods.contains(&GrpcMethod::GetShardKey)); // commented out in the config
}
}
Loading

0 comments on commit a3d7cf7

Please sign in to comment.