rpc: change the type of BlockFilter.Primary from int to byte

BlockFilter has PrinaryIndex of int type while block.Block structure
itself has PrimaryIndex of byte. It's needed to prevent changing
filters field type and all associated subscriptions logic on
server side.

Refs #3241.

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
Ekaterina Pavlova 2023-12-12 13:59:03 +03:00
parent 9015215228
commit 275e814271
7 changed files with 26 additions and 26 deletions

View file

@ -67,11 +67,11 @@ omitted if empty).
Recognized stream names:
* `block_added`
Filter: `primary` as an integer 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
block notifications will be received.
Filter: `primary` as an integer with a valid range of 0-255 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 block notifications will be received.
* `header_of_added_block`
Filter: `primary` as an integer with primary (speaker) node index from
ConsensusData and/or `since` field as an integer value with header

View file

@ -11,7 +11,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"`
}
@ -56,7 +56,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 {

View file

@ -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)

View file

@ -42,7 +42,7 @@ func Matches(f Comparator, r Container) bool {
} else {
b = &r.EventPayload().(*block.Block).Header
}
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

View file

@ -40,8 +40,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

View file

@ -381,7 +381,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
}{
{"block header primary",
func(t *testing.T, wsc *WSClient) {
primary := 3
primary := byte(3)
_, err := wsc.ReceiveHeadersOfAddedBlocks(&neorpc.BlockFilter{Primary: &primary}, make(chan *block.Header))
require.NoError(t, err)
},
@ -389,7 +389,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, 3, *filt.Primary)
require.Equal(t, byte(3), *filt.Primary)
require.Equal(t, (*uint32)(nil), filt.Since)
require.Equal(t, (*uint32)(nil), filt.Till)
},
@ -404,7 +404,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)
},
@ -419,7 +419,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)
},
@ -428,7 +428,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.ReceiveHeadersOfAddedBlocks(&neorpc.BlockFilter{
@ -442,14 +442,14 @@ 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)
},
},
{"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)
},
@ -457,7 +457,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, 3, *filt.Primary)
require.Equal(t, byte(3), *filt.Primary)
require.Equal(t, (*uint32)(nil), filt.Since)
require.Equal(t, (*uint32)(nil), filt.Till)
},
@ -472,7 +472,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)
},
@ -487,7 +487,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)
},
@ -496,7 +496,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{
@ -510,7 +510,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)
},

View file

@ -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"