Skip to content

[Version-unspecific] Querier: For skipping conditionals, append to maximum-capacity initial-length-0 slices rather than using maximum-length slices with empty entries

Multipartite requested to merge Multi/querier-no-set-length-slices into develop

[I defer to (and imagine in future this MR and Issue can be closed by/in favour of) the branch mentioned here:
!3345 (comment 1716448506)
. That said, if found to have merit, merging this querier.go-specific MR first is also welcome.]

[Version-unspecific]

Intended to close #1811 (closed)
'Querier returns empty responses from loop 'continue' due to set-length slices rather than appending'.


2024-01-08 update:
Following the merge of !3350 (merged), as per
!3350 (comment 1718694780)
, I have now added a commit (ad054204) to avoid nil querier responses instead of empty slices,
as well as a commit (f6ba0535) to fix TestQueryPoolAddresses which was apparently only passing because the result was nil
(and was unable to Unmarshal a slice to the struct target).
|
Unit test job without that second commit:
https://gitlab.com/thorchain/thornode/-/jobs/5885826766

FAIL: querier_test.go:648: QuerierSuite.TestQueryPoolAddresses
querier_test.go:666:
    c.Assert(json.Unmarshal(result, &resp), IsNil)
... value *json.UnmarshalTypeError = &json.UnmarshalTypeError{Value:"array", Type:(*reflect.rtype)(0x2dc1920), Offset:1, Struct:"", Field:""} ("json: cannot unmarshal array into Go value of type struct { Current []struct { Chain common.Chain \"json:\\\"chain\\\"\"; PubKey common.PubKey \"json:\\\"pub_key\\\"\"; Address common.Address \"json:\\\"address\\\"\"; Halted bool \"json:\\\"halted\\\"\" } \"json:\\\"current\\\"\" }")

2024-01-30 update:

A three-argument make may have the best of both worlds:
Initial length 0 and append use to not have empty entries,
and maximum-size capacity to not have to make and copy to a new slice with every append.

Prompting information: https://github.com/cosmos/cosmos-sdk/blob/v0.45.1/types/coin.go#L611-L625
https://go.dev/tour/moretypes/11
https://www.reddit.com/r/golang/comments/o3e6h0/noob_question_appending_to_max_capacity_slices/

Outside the querier, this should be done with care as append cannot be assumed to implicitly create a new slice (as it does when increasing a slice's capacity by making a new slice).


2024-04-12:

If I understand correctly, this Issue (and now this MR) are closed as the main querier response affected--empty /thorchain/nodes items--has been resolved by the KVStore deletion of low-bond nodes
(RemoveLowBondValidatorAccounts from !3321 (merged) 'Remove Low bond Node accounts').

Edited by Multipartite

Merge request reports