Skip to content

Commit c76ccc4

Browse files
authored
refactor: improve price cap configuration (#101)
1 parent 533520a commit c76ccc4

File tree

6 files changed

+21
-28
lines changed

6 files changed

+21
-28
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-agent"
3-
version = "2.4.2"
3+
version = "2.4.3"
44
edition = "2021"
55

66
[[bin]]

config/config.sample.pythnet.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,8 @@ exporter.compute_unit_limit = 20000
5858
# during periods of high network congestion.
5959
exporter.dynamic_compute_unit_pricing_enabled = true
6060

61-
# Maximum slot gap between the current slot and the oldest slot amongst all the accounts in
62-
# the batch. This is used to calculate the dynamic price per compute unit. When the slot gap
63-
# reaches this number we will use the maximum total_compute_fee for the transaction.
64-
exporter.maximum_slot_gap_for_dynamic_compute_unit_price = 40
65-
66-
# The interval with which to poll account information. We are adding it as an extra
67-
# layer of protection to ensure we get the latest account information if there are
68-
# any issues with the ws subscription.
69-
oracle.poll_interval_duration = "5s"
61+
# Price per compute unit offered for update_price transactions
62+
exporter.compute_unit_price_micro_lamports = 1000
7063

7164
# Configuration for the JRPC API
7265
[pythd_adapter]

config/config.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ key_store.mapping_key = "RelevantOracleMappingAddress"
8383
# calculated based on the network previous prioritization fees.
8484
# exporter.dynamic_compute_unit_pricing_enabled = false
8585

86-
# Maximum total compute unit fee paid for a single transaction. Defaults to 0.001 SOL. This
87-
# is a safety measure while using dynamic compute price to prevent the exporter from paying
88-
# too much for a single transaction. The default is 10**12 micro lamports (0.001 SOL).
89-
# exporter.maximum_total_compute_fee_micro_lamports = 1000000000000
86+
# Maximum compute unit price offered for update_price transactions. Defaults to
87+
# 1 million microlamports. This is a safety measure while using dynamic compute
88+
# price to prevent the exporter from paying too much for a single transaction.
89+
# exporter.maximum_compute_unit_price_micro_lamports = 1000000
9090

9191
# Maximum slot gap between the current slot and the oldest slot amongst all the accounts in
9292
# the batch. This is used to calculate the dynamic price per compute unit. When the slot gap

src/agent/solana/exporter.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub struct Config {
135135
/// Maximum total compute unit fee paid for a single transaction. Defaults to 0.001 SOL. This
136136
/// is a safety measure while using dynamic compute price to prevent the exporter from paying
137137
/// too much for a single transaction
138-
pub maximum_total_compute_fee_micro_lamports: u64,
138+
pub maximum_compute_unit_price_micro_lamports: u64,
139139
/// Maximum slot gap between the current slot and the oldest slot amongst all the accounts in
140140
/// the batch. This is used to calculate the dynamic price per compute unit. When the slot gap
141141
/// reaches this number we will use the maximum total_compute_fee for the transaction.
@@ -156,12 +156,12 @@ impl Default for Config {
156156
compute_unit_limit: 40000,
157157
compute_unit_price_micro_lamports: None,
158158
dynamic_compute_unit_pricing_enabled: false,
159-
// Maximum total compute unit fee paid for a single transaction (0.00003 SOL)
160-
maximum_total_compute_fee_micro_lamports: 30_000_000_000,
159+
// Maximum compute unit price (as a cap on the dynamic price)
160+
maximum_compute_unit_price_micro_lamports: 1_000_000,
161161
// A publisher update is not included if it is 25 slots behind the current slot.
162-
// Due to the delay in the network (until a block gets confirmed) we add 5 slots
163-
// to make sure we do not overpay.
164-
maximum_slot_gap_for_dynamic_compute_unit_price: 30,
162+
// Due to the delay in the network (until a block gets confirmed) and potential
163+
// ws issues we add 15 slots to make sure we do not overpay.
164+
maximum_slot_gap_for_dynamic_compute_unit_price: 40,
165165
}
166166
}
167167
}
@@ -710,17 +710,14 @@ impl Exporter {
710710
// keep the uptime high during congestion whereas without it we would publish price after a
711711
// large gap and then we can publish it again after the next large gap.
712712
if self.config.dynamic_compute_unit_pricing_enabled {
713-
let maximum_unit_price =
714-
self.config.maximum_total_compute_fee_micro_lamports / total_compute_limit as u64;
715-
716713
// Use the estimated previous price if it is higher
717714
// than the current price.
718715
if let Some(estimated_recent_price) = self.recent_compute_unit_price_micro_lamports {
719716
// Get the estimated compute unit price and wrap it so it stays below the maximum
720717
// total compute unit fee. We additionally divide such price by 2 to create an
721718
// exponential decay. This will make sure that a spike doesn't get propagated
722719
// forever.
723-
let estimated_price = (estimated_recent_price >> 1).min(maximum_unit_price);
720+
let estimated_price = estimated_recent_price >> 1;
724721

725722
compute_unit_price_micro_lamports = compute_unit_price_micro_lamports
726723
.map(|price| price.max(estimated_price))
@@ -770,7 +767,7 @@ impl Exporter {
770767
// 15 : 3_906
771768
// 13 : 976
772769
// 10 : 122
773-
let exponential_price = maximum_unit_price
770+
let exponential_price = self.config.maximum_compute_unit_price_micro_lamports
774771
>> self
775772
.config
776773
.maximum_slot_gap_for_dynamic_compute_unit_price
@@ -782,7 +779,10 @@ impl Exporter {
782779
}
783780
}
784781

785-
if let Some(compute_unit_price_micro_lamports) = compute_unit_price_micro_lamports {
782+
if let Some(mut compute_unit_price_micro_lamports) = compute_unit_price_micro_lamports {
783+
compute_unit_price_micro_lamports = compute_unit_price_micro_lamports
784+
.min(self.config.maximum_compute_unit_price_micro_lamports);
785+
786786
debug!(self.logger, "setting compute unit price"; "unit_price" => compute_unit_price_micro_lamports);
787787
instructions.push(ComputeBudgetInstruction::set_compute_unit_price(
788788
compute_unit_price_micro_lamports,

src/agent/solana/oracle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Default for Config {
121121
fn default() -> Self {
122122
Self {
123123
commitment: CommitmentLevel::Confirmed,
124-
poll_interval_duration: Duration::from_secs(2 * 60),
124+
poll_interval_duration: Duration::from_secs(5),
125125
subscriber_enabled: true,
126126
updates_channel_capacity: 10000,
127127
data_channel_capacity: 10000,

0 commit comments

Comments
 (0)