[#147] Add context to waiter #148
Labels
No labels
P0
P1
P2
P3
good first issue
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-contract#148
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "vdomnich-yadro/frostfs-contract:vd/wait-ctx"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds new method
WaitCtx
that takes a context as a parameter. Application can cancel this context to terminate transaction awaiting.@ -13,6 +13,16 @@ import (
const alreadyExistsError = "already exists"
// ContextWaiter is an interface for wrapper around [waiter.Waiter] that respects
It is not necessarily a wrapper, it is an interface, after all.
Re-phrased the comment.
@ -16,0 +16,4 @@
// ContextWaiter is an interface for wrapper around [waiter.Waiter] that respects
// a context while waiting for a transaction.
type ContextWaiter interface {
// Deprecated: use WaitCtx instead to prevent waiter hang up when discrete time stops ticking.
Wait()
andWaitAny()
could be combined in waiter.WaiterYep. I didn't do this in the first place in order to place the deprecation mark.
As it seems you would prefer to not have the deprecation mark, I will just embed the Waiter interface here, np.
@ -44,6 +54,7 @@ func NewWaiter(waiter waiter.Waiter, options WaiterOptions) *Waiter {
}
// Wait allows to wait until transaction will be accepted to the chain.
// Deprecated: use WaitCtx instead to prevent waiter hang up when discrete time stops ticking.
I don't see it being deprecated -- we will have both method implemented to retain composability with neo-go utility functions.
I've put Deprecated mark here in order to discourage the usage of this method. The deprecation mark raises warnings in the code where we use this method.
I am fine to remove the deprecation here if that is your preference. I have no strong feelings about it at all.
@ -54,1 +65,4 @@
// WaitCtx allows to wait until transaction is accepted to the chain.
// Waiting is limited by the specified context.
func (w *Waiter) WaitCtx(ctx context.Context, h util.Uint256, vub uint32, err error) (*state.AppExecResult, error) {
Wait()
has 3 parameters to be easily composable with actor methods, so that we could writew.Wait(a.SignAndSend(tx))
succinctly.WIth this signature we no longer have this property, so I am now wondering whether it is still useful to have an error here (I don't see the code you have)?
E.g. in morph we have
func (c *Client) WaitTxHalt(ctx context.Context, vub uint32, h util.Uint256) error {
Yes, it is still useful to have an error as an extra parameter. In some implementations of waiters we have error conversion logic (that parses blockchain error text and transforms it into a Go error). It is convenient to pass both "tx send error" and "tx wait error" to waiter so that it applies the conversion logic.
88232efe67
to51bccdbcfb
51bccdbcfb
to01a724d449
LGTM
@ -71,3 +69,3 @@
sendErr := fmt.Errorf("transaction already exists")
mw := &mockWaiter{}
mw.On("Wait", txHash, vub, mock.Anything).Return(mw.successfulResult(txHash), nil)
mw.On("WaitAny", mock.Anything, vub, txHashes).Return(mw.successfulResult(txHash), nil)
What is the goal of changing all the tests?
Do we still test
Wait()
after all these changes?IMO it would be better to just write tests on
WaitCtx()
in this PR, specifically that it callsWaitAny()
inside.No, we don't.
If I get your proposal correctly, you would like to keep tests on
Wait
intact and add new tests to coverWaitCtx
, right?If so, sure, will do. Thanks!
Other than the comment, LGTM
@ -55,0 +61,4 @@
// WaitCtx allows to wait until transaction is accepted to the chain.
// Waiting is limited by the specified context.
func (w *Waiter) WaitCtx(ctx context.Context, h util.Uint256, vub uint32, err error) (*state.AppExecResult, error) {
if err != nil {
Why not to use one
if
as inWaiter.Wait(...)
?Because if
!errIsAlreadyExists(err) && err != nil
, the error will be skipped in your case.In
Wait()
that is handled byWait()
method of the inner struct.Right,
if
should be a bit different:View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.