forked from AcalaNetwork/subway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to customize method rate limit weight (AcalaNetwork#149)
- Loading branch information
1 parent
e9ab79b
commit 9a1124f
Showing
13 changed files
with
155 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::config::RpcMethod; | ||
use std::collections::BTreeMap; | ||
|
||
#[derive(Clone, Debug, Default)] | ||
pub struct MethodWeights(BTreeMap<String, u32>); | ||
|
||
impl MethodWeights { | ||
pub fn add(&mut self, method: &str, weight: u32) { | ||
self.0.insert(method.to_owned(), weight); | ||
} | ||
|
||
pub fn get(&self, method: &str) -> u32 { | ||
self.0.get(method).cloned().unwrap_or(1) | ||
} | ||
} | ||
|
||
impl MethodWeights { | ||
pub fn from_config(methods: &[RpcMethod]) -> Self { | ||
let mut weights = MethodWeights::default(); | ||
for method in methods { | ||
weights.add(&method.method, method.rate_limit_weight); | ||
} | ||
weights | ||
} | ||
} |
Oops, something went wrong.