Skip to content

Commit 6eb3701

Browse files
committed
feat: support decimal rpc weights
1 parent 1b04a9f commit 6eb3701

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

chain/ethereum/src/network.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct EthereumNetworkAdapter {
3131
/// that limit. That's a somewhat imprecise but convenient way to
3232
/// determine the number of connections
3333
limit: SubgraphLimit,
34-
weight: usize,
34+
weight: f64,
3535
}
3636

3737
#[async_trait]
@@ -55,7 +55,7 @@ impl EthereumNetworkAdapter {
5555
capabilities: NodeCapabilities,
5656
adapter: Arc<EthereumAdapter>,
5757
limit: SubgraphLimit,
58-
weight: usize,
58+
weight: f64,
5959
) -> Self {
6060
Self {
6161
endpoint_metrics,

node/src/config.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ impl ChainSection {
508508
headers: Default::default(),
509509
rules: vec![],
510510
}),
511-
weight: 1,
511+
weight: 1.0,
512512
};
513513
let entry = chains.entry(name.to_string()).or_insert_with(|| Chain {
514514
shard: PRIMARY_SHARD.to_string(),
@@ -608,8 +608,8 @@ fn btree_map_to_http_headers(kvs: BTreeMap<String, String>) -> HeaderMap {
608608
pub struct Provider {
609609
pub label: String,
610610
pub details: ProviderDetails,
611-
#[serde(default = "one")]
612-
pub weight: usize,
611+
#[serde(default = "one_f64")]
612+
pub weight: f64,
613613
}
614614

615615
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
@@ -734,8 +734,8 @@ const DEFAULT_PROVIDER_FEATURES: [&str; 2] = ["traces", "archive"];
734734
impl Provider {
735735
fn validate(&mut self) -> Result<()> {
736736
validate_name(&self.label).context("illegal provider name")?;
737-
if self.weight == 0 {
738-
bail!("provider {} must have a weight greater than 0", self.label);
737+
if self.weight < 0.0 || self.weight > 1.0 {
738+
bail!("provider {} must have a weight between 0 and 1", self.label);
739739
}
740740

741741
match self.details {
@@ -925,7 +925,7 @@ impl<'de> Deserialize<'de> for Provider {
925925
Ok(Provider {
926926
label,
927927
details,
928-
weight: weight.unwrap_or(1),
928+
weight: weight.unwrap_or(1.0),
929929
})
930930
}
931931
}
@@ -1186,6 +1186,10 @@ fn one() -> usize {
11861186
1
11871187
}
11881188

1189+
fn one_f64() -> f64 {
1190+
1.0
1191+
}
1192+
11891193
fn default_node_id() -> NodeId {
11901194
NodeId::new("default").unwrap()
11911195
}
@@ -1332,7 +1336,7 @@ mod tests {
13321336
headers: HeaderMap::new(),
13331337
rules: Vec::new(),
13341338
}),
1335-
weight: 1,
1339+
weight: 1.0,
13361340
},
13371341
actual
13381342
);
@@ -1359,7 +1363,7 @@ mod tests {
13591363
headers: HeaderMap::new(),
13601364
rules: Vec::new(),
13611365
}),
1362-
weight: 1,
1366+
weight: 1.0,
13631367
},
13641368
actual
13651369
);
@@ -1467,7 +1471,7 @@ mod tests {
14671471
headers,
14681472
rules: Vec::new(),
14691473
}),
1470-
weight: 1,
1474+
weight: 1.0,
14711475
},
14721476
actual
14731477
);
@@ -1493,7 +1497,7 @@ mod tests {
14931497
headers: HeaderMap::new(),
14941498
rules: Vec::new(),
14951499
}),
1496-
weight: 1,
1500+
weight: 1.0,
14971501
},
14981502
actual
14991503
);
@@ -1535,7 +1539,7 @@ mod tests {
15351539
conn_pool_size: 20,
15361540
rules: vec![],
15371541
}),
1538-
weight: 1,
1542+
weight: 1.0,
15391543
},
15401544
actual
15411545
);
@@ -1562,7 +1566,7 @@ mod tests {
15621566
conn_pool_size: 20,
15631567
rules: vec![],
15641568
}),
1565-
weight: 1,
1569+
weight: 1.0,
15661570
},
15671571
actual
15681572
);
@@ -1589,7 +1593,7 @@ mod tests {
15891593
conn_pool_size: 20,
15901594
rules: vec![],
15911595
}),
1592-
weight: 1,
1596+
weight: 1.0,
15931597
},
15941598
actual
15951599
);
@@ -1616,7 +1620,7 @@ mod tests {
16161620
conn_pool_size: 20,
16171621
rules: vec![],
16181622
}),
1619-
weight: 1,
1623+
weight: 1.0,
16201624
},
16211625
actual
16221626
);
@@ -1656,7 +1660,7 @@ mod tests {
16561660
}
16571661
],
16581662
}),
1659-
weight: 1,
1663+
weight: 1.0,
16601664
},
16611665
actual
16621666
);
@@ -1696,7 +1700,7 @@ mod tests {
16961700
}
16971701
],
16981702
}),
1699-
weight: 1,
1703+
weight: 1.0,
17001704
},
17011705
actual
17021706
);
@@ -1736,7 +1740,7 @@ mod tests {
17361740
}
17371741
],
17381742
}),
1739-
weight: 1,
1743+
weight: 1.0,
17401744
},
17411745
actual
17421746
);
@@ -1776,7 +1780,7 @@ mod tests {
17761780
}
17771781
],
17781782
}),
1779-
weight: 1,
1783+
weight: 1.0,
17801784
},
17811785
actual
17821786
);
@@ -1871,7 +1875,7 @@ mod tests {
18711875
headers: HeaderMap::new(),
18721876
rules: Vec::new(),
18731877
}),
1874-
weight: 1,
1878+
weight: 1.0,
18751879
},
18761880
actual
18771881
);

0 commit comments

Comments
 (0)