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

refactor: Add NodeService and ServiceState interfaces #688

Merged
merged 5 commits into from
Jan 15, 2025

Conversation

Zurcusa
Copy link
Collaborator

@Zurcusa Zurcusa commented Jan 15, 2025

Description

This PR aims to improve the overall structure of Fruzhin in 2 ways:

  • Add a shared interface for services (sync and network, babe and grandpa are to follow) NodeService. This enables services to share a class signature and be started/stopped in a similar fashion. It also helps separate what services are required and started for each type of node.
  • Add a shared interface for states (block, sync, epoch, grandpa and transaction) ServiceState. Reasoning is similar to the service one, but it also aims to centralize the initialization of the states as they were not concise. It also prepares Fruzhin to follow the Runtime to Consensus engine communication. (initializing states at genesis and using consensus message to update)

@Zurcusa Zurcusa added this to the Fruzhin Phase 3 - M2. GRANDPA milestone Jan 15, 2025
@Zurcusa Zurcusa self-assigned this Jan 15, 2025
@Zurcusa Zurcusa requested a review from georg-getz January 15, 2025 10:47
@nistanimirov nistanimirov linked an issue Jan 15, 2025 that may be closed by this pull request

@Override
public void persistState() {
//There's no need to store historical transaction data in DB.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not the biggest improvement but you can add default empty implementation to the AbstractState class in order not to add this overrides here.
Screenshot 2025-01-15 at 14 22 47

@@ -1,89 +1,13 @@
package com.limechain.client;

import com.limechain.cli.CliArguments;
Copy link
Collaborator

Choose a reason for hiding this comment

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

With this refactoring, we don't need this class anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean AbstractNode, not the one in the import.

Comment on lines 102 to 106
try {
BlockState.getInstance().setFinalizedHash(
blockByHash.getHeader(), commitMessage.getRoundNumber(), commitMessage.getSetId());
blockState.setFinalizedHash(blockHeader, commitMessage.getRoundNumber(), commitMessage.getSetId());
} catch (Exception e) {
log.fine(e.getMessage());
return false;
Copy link
Member

Choose a reason for hiding this comment

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

What exception are we catching here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Various errors from BlockState. Such as BlockNodeNotFoundException, LowerThanRootException

Copy link
Member

Choose a reason for hiding this comment

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

Change Exception to RuntimeException so that it's clear that there are no checked exceptons.

Comment on lines +121 to 123
public void onFinish(Runnable... function) {
onFinishCallbacks.addAll(List.of(function));
}
Copy link
Member

Choose a reason for hiding this comment

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

When are we giving this more than 1 runnable?

Copy link
Member

Choose a reason for hiding this comment

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

Also should be functions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In SyncService

warpSyncMachine.onFinish(() -> AbstractState.setSyncMode(SyncMode.HEAD), messageCoordinator::handshakeBootNodes);
warpSyncMachine.onFinish(() -> AbstractState.setSyncMode(SyncMode.FULL), fullSyncMachine::start);

Copy link

@Zurcusa Zurcusa merged commit 438a9d7 into 666-refactor-services-states Jan 15, 2025
3 checks passed
@Zurcusa Zurcusa deleted the 684-interfaces-states-services branch January 15, 2025 16:04
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.

Add interfaces for services and states and refactor related code.
3 participants