more logs
This commit is contained in:
@@ -177,7 +177,7 @@ open class ConfiguredUpstreams(
|
||||
execution,
|
||||
chain,
|
||||
urls,
|
||||
NoChoiceWithPriorityForkChoice(conn.upstreamRating),
|
||||
NoChoiceWithPriorityForkChoice(conn.upstreamRating, config.id!!),
|
||||
BlockValidator.ALWAYS_VALID
|
||||
)
|
||||
val methods = buildMethods(config, chain)
|
||||
|
||||
@@ -3,14 +3,19 @@ package io.emeraldpay.dshackle.upstream.forkchoice
|
||||
import io.emeraldpay.dshackle.data.BlockContainer
|
||||
import io.emeraldpay.dshackle.data.BlockId
|
||||
import io.emeraldpay.dshackle.data.RingSet
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
class NoChoiceWithPriorityForkChoice(
|
||||
private val nodeRating: Int
|
||||
private val nodeRating: Int,
|
||||
private val upstreamId: String
|
||||
) : ForkChoice {
|
||||
private val head = AtomicReference<BlockContainer>(null)
|
||||
private val seenBlocks = RingSet<BlockId>(100)
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(NoChoiceWithPriorityForkChoice::class.java)
|
||||
}
|
||||
override fun getHead(): BlockContainer? {
|
||||
return head.get()
|
||||
}
|
||||
@@ -20,8 +25,10 @@ class NoChoiceWithPriorityForkChoice(
|
||||
}
|
||||
|
||||
override fun choose(block: BlockContainer): ForkChoice.ChoiceResult {
|
||||
log.debug("Adding priority to $upstreamId block ${block.height}")
|
||||
val nwhead = head.updateAndGet { curr ->
|
||||
if (!filter(block)) {
|
||||
log.debug("Already seen block ${block.height} from $upstreamId")
|
||||
curr
|
||||
} else {
|
||||
seenBlocks.add(block.hash)
|
||||
@@ -29,8 +36,10 @@ class NoChoiceWithPriorityForkChoice(
|
||||
}
|
||||
}
|
||||
if (nwhead.hash == block.hash) {
|
||||
log.debug("Accepted block ${block.height} from $upstreamId with $nodeRating")
|
||||
return ForkChoice.ChoiceResult.Updated(nwhead)
|
||||
}
|
||||
log.debug("Declined block ${block.height} from $upstreamId with $nodeRating")
|
||||
return ForkChoice.ChoiceResult.Same(nwhead)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ open class EthereumPosGrpcUpstream(
|
||||
|
||||
private val log = LoggerFactory.getLogger(EthereumGrpcUpstream::class.java)
|
||||
private val upstreamStatus = GrpcUpstreamStatus(overrideLabels)
|
||||
private val grpcHead = GrpcHead(chain, this, remote, blockConverter, reloadBlock, NoChoiceWithPriorityForkChoice(nodeRating))
|
||||
private val grpcHead = GrpcHead(chain, this, remote, blockConverter, reloadBlock, NoChoiceWithPriorityForkChoice(nodeRating, parentId))
|
||||
private var capabilities: Set<Capability> = emptySet()
|
||||
|
||||
private val defaultReader: Reader<JsonRpcRequest, JsonRpcResponse> = client.getReader()
|
||||
|
||||
@@ -16,7 +16,7 @@ class NoChoiceWithPriorityForkChoiceSpec extends Specification {
|
||||
def "filters blocks"() {
|
||||
def blockR0 = blocks[0].copyWithRating(10)
|
||||
def blockR1 = blocks[1].copyWithRating(10)
|
||||
def choice = new NoChoiceWithPriorityForkChoice(10)
|
||||
def choice = new NoChoiceWithPriorityForkChoice(10, "test")
|
||||
when:
|
||||
choice.choose(blocks[0])
|
||||
then:
|
||||
@@ -34,7 +34,7 @@ class NoChoiceWithPriorityForkChoiceSpec extends Specification {
|
||||
def "chooses blocks and adds rating"() {
|
||||
def blockR0 = blocks[0].copyWithRating(10)
|
||||
def blockR1 = blocks[1].copyWithRating(10)
|
||||
def choice = new NoChoiceWithPriorityForkChoice(10)
|
||||
def choice = new NoChoiceWithPriorityForkChoice(10, "test")
|
||||
when:
|
||||
choice.choose(blocks[0])
|
||||
then:
|
||||
|
||||
Reference in New Issue
Block a user