Skip to content

Commit fb4c254

Browse files
author
Dev Kalra
authored
[fortuna] improve logging and update uri encoding (#1317)
* [fortuna] improve logging * update version * update uri encoding
1 parent f22c0c8 commit fb4c254

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

fortuna/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.

fortuna/Cargo.toml

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

66
[dependencies]

fortuna/src/command/register_provider.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use {
99
},
1010
anyhow::Result,
1111
ethers::{
12+
abi::Bytes,
1213
signers::{
1314
LocalWallet,
1415
Signer,
@@ -60,7 +61,9 @@ pub async fn register_provider(opts: &RegisterProviderOptions) -> Result<()> {
6061
commitment,
6162
bincode::serialize(&commitment_metadata)?.into(),
6263
commitment_length,
63-
bincode::serialize(&opts.uri)?.into(),
64+
// Use Bytes to serialize the uri. Most users will be using JS/TS to deserialize this uri.
65+
// Bincode is a different encoding mechanisms, and I didn't find any JS/TS library to parse bincode.
66+
Bytes::from(opts.uri.as_str()).into(),
6467
);
6568
let mut gas_estimate = call.estimate_gas().await?;
6669
let gas_multiplier = U256::from(2); //TODO: smarter gas estimation

fortuna/src/command/setup_provider.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ use {
1717
},
1818
},
1919
anyhow::Result,
20-
ethers::signers::{
21-
LocalWallet,
22-
Signer,
20+
ethers::{
21+
abi::Bytes as AbiBytes,
22+
signers::{
23+
LocalWallet,
24+
Signer,
25+
},
26+
types::Bytes,
2327
},
2428
std::sync::Arc,
2529
};
@@ -40,22 +44,25 @@ pub async fn setup_provider(opts: &SetupProviderOptions) -> Result<()> {
4044
// Initialize a Provider to interface with the EVM contract.
4145
let contract =
4246
Arc::new(SignablePythContract::from_config(&chain_config, &private_key).await?);
47+
48+
tracing::info!("{}: fetching provider info", chain_id);
4349
let provider_info = contract.get_provider_info(provider_address).call().await?;
44-
tracing::info!("Provider info: {:?}", provider_info);
50+
tracing::info!("{0}: provider info: {1:?}", chain_id, provider_info);
4551

4652
let mut register = false;
4753

4854
let uri = get_register_uri(&opts.base_uri, &chain_id)?;
55+
let uri_as_bytes: Bytes = AbiBytes::from(uri.as_str()).into();
4956

5057
// This condition satisfies for both when there is no registration and when there are no
5158
// more random numbers left to request
5259
if provider_info.end_sequence_number <= provider_info.sequence_number {
5360
tracing::info!(
54-
"endSequenceNumber <= sequenceNumber. endSequenceNumber={0}, sequenceNumber={1}",
61+
"{0}: endSequenceNumber <= sequenceNumber. endSequenceNumber={1}, sequenceNumber={2}",
62+
chain_id,
5563
provider_info.end_sequence_number,
5664
provider_info.sequence_number
5765
);
58-
tracing::info!("Registering to {}", &chain_id);
5966
register = true;
6067
} else {
6168
let metadata =
@@ -80,13 +87,16 @@ pub async fn setup_provider(opts: &SetupProviderOptions) -> Result<()> {
8087
if chain_state.reveal(provider_info.original_commitment_sequence_number)?
8188
!= provider_info.original_commitment
8289
{
83-
tracing::info!("The root of the generated hash chain for chain id {} does not match the commitment", &chain_id);
84-
tracing::info!("Registering to {}", &chain_id);
90+
tracing::info!(
91+
"{}: the root of the generated hash chain does not match the commitment",
92+
&chain_id
93+
);
8594
register = true;
8695
}
8796
}
8897

8998
if register {
99+
tracing::info!("{}: registering", &chain_id);
90100
register_provider(&RegisterProviderOptions {
91101
config: opts.config.clone(),
92102
chain_id: chain_id.clone(),
@@ -96,22 +106,25 @@ pub async fn setup_provider(opts: &SetupProviderOptions) -> Result<()> {
96106
uri,
97107
})
98108
.await?;
109+
tracing::info!("{}: registered", &chain_id);
99110
} else {
100111
if provider_info.fee_in_wei != opts.fee {
112+
tracing::info!("{}: updating provider fee", chain_id);
101113
if let Some(r) = contract.set_provider_fee(opts.fee).send().await?.await? {
102-
tracing::info!("Updated provider fee: {:?}", r);
114+
tracing::info!("{0}: updated provider fee: {1:?}", chain_id, r);
103115
}
104116
}
105117

106-
if bincode::deserialize::<String>(&provider_info.uri)? != uri {
118+
if &provider_info.uri != &uri_as_bytes {
119+
tracing::info!("{}: updating provider uri", chain_id);
107120
if let Some(receipt) = contract
108-
.set_provider_uri(bincode::serialize(&uri)?.into())
121+
.set_provider_uri(uri_as_bytes)
109122
.send()
110123
.await?
111124
.log_msg("Pending transfer hash")
112125
.await?
113126
{
114-
tracing::info!("Updated provider uri: {:?}", receipt);
127+
tracing::info!("{0}: updated provider uri: {1:?}", chain_id, receipt);
115128
}
116129
}
117130
}

0 commit comments

Comments
 (0)