-
Notifications
You must be signed in to change notification settings - Fork 184
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
starknet_subscribeTransactionStatus websocket method #2210
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2210 +/- ##
==========================================
- Coverage 74.33% 73.90% -0.43%
==========================================
Files 110 110
Lines 11531 11614 +83
==========================================
+ Hits 8571 8583 +12
- Misses 2290 2363 +73
+ Partials 670 668 -2 ☔ View full report in Codecov by Sentry. |
c5eb695
to
abfec15
Compare
dae4ff2
to
bffd2bf
Compare
rpc/events.go
Outdated
return err | ||
} | ||
|
||
func (h *Handler) SubscribeTxnStatus(ctx context.Context, txHash felt.Felt, _ *BlockID) (*SubscriptionID, *jsonrpc.Error) { |
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.
As per the specs, we also need to support historical blocks. Or is it not possible?
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.
It's not possible. I added a comment explaining this.
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.
maybe we should return error in this case? otherwise users will be confused why it's behaving differently from other possible impl.
0ce1ae2
to
b170da1
Compare
b170da1
to
b617595
Compare
6b842a7
to
e65a8a4
Compare
rpc/events.go
Outdated
@@ -9,11 +9,20 @@ import ( | |||
"github.com/NethermindEth/juno/jsonrpc" | |||
) | |||
|
|||
const ( | |||
MaxBlocksBack = 1024 |
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.
There is new constant introduced in Aneeque's PR maxBlocksBack
in rpc/handlers.go
. If both of them related consider to reuse existing one
rpc/events.go
Outdated
} | ||
|
||
id := h.idgen() | ||
subscriptionCtx, subscriptionCtxCancel := context.WithCancel(ctx) |
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.
do you need to call defer subscriptionCtxCancel()
?
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.
It's called by sub.unsubscribe()
rpc/events.go
Outdated
}() | ||
|
||
if err := h.sendTxnStatus(sub.conn, wrapResult(lastKnownStatus), id); err != nil { | ||
h.log.Warnw("Error while sending Txn status", "txHash", txHash) |
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.
maybe correct severity would be Error
instead of Warnw
? Also please add "err", err
as last arguments
rpc/events.go
Outdated
case <-headerSub.Recv(): | ||
lastKnownStatus, rpcErr = h.TransactionStatus(subscriptionCtx, txHash) | ||
if rpcErr != nil { | ||
h.log.Warnw("Failed to get Tx status", "txHash", txHash, "rpcErr", rpcErr) |
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.
same question: maybe it should be an error ?
rpc/events.go
Outdated
} | ||
|
||
// Stop when final status reached and notified | ||
if isFinal(lastSendStatus) { |
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.
is it according to the spec ?
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.
It's not in written the spec.
I remember we are talking about the final statuses (=no next status in diagram)
I cannot recall why - if it was me who deducted that the subscription should be dropped in this case or it was in the group conversation 🤔
rpc/handlers.go
Outdated
@@ -512,7 +523,7 @@ func (h *Handler) MethodsV0_7() ([]jsonrpc.Method, string) { //nolint: funlen | |||
Handler: h.SpecVersionV0_7, | |||
}, | |||
{ | |||
Name: "juno_subscribeNewHeads", | |||
Name: "starknet_subscribeNewHeads", |
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.
why do you need to update starknet_subscribeNewHeads
in this PR ?
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.
I'll revert 👍 - I based on Han's PR - and then reverted when Anique's PR get merged
bd4e154
to
a552376
Compare
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.
Can you please move SubscribeTxnStatus to subscription.go?
rpc/events_test.go
Outdated
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.
Please move the following test to subscription_test.go
rpc/events.go
Outdated
|
||
// sendHeader creates a request and sends it to the client | ||
func (h *Handler) sendTxnStatus(w jsonrpc.Conn, status *NewTransactionStatus, id uint64) error { | ||
resp, err := json.Marshal(jsonrpc.Request{ |
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.
Please. use SubscriptionResponse struct instead of jsonrpc.Request
rpc/events.go
Outdated
h.subscriptions[id] = sub | ||
h.mu.Unlock() | ||
|
||
statusSub := h.txnStatus.Subscribe() |
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.
No one is sending on this subscription nor is anyone reading from it so why is this required?
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.
Good catch 👍
rpc/events.go
Outdated
select { | ||
case <-subscriptionCtx.Done(): | ||
return | ||
case <-headerSub.Recv(): |
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.
HeaderSub is not enough to get all of the transaction status in particular AcceptedOnL1 since that is updated in a separate go routine.
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.
So header Recv here is more than a timer tick than taking the Tx status.
In other words:
- I'm getting the current status of Tx (the way rpc method does)
- I should check it again in a while to send an eventual update
- I can wait some arbitrary time period
- I can wait until next block which more likely brings some changes (but not in all cases as you mentioned)
- I'm getting the current status of Tx (the way rpc method does)
a552376
to
5150b5f
Compare
713b244
to
2d073dd
Compare
2d073dd
to
20c0587
Compare
Fixes #2209
Comments:
utils/check.go
(Add IsNil() #2340)I renamed
utils/check.go
toutils/nil.go
because of this suggestion