-
Notifications
You must be signed in to change notification settings - Fork 18
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
Conversation
src/agent/services/lazer_exporter.rs
Outdated
let publisher_timestamp = MessageField::some(Timestamp { | ||
seconds: now / 1_000_000, | ||
nanos: (now % 1_000_000 * 1000) as i32, | ||
special_fields: Default::default(), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm? It is well_known_types/timestamp.rs
?
https://github.com/pyth-network/pyth-lazer/blob/main/internal-protocol/src/lib.rs#L1
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lgtm! |
There was a problem hiding this 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:
- Receive Publisher Updates from a WS
- Collect, convert, and dedupe updates
- Batch updates into a payload on an interval
- Encode payload, sign payload, make transaction with encoded payload and signature
- Encode transaction and send it
Hopefully that helps you plan out abstractions and how to break code up!
src/agent/services/lazer_exporter.rs
Outdated
pub authorization_token: String, | ||
pub publisher_signing_key: Vec<u8>, |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
Initial attempt at publishing a SignedLazerTransaction on each publish interval..