Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix(node_framework): Run gas adjuster task only if necessary (matter-…
Browse files Browse the repository at this point in the history
…labs#2266)

## What ❔

Adds a check that would prevent gas adjuster task from actually running
if there are no users of `GasAdjuster`.

## Why ❔

`GasAdjuster` is provided as a resource for anyone to use, but its
support task uses RPC (which has usage limits), so it doesn't make sense
to run it if nobody uses `GasAdjuster`.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
  • Loading branch information
popzxc authored Jun 19, 2024
1 parent f05b0ae commit 2dac846
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/node/node_framework/src/implementations/layers/l1_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,17 @@ impl Task for GasAdjusterTask {
"gas_adjuster".into()
}

async fn run(self: Box<Self>, stop_receiver: StopReceiver) -> anyhow::Result<()> {
async fn run(self: Box<Self>, mut stop_receiver: StopReceiver) -> anyhow::Result<()> {
// Gas adjuster layer is added to provide a resource for anyone to use, but it comes with
// a support task. If nobody has used the resource, we don't need to run the support task.
if Arc::strong_count(&self.gas_adjuster) == 1 {
tracing::info!(
"Gas adjuster is not used by any other task, not running the support task"
);
stop_receiver.0.changed().await?;
return Ok(());
}

self.gas_adjuster.run(stop_receiver.0).await
}
}

0 comments on commit 2dac846

Please sign in to comment.