Переглянути джерело

fix(pyth-lazer-agent): add back optional authorization_key

Mike Rolish 5 місяців тому
батько
коміт
b80ca8a00e

+ 3 - 3
apps/pyth-lazer-agent/Cargo.lock

@@ -250,9 +250,9 @@ dependencies = [
 
 [[package]]
 name = "bumpalo"
-version = "3.18.1"
+version = "3.19.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee"
+checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
 
 [[package]]
 name = "bytecheck"
@@ -1643,7 +1643,7 @@ dependencies = [
 
 [[package]]
 name = "pyth-lazer-agent"
-version = "0.1.0"
+version = "0.1.1"
 dependencies = [
  "anyhow",
  "backoff",

+ 1 - 1
apps/pyth-lazer-agent/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "pyth-lazer-agent"
-version = "0.1.0"
+version = "0.1.1"
 edition = "2024"
 
 [dependencies]

+ 1 - 0
apps/pyth-lazer-agent/src/config.rs

@@ -12,6 +12,7 @@ use url::Url;
 pub struct Config {
     pub listen_address: SocketAddr,
     pub relayer_urls: Vec<Url>,
+    pub authorization_token: Option<String>,
     #[derivative(Debug = "ignore")]
     pub publish_keypair_path: PathBuf,
     #[serde(with = "humantime_serde", default = "default_publish_interval")]

+ 11 - 1
apps/pyth-lazer-agent/src/lazer_publisher.rs

@@ -56,11 +56,20 @@ impl LazerPublisher {
             }
         };
 
+        let authorization_token =
+            if let Some(authorization_token) = config.authorization_token.clone() {
+                // If authorization_token is configured, use it.
+                authorization_token
+            } else {
+                // Otherwise, use the base64 pubkey.
+                BASE64_STANDARD.encode(signing_key.verifying_key().to_bytes())
+            };
+
         let (relayer_sender, _) = broadcast::channel(CHANNEL_CAPACITY);
         for url in config.relayer_urls.iter() {
             let mut task = RelayerSessionTask {
                 url: url.clone(),
-                token: BASE64_STANDARD.encode(signing_key.verifying_key().to_bytes()),
+                token: authorization_token.clone(),
                 receiver: relayer_sender.subscribe(),
             };
             tokio::spawn(async move { task.run().await });
@@ -203,6 +212,7 @@ mod tests {
         let config = Config {
             listen_address: "0.0.0.0:12345".parse().unwrap(),
             relayer_urls: vec![Url::parse("http://127.0.0.1:12346").unwrap()],
+            authorization_token: None,
             publish_keypair_path: PathBuf::from(signing_key_file.path()),
             publish_interval_duration: Duration::from_millis(25),
         };