Skip to content

Commit

Permalink
Added DTO objects for easier instantination
Browse files Browse the repository at this point in the history
  • Loading branch information
Filter94 committed Sep 12, 2024
1 parent acd48b0 commit 34acc64
Show file tree
Hide file tree
Showing 14 changed files with 454 additions and 186 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ max_line_length=120
insert_final_newline = true
trim_trailing_whitespace = true

[*.{kt,kts}]
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL

ij_kotlin_name_count_to_use_star_import = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
ij_kotlin_packages_to_use_import_on_demand = unset

[*.go]
indent_style = tab
indent_size = tab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class L1DependentApp(
if (configs.messageAnchoringService.disabled) {
log.warn("Message anchoring service is disabled")
}
if (configs.l2NetworkGasPricing.disabled) {
if (configs.l2NetworkGasPricingService == null) {
log.warn("Dynamic gas price service is disabled")
}
}
Expand Down Expand Up @@ -907,14 +907,14 @@ class L1DependentApp(
null
}

private val gasPriceUpdaterApp: GasPriceUpdaterApp? =
if (configs.l2NetworkGasPricing.enabled) {
GasPriceUpdaterApp(
private val l2NetworkGasPricingService: L2NetworkGasPricingService? =
if (configs.l2NetworkGasPricingService != null) {
L2NetworkGasPricingService(
vertx = vertx,
httpJsonRpcClientFactory = httpJsonRpcClientFactory,
l1Web3jClient = l1Web3jClient,
l1Web3jService = l1Web3jService,
config = configs.l2NetworkGasPricing
config = configs.l2NetworkGasPricingService
)
} else {
null
Expand Down Expand Up @@ -1001,7 +1001,7 @@ class L1DependentApp(
.thenCompose { aggregationFinalizationCoordinator.start() }
.thenCompose { proofAggregationCoordinatorService.start() }
.thenCompose { messageAnchoringApp?.start() ?: SafeFuture.completedFuture(Unit) }
.thenCompose { gasPriceUpdaterApp?.start() ?: SafeFuture.completedFuture(Unit) }
.thenCompose { l2NetworkGasPricingService?.start() ?: SafeFuture.completedFuture(Unit) }
.thenCompose { l1FeeHistoryCachingService.start() }
.thenCompose { deadlineConflationCalculatorRunnerOld.start() }
.thenCompose { deadlineConflationCalculatorRunnerNew.start() }
Expand All @@ -1019,7 +1019,7 @@ class L1DependentApp(
aggregationFinalizationCoordinator.stop(),
proofAggregationCoordinatorService.stop(),
messageAnchoringApp?.stop() ?: SafeFuture.completedFuture(Unit),
gasPriceUpdaterApp?.stop() ?: SafeFuture.completedFuture(Unit),
l2NetworkGasPricingService?.stop() ?: SafeFuture.completedFuture(Unit),
l1FeeHistoryCachingService.stop(),
blockCreationMonitor.stop(),
deadlineConflationCalculatorRunnerOld.stop(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,61 @@ import net.consensys.linea.ethereum.gaspricing.staticcap.MinerExtraDataV1Calcula
import net.consensys.linea.ethereum.gaspricing.staticcap.VariableFeesCalculator
import net.consensys.linea.jsonrpc.client.VertxHttpJsonRpcClientFactory
import net.consensys.linea.web3j.Web3jBlobExtended
import net.consensys.toKWeiUInt
import net.consensys.zkevm.LongRunningService
import net.consensys.zkevm.coordinator.app.config.L2NetworkGasPricing
import org.apache.logging.log4j.LogManager
import org.web3j.protocol.Web3j
import tech.pegasys.teku.infrastructure.async.SafeFuture
import java.util.concurrent.CompletableFuture
import kotlin.time.toKotlinDuration
import kotlin.time.Duration

class GasPriceUpdaterApp(
class L2NetworkGasPricingService(
vertx: Vertx,
httpJsonRpcClientFactory: VertxHttpJsonRpcClientFactory,
l1Web3jClient: Web3j,
l1Web3jService: Web3jBlobExtended,
config: L2NetworkGasPricing
config: Config
) : LongRunningService {
data class Config(
val feeHistoryFetcherConfig: FeeHistoryFetcherImpl.Config,
val jsonRpcPricingPropagationEnabled: Boolean,
val naiveGasPricingCalculatorConfig: GasUsageRatioWeightedAverageFeesCalculator.Config,
val naiveGasPricingCalculatorBounds: BoundableFeeCalculator.Config,
val jsonRpcGasPriceUpdaterConfig: GasPriceUpdaterImpl.Config,
val jsonRpcPriceUpdateInterval: Duration,
val extraDataPricingPropagationEnabled: Boolean,
val extraDataUpdateInterval: Duration,
val variableFeesCalculatorConfig: VariableFeesCalculator.Config,
val variableFeesCalculatorBounds: BoundableFeeCalculator.Config,
val extraDataCalculatorConfig: MinerExtraDataV1CalculatorImpl.Config,
val extraDataUpdaterConfig: ExtraDataV1UpdaterImpl.Config
)
private val log = LogManager.getLogger(this::class.java)

private val gasPricingFeesFetcher: FeesFetcher = FeeHistoryFetcherImpl(
l1Web3jClient,
l1Web3jService,
FeeHistoryFetcherImpl.Config(
config.feeHistoryBlockCount.toUInt(),
config.feeHistoryRewardPercentile
)
config.feeHistoryFetcherConfig
)

private val naiveGasPricingCalculator: FeesCalculator = run {
val gasUsageRatioWeightedAverageFeesCalculator = GasUsageRatioWeightedAverageFeesCalculator(
GasUsageRatioWeightedAverageFeesCalculator.Config(
baseFeeCoefficient = config.naiveGasPricing.baseFeeCoefficient,
priorityFeeCoefficient = config.naiveGasPricing.priorityFeeCoefficient,
baseFeeBlobCoefficient = config.naiveGasPricing.baseFeeBlobCoefficient,
blobSubmissionExpectedExecutionGas = config.blobSubmissionExpectedExecutionGas,
expectedBlobGas = config.l1BlobGas
)
config.naiveGasPricingCalculatorConfig
)
BoundableFeeCalculator(
BoundableFeeCalculator.Config(
config.naiveGasPricing.gasPriceUpperBound.toDouble(),
config.naiveGasPricing.gasPriceLowerBound.toDouble(),
0.0
),
config.naiveGasPricingCalculatorBounds,
gasUsageRatioWeightedAverageFeesCalculator
)
}

private val minMineableFeesPricerService: MinMineableFeesPricerService? =
if (config.jsonRpcPricingPropagation.enabled) {
if (config.jsonRpcPricingPropagationEnabled) {
val l2SetGasPriceUpdater: GasPriceUpdater = GasPriceUpdaterImpl(
httpJsonRpcClientFactory = httpJsonRpcClientFactory,
config = GasPriceUpdaterImpl.Config(
gethEndpoints = config.jsonRpcPricingPropagation.gethGasPriceUpdateRecipients,
besuEndPoints = config.jsonRpcPricingPropagation.besuGasPriceUpdateRecipients,
retryConfig = config.requestRetryConfig
)
config = config.jsonRpcGasPriceUpdaterConfig
)

MinMineableFeesPricerService(
pollingInterval = config.priceUpdateInterval.toKotlinDuration(),
pollingInterval = config.jsonRpcPriceUpdateInterval,
vertx = vertx,
feesFetcher = gasPricingFeesFetcher,
feesCalculator = naiveGasPricingCalculator,
Expand All @@ -84,41 +79,26 @@ class GasPriceUpdaterApp(
null
}

private val extraDataPricerService: ExtraDataV1PricerService? = if (config.extraDataPricingPropagation.enabled) {
private val extraDataPricerService: ExtraDataV1PricerService? = if (config.extraDataPricingPropagationEnabled) {
val variableCostCalculator = VariableFeesCalculator(
VariableFeesCalculator.Config(
blobSubmissionExpectedExecutionGas = config.blobSubmissionExpectedExecutionGas,
bytesPerDataSubmission = config.l1BlobGas,
expectedBlobGas = config.bytesPerDataSubmission,
margin = config.variableCostPricing.margin
)
config.variableFeesCalculatorConfig
)
val boundedVariableCostCalculator = BoundableFeeCalculator(
config = BoundableFeeCalculator.Config(
feeUpperBound = config.variableCostPricing.variableCostUpperBound.toDouble(),
feeLowerBound = config.variableCostPricing.variableCostLowerBound.toDouble(),
feeMargin = 0.0
),
config = config.variableFeesCalculatorBounds,
feesCalculator = variableCostCalculator
)
ExtraDataV1PricerService(
pollingInterval = config.priceUpdateInterval.toKotlinDuration(),
pollingInterval = config.extraDataUpdateInterval,
vertx = vertx,
feesFetcher = gasPricingFeesFetcher,
minerExtraDataCalculatorImpl = MinerExtraDataV1CalculatorImpl(
config = MinerExtraDataV1CalculatorImpl.Config(
fixedCostInKWei = config.variableCostPricing.gasPriceFixedCost.toKWeiUInt(),
ethGasPriceMultiplier = config.variableCostPricing.legacyFeesMultiplier
),
config = config.extraDataCalculatorConfig,
variableFeesCalculator = boundedVariableCostCalculator,
legacyFeesCalculator = naiveGasPricingCalculator
),
extraDataUpdater = ExtraDataV1UpdaterImpl(
httpJsonRpcClientFactory = httpJsonRpcClientFactory,
config = ExtraDataV1UpdaterImpl.Config(
config.extraDataPricingPropagation.extraDataUpdateRecipient,
config.requestRetryConfig
)
config = config.extraDataUpdaterConfig
)
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import net.consensys.linea.traces.TracesCountersV2
import net.consensys.linea.traces.TracingModuleV1
import net.consensys.linea.traces.TracingModuleV2
import net.consensys.linea.web3j.SmartContractErrors
import net.consensys.zkevm.coordinator.app.L2NetworkGasPricingService
import net.consensys.zkevm.coordinator.clients.prover.ProversConfig
import net.consensys.zkevm.coordinator.clients.smartcontract.BlockParameter
import java.math.BigInteger
Expand Down Expand Up @@ -120,7 +121,7 @@ data class PersistenceRetryConfig(
override val timeout: Duration? = 10.minutes.toJavaDuration()
) : RetryConfig

private interface RequestRetryConfigurable {
internal interface RequestRetryConfigurable {
val requestRetry: RequestRetryConfigTomlFriendly
val requestRetryConfig: RequestRetryConfig
get() = requestRetry.asDomain
Expand Down Expand Up @@ -366,82 +367,6 @@ data class MessageAnchoringServiceConfig(
}
}

data class NaiveGasPricing(
val baseFeeCoefficient: Double,
val priorityFeeCoefficient: Double,
val baseFeeBlobCoefficient: Double,

val gasPriceUpperBound: ULong,
val gasPriceLowerBound: ULong
) {
init {
require(gasPriceUpperBound >= gasPriceLowerBound) {
"gasPriceUpperBound must be greater than or equal to gasPriceLowerBound"
}
}
}

data class VariableCostPricing(
val gasPriceFixedCost: ULong,
val legacyFeesMultiplier: Double,
val margin: Double,
val variableCostUpperBound: ULong,
val variableCostLowerBound: ULong
) {
init {
require(variableCostUpperBound >= variableCostLowerBound) {
"variableCostUpperBound must be greater than or equal to variableCostLowerBound"
}
}
}

data class JsonRpcPricingPropagation(
override var disabled: Boolean = false,
val gethGasPriceUpdateRecipients: List<URL>,
val besuGasPriceUpdateRecipients: List<URL>
) : FeatureToggleable {
init {
require(disabled || (gethGasPriceUpdateRecipients.isNotEmpty() || besuGasPriceUpdateRecipients.isNotEmpty())) {
"There is no point of enabling JSON RPC pricing propagation if there are no " +
"gethGasPriceUpdateRecipients or besuGasPriceUpdateRecipients defined"
}
}
}

data class ExtraDataPricingPropagation(
override var disabled: Boolean = false,
val extraDataUpdateRecipient: URL
) : FeatureToggleable

data class L2NetworkGasPricing(
override var disabled: Boolean = false,
override val requestRetry: RequestRetryConfigTomlFriendly,

val priceUpdateInterval: Duration,
val feeHistoryBlockCount: Int,
val feeHistoryRewardPercentile: Double,

val blobSubmissionExpectedExecutionGas: Int,
@ConfigAlias("bytesPerDataSubmission") val _bytesPerDataSubmission: Int?,
val l1BlobGas: Int,

val naiveGasPricing: NaiveGasPricing,
val variableCostPricing: VariableCostPricing,
val jsonRpcPricingPropagation: JsonRpcPricingPropagation,
val extraDataPricingPropagation: ExtraDataPricingPropagation
) : FeatureToggleable, RequestRetryConfigurable {
init {
require(feeHistoryBlockCount > 0) { "feeHistoryBlockCount must be greater than 0" }

require(disabled || (jsonRpcPricingPropagation.enabled || extraDataPricingPropagation.enabled)) {
"There is no point of enabling L2 network gas pricing if " +
"both jsonRpcPricingPropagation and extraDataPricingPropagation are disabled"
}
}

val bytesPerDataSubmission = _bytesPerDataSubmission ?: l1BlobGas
}

data class L1DynamicGasPriceCapServiceConfig(
val gasPriceCapCalculation: GasPriceCapCalculation,
val feeHistoryFetcher: FeeHistoryFetcher,
Expand Down Expand Up @@ -603,7 +528,7 @@ data class CoordinatorConfigTomlDto(
val api: ApiConfig,
val l2Signer: SignerConfig,
val messageAnchoringService: MessageAnchoringServiceConfig,
val l2NetworkGasPricing: L2NetworkGasPricing,
val l2NetworkGasPricing: L2NetworkGasPricingTomlDto,
val l1DynamicGasPriceCapService: L1DynamicGasPriceCapServiceConfig,
val testL1Disabled: Boolean = false,
val prover: ProverConfigTomlDto
Expand All @@ -628,7 +553,7 @@ data class CoordinatorConfigTomlDto(
api = api,
l2Signer = l2Signer,
messageAnchoringService = messageAnchoringService,
l2NetworkGasPricing = l2NetworkGasPricing,
l2NetworkGasPricingService = if (!testL1Disabled) l2NetworkGasPricing.reified() else null,
l1DynamicGasPriceCapService = l1DynamicGasPriceCapService,
testL1Disabled = testL1Disabled,
proversConfig = prover.reified()
Expand All @@ -655,7 +580,7 @@ data class CoordinatorConfig(
val api: ApiConfig,
val l2Signer: SignerConfig,
val messageAnchoringService: MessageAnchoringServiceConfig,
val l2NetworkGasPricing: L2NetworkGasPricing,
val l2NetworkGasPricingService: L2NetworkGasPricingService.Config?,
val l1DynamicGasPriceCapService: L1DynamicGasPriceCapServiceConfig,
val testL1Disabled: Boolean = false,
val proversConfig: ProversConfig
Expand All @@ -680,7 +605,6 @@ data class CoordinatorConfig(

if (testL1Disabled) {
messageAnchoringService.disabled = true
l2NetworkGasPricing.disabled = true
l1DynamicGasPriceCapService.disabled = true
}
}
Expand Down
Loading

0 comments on commit 34acc64

Please sign in to comment.