Sfoglia il codice sorgente

[scheduler] Default to early updates (#1140)

* make early updates the default

* make early updates the default
Jayant Krishnamurthy 2 anni fa
parent
commit
cc7054b6f3
3 ha cambiato i file con 30 aggiunte e 1 eliminazioni
  1. 19 0
      price_pusher/README.md
  2. 1 1
      price_pusher/package.json
  3. 10 0
      price_pusher/src/price-config.ts

+ 19 - 0
price_pusher/README.md

@@ -37,6 +37,7 @@ The parameters above are configured per price feed in a price configuration YAML
   time_difference: 60 # Time difference threshold (in seconds) to push a newer price feed.
   price_deviation: 0.5 # The price deviation (%) threshold to push a newer price feed.
   confidence_ratio: 1 # The confidence/price (%) threshold to push a newer price feed.
+
   # Optional block to configure whether this feed can be early updated. If at least one feed meets the
   # triggering conditions above, all other feeds who meet the early update conditions will be included in
   # the submitted batch of prices. This logic takes advantage of the fact that adding a feed to a larger
@@ -49,6 +50,24 @@ The parameters above are configured per price feed in a price configuration YAML
 - ...
 ```
 
+By default, the price pusher will automatically update the price of all listed price feeds whenever the
+triggering condition for a single feed is met. This behavior takes advantage of the reduced cost of batch price updates
+provided by the [Perseus upgrade](https://medium.com/@antonia.vanna.delgado/pyth-network-perseus-first-party-data-matters-e3379bf0d019),
+and is typically the lowest cost way to schedule price updates for multiple feeds.
+
+However, if you would like to customize this behavior, you can add an `early_update` section to the YAML configuration file for
+the feed.
+
+```yaml
+- alias: A/USD # Arbitrary alias for the price feed. It is used in enhance logging.
+  ...
+  # If provided, only early update this price feed if at least one of the listed triggering conditions is met.
+  early_update:
+    time_difference: 30
+    price_deviation: 0.1
+    confidence_ratio: 0.5
+```
+
 Two sample YAML configuration files are available in the root of this repo.
 
 You can get the list of available price feeds from

+ 1 - 1
price_pusher/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/price-pusher",
-  "version": "5.7.1",
+  "version": "6.0.0",
   "description": "Pyth Price Pusher",
   "homepage": "https://pyth.network",
   "main": "lib/index.js",

+ 10 - 0
price_pusher/src/price-config.ts

@@ -35,6 +35,13 @@ export type PriceConfig = {
 
   // An early update happens when another price has met the conditions to be pushed, so this
   // price can be included in a batch update for minimal gas cost.
+  // By default, every price feed will be early updated in a batch if any other price update triggers
+  // the conditions. This configuration will typically minimize gas usage.
+  //
+  // However, if you would like to customize this behavior, set `customEarlyUpdate: true` in your config
+  // for the price feed, then set the specific conditions (time / price / confidence) under which you would
+  // like the early update to trigger.
+  customEarlyUpdate: boolean | undefined;
   earlyUpdateTimeDifference: DurationInSeconds | undefined;
   earlyUpdatePriceDeviation: PctNumber | undefined;
   earlyUpdateConfidenceRatio: PctNumber | undefined;
@@ -56,6 +63,7 @@ export function readPriceConfigFile(path: string): PriceConfig[] {
       priceDeviation: priceConfigRaw.price_deviation,
       confidenceRatio: priceConfigRaw.confidence_ratio,
 
+      customEarlyUpdate: priceConfigRaw.early_update !== undefined,
       earlyUpdateTimeDifference: priceConfigRaw.early_update?.time_difference,
       earlyUpdatePriceDeviation: priceConfigRaw.early_update?.price_deviation,
       earlyUpdateConfidenceRatio: priceConfigRaw.early_update?.confidence_ratio,
@@ -139,6 +147,8 @@ export function shouldUpdate(
   ) {
     return UpdateCondition.YES;
   } else if (
+    priceConfig.customEarlyUpdate === undefined ||
+    !priceConfig.customEarlyUpdate ||
     (priceConfig.earlyUpdateTimeDifference !== undefined &&
       timeDifference >= priceConfig.earlyUpdateTimeDifference) ||
     (priceConfig.earlyUpdatePriceDeviation !== undefined &&