-
Notifications
You must be signed in to change notification settings - Fork 359
feat(miner): Add NewPayloadTimeout
to the miner.
#1244
Conversation
WalkthroughThis 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
TipsChat with CodeRabbit Bot (
|
Signed-off-by: Devon Bear <[email protected]>
There was a problem hiding this 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
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
andWrappedTxPool
has been moved from theBuild
function to theNew
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 ifNew
andBuild
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 newpayloadTimeout
feature. This is necessary for the timeout functionality.54-61: A new field
payloadTimeout
is added to theMiner
struct and is initialized in theNew
function. This is a good practice as it allows the timeout duration to be configurable.84-89: The
buildBlock
function now accepts acontext.Context
argument and uses it to callsubmitPayloadForBuilding
andresolveEnvelope
. 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.
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 | ||
} | ||
} |
There was a problem hiding this comment.
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)
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()) |
tbh we don't need this |
Summary by CodeRabbit
These changes aim to improve the system's efficiency, responsiveness, and maintainability, providing a smoother and more reliable user experience.