add logs for forkchoice
This commit is contained in:
@@ -3,12 +3,17 @@ package io.emeraldpay.dshackle.upstream.forkchoice
|
|||||||
import io.emeraldpay.dshackle.data.BlockContainer
|
import io.emeraldpay.dshackle.data.BlockContainer
|
||||||
import io.emeraldpay.dshackle.data.BlockId
|
import io.emeraldpay.dshackle.data.BlockId
|
||||||
import io.emeraldpay.dshackle.data.RingSet
|
import io.emeraldpay.dshackle.data.RingSet
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
import java.util.concurrent.atomic.AtomicReference
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
|
||||||
class PriorityForkChoice : ForkChoice {
|
class PriorityForkChoice : ForkChoice {
|
||||||
private val head = AtomicReference<BlockContainer>(null)
|
private val head = AtomicReference<BlockContainer>(null)
|
||||||
private val seenBlocks = RingSet<BlockId>(10)
|
private val seenBlocks = RingSet<BlockId>(10)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val log = LoggerFactory.getLogger(PriorityForkChoice::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getHead(): BlockContainer? {
|
override fun getHead(): BlockContainer? {
|
||||||
return head.get()
|
return head.get()
|
||||||
}
|
}
|
||||||
@@ -19,17 +24,24 @@ class PriorityForkChoice : ForkChoice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun choose(block: BlockContainer): ForkChoice.ChoiceResult {
|
override fun choose(block: BlockContainer): ForkChoice.ChoiceResult {
|
||||||
|
head.get()?.let {
|
||||||
|
log.debug("Candidate for priority forkchoice (${block.height}, ${block.nodeRating}), current is (${it.height},${it.nodeRating}")
|
||||||
|
}
|
||||||
val nwhead = head.updateAndGet { curr ->
|
val nwhead = head.updateAndGet { curr ->
|
||||||
if (!filter(block)) {
|
if (!filter(block)) {
|
||||||
|
log.debug("Preparing to deny block ${block.height}")
|
||||||
curr
|
curr
|
||||||
} else {
|
} else {
|
||||||
|
log.debug("Preparing to accept block ${block.height}")
|
||||||
seenBlocks.add(block.hash)
|
seenBlocks.add(block.hash)
|
||||||
block
|
block
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nwhead.hash == block.hash) {
|
if (nwhead.hash == block.hash) {
|
||||||
|
log.debug("Accepted block ${block.height}")
|
||||||
return ForkChoice.ChoiceResult.Updated(nwhead)
|
return ForkChoice.ChoiceResult.Updated(nwhead)
|
||||||
}
|
}
|
||||||
|
log.debug("Denied block ${block.height}")
|
||||||
return ForkChoice.ChoiceResult.Same(nwhead)
|
return ForkChoice.ChoiceResult.Same(nwhead)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user