improve compute unit method matching

and punish admin queries
This commit is contained in:
Bryan Stitt 2023-10-25 12:32:44 -07:00
parent 9198b861fe
commit 3aef84d32b

View File

@ -47,16 +47,7 @@ where
impl ComputeUnit {
/// costs can vary widely depending on method and chain
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
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) {
let cu = match (chain_id, method) {
(1101, "zkevm_batchNumber") => 0,
(1101, "zkevm_batchNumberByBlockNumber") => 0,
(1101, "zkevm_consolidatedBlockNumber") => 0,
@ -193,8 +184,28 @@ impl ComputeUnit {
(_, "ots_getTransactionBySenderAndNonce") => 1000,
(_, "ots_getContractCreator") => 1000,
(_, method) => {
// TODO: emit a stat
warn!("unknown method {}", method);
// TODO: this works, but this is fragile. think of a better way to check the method is a subscription
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()
+ Self::variable_price(chain_id, method, response_bytes).0;
}