Merge pull request #98 from p2p-org/fix-upstream-id
now return first resolver as upstream-id in case of quorum rpc read.
This commit is contained in:
@@ -119,7 +119,7 @@ class QuorumRpcReader(
|
|||||||
.filter { it.isResolved() } // return nothing if not resolved
|
.filter { it.isResolved() } // return nothing if not resolved
|
||||||
.map { quorum ->
|
.map { quorum ->
|
||||||
// TODO find actual quorum number
|
// TODO find actual quorum number
|
||||||
Result(quorum.getResult()!!, quorum.getSignature(), 1, quorum.getResolvedBy().map { it.nodeId() })
|
Result(quorum.getResult()!!, quorum.getSignature(), 1, quorum.getResolvedBy())
|
||||||
}
|
}
|
||||||
.switchIfEmpty(defaultResult)
|
.switchIfEmpty(defaultResult)
|
||||||
}
|
}
|
||||||
@@ -198,6 +198,6 @@ class QuorumRpcReader(
|
|||||||
val value: ByteArray,
|
val value: ByteArray,
|
||||||
val signature: ResponseSigner.Signature?,
|
val signature: ResponseSigner.Signature?,
|
||||||
val quorum: Int,
|
val quorum: Int,
|
||||||
val resolvers: Collection<Byte>
|
val resolvers: Collection<Upstream>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ open class NativeCall(
|
|||||||
.map {
|
.map {
|
||||||
val bytes = ctx.resultDecorator.processResult(it)
|
val bytes = ctx.resultDecorator.processResult(it)
|
||||||
validateResult(bytes, "remote", ctx)
|
validateResult(bytes, "remote", ctx)
|
||||||
CallResult.ok(ctx.id, ctx.nonce, bytes, it.signature, ctx.upstream.getId(), ctx)
|
CallResult.ok(ctx.id, ctx.nonce, bytes, it.signature, it.resolvers.first().getId(), ctx)
|
||||||
}
|
}
|
||||||
.onErrorResume { t ->
|
.onErrorResume { t ->
|
||||||
Mono.just(CallResult.fail(ctx.id, ctx.nonce, t, ctx))
|
Mono.just(CallResult.fail(ctx.id, ctx.nonce, t, ctx))
|
||||||
@@ -393,7 +393,11 @@ open class NativeCall(
|
|||||||
override fun processResult(result: QuorumRpcReader.Result): ByteArray {
|
override fun processResult(result: QuorumRpcReader.Result): ByteArray {
|
||||||
val bytes = result.value
|
val bytes = result.value
|
||||||
if (bytes.last() == quoteCode) {
|
if (bytes.last() == quoteCode) {
|
||||||
val suffix = result.resolvers.first().toUByte().toString(16).padStart(2, padChar = '0').toByteArray()
|
val suffix = result.resolvers
|
||||||
|
.map { it.nodeId() }
|
||||||
|
.first()
|
||||||
|
.toUByte()
|
||||||
|
.toString(16).padStart(2, padChar = '0').toByteArray()
|
||||||
bytes[bytes.lastIndex] = suffix.first()
|
bytes[bytes.lastIndex] = suffix.first()
|
||||||
return bytes + suffix.last() + quoteCode
|
return bytes + suffix.last() + quoteCode
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import io.emeraldpay.dshackle.upstream.Head
|
|||||||
import io.emeraldpay.dshackle.upstream.Multistream
|
import io.emeraldpay.dshackle.upstream.Multistream
|
||||||
import io.emeraldpay.dshackle.upstream.Selector
|
import io.emeraldpay.dshackle.upstream.Selector
|
||||||
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
import io.emeraldpay.dshackle.upstream.MultistreamHolder
|
||||||
|
import io.emeraldpay.dshackle.upstream.Upstream
|
||||||
import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods
|
import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods
|
||||||
import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods
|
import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods
|
||||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcError
|
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcError
|
||||||
@@ -119,10 +120,14 @@ class NativeCallSpec extends Specification {
|
|||||||
setup:
|
setup:
|
||||||
def quorum = new AlwaysQuorum()
|
def quorum = new AlwaysQuorum()
|
||||||
|
|
||||||
|
def ups = Mock(Upstream) {
|
||||||
|
_ * nodeId() >> (byte) 1
|
||||||
|
}
|
||||||
|
|
||||||
def nativeCall = nativeCall()
|
def nativeCall = nativeCall()
|
||||||
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
|
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
|
||||||
1 * create(_, _, _) >> Mock(Reader) {
|
1 * create(_, _, _) >> Mock(Reader) {
|
||||||
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"foo\"".bytes, null, 1, Collections.singletonList((byte) 1)))
|
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"foo\"".bytes, null, 1, Collections.singletonList(ups)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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()), Selector.empty, quorum,
|
||||||
@@ -586,6 +591,9 @@ class NativeCallSpec extends Specification {
|
|||||||
|
|
||||||
def "Decorate eth_newFilter result"() {
|
def "Decorate eth_newFilter result"() {
|
||||||
setup:
|
setup:
|
||||||
|
def ups = Mock(Upstream) {
|
||||||
|
_ * nodeId() >> (byte)255
|
||||||
|
}
|
||||||
def quorum = new AlwaysQuorum()
|
def quorum = new AlwaysQuorum()
|
||||||
def methods = new ManagedCallMethods(
|
def methods = new ManagedCallMethods(
|
||||||
new DefaultEthereumMethods(Chain.ETHEREUM),
|
new DefaultEthereumMethods(Chain.ETHEREUM),
|
||||||
@@ -601,7 +609,7 @@ class NativeCallSpec extends Specification {
|
|||||||
def nativeCall = nativeCall(multistreamHolder)
|
def nativeCall = nativeCall(multistreamHolder)
|
||||||
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
|
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
|
||||||
1 * create(_, _, _) >> Mock(Reader) {
|
1 * create(_, _, _) >> Mock(Reader) {
|
||||||
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"0xab\"".bytes, null, 1, Collections.singletonList((byte)255)))
|
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"0xab\"".bytes, null, 1, Collections.singletonList(ups)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
def call = new NativeCall.ValidCallContext(1, 10, multistream, Selector.empty, quorum,
|
def call = new NativeCall.ValidCallContext(1, 10, multistream, Selector.empty, quorum,
|
||||||
@@ -618,6 +626,9 @@ class NativeCallSpec extends Specification {
|
|||||||
|
|
||||||
def "Decorate eth_newFilter result with short nodeId"() {
|
def "Decorate eth_newFilter result with short nodeId"() {
|
||||||
setup:
|
setup:
|
||||||
|
def ups = Mock(Upstream) {
|
||||||
|
_ * nodeId() >> (byte)1
|
||||||
|
}
|
||||||
def quorum = new AlwaysQuorum()
|
def quorum = new AlwaysQuorum()
|
||||||
def methods = new ManagedCallMethods(
|
def methods = new ManagedCallMethods(
|
||||||
new DefaultEthereumMethods(Chain.ETHEREUM),
|
new DefaultEthereumMethods(Chain.ETHEREUM),
|
||||||
@@ -633,7 +644,7 @@ class NativeCallSpec extends Specification {
|
|||||||
def nativeCall = nativeCall(multistreamHolder)
|
def nativeCall = nativeCall(multistreamHolder)
|
||||||
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
|
nativeCall.quorumReaderFactory = Mock(QuorumReaderFactory) {
|
||||||
1 * create(_, _, _) >> Mock(Reader) {
|
1 * create(_, _, _) >> Mock(Reader) {
|
||||||
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"0xab\"".bytes, null, 1, Collections.singletonList((byte)1)))
|
1 * read(_) >> Mono.just(new QuorumRpcReader.Result("\"0xab\"".bytes, null, 1, Collections.singletonList(ups)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
def call = new NativeCall.ValidCallContext(1, 10, multistream, Selector.empty, quorum,
|
def call = new NativeCall.ValidCallContext(1, 10, multistream, Selector.empty, quorum,
|
||||||
|
|||||||
Reference in New Issue
Block a user