-
Notifications
You must be signed in to change notification settings - Fork 129
[PAN-3023] Add command line option for target gas limit #1917
base: master
Are you sure you want to change the base?
Changes from 1 commit
e60efe8
5d1db9a
453d65f
274f06c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,7 @@ | |
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.function.Function; | ||
| import java.util.function.Supplier; | ||
| import java.util.stream.Collectors; | ||
|
|
||
|
|
@@ -633,6 +634,12 @@ void setBannedNodeIds(final List<String> values) { | |
| "The name of a file containing the private key used to sign privacy marker transactions. If unset, each will be signed with a random key.") | ||
| private final Path privacyMarkerTransactionSigningKeyPath = null; | ||
|
|
||
| @Option( | ||
| names = {"--target-gas-limit"}, | ||
| description = | ||
| "Sets target gas limit per block. If set each blocks gas limit will approach this setting over time if the current gas limit is different.") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MadelineMurray for help description text review |
||
| private final Long targetGasLimit = null; | ||
|
|
||
| @Option( | ||
| names = {"--tx-pool-max-size"}, | ||
| paramLabel = MANDATORY_INTEGER_FORMAT_HELP, | ||
|
|
@@ -657,6 +664,7 @@ void setBannedNodeIds(final List<String> values) { | |
| private MetricsConfiguration metricsConfiguration; | ||
| private Optional<PermissioningConfiguration> permissioningConfiguration; | ||
| private Collection<EnodeURL> staticNodes; | ||
| private Function<Long, Long> gasLimitCalculator; | ||
| private PantheonController<?> pantheonController; | ||
|
|
||
| private final Supplier<ObservableMetricsSystem> metricsSystem = | ||
|
|
@@ -879,6 +887,7 @@ private PantheonCommand configure() throws Exception { | |
| webSocketConfiguration = webSocketConfiguration(); | ||
| permissioningConfiguration = permissioningConfiguration(); | ||
| staticNodes = loadStaticNodes(); | ||
| gasLimitCalculator = gasLimitCalculator(); | ||
| logger.info("Connecting to {} static nodes.", staticNodes.size()); | ||
| logger.trace("Static Nodes = {}", staticNodes); | ||
| final List<URI> enodeURIs = | ||
|
|
@@ -946,7 +955,8 @@ public PantheonControllerBuilder<?> getControllerBuilder() { | |
| .clock(Clock.systemUTC()) | ||
| .isRevertReasonEnabled(isRevertReasonEnabled) | ||
| .isPruningEnabled(isPruningEnabled) | ||
| .pruningConfiguration(buildPruningConfiguration()); | ||
| .pruningConfiguration(buildPruningConfiguration()) | ||
| .gasLimitCalculator(gasLimitCalculator); | ||
| } catch (final IOException e) { | ||
| throw new ExecutionException(this.commandLine, "Invalid path", e); | ||
| } | ||
|
|
@@ -1536,6 +1546,31 @@ private Set<EnodeURL> loadStaticNodes() throws IOException { | |
| return StaticNodesParser.fromPath(staticNodesPath); | ||
| } | ||
|
|
||
| private Function<Long, Long> gasLimitCalculator() { | ||
cfelde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| final long targetGasLimit = this.targetGasLimit == null ? 0L : this.targetGasLimit; | ||
| final long adjustmentFactor = 1024L; | ||
|
|
||
| if (targetGasLimit > 0L) { | ||
| return (gasLimit) -> { | ||
| long newGasLimit; | ||
|
|
||
| if (targetGasLimit > gasLimit) { | ||
| newGasLimit = Math.min(targetGasLimit, gasLimit + adjustmentFactor); | ||
| } else if (targetGasLimit < gasLimit) { | ||
| newGasLimit = Math.max(targetGasLimit, gasLimit - adjustmentFactor); | ||
| } else { | ||
| return gasLimit; | ||
| } | ||
|
|
||
| logger.debug("Adjusting block gas limit from {} to {}", gasLimit, newGasLimit); | ||
|
|
||
| return newGasLimit; | ||
| }; | ||
| } else { | ||
| return gasLimit -> gasLimit; | ||
| } | ||
| } | ||
|
|
||
| public PantheonExceptionHandler exceptionHandler() { | ||
| return new PantheonExceptionHandler(this::getLogLevel); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ | |
| import java.util.Optional; | ||
| import java.util.OptionalLong; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.function.Function; | ||
|
|
||
| import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
| import org.apache.logging.log4j.LogManager; | ||
|
|
@@ -84,6 +85,7 @@ public abstract class PantheonControllerBuilder<C> { | |
| protected Clock clock; | ||
| protected KeyPair nodeKeys; | ||
| protected boolean isRevertReasonEnabled; | ||
| protected Function<Long, Long> gasLimitCalculator; | ||
|
||
| private StorageProvider storageProvider; | ||
| private final List<Runnable> shutdownActions = new ArrayList<>(); | ||
| private RocksDbConfiguration rocksDbConfiguration; | ||
|
|
@@ -181,6 +183,12 @@ public PantheonControllerBuilder<C> pruningConfiguration( | |
| return this; | ||
| } | ||
|
|
||
| public PantheonControllerBuilder<C> gasLimitCalculator( | ||
| final Function<Long, Long> gasLimitCalculator) { | ||
| this.gasLimitCalculator = gasLimitCalculator; | ||
| return this; | ||
| } | ||
|
|
||
| public PantheonController<C> build() throws IOException { | ||
| checkNotNull(genesisConfig, "Missing genesis config"); | ||
| checkNotNull(syncConfig, "Missing sync config"); | ||
|
|
@@ -193,6 +201,7 @@ public PantheonController<C> build() throws IOException { | |
| checkNotNull(clock, "Mising clock"); | ||
| checkNotNull(transactionPoolConfiguration, "Missing transaction pool configuration"); | ||
| checkNotNull(nodeKeys, "Missing node keys"); | ||
| checkNotNull(gasLimitCalculator, "Missing gas limit calculator"); | ||
| checkArgument( | ||
| storageProvider != null || rocksDbConfiguration != null, | ||
| "Must supply either a storage provider or RocksDB configuration"); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.