-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: georgi-l95 <[email protected]> Signed-off-by: Alfredo Gutierrez <[email protected]> Co-authored-by: georgi-l95 <[email protected]>
- Loading branch information
1 parent
e957565
commit e392f2b
Showing
21 changed files
with
745 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
buildSrc/src/main/kotlin/com.hedera.block.simulator.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
plugins { | ||
id("application") | ||
id("com.hedera.block.conventions") | ||
id("me.champeau.jmh") | ||
} | ||
|
||
val maven = publishing.publications.create<MavenPublication>("maven") { from(components["java"]) } | ||
|
||
signing.sign(maven) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
plugins { | ||
id("application") | ||
id("com.hedera.block.simulator") | ||
} | ||
|
||
description = "Hedera Block Stream Simulator" | ||
|
||
application { | ||
mainModule = "com.hedera.block.simulator" | ||
mainClass = "com.hedera.block.simulator.BlockStreamSimulator" | ||
} | ||
|
||
mainModuleInfo { | ||
annotationProcessor("dagger.compiler") | ||
annotationProcessor("com.google.auto.service.processor") | ||
runtimeOnly("com.swirlds.config.impl") | ||
} | ||
|
||
testModuleInfo { | ||
requires("org.junit.jupiter.api") | ||
requires("org.mockito") | ||
requires("org.mockito.junit.jupiter") | ||
requiresStatic("com.github.spotbugs.annotations") | ||
} |
62 changes: 62 additions & 0 deletions
62
simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.block.simulator; | ||
|
||
import static java.lang.System.Logger.Level.INFO; | ||
|
||
import com.swirlds.config.api.Configuration; | ||
import com.swirlds.config.api.ConfigurationBuilder; | ||
import com.swirlds.config.extensions.sources.ClasspathFileConfigSource; | ||
import com.swirlds.config.extensions.sources.SystemEnvironmentConfigSource; | ||
import com.swirlds.config.extensions.sources.SystemPropertiesConfigSource; | ||
import java.io.IOException; | ||
import java.lang.System.Logger; | ||
import java.nio.file.Path; | ||
|
||
/** The BlockStreamSimulator class defines the simulator for the block stream. */ | ||
public class BlockStreamSimulator { | ||
private static final Logger LOGGER = System.getLogger(BlockStreamSimulator.class.getName()); | ||
|
||
/** This constructor should not be instantiated. */ | ||
private BlockStreamSimulator() {} | ||
|
||
/** | ||
* The main entry point for the block stream simulator. | ||
* | ||
* @param args the arguments to be passed to the block stream simulator | ||
* @throws IOException if an I/O error occurs | ||
*/ | ||
public static void main(String[] args) throws IOException { | ||
|
||
LOGGER.log(INFO, "Starting Block Stream Simulator"); | ||
|
||
ConfigurationBuilder configurationBuilder = | ||
ConfigurationBuilder.create() | ||
.withSource(SystemEnvironmentConfigSource.getInstance()) | ||
.withSource(SystemPropertiesConfigSource.getInstance()) | ||
.withSource(new ClasspathFileConfigSource(Path.of("app.properties"))) | ||
.autoDiscoverExtensions(); | ||
|
||
Configuration configuration = configurationBuilder.build(); | ||
|
||
BlockStreamSimulatorInjectionComponent DIComponent = | ||
DaggerBlockStreamSimulatorInjectionComponent.factory().create(configuration); | ||
|
||
BlockStreamSimulatorApp blockStreamSimulatorApp = DIComponent.getBlockStreamSimulatorApp(); | ||
blockStreamSimulatorApp.start(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulatorApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.block.simulator; | ||
|
||
import com.hedera.block.simulator.generator.BlockStreamManager; | ||
import com.swirlds.config.api.Configuration; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import javax.inject.Inject; | ||
|
||
/** BlockStream Simulator App */ | ||
public class BlockStreamSimulatorApp { | ||
|
||
private static final System.Logger LOGGER = | ||
System.getLogger(BlockStreamSimulatorApp.class.getName()); | ||
|
||
Configuration configuration; | ||
BlockStreamManager blockStreamManager; | ||
boolean isRunning = false; | ||
|
||
/** | ||
* Creates a new BlockStreamSimulatorApp instance. | ||
* | ||
* @param configuration the configuration to be used by the block stream simulator | ||
* @param blockStreamManager the block stream manager to be used by the block stream simulator | ||
*/ | ||
@Inject | ||
public BlockStreamSimulatorApp( | ||
@NonNull Configuration configuration, @NonNull BlockStreamManager blockStreamManager) { | ||
this.configuration = configuration; | ||
this.blockStreamManager = blockStreamManager; | ||
} | ||
|
||
/** Starts the block stream simulator. */ | ||
public void start() { | ||
|
||
// use blockStreamManager to get block stream | ||
|
||
// use PublishStreamGrpcClient to stream it to the block-node. | ||
isRunning = true; | ||
LOGGER.log(System.Logger.Level.INFO, "Block Stream Simulator has started"); | ||
} | ||
|
||
/** | ||
* Returns whether the block stream simulator is running. | ||
* | ||
* @return true if the block stream simulator is running, false otherwise | ||
*/ | ||
public boolean isRunning() { | ||
return isRunning; | ||
} | ||
|
||
/** Stops the block stream simulator. */ | ||
public void stop() { | ||
isRunning = false; | ||
LOGGER.log(System.Logger.Level.INFO, "Block Stream Simulator has stopped"); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...ator/src/main/java/com/hedera/block/simulator/BlockStreamSimulatorInjectionComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.block.simulator; | ||
|
||
import com.hedera.block.simulator.config.ConfigInjectionModule; | ||
import com.hedera.block.simulator.generator.GeneratorInjectionModule; | ||
import com.swirlds.config.api.Configuration; | ||
import dagger.BindsInstance; | ||
import dagger.Component; | ||
import javax.inject.Singleton; | ||
|
||
/** The component used to inject the block stream simulator into the application. */ | ||
@Singleton | ||
@Component( | ||
modules = { | ||
ConfigInjectionModule.class, | ||
GeneratorInjectionModule.class, | ||
}) | ||
public interface BlockStreamSimulatorInjectionComponent { | ||
|
||
/** | ||
* Gets the block stream simulator. | ||
* | ||
* @return the block stream simulator | ||
*/ | ||
BlockStreamSimulatorApp getBlockStreamSimulatorApp(); | ||
|
||
/** The factory used to create the block stream simulator injection component. */ | ||
@Component.Factory | ||
interface Factory { | ||
/** | ||
* Creates the block stream simulator injection component. | ||
* | ||
* @param configuration the configuration to be used by the block stream simulator | ||
* @return the block stream simulator injection component | ||
*/ | ||
BlockStreamSimulatorInjectionComponent create(@BindsInstance Configuration configuration); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
simulator/src/main/java/com/hedera/block/simulator/config/ConfigInjectionModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.block.simulator.config; | ||
|
||
import com.hedera.block.simulator.config.data.BlockStreamConfig; | ||
import com.hedera.block.simulator.config.data.GrpcConfig; | ||
import com.swirlds.config.api.Configuration; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import javax.inject.Singleton; | ||
|
||
/** The module used to inject the configuration data into the application. */ | ||
@Module | ||
public interface ConfigInjectionModule { | ||
|
||
/** | ||
* Provides the block stream configuration. | ||
* | ||
* @param configuration the configuration to be used by the block stream | ||
* @return the block stream configuration | ||
*/ | ||
@Singleton | ||
@Provides | ||
static BlockStreamConfig provideBlockStreamConfig(Configuration configuration) { | ||
return configuration.getConfigData(BlockStreamConfig.class); | ||
} | ||
|
||
/** | ||
* Provides the gRPC configuration. | ||
* | ||
* @param configuration the configuration to be used by the gRPC | ||
* @return the gRPC configuration | ||
*/ | ||
@Singleton | ||
@Provides | ||
static GrpcConfig provideGrpcConfig(Configuration configuration) { | ||
return configuration.getConfigData(GrpcConfig.class); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
simulator/src/main/java/com/hedera/block/simulator/config/SimulatorConfigExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.block.simulator.config; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.hedera.block.simulator.config.data.BlockStreamConfig; | ||
import com.hedera.block.simulator.config.data.GrpcConfig; | ||
import com.swirlds.config.api.ConfigurationExtension; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import java.util.Set; | ||
|
||
/** Sets up configuration for services. */ | ||
@AutoService(ConfigurationExtension.class) | ||
public class SimulatorConfigExtension implements ConfigurationExtension { | ||
|
||
/** Explicitly defined constructor. */ | ||
public SimulatorConfigExtension() { | ||
super(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Set<Class<? extends Record>> getConfigDataTypes() { | ||
return Set.of(BlockStreamConfig.class, GrpcConfig.class); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
simulator/src/main/java/com/hedera/block/simulator/config/data/BlockStreamConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hedera.block.simulator.config.data; | ||
|
||
import com.hedera.block.simulator.config.types.GenerationMode; | ||
import com.swirlds.config.api.ConfigData; | ||
import com.swirlds.config.api.ConfigProperty; | ||
|
||
/** | ||
* The BlockStreamConfig class defines the configuration data for the block stream. | ||
* | ||
* @param generationMode the mode of generation for the block stream | ||
*/ | ||
@ConfigData("blockStream") | ||
public record BlockStreamConfig( | ||
@ConfigProperty(defaultValue = "DIR") GenerationMode generationMode) {} |
Oops, something went wrong.