-
Notifications
You must be signed in to change notification settings - Fork 4
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
docs: documented network config #35
base: main
Are you sure you want to change the base?
Conversation
@akorchyn Thank you for your contribution! Your pull request is now a part of the Race of Sloths! Current status: waiting for merge
Your contribution is much appreciated with a final score of 5! @dj8yfo received 25 Sloth Points for reviewing and scoring this pull request. What is the Race of SlothsRace of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow For contributors:
For maintainers:
Feel free to check our website for additional details! Bot commands
|
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.
@race-of-sloths score 5
pub api_key: Option<crate::types::ApiKey>, | ||
/// Number of consecutive failures to move on to the next endpoint. | ||
pub retries: u8, | ||
/// Whether to use exponential backoff between retries | ||
/// | ||
/// The formula is `d = initial_sleep * factor^retry` |
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.
it's left unspecified what backoff behaviour will look like if exponential_backoff
is false.
it can be defined more accurately with a doc comment or
by using an enum like the following instead of exponential_backoff: bool
:
pub retry_algorithm: RetryAlgorithm,
....
pub enum RetryAlgorithm {
ExponentialBackoff {
initial_sleep: std::time::Duration,
factor: u8,
},
SomeOtherWay { ... },
}
pub exponential_backoff: bool, | ||
/// Multiplier for exponential backoff calculation | ||
pub factor: 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.
the backoff multiplier is somewhat simplejack instead of e.g. an f32
(where a factor can be 1.2f32
),
but this is not necessarily a bad thing
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.
Don't love floats, to be honest
pub linkdrop_account_id: Option<near_primitives::types::AccountId>, | ||
// https://docs.near.org/social/contract | ||
/// Account ID of the [NEAR Social contract](https://docs.near.org/social/contract) |
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.
link for NEAR Social contract appears to be broken
pub fn testnet() -> Self { | ||
Self { | ||
network_name: "testnet".to_string(), | ||
rpc_endpoints: vec![RPCEndpoint::testnet()], | ||
linkdrop_account_id: Some("testnet".parse().unwrap()), | ||
near_social_db_contract_account_id: Some("v1.social08.testnet".parse().unwrap()), | ||
faucet_url: Some("https://helper.nearprotocol.com/account".parse().unwrap()), | ||
meta_transaction_relayer_url: Some("http://localhost:3030/relay".parse().unwrap()), | ||
meta_transaction_relayer_url: None, |
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.
somewhat unrelated, but bon can be used here instead of ..NetworkConfig::mainnet()
syntax,
// $ cargo add bon
// bon = { version= "3.3.1", features = ["experimental-overwritable"]}
use bon::Builder;
use network_builder::{SetName, SetRpcStuff};
#[derive(Builder)]
struct Network {
name: String,
#[builder(overwritable)]
rpc_stuff: String,
}
impl Network {
pub fn testnet() -> NetworkBuilder<SetRpcStuff<SetName>> {
Self::builder()
.name("testnet".into())
.rpc_stuff("my_fast_near_rpc".to_string())
}
}
fn main() {
{
let network = Network::testnet().build();
assert_eq!(network.name, "testnet");
assert_eq!(network.rpc_stuff, "my_fast_near_rpc");
}
{
let network = Network::testnet()
.rpc_stuff("very_slow_another_rpc".to_owned())
.build();
assert_eq!(network.name, "testnet");
assert_eq!(network.rpc_stuff, "very_slow_another_rpc");
}
}
referencing elastio/bon#149 , as it links to experimental feature needed.
without experimental-overwritable
it kind of not possible to achieve the same with #[builder(default)]
on the same Network
type as there're different defaults for different networks
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.
but this crate being a lib, it won't be too great to use a dependency with experimental feature, which can break on minor releases,
though pinning it with ~3.3.1
(only patch releases updates allowed) or =3.3.1
(fully pinned) would allow to avoid problems for downstream consumers of the library
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.
To be honest, I don't really want ro pull some extra dep for that
Ideally is to remove as much deps as possible, and keep it as slim as possible
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.
If you were to use bon
builder for this, you could alternatively do it this way without the overwritable
feature:
// A `#[derive(bon::Builder)]` here isn't required, but it's not prohibited!
// If you want to have both `Network::builder()` for regular code and
// `Network::testnet()` for test code, then both can coexist just fine
struct Network {
name: String,
rpc_stuff: String,
}
// Define a builder using the method syntax.
// There can be as many builders with as many different defaults as you need
// for different use cases.
#[bon::bon]
impl Network {
#[builder]
pub fn testnet(
#[builder(default = "testnet".into())]
name: String,
#[builder(default = "my_fast_near_rpc".into())]
rpc_stuff: String,
) -> Self {
Self { name, rpc_stuff }
}
}
// Both of these work as expected
Network::testnet().build();
Network::testnet().rpc_stuff("very_slow_another_rpc".to_owned()).build();
// If you were to add `#[derive(bon::Builder)]`, you'd also have this one.
// Here you'd probably make both `name` and `rpc_stuff` required:
// Network::builder().name("foo".into()).rpc_stuff("bar".into()).build();
cc @dj8yfo
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.
@akorchyn well, this dependency has a useful function, it will be pulled in exactly for that and nothing more, it's really convenient to configure options with this stuff, i've tried. Besides Veetaha just showed how to do this with stable features of bon. Anyway, this was just a suggestion how stuff could be improved, not how it must be improved imo.
After having near-*-0.28 in, bon wouldn't be too much of additional weight, cannot compile near-workspaces tests --workspace with default number of builders, only small number -j2 works, othewise it hangs and is later killed with oom.
staking_pools_factory_account_id: None, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
/// Represents the possible outcomes of a retryable operation. | ||
pub enum RetryResponse<R, E> { |
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 type doesn't really bubble up to be eventually visible in documentation, does it
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.
For now, I just not really sure if it's needed to be public. But I kept documentation just in case I will decide to make it public
/// | ||
/// # Arguments | ||
/// * `network` - The network configuration to use for the retryable operation. | ||
/// * `task` - The task to retry. | ||
pub async fn retry<R, E, T, F>(network: NetworkConfig, mut task: F) -> Result<R, RetryError<E>> |
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.
same here, it doesn't really show up in documentation
@race-of-sloths