Skip to content

refactor: create TransactionService class #3646

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

Conversation

konstantinabl
Copy link
Contributor

@konstantinabl konstantinabl commented Apr 7, 2025

Description:

This PR refactors the JSON-RPC relay by extracting transaction-related functionality from the eth.ts file into a dedicated TransactionService class and moving shared code into a CommonService. This improves code organization, testability, and maintainability.

Changes:

  • Created new TransactionService to handle all transaction-related RPC methods
  • Moved methods used only from the transaction related methods to the TransactionService - sendRawTransactionProcessor, prune0x, parseRawTxAndPrecheck, sendRawTransactionErrorHandler
  • Moved common static variables into a CommonService class
  • Changed the way we use ethExecutionsCounter - moved it to the metric service as an event listener, similar to other metrics we have
  • Created TransactionReceiptFactory to standardize creation of transaction receipts
  • Added JSDoc where missing

Moved methods to TransactionService

  • getTransactionByBlockHashAndIndex
  • getTransactionByBlockNumberAndIndex
  • getTransactionByHash
  • getTransactionReceipt
  • sendRawTransaction
  • sendTransaction
  • signTransaction
  • sign

Fixes:

#3570
#3622

@konstantinabl konstantinabl linked an issue Apr 7, 2025 that may be closed by this pull request
@konstantinabl konstantinabl changed the base branch from main to poc-eth-service-apporach April 7, 2025 21:21
@konstantinabl konstantinabl self-assigned this Apr 8, 2025
@konstantinabl konstantinabl force-pushed the 3570-refactor-create-transactionservice-class branch from dc202fb to 58d2386 Compare April 8, 2025 11:32
@konstantinabl konstantinabl changed the base branch from poc-eth-service-apporach to main April 8, 2025 11:32
@konstantinabl konstantinabl added this to the 0.69.0 milestone Apr 8, 2025
@konstantinabl konstantinabl changed the base branch from main to poc-eth-service-apporach April 8, 2025 13:01
@konstantinabl konstantinabl changed the title 3570 refactor create transactionservice class refactor: create TransactionService class Apr 8, 2025
@konstantinabl konstantinabl marked this pull request as ready for review April 8, 2025 13:14
@konstantinabl konstantinabl requested review from a team as code owners April 8, 2025 13:14
@konstantinabl konstantinabl force-pushed the 3570-refactor-create-transactionservice-class branch from 081948b to b790ba2 Compare April 8, 2025 13:49
@konstantinabl konstantinabl added the enhancement New feature or request label Apr 8, 2025
Copy link
Contributor

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

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

Great work! Much cleaner and more organized now. Left some Qs and suggestions around.

* @param requestDetails The request details for logging and tracking
* @returns {Promise<string>} A promise that resolves to the gas price as a hex string
*/
private async getCurrentGasPriceForBlock(blockHash: string, requestDetails: RequestDetails): Promise<string> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm I think we should think about migrating these private methods, e.g. getCurrentGasPriceForBlock(), getCurrentNetworkExchangeRateInCents(), etc., to a different module as to me these are not necessarily related to transaction per se but more of helper or utility function. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the thing is they are only used here, thus i moved them i nthe service, since only this service need them. Maybe we can create a util file for each service, but that kinda seems like an overkill

Copy link
Contributor

@quiet-node quiet-node Apr 11, 2025

Choose a reason for hiding this comment

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

Ah, I see thanks for clarifying. Yeah, maybe if we consider grouping services like BlockService, AccountService, TransactionService, FeeService, etc. into the ethService folder like discussed last time we can migrate these into an ethCommonService or perhaps create a new module like ethServiceHelper or ethServiceUtils to house all the helper functions. That way, we avoid cluttering the space with public transaction-related or account-related etc. methods. Just a suggestion though it’s not within the scope of this PR.

Comment on lines +337 to 335
this.eventEmitter.emit(constants.EVENTS.ETH_EXECUTION, {
method: EthImpl.ethEstimateGas,
functionSelector: callData!.substring(0, constants.FUNCTION_SELECTOR_CHAR_LENGTH),
from: transaction.from || '',
to: transaction.to || '',
requestDetails: requestDetails,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I like this centralized solution, but it does make me a bit angsty. Let’s ensure the metrics work as expected and use the correct keyword for the metric names. Otherwise, Grafana might fail to collect them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what exactly do you think should be changed?

Copy link
Contributor

@quiet-node quiet-node Apr 11, 2025

Choose a reason for hiding this comment

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

Oh it's not about changing things but just make sure that we don't accidentally rename the metrics name or labels or arguments. Make sure we preserve them so no issue on Grafana. Please resolve the conversation if you're confident we got things right.

@quiet-node quiet-node modified the milestones: 0.69.0, 0.68.0 Apr 10, 2025
…ion methods from eth.ts to TransactionService

Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
@konstantinabl konstantinabl force-pushed the 3570-refactor-create-transactionservice-class branch from bc8fa3b to fdc0b6b Compare April 11, 2025 09:34
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Comment on lines +596 to +604
/**
* Removes the '0x' prefix from a string if present
* @param input The input string
* @returns {string} The input string without the '0x' prefix
*/
private prune0x(input: string): string {
return input.startsWith(CommonService.EMPTY_HEX) ? input.substring(2) : input;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Quick note I see an exact prune0x in the SDKClient class too. If it's newly introduced then I guess we can refactor the other one in SDKClient to utils and reuse it but if it's migrated then nvm we can roll with it since it's outside the scope. Anywho if changes needed we can do it in follow-up PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would require using common service in sdk client and do more changes, can we address in another PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha — yeah, it was just a quick observation. We should do it in another PR if it requires many changes. Also I see several topics that need to be addressed in different PRs particularly for this topic. Let’s create a centralized technical debt issue for the ETH refactor and house all those topics there. We can create the actual tickets when we actually work on them so we have clear priorities and don’t clutter the ticket board too much.

Copy link
Contributor

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

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

Great work! Just left some notes and suggestions if you agree let's create tickets to keep track! Otherwise all good on my end

@konstantinabl konstantinabl requested a review from acuarica April 17, 2025 09:55
@konstantinabl konstantinabl merged commit 073d034 into poc-eth-service-apporach Apr 17, 2025
6 checks passed
@konstantinabl konstantinabl deleted the 3570-refactor-create-transactionservice-class branch April 17, 2025 10:08
konstantinabl added a commit that referenced this pull request Apr 25, 2025
konstantinabl added a commit that referenced this pull request May 5, 2025
konstantinabl added a commit that referenced this pull request May 7, 2025
konstantinabl added a commit that referenced this pull request May 7, 2025
quiet-node pushed a commit that referenced this pull request May 7, 2025
quiet-node pushed a commit that referenced this pull request May 7, 2025
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor: Create TransactionService class
4 participants