Skip to content

Commit

Permalink
rpc: blockFilter Primary field type change to byte
Browse files Browse the repository at this point in the history
BlockFilter has PrinaryIndex of int type while block.Block structure
itself has PrimaryIndex of byte. It needs to prevent change filter's
field type and all associated subscriptions logic on server side.

Refs #3241.

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Dec 9, 2023
1 parent e057835 commit c0dfff9
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ omitted if empty).

Recognized stream names:
* `block_added`
Filter: `primary` as an integer with primary (speaker) node index from
Filter: `primary` as an byte with primary (speaker) node index from
ConsensusData and/or `since` field as an integer value with block
index starting from which new block notifications will be received and/or
`till` field as an integer values containing block index till which new
Expand Down
4 changes: 2 additions & 2 deletions pkg/neorpc/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type (
// since/till the specified index inclusively). nil value treated as missing
// filter.
BlockFilter struct {
Primary *int `json:"primary,omitempty"`
Primary *byte `json:"primary,omitempty"`
Since *uint32 `json:"since,omitempty"`
Till *uint32 `json:"till,omitempty"`
}
Expand Down Expand Up @@ -47,7 +47,7 @@ func (f *BlockFilter) Copy() *BlockFilter {
}
var res = new(BlockFilter)
if f.Primary != nil {
res.Primary = new(int)
res.Primary = new(byte)
*res.Primary = *f.Primary
}
if f.Since != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/neorpc/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ func TestBlockFilterCopy(t *testing.T) {
tf = bf.Copy()
require.Equal(t, bf, tf)

bf.Primary = new(int)
bf.Primary = new(byte)
*bf.Primary = 42

tf = bf.Copy()
require.Equal(t, bf, tf)
*bf.Primary = 100500
*bf.Primary = 100
require.NotEqual(t, bf, tf)

bf.Since = new(uint32)
Expand Down
2 changes: 1 addition & 1 deletion pkg/neorpc/rpcevent/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Matches(f Comparator, r Container) bool {
case neorpc.BlockEventID:
filt := filter.(neorpc.BlockFilter)
b := r.EventPayload().(*block.Block)
primaryOk := filt.Primary == nil || *filt.Primary == int(b.PrimaryIndex)
primaryOk := filt.Primary == nil || *filt.Primary == b.PrimaryIndex
sinceOk := filt.Since == nil || *filt.Since <= b.Index
tillOk := filt.Till == nil || b.Index <= *filt.Till
return primaryOk && sinceOk && tillOk
Expand Down
4 changes: 2 additions & 2 deletions pkg/neorpc/rpcevent/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func (c testContainer) EventPayload() any {
}

func TestMatches(t *testing.T) {
primary := 1
badPrimary := 2
primary := byte(1)
badPrimary := byte(2)
index := uint32(5)
badHigherIndex := uint32(6)
badLowerIndex := index - 1
Expand Down
12 changes: 6 additions & 6 deletions pkg/rpcclient/wsclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,15 @@ func TestWSFilteredSubscriptions(t *testing.T) {
}{
{"blocks primary",
func(t *testing.T, wsc *WSClient) {
primary := 3
primary := byte(3)
_, err := wsc.ReceiveBlocks(&neorpc.BlockFilter{Primary: &primary}, make(chan *block.Block))
require.NoError(t, err)
},
func(t *testing.T, p *params.Params) {
param := p.Value(1)
filt := new(neorpc.BlockFilter)
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
require.Equal(t, 3, *filt.Primary)
require.Equal(t, byte(3), *filt.Primary)
require.Equal(t, (*uint32)(nil), filt.Since)
require.Equal(t, (*uint32)(nil), filt.Till)
},
Expand All @@ -402,7 +402,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
param := p.Value(1)
filt := new(neorpc.BlockFilter)
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
require.Equal(t, (*int)(nil), filt.Primary)
require.Equal(t, (*byte)(nil), filt.Primary)
require.Equal(t, uint32(3), *filt.Since)
require.Equal(t, (*uint32)(nil), filt.Till)
},
Expand All @@ -417,7 +417,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
param := p.Value(1)
filt := new(neorpc.BlockFilter)
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
require.Equal(t, (*int)(nil), filt.Primary)
require.Equal(t, (*byte)(nil), filt.Primary)
require.Equal(t, (*uint32)(nil), filt.Since)
require.Equal(t, (uint32)(3), *filt.Till)
},
Expand All @@ -426,7 +426,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
func(t *testing.T, wsc *WSClient) {
var (
since uint32 = 3
primary = 2
primary = byte(2)
till uint32 = 5
)
_, err := wsc.ReceiveBlocks(&neorpc.BlockFilter{
Expand All @@ -440,7 +440,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
param := p.Value(1)
filt := new(neorpc.BlockFilter)
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
require.Equal(t, 2, *filt.Primary)
require.Equal(t, byte(2), *filt.Primary)
require.Equal(t, uint32(3), *filt.Since)
require.Equal(t, uint32(5), *filt.Till)
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/services/rpcsrv/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2113,9 +2113,9 @@ func TestWSClient_SubscriptionsCompat(t *testing.T) {
blocks := getTestBlocks(t)
bCount := uint32(0)

getData := func(t *testing.T) (*block.Block, int, util.Uint160, string, string) {
getData := func(t *testing.T) (*block.Block, byte, util.Uint160, string, string) {
b1 := blocks[bCount]
primary := int(b1.PrimaryIndex)
primary := b1.PrimaryIndex
tx := b1.Transactions[0]
sender := tx.Sender()
ntfName := "Transfer"
Expand Down

0 comments on commit c0dfff9

Please sign in to comment.