propagate grpc provided upstream id

This commit is contained in:
a10zn8
2023-01-23 20:38:10 +04:00
parent d92ba5ddfa
commit 8eac1178ec
21 changed files with 217 additions and 102 deletions

View File

@@ -42,7 +42,7 @@ class AlwaysQuorumSpec extends Specification {
def quorum = new AlwaysQuorum()
def up = Stub(Upstream)
when:
quorum.record("123".bytes, new ResponseSigner.Signature("sig1".bytes, "test", 100), up)
quorum.record("123".bytes, new ResponseSigner.Signature("sig1".bytes, "test", 100), up, null)
then:
quorum.isResolved()
quorum.getResult() == "123".bytes

View File

@@ -43,21 +43,21 @@ class BroadcastQuorumSpec extends Specification {
!q.isResolved()
when:
q.record('"0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c"'.bytes, null, upstream1)
q.record('"0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c"'.bytes, null, upstream1, null)
then:
!q.isResolved()
1 * q.recordValue(_, "0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c", _, _)
1 * q.recordValue(_, "0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c", _, _, _)
when:
q.record('"0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c"'.bytes, null, upstream2)
q.record('"0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c"'.bytes, null, upstream2, null)
then:
!q.isResolved()
1 * q.recordValue(_, "0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c", _, _)
1 * q.recordValue(_, "0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c", _, _, _)
when:
q.record(new JsonRpcException(1, "Nonce too low"), null, upstream3)
then:
1 * q.recordError(_, _, _, _)
1 * q.recordError(_, _, _, _, _)
q.isResolved()
objectMapper.readValue(q.result, Object) == "0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c"
}
@@ -78,18 +78,18 @@ class BroadcastQuorumSpec extends Specification {
q.record(new JsonRpcException(1, "Internal error"), null, upstream1)
then:
!q.isResolved()
1 * q.recordError(_, _, _, _)
1 * q.recordError(_, _, _, _, _)
when:
q.record('"0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c"'.bytes, null, upstream2)
q.record('"0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c"'.bytes, null, upstream2, null)
then:
!q.isResolved()
1 * q.recordValue(_, "0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c", _, _)
1 * q.recordValue(_, "0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c", _, _, _)
when:
q.record(new JsonRpcException(1, "Nonce too low"), null, upstream3)
then:
1 * q.recordError(_, _, _, _)
1 * q.recordError(_, _, _, _, _)
q.isResolved()
objectMapper.readValue(q.result, Object) == "0xeaa972c0d8d1ecd3e34fbbef6d34e06670e745c788bdba31c4234a1762f0378c"
}

View File

@@ -61,8 +61,6 @@ class NonEmptyQuorumSpec extends Specification {
setup:
def q = Spy(new NonEmptyQuorum(3))
def upstream1 = Stub(Upstream)
def upstream2 = Stub(Upstream)
def upstream3 = Stub(Upstream)
when:
q.init(Stub(Head))
@@ -71,7 +69,7 @@ class NonEmptyQuorumSpec extends Specification {
!q.isFailed()
when:
q.record('"0x11"'.bytes, null, upstream1)
q.record('"0x11"'.bytes, null, upstream1, null)
then:
q.isResolved()
!q.isFailed()
@@ -82,7 +80,6 @@ class NonEmptyQuorumSpec extends Specification {
def q = Spy(new NonEmptyQuorum(3))
def upstream1 = Stub(Upstream)
def upstream2 = Stub(Upstream)
def upstream3 = Stub(Upstream)
when:
q.init(Stub(Head))
@@ -98,7 +95,7 @@ class NonEmptyQuorumSpec extends Specification {
q.signature == null
when:
q.record('"0x11"'.bytes, null, upstream2)
q.record('"0x11"'.bytes, null, upstream2, null)
then:
q.isResolved()
!q.isFailed()
@@ -108,8 +105,6 @@ class NonEmptyQuorumSpec extends Specification {
setup:
def q = Spy(new NonEmptyQuorum(3))
def upstream1 = Stub(Upstream)
def upstream2 = Stub(Upstream)
def upstream3 = Stub(Upstream)
when:
q.init(Stub(Head))
@@ -118,14 +113,14 @@ class NonEmptyQuorumSpec extends Specification {
!q.isFailed()
when:
q.record('null'.bytes, null, upstream2)
q.record('null'.bytes, null, upstream1, null)
then:
!q.isFailed()
!q.isResolved()
when:
q.record('"0x11"'.bytes, null, upstream2)
q.record('"0x11"'.bytes, null, upstream1, null)
then:
q.isResolved()
!q.isFailed()

View File

@@ -18,12 +18,9 @@ package io.emeraldpay.dshackle.quorum
import com.fasterxml.jackson.databind.ObjectMapper
import io.emeraldpay.dshackle.Global
import io.emeraldpay.dshackle.test.TestingCommons
import io.emeraldpay.dshackle.upstream.Head
import io.emeraldpay.dshackle.upstream.Upstream
import io.emeraldpay.dshackle.quorum.NonceQuorum
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcException
import io.emeraldpay.etherjar.rpc.RpcException
import spock.lang.Specification
class NonceQuorumSpec extends Specification {
@@ -43,21 +40,21 @@ class NonceQuorumSpec extends Specification {
!q.isResolved()
when:
q.record('"0x10"'.bytes, null, upstream1)
q.record('"0x10"'.bytes, null, upstream1, null)
then:
!q.isResolved()
1 * q.recordValue(_, "0x10", _, _)
1 * q.recordValue(_, "0x10", _, _, _)
when:
q.record('"0x11"'.bytes, null, upstream2)
q.record('"0x11"'.bytes, null, upstream2, null)
then:
!q.isResolved()
1 * q.recordValue(_, "0x11", _, _)
1 * q.recordValue(_, "0x11", _, _, _)
when:
q.record('"0x10"'.bytes, null, upstream3)
q.record('"0x10"'.bytes, null, upstream3, null)
then:
1 * q.recordValue(_, "0x10", _, _)
1 * q.recordValue(_, "0x10", _, _, _)
q.isResolved()
objectMapper.readValue(q.result, Object) == "0x11"
}
@@ -78,24 +75,24 @@ class NonceQuorumSpec extends Specification {
q.record(new JsonRpcException(1, "Internal"), null, upstream1)
then:
!q.isResolved()
1 * q.recordError(_, _, _, _)
1 * q.recordError(_, _, _, _, _)
when:
q.record('"0x11"'.bytes, null, upstream2)
q.record('"0x11"'.bytes, null, upstream2, null)
then:
!q.isResolved()
1 * q.recordValue(_, "0x11", _, _)
1 * q.recordValue(_, "0x11", _, _, _)
when:
q.record('"0x10"'.bytes, null, upstream3)
q.record('"0x10"'.bytes, null, upstream3, null)
then:
1 * q.recordValue(_, "0x10", _, _)
1 * q.recordValue(_, "0x10", _, _, _)
!q.isResolved()
when:
q.record('"0x11"'.bytes, null, upstream1)
q.record('"0x11"'.bytes, null, upstream1, null)
then:
1 * q.recordValue(_, "0x11", _, _)
1 * q.recordValue(_, "0x11", _, _, _)
q.isResolved()
objectMapper.readValue(q.result, Object) == "0x11"
}

View File

@@ -32,7 +32,7 @@ class NotLaggingQuorumSpec extends Specification {
def quorum = new NotLaggingQuorum(1)
when:
quorum.record(value, null, up)
quorum.record(value, null, up, null)
then:
1 * up.getLag() >> 0
quorum.isResolved()
@@ -40,20 +40,21 @@ class NotLaggingQuorumSpec extends Specification {
quorum.result == value
}
def "Keeps signature"() {
def "Keeps signature and upstream"() {
setup:
def up = Mock(Upstream)
def value = "foo".getBytes()
def quorum = new NotLaggingQuorum(1)
when:
quorum.record(value, new ResponseSigner.Signature("sig1".bytes, "test", 100), up)
quorum.record(value, new ResponseSigner.Signature("sig1".bytes, "test", 100), up, "test")
then:
1 * up.getLag() >> 0
quorum.isResolved()
!quorum.isFailed()
quorum.result == value
quorum.signature == new ResponseSigner.Signature("sig1".bytes, "test", 100)
quorum.providedUpstreamId == "test"
}
def "Resolves if ok lag"() {
@@ -63,7 +64,7 @@ class NotLaggingQuorumSpec extends Specification {
def quorum = new NotLaggingQuorum(1)
when:
quorum.record(value, null, up)
quorum.record(value, null, up, null)
then:
1 * up.getLag() >> 1
quorum.isResolved()
@@ -78,7 +79,7 @@ class NotLaggingQuorumSpec extends Specification {
def quorum = new NotLaggingQuorum(1)
when:
quorum.record(value, null, up)
quorum.record(value, null, up, null)
then:
1 * up.getLag() >> 2
!quorum.isResolved()

View File

@@ -66,14 +66,14 @@ class ValueAwareQuorumSpec extends Specification {
}
@Override
void recordValue(@NotNull byte[] response, @Nullable Object responseValue, @Nullable ResponseSigner.Signature signature, @NotNull Upstream upstream) {
void recordValue(@NotNull byte[] response, @Nullable Object responseValue, @Nullable ResponseSigner.Signature signature, @NotNull Upstream upstream, @Nullable String providedUpstreamId) {
}
@Override
void recordError(@Nullable byte[] response, @Nullable String errorMessage, @Nullable ResponseSigner.Signature signature, @NotNull Upstream upstream) {
void recordError(@Nullable byte[] response, @Nullable String errorMessage, @Nullable ResponseSigner.Signature signature, @NotNull Upstream upstream, @Nullable String providedUpstreamId) {
}
@@ -101,5 +101,10 @@ class ValueAwareQuorumSpec extends Specification {
boolean isFailed() {
return false
}
@Override
String getProvidedUpstreamId() {
return null
}
}
}

View File

@@ -131,7 +131,7 @@ class NativeCallSpec extends Specification {
def nativeCall = nativeCall()
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"foo\"".bytes, null, 1, Collections.singletonList(ups)))
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"foo\"".bytes, null, 1, Collections.singletonList(ups), null))
}
}
def call = new NativeCall.ValidCallContext(1, 10, TestingCommons.multistream(TestingCommons.api()), Selector.empty, quorum,
@@ -613,7 +613,7 @@ class NativeCallSpec extends Specification {
def nativeCall = nativeCall(multistreamHolder)
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"0xab\"".bytes, null, 1, Collections.singletonList(ups)))
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"0xab\"".bytes, null, 1, Collections.singletonList(ups), null))
}
}
def call = new NativeCall.ValidCallContext(1, 10, multistream, Selector.empty, quorum,
@@ -648,7 +648,7 @@ class NativeCallSpec extends Specification {
def nativeCall = nativeCall(multistreamHolder)
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"0xab\"".bytes, null, 1, Collections.singletonList(ups)))
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"0xab\"".bytes, null, 1, Collections.singletonList(ups), null))
}
}
def call = new NativeCall.ValidCallContext(1, 10, multistream, Selector.empty, quorum,

View File

@@ -108,7 +108,7 @@ class ApiReaderMock implements Reader<JsonRpcRequest, JsonRpcResponse> {
}
error = new JsonRpcError(-32601, "Method ${request.method} with ${request.params} is not mocked")
}
return new JsonRpcResponse(result, error, JsonRpcResponse.Id.from(request.id), null)
return new JsonRpcResponse(result, error, JsonRpcResponse.Id.from(request.id), null, null)
} as Callable<JsonRpcResponse>
return Mono.fromCallable(call)
}

View File

@@ -55,7 +55,7 @@ class EthereumDirectReaderSpec extends Specification {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_getBlockByHash", [hash1, false])) >> Mono.just(
new QuorumRpcReader.Result(
Global.objectMapper.writeValueAsBytes(json), null, 1, resolvers)
Global.objectMapper.writeValueAsBytes(json), null, 1, resolvers, null)
)
}
}
@@ -85,7 +85,7 @@ class EthereumDirectReaderSpec extends Specification {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_getBlockByHash", [hash1, false])) >> Mono.just(
new QuorumRpcReader.Result(
Global.objectMapper.writeValueAsBytes(null), null, 1, resolvers
Global.objectMapper.writeValueAsBytes(null), null, 1, resolvers, null
)
)
}
@@ -120,7 +120,7 @@ class EthereumDirectReaderSpec extends Specification {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_getBlockByNumber", ["0x64", false])) >> Mono.just(
new QuorumRpcReader.Result(
Global.objectMapper.writeValueAsBytes(json), null, 1, resolvers
Global.objectMapper.writeValueAsBytes(json), null, 1, resolvers, null
)
)
}
@@ -156,7 +156,7 @@ class EthereumDirectReaderSpec extends Specification {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_getTransactionByHash", [hash1])) >> Mono.just(
new QuorumRpcReader.Result(
Global.objectMapper.writeValueAsBytes(json), null, 1, resolvers
Global.objectMapper.writeValueAsBytes(json), null, 1, resolvers, null
)
)
}
@@ -192,7 +192,7 @@ class EthereumDirectReaderSpec extends Specification {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_getTransactionReceipt", [hash1])) >> Mono.just(
new QuorumRpcReader.Result(
Global.objectMapper.writeValueAsBytes(json), null, 1, new ArrayList<Byte>()
Global.objectMapper.writeValueAsBytes(json), null, 1, new ArrayList<Byte>(), null
)
)
}
@@ -229,7 +229,7 @@ class EthereumDirectReaderSpec extends Specification {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_getTransactionReceipt", [hash1])) >> Mono.just(
new QuorumRpcReader.Result(
Global.objectMapper.writeValueAsBytes(json), null, 1, new ArrayList<Byte>()
Global.objectMapper.writeValueAsBytes(json), null, 1, new ArrayList<Byte>(), null
)
)
}
@@ -257,7 +257,7 @@ class EthereumDirectReaderSpec extends Specification {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_getTransactionByHash", [hash1])) >> Mono.just(
new QuorumRpcReader.Result(
Global.objectMapper.writeValueAsBytes(null), null, 1, resolvers
Global.objectMapper.writeValueAsBytes(null), null, 1, resolvers, null
)
)
}
@@ -288,7 +288,7 @@ class EthereumDirectReaderSpec extends Specification {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_getBalance", [address1, "latest"])) >> Mono.just(
new QuorumRpcReader.Result(
Global.objectMapper.writeValueAsBytes("0x100"), null, 1, resolvers
Global.objectMapper.writeValueAsBytes("0x100"), null, 1, resolvers, null
)
)
}
@@ -320,7 +320,7 @@ class EthereumDirectReaderSpec extends Specification {
1 * create(_, _, _) >> Mock(Reader) {
1 * read(new JsonRpcRequest("eth_getBalance", [address1, "0xa8c9bb"])) >> Mono.just(
new QuorumRpcReader.Result(
Global.objectMapper.writeValueAsBytes("0x100"), null, 1, resolvers
Global.objectMapper.writeValueAsBytes("0x100"), null, 1, resolvers, null
)
)
}

View File

@@ -63,7 +63,7 @@ class JsonRpcResponseSpec extends Specification {
def "Serialize int id and null result"() {
setup:
def json = new JsonRpcResponse("null".bytes, null, new JsonRpcResponse.NumberId(1), null)
def json = new JsonRpcResponse("null".bytes, null, new JsonRpcResponse.NumberId(1), null, null)
when:
def act = objectMapper.writeValueAsString(json)
then:
@@ -72,7 +72,7 @@ class JsonRpcResponseSpec extends Specification {
def "Serialize int id and string result"() {
setup:
def json = new JsonRpcResponse('"Hello World"'.bytes, null, new JsonRpcResponse.NumberId(10), null)
def json = new JsonRpcResponse('"Hello World"'.bytes, null, new JsonRpcResponse.NumberId(10), null, null)
when:
def act = objectMapper.writeValueAsString(json)
then:
@@ -81,7 +81,7 @@ class JsonRpcResponseSpec extends Specification {
def "Serialize int id and object result"() {
setup:
def json = new JsonRpcResponse('{"foo": "Hello World", "bar": 1}'.bytes, null, new JsonRpcResponse.NumberId(101), null)
def json = new JsonRpcResponse('{"foo": "Hello World", "bar": 1}'.bytes, null, new JsonRpcResponse.NumberId(101), null, null)
when:
def act = objectMapper.writeValueAsString(json)
then:
@@ -90,7 +90,7 @@ class JsonRpcResponseSpec extends Specification {
def "Serialize int id and error"() {
setup:
def json = new JsonRpcResponse(null, new JsonRpcError(-32041, "Oooops"), new JsonRpcResponse.NumberId(101), null)
def json = new JsonRpcResponse(null, new JsonRpcError(-32041, "Oooops"), new JsonRpcResponse.NumberId(101), null, null)
when:
def act = objectMapper.writeValueAsString(json)
then:
@@ -99,7 +99,7 @@ class JsonRpcResponseSpec extends Specification {
def "Serialize string id and null result"() {
setup:
def json = new JsonRpcResponse("null".bytes, null, new JsonRpcResponse.StringId("asf01t1gg"), null)
def json = new JsonRpcResponse("null".bytes, null, new JsonRpcResponse.StringId("asf01t1gg"), null, null)
when:
def act = objectMapper.writeValueAsString(json)
then:
@@ -108,7 +108,7 @@ class JsonRpcResponseSpec extends Specification {
def "Serialize string id and string result"() {
setup:
def json = new JsonRpcResponse('"Hello World"'.bytes, null, new JsonRpcResponse.StringId("10"), null)
def json = new JsonRpcResponse('"Hello World"'.bytes, null, new JsonRpcResponse.StringId("10"), null, null)
when:
def act = objectMapper.writeValueAsString(json)
then:
@@ -117,7 +117,7 @@ class JsonRpcResponseSpec extends Specification {
def "Serialize string id and object result"() {
setup:
def json = new JsonRpcResponse('{"foo": "Hello World", "bar": 1}'.bytes, null, new JsonRpcResponse.StringId("g8gk19g"), null)
def json = new JsonRpcResponse('{"foo": "Hello World", "bar": 1}'.bytes, null, new JsonRpcResponse.StringId("g8gk19g"), null, null)
when:
def act = objectMapper.writeValueAsString(json)
then:
@@ -128,7 +128,7 @@ class JsonRpcResponseSpec extends Specification {
setup:
def json = new JsonRpcResponse(null,
new JsonRpcError(-32041, "Oooops"),
new JsonRpcResponse.StringId("9kbo29gkaasf"), null)
new JsonRpcResponse.StringId("9kbo29gkaasf"), null, null)
when:
def act = objectMapper.writeValueAsString(json)
then: