Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

feat(miner): Add NewPayloadTimeout to the miner. #1244

Closed
wants to merge 7 commits into from

Conversation

itsdevbear
Copy link

@itsdevbear itsdevbear commented Oct 23, 2023

Summary by CodeRabbit

  • Performance Improvement: Reduced the number of times a transaction can be rechecked before being ejected from the mempool, enhancing system efficiency and reducing unnecessary processing.
  • New Feature: Introduced a payload timeout in the Miner structure, providing more control over transaction processing times and improving system responsiveness.
  • Refactor: Simplified the creation of WrappedMiner and WrappedTxPool objects, streamlining the system setup process and enhancing maintainability.
  • Performance Improvement: Increased the default mempool size, allowing for more transactions to be processed simultaneously, leading to improved throughput.

These changes aim to improve the system's efficiency, responsiveness, and maintainability, providing a smoother and more reliable user experience.

@coderabbitai
Copy link

coderabbitai bot commented Oct 23, 2023

Walkthrough

This update introduces changes to the transaction handling and mining processes in the Cosmos blockchain. It modifies the transaction recheck limit, introduces a payload timeout for miners, and adjusts the mempool size. It also refactors the runtime setup and miner creation for better maintainability and performance.

Changes

File Summary
cosmos/lib/ante/eject.go Modified the transaction recheck limit from 25 to 15 and updated the error message.
cosmos/miner/miner.go Introduced a payload timeout for miners, refactored the buildBlock and resolveEnvelope functions to use context.Context, and added helper functions for payload resolution.
cosmos/runtime/runtime.go Refactored the creation of WrappedMiner and WrappedTxPool objects and updated the Build function. Removed the ek.Setup function call.
e2e/testapp/polard/cmd/root.go Increased the default mempool size to 50000 in the initCometBFTConfig function.

🐇

"In the land of code, where logic is king,

Changes are made, improvements they bring.

Transactions rechecked, but not too much,

Miners with timeouts, a gentle touch.

Mempool expanded, room to play,

In the world of Cosmos, it's a brighter day." 🌟


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json

@itsdevbear itsdevbear requested review from calbera and ocnc October 23, 2023 02:58
@codecov
Copy link

codecov bot commented Oct 23, 2023

Codecov Report

Merging #1244 (7df5063) into main (bf146d5) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1244   +/-   ##
=======================================
  Coverage   49.14%   49.14%           
=======================================
  Files          77       77           
  Lines        4631     4631           
=======================================
  Hits         2276     2276           
  Misses       2192     2192           
  Partials      163      163           

Base automatically changed from retry-handler to main October 23, 2023 16:39
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between bf146d5 and 7df5063.
Files ignored due to filter (2)
  • cosmos/go.mod
  • cosmos/go.sum
Files selected for processing (4)
  • cosmos/lib/ante/eject.go (1 hunks)
  • cosmos/miner/miner.go (5 hunks)
  • cosmos/runtime/runtime.go (1 hunks)
  • e2e/testapp/polard/cmd/root.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • e2e/testapp/polard/cmd/root.go
Additional comments: 9
cosmos/runtime/runtime.go (2)
  • 93-94: The creation of WrappedMiner and WrappedTxPool has been moved from the Build function to the New function. This change could potentially affect the lifecycle of these objects. Ensure that this change does not introduce any lifecycle issues or race conditions, especially if New and Build are called from different goroutines.

  • 103-103: The ek.Setup function call has been removed. If this function was responsible for any crucial setup steps, its removal could lead to issues. Please verify that the setup is still correctly performed elsewhere.

cosmos/lib/ante/eject.go (2)
  • 62-62: The threshold for ejecting a transaction from the mempool has been reduced from 25 to 15 rechecks. Ensure that this change does not negatively impact the system's performance or the user experience.

  • 64-64: The error message has been updated to provide more context about the error. This is a good practice as it helps in debugging and understanding the error's cause.

cosmos/miner/miner.go (5)
  • 26-26: The time package is imported to handle the new payloadTimeout feature. This is necessary for the timeout functionality.

  • 54-61: A new field payloadTimeout is added to the Miner struct and is initialized in the New function. This is a good practice as it allows the timeout duration to be configurable.

  • 84-89: The buildBlock function now accepts a context.Context argument and uses it to call submitPayloadForBuilding and resolveEnvelope. This is a good practice as it allows for better control over timeouts and cancellations.

  • 143-154: The resolvePayload function is a helper function that resolves the payload in a separate goroutine. It sends the result and any error to the provided channels. This is a good practice as it allows for better control over timeouts and cancellations.

  • 157-159: The resolveEmptyPayload function is a helper function that resolves an empty payload. This is a good practice as it allows for better control over timeouts and cancellations.

Comment on lines +121 to +141
func (m *Miner) resolveEnvelope(ctx context.Context, timeout time.Duration) ([]byte, error) {
sCtx := sdk.UnwrapSDKContext(ctx).Logger()
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()

resultChan := make(chan []byte, 1)
errChan := make(chan error, 1)

go m.resolvePayload(resultChan, errChan)

select {
case <-ctx.Done():
// If we timed out, return an empty payload.
// TODO: penalize validators for not being able to deliver the payload?
sCtx.Error("failed to resolve envelope, proposing empty payload", "err", ctx.Err())
return m.resolveEmptyPayload()
case result := <-resultChan:
sdk.UnwrapSDKContext(ctx).Logger().Info("successfully resolved envelope")
return result, <-errChan
}
}
Copy link

Choose a reason for hiding this comment

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

The resolveEnvelope function now accepts a context.Context and a timeout argument. It creates a new context with the provided timeout and uses it to resolve the payload in a separate goroutine. If the context times out, it logs an error and returns an empty payload. This is a good practice as it allows for better control over timeouts and cancellations. However, the error handling could be improved. Currently, if the context times out, the function logs an error and returns an empty payload. It might be better to return the error to the caller so that they can decide how to handle it.

-		sCtx.Error("failed to resolve envelope, proposing empty payload", "err", ctx.Err())
-		return m.resolveEmptyPayload()
+		return nil, fmt.Errorf("failed to resolve envelope: %w", ctx.Err())
Committable suggestion (Beta)
Suggested change
func (m *Miner) resolveEnvelope(ctx context.Context, timeout time.Duration) ([]byte, error) {
sCtx := sdk.UnwrapSDKContext(ctx).Logger()
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
resultChan := make(chan []byte, 1)
errChan := make(chan error, 1)
go m.resolvePayload(resultChan, errChan)
select {
case <-ctx.Done():
// If we timed out, return an empty payload.
// TODO: penalize validators for not being able to deliver the payload?
sCtx.Error("failed to resolve envelope, proposing empty payload", "err", ctx.Err())
return m.resolveEmptyPayload()
case result := <-resultChan:
sdk.UnwrapSDKContext(ctx).Logger().Info("successfully resolved envelope")
return result, <-errChan
}
}
return nil, fmt.Errorf("failed to resolve envelope: %w", ctx.Err())

@itsdevbear
Copy link
Author

tbh we don't need this

@itsdevbear itsdevbear closed this Nov 4, 2023
@calbera calbera deleted the upgrade-stuff branch November 8, 2023 18:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant