Filter and sort upstreams if latest (#476)

This commit is contained in:
KirillPamPam
2024-05-15 14:50:24 +04:00
committed by GitHub
parent de4e16309b
commit b468b4039d
12 changed files with 90 additions and 60 deletions

View File

@@ -80,7 +80,7 @@ class NativeCallSpec extends Specification {
def nativeCall = nativeCall()
def ctx = new NativeCall.ValidCallContext<NativeCall.ParsedCallDetails>(
1, null, upstream, Selector.empty, new AlwaysQuorum(),
1, null, upstream, new Selector.UpstreamFilter(Selector.empty), new AlwaysQuorum(),
new NativeCall.ParsedCallDetails("eth_test", new ListParams()), "reqId", 1
)
@@ -101,7 +101,7 @@ class NativeCallSpec extends Specification {
def nativeCall = nativeCall()
def ctx = new NativeCall.ValidCallContext<NativeCall.ParsedCallDetails>(
15, null, upstream, Selector.empty, new AlwaysQuorum(),
15, null, upstream, new Selector.UpstreamFilter(Selector.empty), new AlwaysQuorum(),
new NativeCall.ParsedCallDetails("eth_test", new ListParams()), "reqId", 1
)
@@ -126,7 +126,7 @@ class NativeCallSpec extends Specification {
1 * read(_) >> Mono.just(new RequestReader.Result("\"foo\"".bytes, null, 1, new Upstream.UpstreamSettingsData((byte)1, "test", "v"), null))
}
}
def call = new NativeCall.ValidCallContext(1, 10, TestingCommons.multistream(TestingCommons.api()), Selector.empty, quorum,
def call = new NativeCall.ValidCallContext(1, 10, TestingCommons.multistream(TestingCommons.api()), new Selector.UpstreamFilter(Selector.empty), quorum,
new NativeCall.ParsedCallDetails("eth_test", new ListParams()), "reqId", 1)
when:
@@ -148,7 +148,7 @@ class NativeCallSpec extends Specification {
1 * read(new ChainRequest("eth_test", new ListParams(), 10)) >> Mono.empty()
}
}
def call = new NativeCall.ValidCallContext(1, 10, TestingCommons.multistream(TestingCommons.api()), Selector.empty, quorum,
def call = new NativeCall.ValidCallContext(1, 10, TestingCommons.multistream(TestingCommons.api()), new Selector.UpstreamFilter(Selector.empty), quorum,
new NativeCall.ParsedCallDetails("eth_test", new ListParams()), "reqId", 1)
when:
@@ -174,7 +174,7 @@ class NativeCallSpec extends Specification {
)
}
}
def call = new NativeCall.ValidCallContext(12, 10, TestingCommons.multistream(TestingCommons.api()), Selector.empty, quorum,
def call = new NativeCall.ValidCallContext(12, 10, TestingCommons.multistream(TestingCommons.api()), new Selector.UpstreamFilter(Selector.empty), quorum,
new NativeCall.ParsedCallDetails("eth_test", new ListParams()), "reqId", 1)
when:
@@ -420,9 +420,9 @@ class NativeCallSpec extends Specification {
def act = nativeCall.prepareCall(req, multistream)
.collectList().block(Duration.ofSeconds(1)).first()
then:
act.matcher != null
act.matcher instanceof Selector.MultiMatcher
with((Selector.MultiMatcher) act.matcher) {
act.upstreamFilter.matcher != null
act.upstreamFilter.matcher instanceof Selector.MultiMatcher
with((Selector.MultiMatcher) act.upstreamFilter.matcher) {
it.getMatchers().size() >= 1
it.getMatcher(Selector.HeightMatcher) != null
with(it.getMatcher(Selector.HeightMatcher)) {
@@ -528,7 +528,7 @@ class NativeCallSpec extends Specification {
def "Parse empty params"() {
setup:
def nativeCall = nativeCall()
def ctx = new NativeCall.ValidCallContext(1, null, Stub(Multistream), Selector.empty, new AlwaysQuorum(),
def ctx = new NativeCall.ValidCallContext(1, null, Stub(Multistream), new Selector.UpstreamFilter(Selector.empty), new AlwaysQuorum(),
new NativeCall.ParsedCallDetails("eth_test", new ListParams()), "reqId", 1)
when:
def act = nativeCall.parseParams(ctx)
@@ -541,7 +541,7 @@ class NativeCallSpec extends Specification {
def "Parse none params"() {
setup:
def nativeCall = nativeCall()
def ctx = new NativeCall.ValidCallContext(1, null, Stub(Multistream), Selector.empty, new AlwaysQuorum(),
def ctx = new NativeCall.ValidCallContext(1, null, Stub(Multistream), new Selector.UpstreamFilter(Selector.empty), new AlwaysQuorum(),
new NativeCall.ParsedCallDetails("eth_test", new ListParams()), "reqId", 1)
when:
def act = nativeCall.parseParams(ctx)
@@ -554,7 +554,7 @@ class NativeCallSpec extends Specification {
def "Parse single param"() {
setup:
def nativeCall = nativeCall()
def ctx = new NativeCall.ValidCallContext(1, null, Stub(Multistream), Selector.empty, new AlwaysQuorum(),
def ctx = new NativeCall.ValidCallContext(1, null, Stub(Multistream), new Selector.UpstreamFilter(Selector.empty), new AlwaysQuorum(),
new NativeCall.ParsedCallDetails("eth_test", new ListParams(false)), "reqId", 1)
when:
def act = nativeCall.parseParams(ctx)
@@ -567,7 +567,7 @@ class NativeCallSpec extends Specification {
def "Parse multi param"() {
setup:
def nativeCall = nativeCall()
def ctx = new NativeCall.ValidCallContext(1, null, Stub(Multistream), Selector.empty, new AlwaysQuorum(),
def ctx = new NativeCall.ValidCallContext(1, null, Stub(Multistream), new Selector.UpstreamFilter(Selector.empty), new AlwaysQuorum(),
new NativeCall.ParsedCallDetails("eth_test", new ListParams(false, 123)), "reqId", 1)
when:
def act = nativeCall.parseParams(ctx)
@@ -580,7 +580,7 @@ class NativeCallSpec extends Specification {
def "Decorate eth_getFilterUpdates params"() {
setup:
def nativeCall = nativeCall()
def ctx = new NativeCall.ValidCallContext(1, null, Stub(Multistream), Selector.empty, new AlwaysQuorum(),
def ctx = new NativeCall.ValidCallContext(1, null, Stub(Multistream), new Selector.UpstreamFilter(Selector.empty), new AlwaysQuorum(),
new NativeCall.ParsedCallDetails("eth_getFilterUpdates", new ListParams("0xabcd")),
new NativeCall.WithFilterIdDecorator(), new NativeCall.NoneResultDecorator(), null, false, "reqId", 1)
when:
@@ -612,7 +612,7 @@ class NativeCallSpec extends Specification {
1 * read(_) >> Mono.just(new RequestReader.Result("\"0xab\"".bytes, null, 1, new Upstream.UpstreamSettingsData((byte) 255, "", ""), null))
}
}
def call = new NativeCall.ValidCallContext(1, 10, multistream, Selector.empty, quorum,
def call = new NativeCall.ValidCallContext(1, 10, multistream, new Selector.UpstreamFilter(Selector.empty), quorum,
new NativeCall.ParsedCallDetails("eth_getFilterChanges", new ListParams()),
new NativeCall.WithFilterIdDecorator(), new NativeCall.CreateFilterDecorator(), null, false, "reqId", 1)
@@ -645,7 +645,7 @@ class NativeCallSpec extends Specification {
1 * read(_) >> Mono.just(new RequestReader.Result("\"0xab\"".bytes, null, 1, new Upstream.UpstreamSettingsData((byte) 1, "", ""), null))
}
}
def call = new NativeCall.ValidCallContext(1, 10, multistream, Selector.empty, quorum,
def call = new NativeCall.ValidCallContext(1, 10, multistream, new Selector.UpstreamFilter(Selector.empty), quorum,
new NativeCall.ParsedCallDetails("eth_getFilterChanges", new ListParams()),
new NativeCall.WithFilterIdDecorator(), new NativeCall.CreateFilterDecorator(), null, false, "reqId", 1)
@@ -667,7 +667,7 @@ class NativeCallSpec extends Specification {
def ctx = new NativeCall.ValidCallContext<NativeCall.ParsedCallDetails>(10, null,
upstream,
Selector.empty, new AlwaysQuorum(),
new Selector.UpstreamFilter(Selector.empty), new AlwaysQuorum(),
new NativeCall.ParsedCallDetails("eth_test", new ListParams()), "reqId", 1)
when:
nativeCall.fetch(ctx)
@@ -684,7 +684,7 @@ class NativeCallSpec extends Specification {
def ctx = new NativeCall.ValidCallContext<NativeCall.ParsedCallDetails>(10, null,
upstream,
Selector.empty, new AlwaysQuorum(),
new Selector.UpstreamFilter(Selector.empty), new AlwaysQuorum(),
new NativeCall.ParsedCallDetails("eth_test", new ListParams()), "reqId", 1)
when:
def act = nativeCall.fetch(ctx)

View File

@@ -86,7 +86,7 @@ class FilteredApisSpec extends Specification {
it.setStatus(UpstreamAvailability.OK)
}
when:
def iter = new FilteredApis(Chain.ETHEREUM__MAINNET, upstreams, matcher, 0, 0)
def iter = new FilteredApis(Chain.ETHEREUM__MAINNET, upstreams, matcher, 0, 0, Selector.Sort.default)
iter.request(10)
then:
StepVerifier.create(iter)
@@ -97,7 +97,7 @@ class FilteredApisSpec extends Specification {
.verify(Duration.ofSeconds(1))
when:
iter = new FilteredApis(Chain.ETHEREUM__MAINNET, upstreams, matcher, 1, 0)
iter = new FilteredApis(Chain.ETHEREUM__MAINNET, upstreams, matcher, 1, 0, Selector.Sort.default)
iter.request(10)
then:
StepVerifier.create(iter)
@@ -108,7 +108,7 @@ class FilteredApisSpec extends Specification {
.verify(Duration.ofSeconds(1))
when:
iter = new FilteredApis(Chain.ETHEREUM__MAINNET, upstreams, matcher, 1, 2)
iter = new FilteredApis(Chain.ETHEREUM__MAINNET, upstreams, matcher, 1, 2, Selector.Sort.default)
iter.request(10)
then:
StepVerifier.create(iter)
@@ -134,7 +134,7 @@ class FilteredApisSpec extends Specification {
TestingCommons.upstream(it)
}
when:
def act = new FilteredApis(Chain.ETHEREUM__MAINNET, ups, Selector.empty, 2, 0)
def act = new FilteredApis(Chain.ETHEREUM__MAINNET, ups, Selector.empty, 2, 0, Selector.Sort.default)
act.request(10)
then:
StepVerifier.create(act)
@@ -153,7 +153,7 @@ class FilteredApisSpec extends Specification {
TestingCommons.upstream(it)
}
when:
def act = new FilteredApis(Chain.ETHEREUM__MAINNET, ups, Selector.empty, 2, 0)
def act = new FilteredApis(Chain.ETHEREUM__MAINNET, ups, Selector.empty, 2, 0, Selector.Sort.default)
act.request(3)
then:
StepVerifier.create(act)
@@ -212,7 +212,7 @@ class FilteredApisSpec extends Specification {
when:
def act = new FilteredApis(Chain.ETHEREUM__MAINNET,
[] + fallback + standard,
Selector.empty, 0, 1)
Selector.empty, 0, 1, Selector.Sort.default)
act.request(10)
then:
StepVerifier.create(act)
@@ -248,7 +248,7 @@ class FilteredApisSpec extends Specification {
when:
def act = new FilteredApis(Chain.ETHEREUM__MAINNET,
[] + fallback + standard + secondary,
Selector.empty, 0, 2)
Selector.empty, 0, 2, Selector.Sort.default)
act.request(11)
then:
StepVerifier.create(act)
@@ -285,7 +285,7 @@ class FilteredApisSpec extends Specification {
when:
def act = new FilteredApis(Chain.ETHEREUM__MAINNET,
[] + lagging + ok,
Selector.empty, 0, 1)
Selector.empty, 0, 1, Selector.Sort.default)
act.request(4)
then:
StepVerifier.create(act)

View File

@@ -42,9 +42,9 @@ class SelectorSpec extends Specification {
)
.build()
when:
def act = Selector.convertToMatcher(List.of(slotHeightSelector), Stub(Head))
def act = Selector.convertToUpstreamFilter(List.of(slotHeightSelector))
then:
act == new Selector.MultiMatcher(List.of(new Selector.SlotMatcher(10000)))
act.matcher == new Selector.MultiMatcher(List.of(new Selector.SlotMatcher(10000)))
}
def "Convert height selector"() {
@@ -57,16 +57,13 @@ class SelectorSpec extends Specification {
)
.build()
when:
def act = Selector.convertToMatcher(List.of(heightSelector), Stub(Head))
def act = Selector.convertToUpstreamFilter(List.of(heightSelector))
then:
act == new Selector.MultiMatcher(List.of(new Selector.HeightMatcher(10000)))
act.matcher == new Selector.MultiMatcher(List.of(new Selector.HeightMatcher(10000)))
}
def "Convert height selector with latest"() {
setup:
def head = Mock(Head) {
1 * getCurrentHeight() >> 15000
}
def heightSelector = BlockchainOuterClass.Selector.newBuilder()
.setHeightSelector(
BlockchainOuterClass.HeightSelector.newBuilder()
@@ -75,9 +72,10 @@ class SelectorSpec extends Specification {
)
.build()
when:
def act = Selector.convertToMatcher(List.of(heightSelector), head)
def act = Selector.convertToUpstreamFilter(List.of(heightSelector))
then:
act == new Selector.MultiMatcher(List.of(new Selector.HeightMatcher(15000)))
act.matcher == new Selector.MultiMatcher(List.of(Selector.empty))
act.sort != Selector.Sort.default
}
def "Convert LABEL match"() {

View File

@@ -34,7 +34,7 @@ class RequestReaderFactoryTest {
Arguments.of(
RequestReaderFactory.ReaderData(
ms,
Selector.empty,
Selector.UpstreamFilter(Selector.empty),
MaximumValueQuorum(),
null,
tracer,
@@ -43,7 +43,7 @@ class RequestReaderFactoryTest {
Arguments.of(
RequestReaderFactory.ReaderData(
ms,
Selector.empty,
Selector.UpstreamFilter(Selector.empty),
BroadcastQuorum(),
null,
tracer,