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)
|
||||
|
||||
Reference in New Issue
Block a user