Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: simulator generation mode improvements #682

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

georgi-l95
Copy link
Member

@georgi-l95 georgi-l95 commented Feb 20, 2025

Description

With this PR we aim to introduce new generator mode for the block stream, by introducing new implementation for the BlockStreamManager. The following changes are included in this pull request:

  • Addition of new CraftBlockStreamManager implementation with the purpose of crafting blocks on the fly and on demand. Currently we are adding random amount of items(transactions) in the block, according to the defined configuration.
  • 4 new configuration properties for managing amount of block items in block
  • ADHOC mode in GenerationMode renamed to CRAFT, to better explain the purpose and function of this mode.
  • Handler for each type of introduced block item.
    • BlockHeaderHandler responsible for crafting block header for each new block with needed fields.
    • BlockProofHandler responsible for crafting block proof with adequte signature(for now) to pass verification.
    • EventHeader and EventTransaction to represent the start of each new event and it's respective transctions.
    • TransactionResult to represent the result of the transactions included in the block. For now we've included only HBAR TransferList and fungible TokenTransferList as result with randomly generated AccountAmounts.
  • Little change to how BlockStreamManager implementation is provided to Dagger.

Related Issue(s)

Fixes #502

@georgi-l95 georgi-l95 added New Feature A new feature, service, or documentation. Major changes that are not backwards compatible. Simulator Issue related to Block Stream Simulator labels Feb 20, 2025
@georgi-l95 georgi-l95 added this to the 0.5.0 milestone Feb 20, 2025
@georgi-l95 georgi-l95 self-assigned this Feb 20, 2025
@georgi-l95 georgi-l95 linked an issue Feb 20, 2025 that may be closed by this pull request
@georgi-l95 georgi-l95 marked this pull request as ready for review February 20, 2025 12:11
@georgi-l95 georgi-l95 requested review from a team as code owners February 20, 2025 12:11
Copy link
Contributor

@mattp-swirldslabs mattp-swirldslabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

import com.hedera.block.common.hasher.Hashes;
import com.hedera.block.common.hasher.HashingUtilities;
import com.hedera.block.common.hasher.NaiveStreamingTreeHasher;
import com.hedera.block.common.hasher.StreamingTreeHasher;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Georgi, we talked about this in a DM. We'll need to talk through whether the Hashing really belongs in the common module since it forces the Simulator to use PBJ types. I'm bringing it up for visibility. We can fix it with a future PR if the team wants to remove the dep here. Feel free to resolve this comment to merge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you for bringing attetion to this, I was not aware that the PBJ types was dep non grata in common module at the time. we can discuss how to decouple the hasher from PBJ or maybe just create new hasher algorithm for simulator and return this one to server there are many alternatives to consider and at the time, I appreciate that you don't consider this to be a blocker 🙏 👍 💯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support creating a different hasher for the simulator and moving the current hasher back to server.
It seemed a good choice, at the time, to share the code, but it's looking like we are better off keeping the two systems more separated in this specific case.
Thanks for the suggestions, @AlfredoG87.

@@ -0,0 +1,27 @@
// SPDX-License-Identifier: Apache-2.0
package com.hedera.block.simulator.generator.itemhandler;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like all the classes in this package are helpers to deal with the PBJ transitive dep. Hopefully we can figure out a way to remove that dep since you already have parsed the full object via protoc. We shouldn't have to use classes like *Unparsed

@ConfigProperty(defaultValue = "") String folderRootPath,
@ConfigProperty(defaultValue = "BlockAsFileBlockStreamManager") String managerImplementation,
@ConfigProperty(defaultValue = "36") int paddedLength,
@ConfigProperty(defaultValue = ".blk.gz") String fileExtension,
// Optional block number range for the BlockAsFileLargeDataSets manager
@ConfigProperty(defaultValue = "1") @Min(1) int startBlockNumber,
@ConfigProperty(defaultValue = "1") @Min(0) int startBlockNumber,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on this min value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did we land on this?
I recall that blocks were supposed to always start at 1 for genesis, and if a client requests a block range it needs to run from 1 to n (where if n is 0 then it means stream forever).
Did we find that the genesis block is numbered 0?

Copy link
Contributor

@AlfredoG87 AlfredoG87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great work!! thank you @georgi-l95 💯

note: all comments are just comments and feel free to resolve them.

import com.hedera.block.common.hasher.Hashes;
import com.hedera.block.common.hasher.HashingUtilities;
import com.hedera.block.common.hasher.NaiveStreamingTreeHasher;
import com.hedera.block.common.hasher.StreamingTreeHasher;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you for bringing attetion to this, I was not aware that the PBJ types was dep non grata in common module at the time. we can discuss how to decouple the hasher from PBJ or maybe just create new hasher algorithm for simulator and return this one to server there are many alternatives to consider and at the time, I appreciate that you don't consider this to be a blocker 🙏 👍 💯

Comment on lines +35 to +36
if ("BlockAsDirBlockStreamManager".equalsIgnoreCase(managerImpl)) {
yield new BlockAsDirBlockStreamManager(config);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might consider to get rid of this implementation in the future to reduce maintenance footprint, I mean, if is no longer needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simulator may find benefit from having the dir option.
For instance, we might want to have an input folder with blocks (in block as dir) as a source and appreciate the ability to swap out individual block items without needing to rewrite entire blocks (or make changes on the fly). The option to use hard links for the parts that don't change is also valuable, at least to some extent.

That said, if it's costing a lot of maintenance, it's fine to remove now, and we can always restore the code or rewrite if it's worthwhile.

Comment on lines +55 to +56
.setRealmNum(0)
.setShardNum(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a story to support non-zero (and non-static) shard and realm in a future sprint?
Consensus is already adding this, and it would be nice to be able to test with the simulator.

Comment on lines +54 to +59
new ConfigMapping("generator.minNumberOfEventsPerBlock", "GENERATOR_MIN_NUMBER_OF_EVENTS_PER_BLOCK"),
new ConfigMapping("generator.maxNumberOfEventsPerBlock", "GENERATOR_MAX_NUMBER_OF_EVENTS_PER_BLOCK"),
new ConfigMapping(
"generator.minNumberOfTransactionsPerEvent", "GENERATOR_MIN_NUMBER_OF_TRANSACTIONS_PER_EVENT"),
new ConfigMapping(
"generator.maxNumberOfTransactionsPerEvent", "GENERATOR_MAX_NUMBER_OF_TRANSACTIONS_PER_EVENT"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it makes sense to elide the NUMBER_OF_ part of these names?

@AlfredoG87 AlfredoG87 modified the milestones: 0.5.0, 0.6.0 Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Feature A new feature, service, or documentation. Major changes that are not backwards compatible. Simulator Issue related to Block Stream Simulator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simulator Generation Mode Improvements
4 participants