Skip to content

feat: publish signed Lazer transactions #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2025
Merged

Conversation

merolish
Copy link
Contributor

Initial attempt at publishing a SignedLazerTransaction on each publish interval..

@merolish merolish requested a review from darunrs April 23, 2025 18:26
@merolish merolish changed the title feat: published signed Lazer transactions feat: publish signed Lazer transactions Apr 23, 2025
Comment on lines 261 to 265
let publisher_timestamp = MessageField::some(Timestamp {
seconds: now / 1_000_000,
nanos: (now % 1_000_000 * 1000) as i32,
special_fields: Default::default(),
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this multiple times in different locations. Maybe we add it to the sdk (if it's not there yet) and re use it.
@darunrs @Riateche

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I didn't see any adapters/helpers in rust-protobuf so just a matter of hooking up our own.

Copy link

@darunrs darunrs Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do Timestamp::now() and it will automatically make one with the current time. MessageField::some(Timestamp::now()) is not wordy at that point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaaaahhh it's in well_known_types_util/timestamp.rs instead of well_known_types/timestamp.rs where the struct is defined. I hate hate hate this about Rust, there's no actual class interface in the code and so you end up having to dig through docs.rs which I don't find terribly ergonomic.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@darunrs darunrs Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think new() also works. Best to use now() anyway though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just meant that in rust-protobuf the Timestamp::now() method is defined in a separate util module, wouldn't have thought to look for it elsewhere. And thanks for the helper, although I don't think I need to touch TimestampUs at all in agent.

@keyvankhademi
Copy link
Contributor

lgtm!

Copy link

@darunrs darunrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice start! There's a couple things that Pyth Agent will need to do:

  1. Receive Publisher Updates from a WS
  2. Collect, convert, and dedupe updates
  3. Batch updates into a payload on an interval
  4. Encode payload, sign payload, make transaction with encoded payload and signature
  5. Encode transaction and send it

Hopefully that helps you plan out abstractions and how to break code up!

pub authorization_token: String,
pub publisher_signing_key: Vec<u8>,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a new type or struct and don't derive Debug on it. We should then get errors if we ever try to print this. Add ignore debug here to make sure it's never printed.

tracing::error!("Error sending price update to relayer: {e:?}");
bail!("Failed to send price update to relayer: {e:?}");
}
let source_timestamp_micros = price_info.timestamp.and_utc().timestamp_micros();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type is this? There is an impl From for SystemTime. Otherwise, let's add a From for DateTime. Also, instead of UTC, convert to epoch instead. I am pretty sure thats still UTC but we should be explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a chrono::NaiveDateTime that is used in the existing local cache struct, so I didn't want to change it for now. If we extricate the pythnet part or rewrite from scratch then yeah, makes sense.

@merolish
Copy link
Contributor Author

In the agent 1 is done with an rpc interface and 2 is done by writing to a "local state" cache, so I'm not touching either at the moment. For 3 the "exporter" takes this latest cache of prices and batch publishes, so I'm following this pattern for now, just sending to the Lazer relayers instead of pythnet. We're just handling 3/4/5 here.

@merolish merolish merged commit 430ee06 into main Apr 24, 2025
@merolish merolish deleted the mike/lazer-publisher-sdk branch April 24, 2025 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants