Skip to content

Commit 97129a3

Browse files
authored
[query] GetTransactionStatus (#148)
#### Type of change - New feature #### Description - Add GetTransactionStatus() API to the query service #### Related issues - resolves #62 Signed-off-by: Liran Funaro <[email protected]>
1 parent 1bef570 commit 97129a3

File tree

8 files changed

+515
-173
lines changed

8 files changed

+515
-173
lines changed

api/protoqueryservice/query.pb.go

Lines changed: 248 additions & 94 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/protoqueryservice/query.proto

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ option go_package = "github.com/hyperledger/fabric-x-committer/api/protoqueryser
1111
package protoqueryservice;
1212

1313
import "api/protoblocktx/block_tx.proto";
14+
import "api/protonotify/notify.proto";
1415
import "google/protobuf/empty.proto";
1516

1617
service QueryService {
@@ -19,6 +20,7 @@ service QueryService {
1920
rpc EndView(View) returns (View) {};
2021
rpc GetNamespacePolicies(google.protobuf.Empty) returns (protoblocktx.NamespacePolicies) {};
2122
rpc GetConfigTransaction(google.protobuf.Empty) returns (protoblocktx.ConfigTransaction) {};
23+
rpc GetTransactionStatus(TxStatusQuery) returns (TxStatusResponse) {};
2224
}
2325

2426
message View {
@@ -62,3 +64,12 @@ message Row {
6264
bytes value = 2;
6365
uint64 version = 3;
6466
}
67+
68+
message TxStatusQuery {
69+
optional View view = 1;
70+
repeated string tx_ids = 2; // List of transaction IDs.
71+
}
72+
73+
message TxStatusResponse {
74+
repeated protonotify.TxStatusEvent statuses = 1;
75+
}

api/protoqueryservice/query_grpc.pb.go

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/test/query_service_test.go

Lines changed: 85 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import (
1515
"github.com/stretchr/testify/require"
1616

1717
"github.com/hyperledger/fabric-x-committer/api/protoblocktx"
18+
"github.com/hyperledger/fabric-x-committer/api/protonotify"
1819
"github.com/hyperledger/fabric-x-committer/api/protoqueryservice"
1920
"github.com/hyperledger/fabric-x-committer/integration/runner"
21+
"github.com/hyperledger/fabric-x-committer/utils/test"
2022
)
2123

2224
func TestQueryService(t *testing.T) {
@@ -33,8 +35,9 @@ func TestQueryService(t *testing.T) {
3335
ctx, cancel := context.WithTimeout(t.Context(), time.Minute*5)
3436
t.Cleanup(cancel)
3537

36-
c.MakeAndSendTransactionsToOrderer(t, [][]*protoblocktx.TxNamespace{{
37-
{
38+
t.Log("Insert TXs")
39+
txIDs := c.MakeAndSendTransactionsToOrderer(t, [][]*protoblocktx.TxNamespace{
40+
{{
3841
NsId: "1",
3942
NsVersion: 0,
4043
BlindWrites: []*protoblocktx.Write{
@@ -47,8 +50,8 @@ func TestQueryService(t *testing.T) {
4750
Value: []byte("v2"),
4851
},
4952
},
50-
},
51-
{
53+
}},
54+
{{
5255
NsId: "2",
5356
NsVersion: 0,
5457
BlindWrites: []*protoblocktx.Write{
@@ -61,72 +64,97 @@ func TestQueryService(t *testing.T) {
6164
Value: []byte("v4"),
6265
},
6366
},
67+
}},
68+
}, []protoblocktx.Status{protoblocktx.Status_COMMITTED, protoblocktx.Status_COMMITTED})
69+
require.Len(t, txIDs, 2)
70+
71+
t.Log("Query TXs status")
72+
status, err := c.QueryServiceClient.GetTransactionStatus(ctx, &protoqueryservice.TxStatusQuery{
73+
TxIds: txIDs,
74+
})
75+
require.NoError(t, err)
76+
require.Len(t, status.Statuses, len(txIDs))
77+
test.RequireProtoElementsMatch(t, []*protonotify.TxStatusEvent{
78+
{
79+
TxId: txIDs[0],
80+
StatusWithHeight: &protoblocktx.StatusWithHeight{
81+
Code: protoblocktx.Status_COMMITTED,
82+
TxNumber: uint32(0),
83+
BlockNumber: uint64(2),
84+
},
6485
},
65-
}}, []protoblocktx.Status{protoblocktx.Status_COMMITTED})
86+
{
87+
TxId: txIDs[1],
88+
StatusWithHeight: &protoblocktx.StatusWithHeight{
89+
Code: protoblocktx.Status_COMMITTED,
90+
TxNumber: uint32(1),
91+
BlockNumber: uint64(2),
92+
},
93+
},
94+
}, status.Statuses)
6695

67-
t.Run("Query-GetRows-Both-Namespaces", func(t *testing.T) {
68-
ret, err := c.QueryServiceClient.GetRows(
69-
ctx,
70-
&protoqueryservice.Query{
71-
Namespaces: []*protoqueryservice.QueryNamespace{
72-
{
73-
NsId: "1",
74-
Keys: [][]byte{
75-
[]byte("k1"), []byte("k2"),
76-
},
96+
t.Log("Query Rows")
97+
ret, err := c.QueryServiceClient.GetRows(
98+
ctx,
99+
&protoqueryservice.Query{
100+
Namespaces: []*protoqueryservice.QueryNamespace{
101+
{
102+
NsId: "1",
103+
Keys: [][]byte{
104+
[]byte("k1"), []byte("k2"),
77105
},
78-
{
79-
NsId: "2",
80-
Keys: [][]byte{
81-
[]byte("k3"), []byte("k4"),
82-
},
106+
},
107+
{
108+
NsId: "2",
109+
Keys: [][]byte{
110+
[]byte("k3"), []byte("k4"),
83111
},
84112
},
85113
},
86-
)
87-
require.NoError(t, err)
114+
},
115+
)
116+
require.NoError(t, err)
88117

89-
testItemsVersion := uint64(0)
118+
testItemsVersion := uint64(0)
90119

91-
requiredItems := []*protoqueryservice.RowsNamespace{
92-
{
93-
NsId: "1",
94-
Rows: []*protoqueryservice.Row{
95-
{
96-
Key: []byte("k1"),
97-
Value: []byte("v1"),
98-
Version: testItemsVersion,
99-
},
100-
{
101-
Key: []byte("k2"),
102-
Value: []byte("v2"),
103-
Version: testItemsVersion,
104-
},
120+
requiredItems := []*protoqueryservice.RowsNamespace{
121+
{
122+
NsId: "1",
123+
Rows: []*protoqueryservice.Row{
124+
{
125+
Key: []byte("k1"),
126+
Value: []byte("v1"),
127+
Version: testItemsVersion,
128+
},
129+
{
130+
Key: []byte("k2"),
131+
Value: []byte("v2"),
132+
Version: testItemsVersion,
105133
},
106134
},
107-
{
108-
NsId: "2",
109-
Rows: []*protoqueryservice.Row{
110-
{
111-
Key: []byte("k3"),
112-
Value: []byte("v3"),
113-
Version: testItemsVersion,
114-
},
115-
{
116-
Key: []byte("k4"),
117-
Value: []byte("v4"),
118-
Version: testItemsVersion,
119-
},
135+
},
136+
{
137+
NsId: "2",
138+
Rows: []*protoqueryservice.Row{
139+
{
140+
Key: []byte("k3"),
141+
Value: []byte("v3"),
142+
Version: testItemsVersion,
143+
},
144+
{
145+
Key: []byte("k4"),
146+
Value: []byte("v4"),
147+
Version: testItemsVersion,
120148
},
121149
},
122-
}
150+
},
151+
}
123152

124-
requireQueryResults(
125-
t,
126-
requiredItems,
127-
ret.Namespaces,
128-
)
129-
})
153+
requireQueryResults(
154+
t,
155+
requiredItems,
156+
ret.Namespaces,
157+
)
130158
}
131159

132160
// requireQueryResults requires that the items retrieved by the Query service

0 commit comments

Comments
 (0)