Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't encode fabric-index in fabric scoped structs for a write. #15268

Conversation

bzbarsky-apple
Copy link
Contributor

Problem

We are encoding (uselessly) fabric indices for a write.

Change overview

Stop doing that, at least when the WriteClient is doing the encoding itself.

Some notes:

  1. I would really prefer it if fabric-scoped things don't have an Encode() at all and have separate EncodeForWrite and EncodeForRead APIs, so when you are encoding them you have to think about what you are doing. That's a slightly more invasive change in terms of needing to change some code that currently calls Encode to call EncodeForRead, but absolutely doable.
  2. Alternately, we could make DataModel::Encode (and presumably the struct's Encode) just take a boolean for whether it's an encode for a write. If we default it to false, that is more or less equivalent to the proposed change. More slightly inscrutable booleans floating around (esp. in all the Encode methods that have nothing to do with structs), a little less template duplication involved.
  3. Or we could add a boolean to DataMode::Encode but only default it for things that are not fabric scoped, while requiring it for things that are fabric-scoped, so consumers have to think about it. This might have the least copy/paste code and should be a little simpler to get to than separate EncodeForRead/EncodeForWrite methods that only exist for fabric-scoped structs, since all Encode signatures would allow passing in the boolean.

Testing

Checked that if I do:

chip-tool accesscontrol write acl '[{"fabricIndex": 0, "privilege": 0, "authMode": 0, "subjects": [], "targets": []}]' 17 0

without this change the recipient sees:

Data = 
{
	0x0 = 0, 
	0x1 = 0, 
	0x2 = 0, 
	0x3 = [
		
	],
	0x4 = [
		
	],
},

and with this change the tag 0x0 is gone.

@bzbarsky-apple bzbarsky-apple marked this pull request as draft February 16, 2022 18:10
@github-actions
Copy link

github-actions bot commented Feb 16, 2022

PR #15268: Size comparison from 6e55dee to 26ad641

Increases (38 builds for cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg, telink)
platform target config section 6e55dee 26ad641 change % change
cyw30739 light cyw930739m2evb_01 (read/write) 597258 597314 56 0.0
.app_xip_area 501176 501232 56 0.0
lock cyw930739m2evb_01 (read/write) 555202 555246 44 0.0
.app_xip_area 460688 460732 44 0.0
ota-requestor cyw930739m2evb_01 (read/write) 576310 576366 56 0.0
.app_xip_area 472364 472420 56 0.0
efr32 lighting-app BRD4161A (read only) 914108 914188 80 0.0
.text 914100 914180 80 0.0
BRD4161A+rpc (read only) 942792 942872 80 0.0
.text 942784 942864 80 0.0
window-app BRD4161A (read only) 847960 848008 48 0.0
.text 847952 848000 48 0.0
esp32 all-clusters-app c3devkit (read only) 947604 947634 30 0.0
.flash.text 947604 947634 30 0.0
m5stack (read only) 997331 997403 72 0.0
.flash.text 991947 992019 72 0.0
k32w light k32w061+release (read/write) 691232 691280 48 0.0
.text 605136 605184 48 0.0
lock k32w061+release (read/write) 693848 693896 48 0.0
.text 607496 607544 48 0.0
linux all-clusters-app debug (read only) 2375169 2375713 544 0.0
.text 2006050 2006594 544 0.0
bridge-app debug+rpc (read only) 1730253 1730557 304 0.0
.text 1471829 1472133 304 0.0
chip-tool debug (read only) 8578997 8579429 432 0.0
.text 7602885 7603317 432 0.0
chip-tool-ipv6only arm64 (read only) 8332196 8332628 432 0.0
.text 7133748 7134180 432 0.0
door-lock-app debug (read only) 1941953 1942273 320 0.0
.text 1619698 1620018 320 0.0
lighting-app debug+rpc (read only) 2068217 2068649 432 0.0
.text 1747090 1747522 432 0.0
ota-provider-app debug (read only) 1875417 1875737 320 0.0
.text 1566178 1566498 320 0.0
ota-requestor-app debug (read only) 1888521 1888937 416 0.0
.text 1586018 1586434 416 0.0
shell debug (read only) 2349865 2350393 528 0.0
.text 1985874 1986402 528 0.0
thermostat-no-ble arm64 (read only) 2162044 2162476 432 0.0
.text 1809888 1810320 432 0.0
tv-app debug (read only) 2537161 2537593 432 0.0
.text 2165650 2166082 432 0.0
mbed all-clusters-app CY8CPROTO_062_4343W+release (read/write) 2428412 2428476 64 0.0
.text 1390984 1391048 64 0.0
lighting-app CY8CPROTO_062_4343W+release (read/write) 2391612 2391676 64 0.0
.text 1354184 1354248 64 0.0
shell CY8CPROTO_062_4343W+release (read/write) 2317820 2317884 64 0.0
.text 1280392 1280456 64 0.0
nrfconnect lighting-app nrf52840dk_nrf52840 (read/write) 1022191 1022255 64 0.0
text 699036 699108 72 0.0
nrf52840dk_nrf52840+rpc (read/write) 991487 991551 64 0.0
text 678936 679008 72 0.0
nrf52840dongle_nrf52840 (read/write) 1037011 1037059 48 0.0
text 702928 702984 56 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 928806 928886 80 0.0
text 614056 614128 72 0.0
lock-app nrf52840dk_nrf52840 (read/write) 950895 950927 32 0.0
text 641228 641268 40 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 858358 858406 48 0.0
text 557024 557068 44 0.0
pump-app nrf52840dk_nrf52840 (read/write) 949347 949379 32 0.0
text 641048 641088 40 0.0
pump-controller-app nrf52840dk_nrf52840 (read/write) 945419 945467 48 0.0
text 637288 637328 40 0.0
p6 all-clusters-app default (read/write) 2485872 2485952 80 0.0
.text 1444136 1444216 80 0.0
light-app default (read/write) 2392760 2392824 64 0.0
.text 1351024 1351088 64 0.0
lock-app default (read/write) 2356240 2356288 48 0.0
.text 1314504 1314552 48 0.0
qpg lighting-app qpg6105+debug (read only) 598744 598808 64 0.0
.text 593424 593488 64 0.0
lock-app qpg6105+debug (read only) 564352 564408 56 0.0
.text 559032 559088 56 0.0
telink lighting-app tlsr9518adk80d (read/write) 877490 877514 24 0.0
text 617978 618002 24 0.0
Full report (43 builds for cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg, telink)
platform target config section 6e55dee 26ad641 change % change
cyw30739 light cyw930739m2evb_01 (read/write) 597258 597314 56 0.0
.app_xip_area 501176 501232 56 0.0
.bss 78780 78780 0 0.0
.data 644 644 0 0.0
.rodata 0 0 0 0.0
.text 0 0 0 0.0
lock cyw930739m2evb_01 (read/write) 555202 555246 44 0.0
.app_xip_area 460688 460732 44 0.0
.bss 77252 77252 0 0.0
.data 608 608 0 0.0
.rodata 0 0 0 0.0
.text 0 0 0 0.0
ota-requestor cyw930739m2evb_01 (read/write) 576310 576366 56 0.0
.app_xip_area 472364 472420 56 0.0
.bss 86356 86356 0 0.0
.data 552 552 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
efr32 lighting-app BRD4161A (read only) 914108 914188 80 0.0
(read/write) 129524 129524 0 0.0
.bss 127488 127488 0 0.0
.data 2036 2036 0 0.0
.text 914100 914180 80 0.0
BRD4161A+rpc (read only) 942792 942872 80 0.0
(read/write) 146440 146440 0 0.0
.bss 144264 144264 0 0.0
.data 2176 2176 0 0.0
.text 942784 942864 80 0.0
window-app BRD4161A (read only) 847960 848008 48 0.0
(read/write) 127416 127416 0 0.0
.bss 125512 125512 0 0.0
.data 1904 1904 0 0.0
.text 847952 848000 48 0.0
esp32 all-clusters-app c3devkit (read only) 947604 947634 30 0.0
(read/write) 1401130 1401130 0 0.0
.dram0.bss 68296 68296 0 0.0
.dram0.data 14268 14268 0 0.0
.flash.rodata 199664 199664 0 0.0
.flash.text 947604 947634 30 0.0
.iram0.text 62056 62056 0 0.0
m5stack (read only) 997331 997403 72 0.0
(read/write) 466380 466380 0 0.0
.dram0.bss 73432 73432 0 0.0
.dram0.data 34064 34064 0 0.0
.flash.rodata 226756 226756 0 0.0
.flash.text 991947 992019 72 0.0
.iram0.text 123399 123399 0 0.0
k32w light k32w061+release (read/write) 691232 691280 48 0.0
.bss 78384 78384 0 0.0
.data 1912 1912 0 0.0
.text 605136 605184 48 0.0
lock k32w061+release (read/write) 693848 693896 48 0.0
.bss 78600 78600 0 0.0
.data 1952 1952 0 0.0
.text 607496 607544 48 0.0
linux all-clusters-app debug (read only) 2375169 2375713 544 0.0
(read/write) 151072 151072 0 0.0
.bss 65376 65376 0 0.0
.data 1328 1328 0 0.0
.data.rel.ro 78664 78664 0 0.0
.dynamic 592 592 0 0.0
.got 4160 4160 0 0.0
.init 27 27 0 0.0
.init_array 920 920 0 0.0
.rodata 206181 206181 0 0.0
.text 2006050 2006594 544 0.0
bridge-app debug+rpc (read only) 1730253 1730557 304 0.0
(read/write) 94536 94536 0 0.0
.bss 49296 49296 0 0.0
.data 2034 2034 0 0.0
.data.rel.ro 38080 38080 0 0.0
.dynamic 592 592 0 0.0
.got 3952 3952 0 0.0
.init 27 27 0 0.0
.init_array 560 560 0 0.0
.rodata 142092 142092 0 0.0
.text 1471829 1472133 304 0.0
chip-tool debug (read only) 8578997 8579429 432 0.0
(read/write) 254816 254816 0 0.0
.bss 40712 40712 0 0.0
.data 1184 1184 0 0.0
.data.rel.ro 206896 206896 0 0.0
.dynamic 608 608 0 0.0
.got 4784 4784 0 0.0
.init 27 27 0 0.0
.init_array 624 624 0 0.0
.rodata 459701 459701 0 0.0
.text 7602885 7603317 432 0.0
chip-tool-ipv6only arm64 (read only) 8332196 8332628 432 0.0
(read/write) 362609 362609 0 0.0
.bss 58961 58961 0 0.0
.data 1216 1216 0 0.0
.data.rel.ro 249368 249368 0 0.0
.dynamic 560 560 0 0.0
.got 49272 49272 0 0.0
.init 24 24 0 0.0
.init_array 200 200 0 0.0
.rodata 435756 435756 0 0.0
.text 7133748 7134180 432 0.0
door-lock-app debug (read only) 1941953 1942273 320 0.0
(read/write) 120504 120504 0 0.0
.bss 51984 51984 0 0.0
.data 1010 1010 0 0.0
.data.rel.ro 62080 62080 0 0.0
.dynamic 592 592 0 0.0
.got 4136 4136 0 0.0
.init 27 27 0 0.0
.init_array 672 672 0 0.0
.rodata 173394 173394 0 0.0
.text 1619698 1620018 320 0.0
lighting-app debug+rpc (read only) 2068217 2068649 432 0.0
(read/write) 125784 125784 0 0.0
.bss 53024 53024 0 0.0
.data 1400 1400 0 0.0
.data.rel.ro 65832 65832 0 0.0
.dynamic 608 608 0 0.0
.got 4168 4168 0 0.0
.init 27 27 0 0.0
.init_array 720 720 0 0.0
.rodata 166033 166033 0 0.0
.text 1747090 1747522 432 0.0
ota-provider-app debug (read only) 1875417 1875737 320 0.0
(read/write) 116216 116216 0 0.0
.bss 51840 51840 0 0.0
.data 1224 1224 0 0.0
.data.rel.ro 57480 57480 0 0.0
.dynamic 608 608 0 0.0
.got 4392 4392 0 0.0
.init 27 27 0 0.0
.init_array 624 624 0 0.0
.rodata 158275 158275 0 0.0
.text 1566178 1566498 320 0.0
ota-requestor-app debug (read only) 1888521 1888937 416 0.0
(read/write) 117632 117632 0 0.0
.bss 52256 52256 0 0.0
.data 1160 1160 0 0.0
.data.rel.ro 58744 58744 0 0.0
.dynamic 592 592 0 0.0
.got 4200 4200 0 0.0
.init 27 27 0 0.0
.init_array 632 632 0 0.0
.rodata 153044 153044 0 0.0
.text 1586018 1586434 416 0.0
shell debug (read only) 2349865 2350393 528 0.0
(read/write) 153424 153424 0 0.0
.bss 73696 73696 0 0.0
.data 832 832 0 0.0
.data.rel.ro 73224 73224 0 0.0
.dynamic 592 592 0 0.0
.got 4168 4168 0 0.0
.init 27 27 0 0.0
.init_array 904 904 0 0.0
.rodata 207186 207186 0 0.0
.text 1985874 1986402 528 0.0
thermostat-no-ble arm64 (read only) 2162044 2162476 432 0.0
(read/write) 150737 150737 0 0.0
.bss 67489 67489 0 0.0
.data 1032 1032 0 0.0
.data.rel.ro 75024 75024 0 0.0
.dynamic 560 560 0 0.0
.got 4208 4208 0 0.0
.init 24 24 0 0.0
.init_array 336 336 0 0.0
.rodata 133532 133532 0 0.0
.text 1809888 1810320 432 0.0
tv-app debug (read only) 2537161 2537593 432 0.0
(read/write) 151456 151456 0 0.0
.bss 69184 69184 0 0.0
.data 3200 3200 0 0.0
.data.rel.ro 73008 73008 0 0.0
.dynamic 592 592 0 0.0
.got 4552 4552 0 0.0
.init 27 27 0 0.0
.init_array 888 888 0 0.0
.rodata 198197 198197 0 0.0
.text 2165650 2166082 432 0.0
mbed all-clusters-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2428412 2428476 64 0.0
.bss 195916 195916 0 0.0
.data 5328 5328 0 0.0
.text 1390984 1391048 64 0.0
lighting-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2391612 2391676 64 0.0
.bss 188448 188448 0 0.0
.data 5632 5632 0 0.0
.text 1354184 1354248 64 0.0
lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2327056 2327056 0 0.0
.bss 187424 187424 0 0.0
.data 5608 5608 0 0.0
.text 1289656 1289656 0 0.0
pigweed-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 1139840 1139840 0 0.0
.bss 11796 11796 0 0.0
.data 4368 4368 0 0.0
.text 103224 103224 0 0.0
shell CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2317820 2317884 64 0.0
.bss 185972 185972 0 0.0
.data 5440 5440 0 0.0
.text 1280392 1280456 64 0.0
nrfconnect lighting-app nrf52840dk_nrf52840 (read/write) 1022191 1022255 64 0.0
bss 123548 123548 0 0.0
rodata 120604 120604 0 0.0
text 699036 699108 72 0.0
nrf52840dk_nrf52840+rpc (read/write) 991487 991551 64 0.0
bss 120736 120736 0 0.0
rodata 112132 112132 0 0.0
text 678936 679008 72 0.0
nrf52840dongle_nrf52840 (read/write) 1037011 1037059 48 0.0
bss 124768 124768 0 0.0
rodata 119420 119420 0 0.0
text 702928 702984 56 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 928806 928886 80 0.0
bss 120112 120112 0 0.0
rodata 113848 113848 0 0.0
text 614056 614128 72 0.0
lock-app nrf52840dk_nrf52840 (read/write) 950895 950927 32 0.0
bss 121752 121752 0 0.0
rodata 109300 109300 0 0.0
text 641228 641268 40 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 858358 858406 48 0.0
bss 118344 118344 0 0.0
rodata 102472 102472 0 0.0
text 557024 557068 44 0.0
pigweed-app nrf52840dk_nrf52840 (read/write) 527595 527595 0 0.0
bss 53632 53632 0 0.0
rodata 49976 49976 0 0.0
text 361016 361016 0 0.0
pump-app nrf52840dk_nrf52840 (read/write) 949347 949379 32 0.0
bss 121472 121472 0 0.0
rodata 108256 108256 0 0.0
text 641048 641088 40 0.0
pump-controller-app nrf52840dk_nrf52840 (read/write) 945419 945467 48 0.0
bss 121476 121476 0 0.0
rodata 107952 107952 0 0.0
text 637288 637328 40 0.0
shell nrf52840dk_nrf52840 (read/write) 810799 810799 0 0.0
bss 113324 113324 0 0.0
rodata 79364 79364 0 0.0
text 540456 540456 0 0.0
p6 all-clusters-app default (read/write) 2485872 2485952 80 0.0
.bss 124232 124232 0 0.0
.data 2672 2672 0 0.0
.text 1444136 1444216 80 0.0
light-app default (read/write) 2392760 2392824 64 0.0
.bss 113912 113912 0 0.0
.data 2528 2528 0 0.0
.text 1351024 1351088 64 0.0
lock-app default (read/write) 2356240 2356288 48 0.0
.bss 113640 113640 0 0.0
.data 2488 2488 0 0.0
.text 1314504 1314552 48 0.0
qpg lighting-app qpg6105+debug (read only) 598744 598808 64 0.0
(read/write) 146940 146940 0 0.0
.bss 90744 90744 0 0.0
.data 1112 1112 0 0.0
.text 593424 593488 64 0.0
lock-app qpg6105+debug (read only) 564352 564408 56 0.0
(read/write) 146940 146940 0 0.0
.bss 90728 90728 0 0.0
.data 1064 1064 0 0.0
.text 559032 559088 56 0.0
persistent-storage-app qpg6105+debug (read only) 99520 99520 0 0.0
(read/write) 146940 146940 0 0.0
.bss 24004 24004 0 0.0
.data 176 176 0 0.0
.text 94200 94200 0 0.0
telink lighting-app tlsr9518adk80d (read/write) 877490 877514 24 0.0
bss 87520 87520 0 0.0
noinit 37160 37160 0 0.0
text 617978 618002 24 0.0

@bzbarsky-apple
Copy link
Contributor Author

@mrjerryjohns is going to take over this and do the EncodeForWrite and EncodeForRead thing, since he needs something very similar anyway for fabric-sensitive bits.

@bzbarsky-apple bzbarsky-apple deleted the encode-indicate-write branch February 16, 2022 18:53
mrjerryjohns added a commit to mrjerryjohns/connectedhomeip that referenced this pull request Feb 16, 2022
This builds upon bzbarsky's original PR project-chip#15268 based upon discussions
with him to create separate EncodeForWrite/EncodeForRead APIs that only
apply to fabric-scoped structs.

This is then used (for now) to omit encoding the fabric index on writes.

Tests: Ran chip-tool to write an ACL entry and confirmed that that the
fabric index field is omitted on writes.
mrjerryjohns added a commit to mrjerryjohns/connectedhomeip that referenced this pull request Feb 16, 2022
This builds upon bzbarsky's original PR project-chip#15268 based upon discussions
with him to create separate EncodeForWrite/EncodeForRead APIs that only
apply to fabric-scoped structs.

This is then used (for now) to omit encoding the fabric index on writes.

Tests: Ran chip-tool to write an ACL entry and confirmed that that the
fabric index field is omitted on writes.
mrjerryjohns added a commit that referenced this pull request Feb 17, 2022
* Separate DataModel APIs for encoding fabric-sensitive structs

This builds upon bzbarsky's original PR #15268 based upon discussions
with him to create separate EncodeForWrite/EncodeForRead APIs that only
apply to fabric-scoped structs.

This is then used (for now) to omit encoding the fabric index on writes.

Tests: Ran chip-tool to write an ACL entry and confirmed that that the
fabric index field is omitted on writes.

* WIP

* Review feedback

* Tests were using fabric index 0 for fake fabric testing, but that trips the invalid fabric checker in AttributeValueEncoder::EncodeListItem...

* Review feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant