Skip to content

Commit 1caf86f

Browse files
authored
remove block_id from starknet_subscribeTransactionStatus (#2410)
* remove block_id from starknet_subscribeTransactionStatus according to RPCv8-rc2
1 parent 42077d3 commit 1caf86f

File tree

3 files changed

+6
-57
lines changed

3 files changed

+6
-57
lines changed

rpc/handlers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func (h *Handler) Methods() ([]jsonrpc.Method, string) { //nolint: funlen
366366
},
367367
{
368368
Name: "starknet_subscribeTransactionStatus",
369-
Params: []jsonrpc.Parameter{{Name: "transaction_hash"}, {Name: "block_id", Optional: true}},
369+
Params: []jsonrpc.Parameter{{Name: "transaction_hash"}},
370370
Handler: h.SubscribeTransactionStatus,
371371
},
372372
{

rpc/subscriptions.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,14 @@ func (h *Handler) SubscribeEvents(ctx context.Context, fromAddr *felt.Felt, keys
108108
// The optional block_id parameter is ignored, as status changes are not stored and historical data cannot be sent.
109109
//
110110
//nolint:gocyclo,funlen
111-
func (h *Handler) SubscribeTransactionStatus(ctx context.Context, txHash felt.Felt, blockID *BlockID) (*SubscriptionID,
111+
func (h *Handler) SubscribeTransactionStatus(ctx context.Context, txHash felt.Felt) (*SubscriptionID,
112112
*jsonrpc.Error,
113113
) {
114114
w, ok := jsonrpc.ConnFromContext(ctx)
115115
if !ok {
116116
return nil, jsonrpc.Err(jsonrpc.MethodNotFound, nil)
117117
}
118118

119-
// resolveBlockRange is only used to make sure that the requested block id is not older than 1024 block and check
120-
// if the requested block is found. The range is inconsequential since we assume the provided transaction hash
121-
// of a transaction is included in the block range: latest/pending - 1024.
122-
_, _, rpcErr := h.resolveBlockRange(blockID)
123-
if rpcErr != nil {
124-
return nil, rpcErr
125-
}
126-
127119
// If the error is transaction not found that means the transaction has not been submitted to the feeder gateway,
128120
// therefore, we need to wait for a specified time and at regular interval check if the transaction has been found.
129121
// If the transaction is found during the timout expiry, then we continue to keep track of its status otherwise the

rpc/subscriptions_test.go

+4-47
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ func TestSubscribeTxnStatus(t *testing.T) {
341341
mockSyncer := mocks.NewMockSyncReader(mockCtrl)
342342
handler := New(mockChain, mockSyncer, nil, "", log)
343343

344-
mockChain.EXPECT().HeadsHeader().Return(&core.Header{Number: 1}, nil)
345344
mockChain.EXPECT().TransactionByHash(txHash).Return(nil, db.ErrKeyNotFound).AnyTimes()
346345
mockSyncer.EXPECT().PendingBlock().Return(nil).AnyTimes()
347346

@@ -352,50 +351,11 @@ func TestSubscribeTxnStatus(t *testing.T) {
352351

353352
subCtx := context.WithValue(context.Background(), jsonrpc.ConnKey{}, &fakeConn{w: serverConn})
354353

355-
id, rpcErr := handler.SubscribeTransactionStatus(subCtx, *txHash, nil)
354+
id, rpcErr := handler.SubscribeTransactionStatus(subCtx, *txHash)
356355
assert.Nil(t, id)
357356
assert.Equal(t, ErrTxnHashNotFound, rpcErr)
358357
})
359358

360-
t.Run("Return error if block is too far back", func(t *testing.T) {
361-
mockCtrl := gomock.NewController(t)
362-
t.Cleanup(mockCtrl.Finish)
363-
364-
mockChain := mocks.NewMockReader(mockCtrl)
365-
mockSyncer := mocks.NewMockSyncReader(mockCtrl)
366-
handler := New(mockChain, mockSyncer, nil, "", log)
367-
368-
blockID := &BlockID{Number: 0}
369-
370-
serverConn, _ := net.Pipe()
371-
t.Cleanup(func() {
372-
require.NoError(t, serverConn.Close())
373-
})
374-
375-
subCtx := context.WithValue(context.Background(), jsonrpc.ConnKey{}, &fakeConn{w: serverConn})
376-
377-
// Note the end of the window doesn't need to be tested because if requested block number is more than the
378-
// head, a block not found error will be returned. This behaviour has been tested in various other tests, and we
379-
// don't need to test it here again.
380-
t.Run("head is 1024", func(t *testing.T) {
381-
mockChain.EXPECT().HeadsHeader().Return(&core.Header{Number: 1024}, nil)
382-
mockChain.EXPECT().BlockHeaderByNumber(blockID.Number).Return(&core.Header{Number: 0}, nil)
383-
384-
id, rpcErr := handler.SubscribeTransactionStatus(subCtx, *txHash, blockID)
385-
assert.Zero(t, id)
386-
assert.Equal(t, ErrTooManyBlocksBack, rpcErr)
387-
})
388-
389-
t.Run("head is more than 1024", func(t *testing.T) {
390-
mockChain.EXPECT().HeadsHeader().Return(&core.Header{Number: 2024}, nil)
391-
mockChain.EXPECT().BlockHeaderByNumber(blockID.Number).Return(&core.Header{Number: 0}, nil)
392-
393-
id, rpcErr := handler.SubscribeTransactionStatus(subCtx, *txHash, blockID)
394-
assert.Zero(t, id)
395-
assert.Equal(t, ErrTooManyBlocksBack, rpcErr)
396-
})
397-
})
398-
399359
t.Run("Transaction status is final", func(t *testing.T) {
400360
mockCtrl := gomock.NewController(t)
401361
t.Cleanup(mockCtrl.Finish)
@@ -416,13 +376,12 @@ func TestSubscribeTxnStatus(t *testing.T) {
416376
txHash, err := new(felt.Felt).SetString("0x1111")
417377
require.NoError(t, err)
418378

419-
mockChain.EXPECT().HeadsHeader().Return(&core.Header{Number: 1}, nil)
420379
mockChain.EXPECT().TransactionByHash(txHash).Return(nil, db.ErrKeyNotFound)
421380
mockSyncer.EXPECT().PendingBlock().Return(nil)
422381

423382
ctx, cancel := context.WithCancel(context.Background())
424383
subCtx := context.WithValue(ctx, jsonrpc.ConnKey{}, &fakeConn{w: serverConn})
425-
id, rpcErr := handler.SubscribeTransactionStatus(subCtx, *txHash, nil)
384+
id, rpcErr := handler.SubscribeTransactionStatus(subCtx, *txHash)
426385
require.Nil(t, rpcErr)
427386

428387
b, err := TxnStatusRejected.MarshalText()
@@ -447,13 +406,12 @@ func TestSubscribeTxnStatus(t *testing.T) {
447406
txHash, err := new(felt.Felt).SetString("0x1010")
448407
require.NoError(t, err)
449408

450-
mockChain.EXPECT().HeadsHeader().Return(&core.Header{Number: 1}, nil)
451409
mockChain.EXPECT().TransactionByHash(txHash).Return(nil, db.ErrKeyNotFound)
452410
mockSyncer.EXPECT().PendingBlock().Return(nil)
453411

454412
ctx, cancel := context.WithCancel(context.Background())
455413
subCtx := context.WithValue(ctx, jsonrpc.ConnKey{}, &fakeConn{w: serverConn})
456-
id, rpcErr := handler.SubscribeTransactionStatus(subCtx, *txHash, nil)
414+
id, rpcErr := handler.SubscribeTransactionStatus(subCtx, *txHash)
457415
require.Nil(t, rpcErr)
458416

459417
b, err := TxnStatusAcceptedOnL1.MarshalText()
@@ -496,13 +454,12 @@ func TestSubscribeTxnStatus(t *testing.T) {
496454
txHash, err := new(felt.Felt).SetString("0x1001")
497455
require.NoError(t, err)
498456

499-
mockChain.EXPECT().HeadsHeader().Return(&core.Header{Number: block.Number}, nil)
500457
mockChain.EXPECT().TransactionByHash(txHash).Return(nil, db.ErrKeyNotFound)
501458
mockSyncer.EXPECT().PendingBlock().Return(nil)
502459

503460
ctx, cancel := context.WithCancel(context.Background())
504461
subCtx := context.WithValue(ctx, jsonrpc.ConnKey{}, &fakeConn{w: serverConn})
505-
id, rpcErr := handler.SubscribeTransactionStatus(subCtx, *txHash, nil)
462+
id, rpcErr := handler.SubscribeTransactionStatus(subCtx, *txHash)
506463
require.Nil(t, rpcErr)
507464

508465
b, err := TxnStatusReceived.MarshalText()

0 commit comments

Comments
 (0)