Skip to content

Add generic ChainWorker module - #78

Merged
DZakh merged 5 commits into
mainfrom
dz/worker-mod
Jul 23, 2024
Merged

Add generic ChainWorker module#78
DZakh merged 5 commits into
mainfrom
dz/worker-mod

Conversation

@DZakh

@DZakh DZakh commented Jul 17, 2024

Copy link
Copy Markdown
Member

No description provided.

@DZakh
DZakh requested a review from JonoPrest July 17, 2024 15:01

@DZakh DZakh left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In general, nothing important. But I'd say it makes the project more maintainable.

type source<'a, 'b> = HyperSync('a) | Rpc('b)

type syncSource = source<serverUrl, rpcConfig>
type syncSource = HyperSync(hyperSyncConfig) | HyperFuel(hyperFuelConfig) | Rpc(rpcConfig)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

HyperFuel is not used yet. The option fullbacks to HyperSyncWorker

chainConfig,
rpcConfig,
config,
let currentBlockInterval = ref(T.rpcConfig.syncConfig.initialBlockInterval)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

!!! Important: This has become mutable. That should be fine for the case, but I want to double check with you.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Your changes shouldn't change current behaviour but I think with the new partition system, this value should be stored on the partition because they can be fetching very different volumes of data. Or perhaps just have a worker per partition.

@as("latest_processed_block") latestProcessedBlock: option<int>,
@as("num_events_processed") numEventsProcessed: option<int>,
@as("is_hyper_sync") isHyperSync: bool,
@as("is_hyper_sync") poweredByHyperSync: bool,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is going to require changes to the UI & being able to be backwards compatible to query the "is_hyper_sync". Since this table is used for all the sync/progress bars on the hosted service.

It's best not to change this unless we need to to 👍🏼

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, I've seen it in the code. The change is fine, since the @as("is_hyper_sync") stays the same

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was just confused what the variable needed for, so after figuring it out I've decided to rename it on the ReScript side, to make it more readable (in my opinion)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah got you! I didn't see the @as

@DZakh
DZakh requested a review from JonoPrest July 22, 2024 08:47
Comment on lines +2 to +15
open ChainWorker

module Make = (
T: {
let config: Config.t
let rpcConfig: Config.rpcConfig
let chainConfig: Config.chainConfig
},
): Type => {
let name = "RPC"
let config = T.config
let rpcConfig = T.rpcConfig
let chainConfig = T.chainConfig
let chain = chainConfig.chain

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Out of interest what made you want to use a functor for this with static variables?

@DZakh DZakh Jul 22, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Otherwise I'd have to keep state and worker mod separately, and I couldn't figure out how to type them nicely, to tell that they belong to each other. So I've decided it's better to simply have only worker mod

worker: Config.source<'a, 'b>,
}

module type Type = {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just FYI it is idiomatic to call type signature of a Functor module type S, like using type t for a module's main type.

@JonoPrest JonoPrest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Cool Dmitry,

Overall, I like the concept passing around the first class modules to allow mixed types 🙂 I used to do something similar where ChainWorker actually just had a set of functions that would take the variant Rpc(worker) | Hypersync(worker) and then call the appropriate function. But it was getting bloated for the little it was used.

What I'm not a huge fan of is that you end up passing around objects that contain functions rather than just values. Reminds me a lot of classes/OOP 🤔

I think lets also just think through the repercussions of renaming that field in chain metadata.

@DZakh
DZakh requested a review from JonoPrest July 22, 2024 18:36

@JonoPrest JonoPrest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great Dmitry! 🚀

@DZakh
DZakh merged commit 79391c1 into main Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants