improve compute unit method matching
and punish admin queries
This commit is contained in:
parent
9198b861fe
commit
3aef84d32b
@ -47,16 +47,7 @@ where
|
|||||||
impl ComputeUnit {
|
impl ComputeUnit {
|
||||||
/// costs can vary widely depending on method and chain
|
/// costs can vary widely depending on method and chain
|
||||||
pub fn new(method: &str, chain_id: u64, response_bytes: u64) -> Self {
|
pub fn new(method: &str, chain_id: u64, response_bytes: u64) -> Self {
|
||||||
// TODO: this works, but this is fragile. think of a better way to check the method is a subscription
|
let cu = match (chain_id, method) {
|
||||||
if method.ends_with(')') {
|
|
||||||
return Self::variable_price(chain_id, method, response_bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
let cu = if method.starts_with("admin_") || method.starts_with("alchemy_") {
|
|
||||||
// maybe charge extra since they are doing things they aren't supposed to
|
|
||||||
return Self::unimplemented();
|
|
||||||
} else {
|
|
||||||
match (chain_id, method) {
|
|
||||||
(1101, "zkevm_batchNumber") => 0,
|
(1101, "zkevm_batchNumber") => 0,
|
||||||
(1101, "zkevm_batchNumberByBlockNumber") => 0,
|
(1101, "zkevm_batchNumberByBlockNumber") => 0,
|
||||||
(1101, "zkevm_consolidatedBlockNumber") => 0,
|
(1101, "zkevm_consolidatedBlockNumber") => 0,
|
||||||
@ -193,8 +184,28 @@ impl ComputeUnit {
|
|||||||
(_, "ots_getTransactionBySenderAndNonce") => 1000,
|
(_, "ots_getTransactionBySenderAndNonce") => 1000,
|
||||||
(_, "ots_getContractCreator") => 1000,
|
(_, "ots_getContractCreator") => 1000,
|
||||||
(_, method) => {
|
(_, method) => {
|
||||||
// TODO: emit a stat
|
// TODO: this works, but this is fragile. think of a better way to check the method is a subscription
|
||||||
warn!("unknown method {}", method);
|
if method.ends_with(')') {
|
||||||
|
return Self::variable_price(chain_id, method, response_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
if method.starts_with("admin_")
|
||||||
|
|| method.starts_with("miner_")
|
||||||
|
|| method == "personal_unlockAccount"
|
||||||
|
{
|
||||||
|
// charge extra since they are doing things they aren't supposed to
|
||||||
|
return Self::unimplemented() * 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
if method.starts_with("alchemy_")
|
||||||
|
|| method.starts_with("personal_")
|
||||||
|
|| method.starts_with("shh_")
|
||||||
|
|| method.starts_with("db_")
|
||||||
|
{
|
||||||
|
// maybe charge extra since they are doing things they aren't supposed to
|
||||||
|
return Self::unimplemented();
|
||||||
|
|
||||||
|
warn!(%response_bytes, "unknown method {}", method);
|
||||||
return Self::unimplemented()
|
return Self::unimplemented()
|
||||||
+ Self::variable_price(chain_id, method, response_bytes).0;
|
+ Self::variable_price(chain_id, method, response_bytes).0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user