Integrate rx/receipts gold bounds (#781)
This commit is contained in:
@@ -44,6 +44,25 @@ data class ChainsConfig(private val chains: List<ChainConfig>) : Iterable<Chains
|
||||
fun rules() = conditions.joinToString { (op, limit) -> "$op $limit" }
|
||||
}
|
||||
|
||||
enum class LowerBoundType {
|
||||
UNKNOWN, STATE, SLOT, BLOCK, TX, LOGS, TRACE, PROOF, BLOB, EPOCH, RECEIPTS;
|
||||
|
||||
companion object {
|
||||
fun byName(name: String): LowerBoundType {
|
||||
return LowerBoundType.entries.firstOrNull { it.name.equals(name, ignoreCase = true) } ?: UNKNOWN
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class GoldLowerBound(
|
||||
val block: Long,
|
||||
)
|
||||
|
||||
class GoldLowerBoundWithHash(
|
||||
block: Long,
|
||||
val hash: String,
|
||||
) : GoldLowerBound(block)
|
||||
|
||||
data class ChainConfig(
|
||||
val expectedBlockTime: Duration,
|
||||
val syncingLagSize: Int,
|
||||
@@ -59,6 +78,7 @@ data class ChainsConfig(private val chains: List<ChainConfig>) : Iterable<Chains
|
||||
val blockchain: String,
|
||||
val type: String,
|
||||
val gasPriceCondition: GasPriceCondition,
|
||||
val goldLowerBounds: Map<LowerBoundType, GoldLowerBound>
|
||||
) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@@ -80,6 +100,7 @@ data class ChainsConfig(private val chains: List<ChainConfig>) : Iterable<Chains
|
||||
"undefined",
|
||||
"unknown",
|
||||
GasPriceCondition(emptyList()),
|
||||
emptyMap(),
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
@@ -92,4 +113,8 @@ data class ChainsConfig(private val chains: List<ChainConfig>) : Iterable<Chains
|
||||
fun resolve(chain: String): ChainConfig {
|
||||
return chainMap[chain] ?: ChainConfig.default()
|
||||
}
|
||||
|
||||
fun getChainConfigs(): Collection<ChainConfig> {
|
||||
return chainMap.values
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,9 +137,47 @@ class ChainsConfigReader(
|
||||
blockchain = blockchain,
|
||||
type = type,
|
||||
gasPriceCondition = ChainsConfig.GasPriceCondition(gasPriceConditions),
|
||||
goldLowerBounds = readGoldLowerBounds(node),
|
||||
)
|
||||
}
|
||||
|
||||
private fun readGoldLowerBounds(node: MappingNode): Map<ChainsConfig.LowerBoundType, ChainsConfig.GoldLowerBound> {
|
||||
val goldLowerBounds = getMapping(node, "lower-bounds") ?: return emptyMap()
|
||||
|
||||
return goldLowerBounds.value.asSequence()
|
||||
.filter {
|
||||
(it.keyNode.valueAsString()?.isNotBlank() ?: false) && it.valueNode.tag == Tag.MAP
|
||||
}.map {
|
||||
val type = ChainsConfig.LowerBoundType.byName(it.keyNode.valueAsString()!!)
|
||||
val bound = if (type == ChainsConfig.LowerBoundType.TX || type == ChainsConfig.LowerBoundType.RECEIPTS) {
|
||||
readHashGoldLowerBound(it.valueNode as MappingNode)
|
||||
} else {
|
||||
readGoldLowerBound(it.valueNode as MappingNode)
|
||||
}
|
||||
|
||||
if (bound != null) {
|
||||
type to bound
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
.filterNotNull()
|
||||
.associate { it }
|
||||
}
|
||||
|
||||
private fun readGoldLowerBound(node: MappingNode): ChainsConfig.GoldLowerBound? {
|
||||
val block = getValueAsLong(node, "block") ?: return null
|
||||
|
||||
return ChainsConfig.GoldLowerBound(block)
|
||||
}
|
||||
|
||||
private fun readHashGoldLowerBound(node: MappingNode): ChainsConfig.GoldLowerBound? {
|
||||
val hash = getValueAsString(node, "hash") ?: return null
|
||||
val block = getValueAsLong(node, "block") ?: return null
|
||||
|
||||
return ChainsConfig.GoldLowerBoundWithHash(block, hash)
|
||||
}
|
||||
|
||||
override fun read(input: MappingNode?): ChainsConfig {
|
||||
val default = readChains(readNode(defaultConfig))
|
||||
val current = readChains(input)
|
||||
|
||||
Submodule foundation/src/main/resources/public updated: 5ad28fd817...b381391a23
@@ -1,12 +1,13 @@
|
||||
package org.drpc.chainsconfig
|
||||
|
||||
import io.emeraldpay.dshackle.config.ChainsConfig
|
||||
import io.emeraldpay.dshackle.config.ChainsConfigReader
|
||||
import io.emeraldpay.dshackle.foundation.ChainOptionsReader
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.math.BigInteger
|
||||
|
||||
internal class ChainsConfigReaderTest {
|
||||
class ChainsConfigReaderTest {
|
||||
|
||||
@Test
|
||||
fun `read standard config without custom`() {
|
||||
@@ -41,5 +42,17 @@ internal class ChainsConfigReaderTest {
|
||||
assertEquals(config.code, "FTA")
|
||||
assertEquals(config.grpcId, 102)
|
||||
assertEquals(config.netVersion, BigInteger.valueOf(251))
|
||||
assertEquals(15L, config.goldLowerBounds[ChainsConfig.LowerBoundType.STATE]!!.block)
|
||||
assertEquals(150L, config.goldLowerBounds[ChainsConfig.LowerBoundType.BLOCK]!!.block)
|
||||
assertEquals(1L, config.goldLowerBounds[ChainsConfig.LowerBoundType.TX]!!.block)
|
||||
assertEquals(
|
||||
"0x5e77a04531c7c107af1882d76cbff9486d0a9aa53701c30888509d4f5f2b003a",
|
||||
(config.goldLowerBounds[ChainsConfig.LowerBoundType.TX] as ChainsConfig.GoldLowerBoundWithHash).hash,
|
||||
)
|
||||
assertEquals(1000L, config.goldLowerBounds[ChainsConfig.LowerBoundType.RECEIPTS]!!.block)
|
||||
assertEquals(
|
||||
"0x4e72a04531c7c107af1882d76cbff9486d0a9aa53701c30888509d4f5f2b003a",
|
||||
(config.goldLowerBounds[ChainsConfig.LowerBoundType.RECEIPTS] as ChainsConfig.GoldLowerBoundWithHash).hash,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,15 @@ chain-settings:
|
||||
short-names: [fantom]
|
||||
code: FTA
|
||||
grpcId: 102
|
||||
chain-id: 0xfb
|
||||
chain-id: 0xfb
|
||||
lower-bounds:
|
||||
tx:
|
||||
block: 1
|
||||
hash: "0x5e77a04531c7c107af1882d76cbff9486d0a9aa53701c30888509d4f5f2b003a"
|
||||
receipts:
|
||||
block: 1000
|
||||
hash: "0x4e72a04531c7c107af1882d76cbff9486d0a9aa53701c30888509d4f5f2b003a"
|
||||
state:
|
||||
block: 15
|
||||
block:
|
||||
block: 150
|
||||
|
||||
Reference in New Issue
Block a user