-
Notifications
You must be signed in to change notification settings - Fork 791
Conversation
for RPC calls that take a block height we need to ensure that all providers request info at the same height, preferably the minimum height across all providers this is like, |
Good point, |
ff60c0f
to
8d324ca
Compare
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.
In general LGTM. I think it'd be useful if we also had an integration test in the middleware crate showing that Streams / Subscriptions work when paired with 1 Infura and 1 Alchemy node
total / 2 + rem | ||
} | ||
Quorum::Percentage(p) => { | ||
providers.iter().map(|p| p.weight).sum::<u64>() * (p as u64) / 100 |
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.
Maybe add a if p > 100 { panic!() }
here?
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let this = self.get_mut(); | ||
for n in (0..this.requests.len()).rev() { |
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.
Why are we iterating in reverse here?
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.
because how swap_remove works, which replaces the removed element with the last element. but this also means that if we'd start at 0
we would miss the value at the last index, therefor we need to start at the last index.
use crate::{Middleware, MockProvider, Provider}; | ||
use ethers_core::types::U64; | ||
|
||
async fn test_quorum(q: Quorum) { |
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 usage of the mock provider
Motivation
Support multiple provider endpoints
Solution
Adds the
QuorumProvider
type that can run internal multiple providers internally and only returns a response if a quorum was reached. The internal providers can be weighted.This required two Wrapper traits for
JsonRpcClient
PubsubClient
to get rid of the generic types.How a quorum is reached can be configured with
Quorum
, default isQuorum::Majority
which reaches a quorum if >50% of the weighted providers returned the same value