diff --git a/CHANGELOG.md b/CHANGELOG.md index e6abb26f72..7a6584844f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The minor version will be incremented upon a breaking change and the patch versi ### Features +- lang: Change all accounts to have a reference to `AccountInfo` ([#2656](https://github.com/coral-xyz/anchor/pull/2656)). - lang: Add `get_lamports`, `add_lamports` and `sub_lamports` methods for all account types ([#2552](https://github.com/coral-xyz/anchor/pull/2552)). - client: Add a helper struct `DynSigner` to simplify use of `Client where >` with Solana clap CLI utils that loads `Signer` as `Box` ([#2550](https://github.com/coral-xyz/anchor/pull/2550)). - lang: Allow CPI calls matching an interface without pinning program ID ([#2559](https://github.com/coral-xyz/anchor/pull/2559)). diff --git a/bench/BINARY_SIZE.md b/bench/BINARY_SIZE.md index b41f944595..97c2ac99dd 100644 --- a/bench/BINARY_SIZE.md +++ b/bench/BINARY_SIZE.md @@ -16,12 +16,13 @@ The programs and their tests are located in [/tests/bench](https://github.com/co Solana version: 1.17.0 -| Program | Binary Size | +/- | -| ------- | ----------- | ----------------------- | -| bench | 1,049,608 | 🟢 **-104,128 (9.03%)** | +| Program | Binary Size | +/- | +| ------- | ----------- | ------------------------ | +| bench | 764,032 | 🟢 **-389,704 (33.78%)** | ### Notable changes +- Change all accounts to have a reference to `AccountInfo` ([#2656](https://github.com/coral-xyz/anchor/pull/2656)). - `Box` the `anchor_lang::Result` error variants ([#2600](https://github.com/coral-xyz/anchor/pull/2600)). --- diff --git a/bench/COMPUTE_UNITS.md b/bench/COMPUTE_UNITS.md index 0e95e9def7..c81555fe5e 100644 --- a/bench/COMPUTE_UNITS.md +++ b/bench/COMPUTE_UNITS.md @@ -22,89 +22,89 @@ Solana version: 1.17.0 | accountInfo2 | 824 | 🟢 **-651 (44.14%)** | | accountInfo4 | 1,319 | 🟢 **-645 (32.84%)** | | accountInfo8 | 2,531 | 🟢 **-1,310 (34.11%)** | -| accountEmptyInit1 | 5,521 | 🟢 **-296 (5.09%)** | -| accountEmpty1 | 777 | 🟢 **-372 (32.38%)** | -| accountEmptyInit2 | 10,111 | 🟢 **-291 (2.80%)** | -| accountEmpty2 | 1,207 | 🟢 **-547 (31.19%)** | -| accountEmptyInit4 | 19,044 | 🟢 **-464 (2.38%)** | -| accountEmpty4 | 2,074 | 🟢 **-466 (18.35%)** | -| accountEmptyInit8 | 37,265 | - | -| accountEmpty8 | 3,967 | 🟢 **-1,049 (20.91%)** | -| accountSizedInit1 | 5,626 | 🟢 **-298 (5.03%)** | -| accountSized1 | 786 | 🟢 **-428 (35.26%)** | -| accountSizedInit2 | 10,322 | 🟢 **-358 (3.35%)** | -| accountSized2 | 1,234 | 🟢 **-639 (34.12%)** | -| accountSizedInit4 | 19,462 | 🟢 **-508 (2.54%)** | -| accountSized4 | 2,135 | 🟢 **-627 (22.70%)** | -| accountSizedInit8 | 38,122 | - | -| accountSized8 | 4,104 | 🟢 **-1,249 (23.33%)** | -| accountUnsizedInit1 | 5,742 | 🟢 **-310 (5.12%)** | -| accountUnsized1 | 821 | 🟢 **-517 (38.64%)** | -| accountUnsizedInit2 | 10,551 | 🟢 **-378 (3.46%)** | -| accountUnsized2 | 1,312 | 🟢 **-466 (26.21%)** | -| accountUnsizedInit4 | 19,927 | 🟢 **-412 (2.03%)** | -| accountUnsized4 | 2,315 | 🟢 **-821 (26.18%)** | -| accountUnsizedInit8 | 38,699 | 🟢 **-397 (1.02%)** | -| accountUnsized8 | 4,456 | 🟢 **-1,496 (25.13%)** | -| boxedAccountEmptyInit1 | 5,452 | 🟢 **-582 (9.65%)** | -| boxedAccountEmpty1 | 866 | 🟢 **-22 (2.48%)** | -| boxedAccountEmptyInit2 | 10,051 | 🟢 **-582 (5.47%)** | -| boxedAccountEmpty2 | 1,377 | 🟢 **-24 (1.71%)** | -| boxedAccountEmptyInit4 | 19,030 | 🟢 **-281 (1.46%)** | -| boxedAccountEmpty4 | 2,396 | 🟢 **-28 (1.16%)** | -| boxedAccountEmptyInit8 | 37,136 | - | -| boxedAccountEmpty8 | 4,472 | 🟢 **-187 (4.01%)** | -| boxedAccountSizedInit1 | 5,546 | 🟢 **-584 (9.53%)** | -| boxedAccountSized1 | 895 | 🟢 **-22 (2.40%)** | -| boxedAccountSizedInit2 | 10,242 | 🟢 **-586 (5.41%)** | -| boxedAccountSized2 | 1,439 | 🟢 **-24 (1.64%)** | -| boxedAccountSizedInit4 | 19,414 | 🟢 **-289 (1.47%)** | -| boxedAccountSized4 | 2,515 | 🟢 **-28 (1.10%)** | -| boxedAccountSizedInit8 | 37,919 | - | -| boxedAccountSized8 | 4,711 | 🟢 **-187 (3.82%)** | -| boxedAccountUnsizedInit1 | 5,823 | 🟢 **-417 (6.68%)** | -| boxedAccountUnsized1 | 950 | 🟢 **-22 (2.26%)** | -| boxedAccountUnsizedInit2 | 10,621 | 🟢 **-427 (3.86%)** | -| boxedAccountUnsized2 | 1,549 | 🟢 **-21 (1.34%)** | -| boxedAccountUnsizedInit4 | 19,825 | 🟢 **-313 (1.55%)** | -| boxedAccountUnsized4 | 2,737 | 🟢 **-31 (1.12%)** | -| boxedAccountUnsizedInit8 | 38,791 | 🟢 **-9 (0.02%)** | -| boxedAccountUnsized8 | 5,207 | 🟢 **-140 (2.62%)** | -| boxedInterfaceAccountMint1 | 2,137 | 🟢 **-159 (6.93%)** | -| boxedInterfaceAccountMint2 | 3,849 | 🟢 **-280 (6.78%)** | -| boxedInterfaceAccountMint4 | 7,215 | 🟢 **-568 (7.30%)** | -| boxedInterfaceAccountMint8 | 14,044 | 🟢 **-1,237 (8.10%)** | -| boxedInterfaceAccountToken1 | 2,066 | 🔴 **+43 (2.13%)** | -| boxedInterfaceAccountToken2 | 3,706 | 🔴 **+124 (3.46%)** | -| boxedInterfaceAccountToken4 | 6,932 | 🔴 **+240 (3.59%)** | -| boxedInterfaceAccountToken8 | 13,477 | 🔴 **+379 (2.89%)** | -| interfaceAccountMint1 | 2,313 | 🟢 **-51 (2.16%)** | -| interfaceAccountMint2 | 4,270 | 🟢 **-760 (15.11%)** | -| interfaceAccountMint4 | 8,185 | 🟢 **-1,618 (16.51%)** | -| interfaceAccountMint8 | 16,007 | 🟢 **-2,393 (13.01%)** | -| interfaceAccountToken1 | 2,059 | 🟢 **-32 (1.53%)** | -| interfaceAccountToken2 | 3,958 | 🔴 **+10 (0.25%)** | -| interfaceAccountToken4 | 7,816 | 🔴 **+269 (3.56%)** | -| interface1 | 691 | 🟢 **-368 (34.75%)** | -| interface2 | 940 | 🟢 **-539 (36.44%)** | -| interface4 | 1,450 | 🟢 **-450 (23.68%)** | -| interface8 | 2,605 | 🟢 **-1,041 (28.55%)** | -| program1 | 685 | 🟢 **-368 (34.95%)** | -| program2 | 928 | 🟢 **-539 (36.74%)** | -| program4 | 1,428 | 🟢 **-450 (23.96%)** | -| program8 | 2,557 | 🟢 **-1,041 (28.93%)** | -| signer1 | 621 | 🟢 **-397 (39.00%)** | -| signer2 | 895 | 🟢 **-589 (39.69%)** | -| signer4 | 1,455 | 🟢 **-529 (26.66%)** | -| signer8 | 2,721 | 🟢 **-1,159 (29.87%)** | -| systemAccount1 | 675 | 🟢 **-397 (37.03%)** | -| systemAccount2 | 1,001 | 🟢 **-589 (37.04%)** | -| systemAccount4 | 1,666 | 🟢 **-529 (24.10%)** | -| systemAccount8 | 3,146 | 🟢 **-1,159 (26.92%)** | -| uncheckedAccount1 | 583 | 🟢 **-431 (42.50%)** | -| uncheckedAccount2 | 824 | 🟢 **-651 (44.14%)** | -| uncheckedAccount4 | 1,320 | 🟢 **-645 (32.82%)** | -| uncheckedAccount8 | 2,531 | 🟢 **-1,310 (34.11%)** | +| accountEmptyInit1 | 5,099 | 🟢 **-718 (12.34%)** | +| accountEmpty1 | 708 | 🟢 **-441 (38.38%)** | +| accountEmptyInit2 | 9,676 | 🟢 **-726 (6.98%)** | +| accountEmpty2 | 1,064 | 🟢 **-690 (39.34%)** | +| accountEmptyInit4 | 18,477 | 🟢 **-1,031 (5.29%)** | +| accountEmpty4 | 1,766 | 🟢 **-774 (30.47%)** | +| accountEmptyInit8 | 36,113 | 🟢 **-1,152 (3.09%)** | +| accountEmpty8 | 3,179 | 🟢 **-1,837 (36.62%)** | +| accountSizedInit1 | 5,187 | 🟢 **-737 (12.44%)** | +| accountSized1 | 732 | 🟢 **-482 (39.70%)** | +| accountSizedInit2 | 9,851 | 🟢 **-829 (7.76%)** | +| accountSized2 | 1,106 | 🟢 **-767 (40.95%)** | +| accountSizedInit4 | 18,876 | 🟢 **-1,094 (5.48%)** | +| accountSized4 | 1,863 | 🟢 **-899 (32.55%)** | +| accountSizedInit8 | 36,832 | 🟢 **-1,290 (3.38%)** | +| accountSized8 | 3,374 | 🟢 **-1,979 (36.97%)** | +| accountUnsizedInit1 | 5,275 | 🟢 **-777 (12.84%)** | +| accountUnsized1 | 759 | 🟢 **-579 (43.27%)** | +| accountUnsizedInit2 | 10,090 | 🟢 **-839 (7.68%)** | +| accountUnsized2 | 1,168 | 🟢 **-610 (34.31%)** | +| accountUnsizedInit4 | 19,281 | 🟢 **-1,058 (5.20%)** | +| accountUnsized4 | 2,000 | 🟢 **-1,136 (36.22%)** | +| accountUnsizedInit8 | 37,378 | 🟢 **-1,718 (4.39%)** | +| accountUnsized8 | 3,667 | 🟢 **-2,285 (38.39%)** | +| boxedAccountEmptyInit1 | 5,145 | 🟢 **-889 (14.73%)** | +| boxedAccountEmpty1 | 745 | 🟢 **-143 (16.10%)** | +| boxedAccountEmptyInit2 | 9,769 | 🟢 **-864 (8.13%)** | +| boxedAccountEmpty2 | 1,136 | 🟢 **-265 (18.92%)** | +| boxedAccountEmptyInit4 | 18,661 | 🟢 **-650 (3.37%)** | +| boxedAccountEmpty4 | 1,913 | 🟢 **-511 (21.08%)** | +| boxedAccountEmptyInit8 | 36,488 | 🟢 **-648 (1.74%)** | +| boxedAccountEmpty8 | 3,500 | 🟢 **-1,159 (24.88%)** | +| boxedAccountSizedInit1 | 5,222 | 🟢 **-908 (14.81%)** | +| boxedAccountSized1 | 767 | 🟢 **-150 (16.36%)** | +| boxedAccountSizedInit2 | 9,925 | 🟢 **-903 (8.34%)** | +| boxedAccountSized2 | 1,183 | 🟢 **-280 (19.14%)** | +| boxedAccountSizedInit4 | 18,973 | 🟢 **-730 (3.71%)** | +| boxedAccountSized4 | 2,002 | 🟢 **-541 (21.27%)** | +| boxedAccountSizedInit8 | 37,111 | 🟢 **-808 (2.13%)** | +| boxedAccountSized8 | 3,682 | 🟢 **-1,216 (24.83%)** | +| boxedAccountUnsizedInit1 | 5,304 | 🟢 **-936 (15.00%)** | +| boxedAccountUnsized1 | 797 | 🟢 **-175 (18.00%)** | +| boxedAccountUnsizedInit2 | 10,089 | 🟢 **-959 (8.68%)** | +| boxedAccountUnsized2 | 1,246 | 🟢 **-324 (20.64%)** | +| boxedAccountUnsizedInit4 | 19,303 | 🟢 **-835 (4.15%)** | +| boxedAccountUnsized4 | 2,135 | 🟢 **-633 (22.87%)** | +| boxedAccountUnsizedInit8 | 37,770 | 🟢 **-1,030 (2.65%)** | +| boxedAccountUnsized8 | 3,948 | 🟢 **-1,399 (26.16%)** | +| boxedInterfaceAccountMint1 | 2,085 | 🟢 **-211 (9.19%)** | +| boxedInterfaceAccountMint2 | 3,726 | 🟢 **-403 (9.76%)** | +| boxedInterfaceAccountMint4 | 6,991 | 🟢 **-792 (10.18%)** | +| boxedInterfaceAccountMint8 | 13,562 | 🟢 **-1,719 (11.25%)** | +| boxedInterfaceAccountToken1 | 2,015 | 🟢 **-8 (0.40%)** | +| boxedInterfaceAccountToken2 | 3,585 | 🔴 **+3 (0.08%)** | +| boxedInterfaceAccountToken4 | 6,712 | 🔴 **+20 (0.30%)** | +| boxedInterfaceAccountToken8 | 13,003 | 🟢 **-95 (0.73%)** | +| interfaceAccountMint1 | 2,174 | 🟢 **-190 (8.04%)** | +| interfaceAccountMint2 | 4,057 | 🟢 **-973 (19.34%)** | +| interfaceAccountMint4 | 7,823 | 🟢 **-1,980 (20.20%)** | +| interfaceAccountMint8 | 15,357 | 🟢 **-3,043 (16.54%)** | +| interfaceAccountToken1 | 2,101 | 🔴 **+10 (0.48%)** | +| interfaceAccountToken2 | 3,909 | 🟢 **-39 (0.99%)** | +| interfaceAccountToken4 | 7,522 | 🟢 **-25 (0.33%)** | +| interface1 | 630 | 🟢 **-429 (40.51%)** | +| interface2 | 813 | 🟢 **-666 (45.03%)** | +| interface4 | 1,174 | 🟢 **-726 (38.21%)** | +| interface8 | 1,905 | 🟢 **-1,741 (47.75%)** | +| program1 | 630 | 🟢 **-423 (40.17%)** | +| program2 | 813 | 🟢 **-654 (44.58%)** | +| program4 | 1,176 | 🟢 **-702 (37.38%)** | +| program8 | 1,905 | 🟢 **-1,693 (47.05%)** | +| signer1 | 564 | 🟢 **-454 (44.60%)** | +| signer2 | 776 | 🟢 **-708 (47.71%)** | +| signer4 | 1,195 | 🟢 **-789 (39.77%)** | +| signer8 | 2,035 | 🟢 **-1,845 (47.55%)** | +| systemAccount1 | 618 | 🟢 **-454 (42.35%)** | +| systemAccount2 | 882 | 🟢 **-708 (44.53%)** | +| systemAccount4 | 1,406 | 🟢 **-789 (35.95%)** | +| systemAccount8 | 2,460 | 🟢 **-1,845 (42.86%)** | +| uncheckedAccount1 | 546 | 🟢 **-468 (46.15%)** | +| uncheckedAccount2 | 738 | 🟢 **-737 (49.97%)** | +| uncheckedAccount4 | 1,115 | 🟢 **-850 (43.26%)** | +| uncheckedAccount8 | 1,877 | 🟢 **-1,964 (51.13%)** | ### Notable changes diff --git a/bench/STACK_MEMORY.md b/bench/STACK_MEMORY.md index f99f713ad1..c657082976 100644 --- a/bench/STACK_MEMORY.md +++ b/bench/STACK_MEMORY.md @@ -22,62 +22,62 @@ Solana version: 1.17.0 | account_info2 | 128 | 🟢 **-248 (65.96%)** | | account_info4 | 128 | 🟢 **-432 (77.14%)** | | account_info8 | 128 | 🟢 **-600 (82.42%)** | -| account_empty_init1 | 320 | 🟢 **-272 (45.95%)** | -| account_empty_init2 | 400 | 🟢 **-160 (28.57%)** | -| account_empty_init4 | 448 | 🟢 **-184 (29.11%)** | -| account_empty_init8 | 640 | 🟢 **-184 (22.33%)** | +| account_empty_init1 | 176 | 🟢 **-416 (70.27%)** | +| account_empty_init2 | 208 | 🟢 **-352 (62.86%)** | +| account_empty_init4 | 208 | 🟢 **-424 (67.09%)** | +| account_empty_init8 | 240 | 🟢 **-584 (70.87%)** | | account_empty1 | 128 | 🟢 **-192 (60.00%)** | | account_empty2 | 128 | 🟢 **-240 (65.22%)** | | account_empty4 | 128 | 🟢 **-424 (76.81%)** | | account_empty8 | 128 | 🟢 **-600 (82.42%)** | -| account_sized_init1 | 328 | 🟢 **-272 (45.33%)** | -| account_sized_init2 | 416 | 🟢 **-136 (24.64%)** | -| account_sized_init4 | 480 | 🟢 **-184 (27.71%)** | -| account_sized_init8 | 704 | 🟢 **-184 (20.72%)** | +| account_sized_init1 | 208 | 🟢 **-392 (65.33%)** | +| account_sized_init2 | 256 | 🟢 **-296 (53.62%)** | +| account_sized_init4 | 240 | 🟢 **-424 (63.86%)** | +| account_sized_init8 | 304 | 🟢 **-584 (65.77%)** | | account_sized1 | 128 | 🟢 **-200 (60.98%)** | | account_sized2 | 128 | 🟢 **-264 (67.35%)** | | account_sized4 | 128 | 🟢 **-440 (77.46%)** | | account_sized8 | 128 | 🟢 **-664 (83.84%)** | -| account_unsized_init1 | 344 | 🟢 **-280 (44.87%)** | -| account_unsized_init2 | 448 | 🟢 **-136 (23.29%)** | -| account_unsized_init4 | 544 | 🟢 **-184 (25.27%)** | -| account_unsized_init8 | 832 | 🟢 **-184 (18.11%)** | +| account_unsized_init1 | 224 | 🟢 **-400 (64.10%)** | +| account_unsized_init2 | 296 | 🟢 **-288 (49.32%)** | +| account_unsized_init4 | 304 | 🟢 **-424 (58.24%)** | +| account_unsized_init8 | 432 | 🟢 **-584 (57.48%)** | | account_unsized1 | 128 | 🟢 **-216 (62.79%)** | -| account_unsized2 | 128 | 🟢 **-328 (71.93%)** | +| account_unsized2 | 144 | 🟢 **-312 (68.42%)** | | account_unsized4 | 128 | 🟢 **-504 (79.75%)** | | account_unsized8 | 128 | 🟢 **-792 (86.09%)** | | boxed_account_empty_init1 | 176 | 🟢 **-376 (68.12%)** | | boxed_account_empty_init2 | 208 | 🟢 **-192 (48.00%)** | -| boxed_account_empty_init4 | 288 | 🟢 **-144 (33.33%)** | -| boxed_account_empty_init8 | 320 | 🟢 **-176 (35.48%)** | +| boxed_account_empty_init4 | 208 | 🟢 **-224 (51.85%)** | +| boxed_account_empty_init8 | 240 | 🟢 **-256 (51.61%)** | | boxed_account_empty1 | 128 | 🟢 **-192 (60.00%)** | -| boxed_account_empty2 | 144 | 🟢 **-176 (55.00%)** | +| boxed_account_empty2 | 128 | 🟢 **-192 (60.00%)** | | boxed_account_empty4 | 144 | 🟢 **-176 (55.00%)** | -| boxed_account_empty8 | 128 | 🟢 **-208 (61.90%)** | +| boxed_account_empty8 | 144 | 🟢 **-192 (57.14%)** | | boxed_account_sized_init1 | 176 | 🟢 **-376 (68.12%)** | | boxed_account_sized_init2 | 208 | 🟢 **-192 (48.00%)** | -| boxed_account_sized_init4 | 288 | 🟢 **-144 (33.33%)** | -| boxed_account_sized_init8 | 320 | 🟢 **-176 (35.48%)** | +| boxed_account_sized_init4 | 208 | 🟢 **-224 (51.85%)** | +| boxed_account_sized_init8 | 240 | 🟢 **-256 (51.61%)** | | boxed_account_sized1 | 128 | 🟢 **-192 (60.00%)** | -| boxed_account_sized2 | 144 | 🟢 **-176 (55.00%)** | +| boxed_account_sized2 | 128 | 🟢 **-192 (60.00%)** | | boxed_account_sized4 | 144 | 🟢 **-176 (55.00%)** | -| boxed_account_sized8 | 128 | 🟢 **-208 (61.90%)** | -| boxed_account_unsized_init1 | 280 | 🟢 **-272 (49.28%)** | -| boxed_account_unsized_init2 | 320 | 🟢 **-80 (20.00%)** | -| boxed_account_unsized_init4 | 288 | 🟢 **-144 (33.33%)** | -| boxed_account_unsized_init8 | 320 | 🟢 **-176 (35.48%)** | -| boxed_account_unsized1 | 152 | 🟢 **-168 (52.50%)** | +| boxed_account_sized8 | 144 | 🟢 **-192 (57.14%)** | +| boxed_account_unsized_init1 | 176 | 🟢 **-376 (68.12%)** | +| boxed_account_unsized_init2 | 208 | 🟢 **-192 (48.00%)** | +| boxed_account_unsized_init4 | 208 | 🟢 **-224 (51.85%)** | +| boxed_account_unsized_init8 | 240 | 🟢 **-256 (51.61%)** | +| boxed_account_unsized1 | 128 | 🟢 **-192 (60.00%)** | | boxed_account_unsized2 | 144 | 🟢 **-176 (55.00%)** | -| boxed_account_unsized4 | 176 | 🟢 **-144 (45.00%)** | -| boxed_account_unsized8 | 192 | 🟢 **-144 (42.86%)** | +| boxed_account_unsized4 | 128 | 🟢 **-192 (60.00%)** | +| boxed_account_unsized8 | 128 | 🟢 **-208 (61.90%)** | | boxed_interface_account_mint1 | 128 | 🟢 **-192 (60.00%)** | -| boxed_interface_account_mint2 | 144 | 🟢 **-176 (55.00%)** | +| boxed_interface_account_mint2 | 128 | 🟢 **-192 (60.00%)** | | boxed_interface_account_mint4 | 144 | 🟢 **-176 (55.00%)** | -| boxed_interface_account_mint8 | 128 | 🟢 **-208 (61.90%)** | +| boxed_interface_account_mint8 | 144 | 🟢 **-192 (57.14%)** | | boxed_interface_account_token1 | 128 | 🟢 **-192 (60.00%)** | -| boxed_interface_account_token2 | 144 | 🟢 **-176 (55.00%)** | +| boxed_interface_account_token2 | 128 | 🟢 **-192 (60.00%)** | | boxed_interface_account_token4 | 144 | 🟢 **-176 (55.00%)** | -| boxed_interface_account_token8 | 128 | 🟢 **-208 (61.90%)** | +| boxed_interface_account_token8 | 144 | 🟢 **-192 (57.14%)** | | interface_account_mint1 | 128 | 🟢 **-376 (74.60%)** | | interface_account_mint2 | 128 | 🟢 **-552 (81.18%)** | | interface_account_mint4 | 128 | 🟢 **-888 (87.40%)** | diff --git a/lang/src/accounts/account.rs b/lang/src/accounts/account.rs index e9edb0bcde..b027d57f83 100644 --- a/lang/src/accounts/account.rs +++ b/lang/src/accounts/account.rs @@ -225,7 +225,7 @@ use std::ops::{Deref, DerefMut}; #[derive(Clone)] pub struct Account<'info, T: AccountSerialize + AccountDeserialize + Clone> { account: T, - info: AccountInfo<'info>, + info: &'info AccountInfo<'info>, } impl<'info, T: AccountSerialize + AccountDeserialize + Clone + fmt::Debug> fmt::Debug @@ -246,7 +246,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone + fmt::Debug> Accou } impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Account<'a, T> { - pub(crate) fn new(info: AccountInfo<'a>, account: T) -> Account<'a, T> { + pub(crate) fn new(info: &'a AccountInfo<'a>, account: T) -> Account<'a, T> { Self { info, account } } @@ -256,7 +256,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Account<'a, T> { program_id: &Pubkey, ) -> Result<()> { // Only persist if the owner is the current program and the account is not closed. - if expected_owner == program_id && !crate::common::is_closed(&self.info) { + if expected_owner == program_id && !crate::common::is_closed(self.info) { let info = self.to_account_info(); let mut data = info.try_borrow_mut_data()?; let dst: &mut [u8] = &mut data; @@ -302,7 +302,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Account<'a, T> { impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> Account<'a, T> { /// Deserializes the given `info` into a `Account`. #[inline(never)] - pub fn try_from(info: &AccountInfo<'a>) -> Result> { + pub fn try_from(info: &'a AccountInfo<'a>) -> Result> { if info.owner == &system_program::ID && info.lamports() == 0 { return Err(ErrorCode::AccountNotInitialized.into()); } @@ -311,14 +311,14 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> Account<'a, T .with_pubkeys((*info.owner, T::owner()))); } let mut data: &[u8] = &info.try_borrow_data()?; - Ok(Account::new(info.clone(), T::try_deserialize(&mut data)?)) + Ok(Account::new(info, T::try_deserialize(&mut data)?)) } /// Deserializes the given `info` into a `Account` without checking /// the account discriminator. Be careful when using this and avoid it if /// possible. #[inline(never)] - pub fn try_from_unchecked(info: &AccountInfo<'a>) -> Result> { + pub fn try_from_unchecked(info: &'a AccountInfo<'a>) -> Result> { if info.owner == &system_program::ID && info.lamports() == 0 { return Err(ErrorCode::AccountNotInitialized.into()); } @@ -327,10 +327,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> Account<'a, T .with_pubkeys((*info.owner, T::owner()))); } let mut data: &[u8] = &info.try_borrow_data()?; - Ok(Account::new( - info.clone(), - T::try_deserialize_unchecked(&mut data)?, - )) + Ok(Account::new(info, T::try_deserialize_unchecked(&mut data)?)) } } @@ -342,7 +339,7 @@ where #[inline(never)] fn try_accounts( _program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], _ix_data: &[u8], _bumps: &mut B, _reallocs: &mut BTreeSet, @@ -395,7 +392,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef { fn as_ref(&self) -> &AccountInfo<'info> { - &self.info + self.info } } diff --git a/lang/src/accounts/account_loader.rs b/lang/src/accounts/account_loader.rs index b4cbe42d58..caae3057af 100644 --- a/lang/src/accounts/account_loader.rs +++ b/lang/src/accounts/account_loader.rs @@ -95,7 +95,7 @@ use std::ops::DerefMut; /// ``` #[derive(Clone)] pub struct AccountLoader<'info, T: ZeroCopy + Owner> { - acc_info: AccountInfo<'info>, + acc_info: &'info AccountInfo<'info>, phantom: PhantomData<&'info T>, } @@ -109,7 +109,7 @@ impl<'info, T: ZeroCopy + Owner + fmt::Debug> fmt::Debug for AccountLoader<'info } impl<'info, T: ZeroCopy + Owner> AccountLoader<'info, T> { - fn new(acc_info: AccountInfo<'info>) -> AccountLoader<'info, T> { + fn new(acc_info: &'info AccountInfo<'info>) -> AccountLoader<'info, T> { Self { acc_info, phantom: PhantomData, @@ -118,7 +118,7 @@ impl<'info, T: ZeroCopy + Owner> AccountLoader<'info, T> { /// Constructs a new `Loader` from a previously initialized account. #[inline(never)] - pub fn try_from(acc_info: &AccountInfo<'info>) -> Result> { + pub fn try_from(acc_info: &'info AccountInfo<'info>) -> Result> { if acc_info.owner != &T::owner() { return Err(Error::from(ErrorCode::AccountOwnedByWrongProgram) .with_pubkeys((*acc_info.owner, T::owner()))); @@ -133,20 +133,20 @@ impl<'info, T: ZeroCopy + Owner> AccountLoader<'info, T> { return Err(ErrorCode::AccountDiscriminatorMismatch.into()); } - Ok(AccountLoader::new(acc_info.clone())) + Ok(AccountLoader::new(acc_info)) } /// Constructs a new `Loader` from an uninitialized account. #[inline(never)] pub fn try_from_unchecked( _program_id: &Pubkey, - acc_info: &AccountInfo<'info>, + acc_info: &'info AccountInfo<'info>, ) -> Result> { if acc_info.owner != &T::owner() { return Err(Error::from(ErrorCode::AccountOwnedByWrongProgram) .with_pubkeys((*acc_info.owner, T::owner()))); } - Ok(AccountLoader::new(acc_info.clone())) + Ok(AccountLoader::new(acc_info)) } /// Returns a Ref to the account data structure for reading. @@ -218,7 +218,7 @@ impl<'info, B, T: ZeroCopy + Owner> Accounts<'info, B> for AccountLoader<'info, #[inline(never)] fn try_accounts( _program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], _ix_data: &[u8], _bumps: &mut B, _reallocs: &mut BTreeSet, @@ -237,7 +237,7 @@ impl<'info, T: ZeroCopy + Owner> AccountsExit<'info> for AccountLoader<'info, T> // The account *cannot* be loaded when this is called. fn exit(&self, program_id: &Pubkey) -> Result<()> { // Only persist if the owner is the current program and the account is not closed. - if &T::owner() == program_id && !crate::common::is_closed(&self.acc_info) { + if &T::owner() == program_id && !crate::common::is_closed(self.acc_info) { let mut data = self.acc_info.try_borrow_mut_data()?; let dst: &mut [u8] = &mut data; let mut writer = BpfWriter::new(dst); @@ -266,7 +266,7 @@ impl<'info, T: ZeroCopy + Owner> ToAccountMetas for AccountLoader<'info, T> { impl<'info, T: ZeroCopy + Owner> AsRef> for AccountLoader<'info, T> { fn as_ref(&self) -> &AccountInfo<'info> { - &self.acc_info + self.acc_info } } diff --git a/lang/src/accounts/boxed.rs b/lang/src/accounts/boxed.rs index 6905ab2854..cad82440ac 100644 --- a/lang/src/accounts/boxed.rs +++ b/lang/src/accounts/boxed.rs @@ -23,7 +23,7 @@ use std::ops::Deref; impl<'info, B, T: Accounts<'info, B>> Accounts<'info, B> for Box { fn try_accounts( program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], ix_data: &[u8], bumps: &mut B, reallocs: &mut BTreeSet, diff --git a/lang/src/accounts/interface.rs b/lang/src/accounts/interface.rs index b98d8f0894..90e331538a 100644 --- a/lang/src/accounts/interface.rs +++ b/lang/src/accounts/interface.rs @@ -75,22 +75,22 @@ use std::ops::Deref; #[derive(Clone)] pub struct Interface<'info, T>(Program<'info, T>); impl<'a, T> Interface<'a, T> { - pub(crate) fn new(info: AccountInfo<'a>) -> Self { + pub(crate) fn new(info: &'a AccountInfo<'a>) -> Self { Self(Program::new(info)) } pub fn programdata_address(&self) -> Result> { self.0.programdata_address() } } -impl<'a, T: CheckId> TryFrom<&AccountInfo<'a>> for Interface<'a, T> { +impl<'a, T: CheckId> TryFrom<&'a AccountInfo<'a>> for Interface<'a, T> { type Error = Error; /// Deserializes the given `info` into a `Program`. - fn try_from(info: &AccountInfo<'a>) -> Result { + fn try_from(info: &'a AccountInfo<'a>) -> Result { T::check_id(info.key)?; if !info.executable { return Err(ErrorCode::InvalidProgramExecutable.into()); } - Ok(Self::new(info.clone())) + Ok(Self::new(info)) } } impl<'info, T> Deref for Interface<'info, T> { @@ -109,7 +109,7 @@ impl<'info, B, T: CheckId> Accounts<'info, B> for Interface<'info, T> { #[inline(never)] fn try_accounts( _program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], _ix_data: &[u8], _bumps: &mut B, _reallocs: &mut BTreeSet, diff --git a/lang/src/accounts/interface_account.rs b/lang/src/accounts/interface_account.rs index eebbd5bdef..5401641725 100644 --- a/lang/src/accounts/interface_account.rs +++ b/lang/src/accounts/interface_account.rs @@ -173,7 +173,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone + fmt::Debug> fmt:: } impl<'a, T: AccountSerialize + AccountDeserialize + Clone> InterfaceAccount<'a, T> { - fn new(info: AccountInfo<'a>, account: T) -> Self { + fn new(info: &'a AccountInfo<'a>, account: T) -> Self { let owner = *info.owner; Self { account: Account::new(info, account), @@ -215,29 +215,26 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> InterfaceAccount<'a, impl<'a, T: AccountSerialize + AccountDeserialize + CheckOwner + Clone> InterfaceAccount<'a, T> { /// Deserializes the given `info` into a `InterfaceAccount`. #[inline(never)] - pub fn try_from(info: &AccountInfo<'a>) -> Result { + pub fn try_from(info: &'a AccountInfo<'a>) -> Result { if info.owner == &system_program::ID && info.lamports() == 0 { return Err(ErrorCode::AccountNotInitialized.into()); } T::check_owner(info.owner)?; let mut data: &[u8] = &info.try_borrow_data()?; - Ok(Self::new(info.clone(), T::try_deserialize(&mut data)?)) + Ok(Self::new(info, T::try_deserialize(&mut data)?)) } /// Deserializes the given `info` into a `InterfaceAccount` without checking /// the account discriminator. Be careful when using this and avoid it if /// possible. #[inline(never)] - pub fn try_from_unchecked(info: &AccountInfo<'a>) -> Result { + pub fn try_from_unchecked(info: &'a AccountInfo<'a>) -> Result { if info.owner == &system_program::ID && info.lamports() == 0 { return Err(ErrorCode::AccountNotInitialized.into()); } T::check_owner(info.owner)?; let mut data: &[u8] = &info.try_borrow_data()?; - Ok(Self::new( - info.clone(), - T::try_deserialize_unchecked(&mut data)?, - )) + Ok(Self::new(info, T::try_deserialize_unchecked(&mut data)?)) } } @@ -247,7 +244,7 @@ impl<'info, B, T: AccountSerialize + AccountDeserialize + CheckOwner + Clone> Ac #[inline(never)] fn try_accounts( _program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], _ix_data: &[u8], _bumps: &mut B, _reallocs: &mut BTreeSet, diff --git a/lang/src/accounts/option.rs b/lang/src/accounts/option.rs index 8ade56e80a..a1b034a31e 100644 --- a/lang/src/accounts/option.rs +++ b/lang/src/accounts/option.rs @@ -21,7 +21,7 @@ use crate::{ impl<'info, B, T: Accounts<'info, B>> Accounts<'info, B> for Option { fn try_accounts( program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], ix_data: &[u8], bumps: &mut B, reallocs: &mut BTreeSet, diff --git a/lang/src/accounts/program.rs b/lang/src/accounts/program.rs index 25d7189dc2..ac232c4042 100644 --- a/lang/src/accounts/program.rs +++ b/lang/src/accounts/program.rs @@ -77,7 +77,7 @@ use std::ops::Deref; /// #[derive(Clone)] pub struct Program<'info, T> { - info: AccountInfo<'info>, + info: &'info AccountInfo<'info>, _phantom: PhantomData, } @@ -88,7 +88,7 @@ impl<'info, T: fmt::Debug> fmt::Debug for Program<'info, T> { } impl<'a, T> Program<'a, T> { - pub(crate) fn new(info: AccountInfo<'a>) -> Program<'a, T> { + pub(crate) fn new(info: &'a AccountInfo<'a>) -> Program<'a, T> { Self { info, _phantom: PhantomData, @@ -125,10 +125,10 @@ impl<'a, T> Program<'a, T> { } } -impl<'a, T: Id> TryFrom<&AccountInfo<'a>> for Program<'a, T> { +impl<'a, T: Id> TryFrom<&'a AccountInfo<'a>> for Program<'a, T> { type Error = Error; /// Deserializes the given `info` into a `Program`. - fn try_from(info: &AccountInfo<'a>) -> Result { + fn try_from(info: &'a AccountInfo<'a>) -> Result { if info.key != &T::id() { return Err(Error::from(ErrorCode::InvalidProgramId).with_pubkeys((*info.key, T::id()))); } @@ -136,7 +136,7 @@ impl<'a, T: Id> TryFrom<&AccountInfo<'a>> for Program<'a, T> { return Err(ErrorCode::InvalidProgramExecutable.into()); } - Ok(Program::new(info.clone())) + Ok(Program::new(info)) } } @@ -144,7 +144,7 @@ impl<'info, B, T: Id> Accounts<'info, B> for Program<'info, T> { #[inline(never)] fn try_accounts( _program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], _ix_data: &[u8], _bumps: &mut B, _reallocs: &mut BTreeSet, @@ -177,7 +177,7 @@ impl<'info, T> ToAccountInfos<'info> for Program<'info, T> { impl<'info, T> AsRef> for Program<'info, T> { fn as_ref(&self) -> &AccountInfo<'info> { - &self.info + self.info } } @@ -185,7 +185,7 @@ impl<'info, T> Deref for Program<'info, T> { type Target = AccountInfo<'info>; fn deref(&self) -> &Self::Target { - &self.info + self.info } } diff --git a/lang/src/accounts/signer.rs b/lang/src/accounts/signer.rs index 6ce5c22394..e85ea34dcb 100644 --- a/lang/src/accounts/signer.rs +++ b/lang/src/accounts/signer.rs @@ -36,21 +36,21 @@ use std::ops::Deref; /// When creating an account with `init`, the `payer` needs to sign the transaction. #[derive(Debug, Clone)] pub struct Signer<'info> { - info: AccountInfo<'info>, + info: &'info AccountInfo<'info>, } impl<'info> Signer<'info> { - fn new(info: AccountInfo<'info>) -> Signer<'info> { + fn new(info: &'info AccountInfo<'info>) -> Signer<'info> { Self { info } } /// Deserializes the given `info` into a `Signer`. #[inline(never)] - pub fn try_from(info: &AccountInfo<'info>) -> Result> { + pub fn try_from(info: &'info AccountInfo<'info>) -> Result> { if !info.is_signer { return Err(ErrorCode::AccountNotSigner.into()); } - Ok(Signer::new(info.clone())) + Ok(Signer::new(info)) } } @@ -58,7 +58,7 @@ impl<'info, B> Accounts<'info, B> for Signer<'info> { #[inline(never)] fn try_accounts( _program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], _ix_data: &[u8], _bumps: &mut B, _reallocs: &mut BTreeSet, @@ -93,7 +93,7 @@ impl<'info> ToAccountInfos<'info> for Signer<'info> { impl<'info> AsRef> for Signer<'info> { fn as_ref(&self) -> &AccountInfo<'info> { - &self.info + self.info } } @@ -101,7 +101,7 @@ impl<'info> Deref for Signer<'info> { type Target = AccountInfo<'info>; fn deref(&self) -> &Self::Target { - &self.info + self.info } } diff --git a/lang/src/accounts/system_account.rs b/lang/src/accounts/system_account.rs index 66c786e0e0..a2ddd6928c 100644 --- a/lang/src/accounts/system_account.rs +++ b/lang/src/accounts/system_account.rs @@ -16,20 +16,20 @@ use std::ops::Deref; /// - `SystemAccount.info.owner == SystemProgram` #[derive(Debug, Clone)] pub struct SystemAccount<'info> { - info: AccountInfo<'info>, + info: &'info AccountInfo<'info>, } impl<'info> SystemAccount<'info> { - fn new(info: AccountInfo<'info>) -> SystemAccount<'info> { + fn new(info: &'info AccountInfo<'info>) -> SystemAccount<'info> { Self { info } } #[inline(never)] - pub fn try_from(info: &AccountInfo<'info>) -> Result> { + pub fn try_from(info: &'info AccountInfo<'info>) -> Result> { if *info.owner != system_program::ID { return Err(ErrorCode::AccountNotSystemOwned.into()); } - Ok(SystemAccount::new(info.clone())) + Ok(SystemAccount::new(info)) } } @@ -37,7 +37,7 @@ impl<'info, B> Accounts<'info, B> for SystemAccount<'info> { #[inline(never)] fn try_accounts( _program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], _ix_data: &[u8], _bumps: &mut B, _reallocs: &mut BTreeSet, @@ -72,7 +72,7 @@ impl<'info> ToAccountInfos<'info> for SystemAccount<'info> { impl<'info> AsRef> for SystemAccount<'info> { fn as_ref(&self) -> &AccountInfo<'info> { - &self.info + self.info } } @@ -80,7 +80,7 @@ impl<'info> Deref for SystemAccount<'info> { type Target = AccountInfo<'info>; fn deref(&self) -> &Self::Target { - &self.info + self.info } } diff --git a/lang/src/accounts/sysvar.rs b/lang/src/accounts/sysvar.rs index 7edfcf6223..094171c038 100644 --- a/lang/src/accounts/sysvar.rs +++ b/lang/src/accounts/sysvar.rs @@ -31,7 +31,7 @@ use std::ops::{Deref, DerefMut}; /// } /// ``` pub struct Sysvar<'info, T: solana_program::sysvar::Sysvar> { - info: AccountInfo<'info>, + info: &'info AccountInfo<'info>, account: T, } @@ -45,10 +45,10 @@ impl<'info, T: solana_program::sysvar::Sysvar + fmt::Debug> fmt::Debug for Sysva } impl<'info, T: solana_program::sysvar::Sysvar> Sysvar<'info, T> { - pub fn from_account_info(acc_info: &AccountInfo<'info>) -> Result> { + pub fn from_account_info(acc_info: &'info AccountInfo<'info>) -> Result> { match T::from_account_info(acc_info) { Ok(val) => Ok(Sysvar { - info: acc_info.clone(), + info: acc_info, account: val, }), Err(_) => Err(ErrorCode::AccountSysvarMismatch.into()), @@ -59,8 +59,8 @@ impl<'info, T: solana_program::sysvar::Sysvar> Sysvar<'info, T> { impl<'info, T: solana_program::sysvar::Sysvar> Clone for Sysvar<'info, T> { fn clone(&self) -> Self { Self { - info: self.info.clone(), - account: T::from_account_info(&self.info).unwrap(), + info: self.info, + account: T::from_account_info(self.info).unwrap(), } } } @@ -68,7 +68,7 @@ impl<'info, T: solana_program::sysvar::Sysvar> Clone for Sysvar<'info, T> { impl<'info, B, T: solana_program::sysvar::Sysvar> Accounts<'info, B> for Sysvar<'info, T> { fn try_accounts( _program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], _ix_data: &[u8], _bumps: &mut B, _reallocs: &mut BTreeSet, @@ -96,7 +96,7 @@ impl<'info, T: solana_program::sysvar::Sysvar> ToAccountInfos<'info> for Sysvar< impl<'info, T: solana_program::sysvar::Sysvar> AsRef> for Sysvar<'info, T> { fn as_ref(&self) -> &AccountInfo<'info> { - &self.info + self.info } } diff --git a/lang/src/accounts/unchecked_account.rs b/lang/src/accounts/unchecked_account.rs index 562690d919..6ae4398b57 100644 --- a/lang/src/accounts/unchecked_account.rs +++ b/lang/src/accounts/unchecked_account.rs @@ -12,10 +12,10 @@ use std::ops::Deref; /// Explicit wrapper for AccountInfo types to emphasize /// that no checks are performed #[derive(Debug, Clone)] -pub struct UncheckedAccount<'info>(AccountInfo<'info>); +pub struct UncheckedAccount<'info>(&'info AccountInfo<'info>); impl<'info> UncheckedAccount<'info> { - pub fn try_from(acc_info: AccountInfo<'info>) -> Self { + pub fn try_from(acc_info: &'info AccountInfo<'info>) -> Self { Self(acc_info) } } @@ -23,7 +23,7 @@ impl<'info> UncheckedAccount<'info> { impl<'info, B> Accounts<'info, B> for UncheckedAccount<'info> { fn try_accounts( _program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], _ix_data: &[u8], _bumps: &mut B, _reallocs: &mut BTreeSet, @@ -33,7 +33,7 @@ impl<'info, B> Accounts<'info, B> for UncheckedAccount<'info> { } let account = &accounts[0]; *accounts = &accounts[1..]; - Ok(UncheckedAccount(account.clone())) + Ok(UncheckedAccount(account)) } } @@ -58,7 +58,7 @@ impl<'info> AccountsExit<'info> for UncheckedAccount<'info> {} impl<'info> AsRef> for UncheckedAccount<'info> { fn as_ref(&self) -> &AccountInfo<'info> { - &self.0 + self.0 } } @@ -66,7 +66,7 @@ impl<'info> Deref for UncheckedAccount<'info> { type Target = AccountInfo<'info>; fn deref(&self) -> &Self::Target { - &self.0 + self.0 } } diff --git a/lang/src/lib.rs b/lang/src/lib.rs index 0e5afa2605..867d776b91 100644 --- a/lang/src/lib.rs +++ b/lang/src/lib.rs @@ -110,7 +110,7 @@ pub trait Accounts<'info, B>: ToAccountMetas + ToAccountInfos<'info> + Sized { /// so that it cannot be used again. fn try_accounts( program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], ix_data: &[u8], bumps: &mut B, reallocs: &mut BTreeSet, diff --git a/lang/src/vec.rs b/lang/src/vec.rs index 150cd570f8..3250c693ec 100644 --- a/lang/src/vec.rs +++ b/lang/src/vec.rs @@ -23,7 +23,7 @@ impl ToAccountMetas for Vec { impl<'info, B, T: Accounts<'info, B>> Accounts<'info, B> for Vec { fn try_accounts( program_id: &Pubkey, - accounts: &mut &[AccountInfo<'info>], + accounts: &mut &'info [AccountInfo<'info>], ix_data: &[u8], bumps: &mut B, reallocs: &mut BTreeSet, diff --git a/lang/syn/src/codegen/accounts/try_accounts.rs b/lang/syn/src/codegen/accounts/try_accounts.rs index 469a447c23..d9ce4b12b6 100644 --- a/lang/syn/src/codegen/accounts/try_accounts.rs +++ b/lang/syn/src/codegen/accounts/try_accounts.rs @@ -120,7 +120,7 @@ pub fn generate(accs: &AccountsStruct) -> proc_macro2::TokenStream { #[inline(never)] fn try_accounts( __program_id: &anchor_lang::solana_program::pubkey::Pubkey, - __accounts: &mut &[anchor_lang::solana_program::account_info::AccountInfo<'info>], + __accounts: &mut &'info [anchor_lang::solana_program::account_info::AccountInfo<'info>], __ix_data: &[u8], __bumps: &mut #bumps_struct_name, __reallocs: &mut std::collections::BTreeSet, diff --git a/lang/syn/src/codegen/program/dispatch.rs b/lang/syn/src/codegen/program/dispatch.rs index 2c6090b887..ef99b7e56a 100644 --- a/lang/syn/src/codegen/program/dispatch.rs +++ b/lang/syn/src/codegen/program/dispatch.rs @@ -50,9 +50,9 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream { /// With this 8 byte identifier, Anchor performs method dispatch, /// matching the given 8 byte identifier to the associated method /// handler, which leads to user defined code being eventually invoked. - fn dispatch( + fn dispatch<'info>( program_id: &Pubkey, - accounts: &[AccountInfo], + accounts: &'info [AccountInfo<'info>], data: &[u8], ) -> anchor_lang::Result<()> { // Split the instruction data into the first 8 byte method diff --git a/lang/syn/src/codegen/program/entry.rs b/lang/syn/src/codegen/program/entry.rs index 393001a779..4b04da232a 100644 --- a/lang/syn/src/codegen/program/entry.rs +++ b/lang/syn/src/codegen/program/entry.rs @@ -47,14 +47,14 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream { /// /// The `entry` function here, defines the standard entry to a Solana /// program, where execution begins. - pub fn entry(program_id: &Pubkey, accounts: &[AccountInfo], data: &[u8]) -> anchor_lang::solana_program::entrypoint::ProgramResult { + pub fn entry<'info>(program_id: &Pubkey, accounts: &'info [AccountInfo<'info>], data: &[u8]) -> anchor_lang::solana_program::entrypoint::ProgramResult { try_entry(program_id, accounts, data).map_err(|e| { e.log(); e.into() }) } - fn try_entry(program_id: &Pubkey, accounts: &[AccountInfo], data: &[u8]) -> anchor_lang::Result<()> { + fn try_entry<'info>(program_id: &Pubkey, accounts: &'info [AccountInfo<'info>], data: &[u8]) -> anchor_lang::Result<()> { #[cfg(feature = "anchor-debug")] { msg!("anchor-debug is active"); diff --git a/lang/syn/src/codegen/program/handlers.rs b/lang/syn/src/codegen/program/handlers.rs index b9b8962ac4..b89e026b6c 100644 --- a/lang/syn/src/codegen/program/handlers.rs +++ b/lang/syn/src/codegen/program/handlers.rs @@ -20,7 +20,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream { // on chain. #[inline(never)] #[cfg(not(feature = "no-idl"))] - pub fn __idl_dispatch(program_id: &Pubkey, accounts: &[AccountInfo], idl_ix_data: &[u8]) -> anchor_lang::Result<()> { + pub fn __idl_dispatch<'info>(program_id: &Pubkey, accounts: &'info [AccountInfo<'info>], idl_ix_data: &[u8]) -> anchor_lang::Result<()> { let mut accounts = accounts; let mut data: &[u8] = idl_ix_data; @@ -112,9 +112,9 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream { }; quote! { #[inline(never)] - pub fn #ix_method_name( + pub fn #ix_method_name<'info>( __program_id: &Pubkey, - __accounts: &[AccountInfo], + __accounts: &'info[AccountInfo<'info>], __ix_data: &[u8], ) -> anchor_lang::Result<()> { #[cfg(not(feature = "no-log-ix-name"))] diff --git a/lang/syn/src/lib.rs b/lang/syn/src/lib.rs index 7edfbf45aa..48c4fa3e80 100644 --- a/lang/syn/src/lib.rs +++ b/lang/syn/src/lib.rs @@ -322,7 +322,7 @@ impl Field { match &self.ty { Ty::AccountInfo => quote! { #field.to_account_info() }, Ty::UncheckedAccount => { - quote! { UncheckedAccount::try_from(#field.to_account_info()) } + quote! { UncheckedAccount::try_from(&#field) } } Ty::Account(AccountTy { boxed, .. }) | Ty::InterfaceAccount(InterfaceAccountTy { boxed, .. }) => { diff --git a/tests/auction-house/programs/auction-house/src/lib.rs b/tests/auction-house/programs/auction-house/src/lib.rs index aff27a38dd..803be95af1 100644 --- a/tests/auction-house/programs/auction-house/src/lib.rs +++ b/tests/auction-house/programs/auction-house/src/lib.rs @@ -671,7 +671,7 @@ pub mod auction_house { let token_account = &ctx.accounts.token_account; let token_mint = &ctx.accounts.token_mint; let metadata = &ctx.accounts.metadata; - let treasury_mint = &ctx.accounts.treasury_mint.to_account_info(); + let treasury_mint = &ctx.accounts.treasury_mint; let seller_payment_receipt_account = &ctx.accounts.seller_payment_receipt_account; let buyer_receipt_token_account = &ctx.accounts.buyer_receipt_token_account; let escrow_payment_account = &ctx.accounts.escrow_payment_account; @@ -1450,8 +1450,7 @@ pub struct ExecuteSale<'info> { token_mint: UncheckedAccount<'info>, metadata: UncheckedAccount<'info>, // cannot mark these as real Accounts or else we blow stack size limit - //TODO revert this change in a near future - treasury_mint: Box>, + treasury_mint: UncheckedAccount<'info>, #[account(mut)] seller_payment_receipt_account: UncheckedAccount<'info>, #[account(mut)] @@ -1462,7 +1461,7 @@ pub struct ExecuteSale<'info> { seeds=[ PREFIX.as_bytes(), authority.key.as_ref(), - treasury_mint.key().as_ref(), + treasury_mint.key.as_ref(), ], bump=auction_house.bump, has_one=authority, diff --git a/tests/bench/bench.json b/tests/bench/bench.json index 3931093015..2f8b594353 100644 --- a/tests/bench/bench.json +++ b/tests/bench/bench.json @@ -375,158 +375,158 @@ "solanaVersion": "1.17.0", "result": { "binarySize": { - "bench": 1049608 + "bench": 764032 }, "computeUnits": { "accountInfo1": 584, "accountInfo2": 824, "accountInfo4": 1319, "accountInfo8": 2531, - "accountEmptyInit1": 5521, - "accountEmpty1": 777, - "accountEmptyInit2": 10111, - "accountEmpty2": 1207, - "accountEmptyInit4": 19044, - "accountEmpty4": 2074, - "accountEmptyInit8": 37265, - "accountEmpty8": 3967, - "accountSizedInit1": 5626, - "accountSized1": 786, - "accountSizedInit2": 10322, - "accountSized2": 1234, - "accountSizedInit4": 19462, - "accountSized4": 2135, - "accountSizedInit8": 38122, - "accountSized8": 4104, - "accountUnsizedInit1": 5742, - "accountUnsized1": 821, - "accountUnsizedInit2": 10551, - "accountUnsized2": 1312, - "accountUnsizedInit4": 19927, - "accountUnsized4": 2315, - "accountUnsizedInit8": 38699, - "accountUnsized8": 4456, - "boxedAccountEmptyInit1": 5452, - "boxedAccountEmpty1": 866, - "boxedAccountEmptyInit2": 10051, - "boxedAccountEmpty2": 1377, - "boxedAccountEmptyInit4": 19030, - "boxedAccountEmpty4": 2396, - "boxedAccountEmptyInit8": 37136, - "boxedAccountEmpty8": 4472, - "boxedAccountSizedInit1": 5546, - "boxedAccountSized1": 895, - "boxedAccountSizedInit2": 10242, - "boxedAccountSized2": 1439, - "boxedAccountSizedInit4": 19414, - "boxedAccountSized4": 2515, - "boxedAccountSizedInit8": 37919, - "boxedAccountSized8": 4711, - "boxedAccountUnsizedInit1": 5823, - "boxedAccountUnsized1": 950, - "boxedAccountUnsizedInit2": 10621, - "boxedAccountUnsized2": 1549, - "boxedAccountUnsizedInit4": 19825, - "boxedAccountUnsized4": 2737, - "boxedAccountUnsizedInit8": 38791, - "boxedAccountUnsized8": 5207, - "boxedInterfaceAccountMint1": 2137, - "boxedInterfaceAccountMint2": 3849, - "boxedInterfaceAccountMint4": 7215, - "boxedInterfaceAccountMint8": 14044, - "boxedInterfaceAccountToken1": 2066, - "boxedInterfaceAccountToken2": 3706, - "boxedInterfaceAccountToken4": 6932, - "boxedInterfaceAccountToken8": 13477, - "interfaceAccountMint1": 2313, - "interfaceAccountMint2": 4270, - "interfaceAccountMint4": 8185, - "interfaceAccountMint8": 16007, - "interfaceAccountToken1": 2059, - "interfaceAccountToken2": 3958, - "interfaceAccountToken4": 7816, - "interface1": 691, - "interface2": 940, - "interface4": 1450, - "interface8": 2605, - "program1": 685, - "program2": 928, - "program4": 1428, - "program8": 2557, - "signer1": 621, - "signer2": 895, - "signer4": 1455, - "signer8": 2721, - "systemAccount1": 675, - "systemAccount2": 1001, - "systemAccount4": 1666, - "systemAccount8": 3146, - "uncheckedAccount1": 583, - "uncheckedAccount2": 824, - "uncheckedAccount4": 1320, - "uncheckedAccount8": 2531 + "accountEmptyInit1": 5099, + "accountEmpty1": 708, + "accountEmptyInit2": 9676, + "accountEmpty2": 1064, + "accountEmptyInit4": 18477, + "accountEmpty4": 1766, + "accountEmptyInit8": 36113, + "accountEmpty8": 3179, + "accountSizedInit1": 5187, + "accountSized1": 732, + "accountSizedInit2": 9851, + "accountSized2": 1106, + "accountSizedInit4": 18876, + "accountSized4": 1863, + "accountSizedInit8": 36832, + "accountSized8": 3374, + "accountUnsizedInit1": 5275, + "accountUnsized1": 759, + "accountUnsizedInit2": 10090, + "accountUnsized2": 1168, + "accountUnsizedInit4": 19281, + "accountUnsized4": 2000, + "accountUnsizedInit8": 37378, + "accountUnsized8": 3667, + "boxedAccountEmptyInit1": 5145, + "boxedAccountEmpty1": 745, + "boxedAccountEmptyInit2": 9769, + "boxedAccountEmpty2": 1136, + "boxedAccountEmptyInit4": 18661, + "boxedAccountEmpty4": 1913, + "boxedAccountEmptyInit8": 36488, + "boxedAccountEmpty8": 3500, + "boxedAccountSizedInit1": 5222, + "boxedAccountSized1": 767, + "boxedAccountSizedInit2": 9925, + "boxedAccountSized2": 1183, + "boxedAccountSizedInit4": 18973, + "boxedAccountSized4": 2002, + "boxedAccountSizedInit8": 37111, + "boxedAccountSized8": 3682, + "boxedAccountUnsizedInit1": 5304, + "boxedAccountUnsized1": 797, + "boxedAccountUnsizedInit2": 10089, + "boxedAccountUnsized2": 1246, + "boxedAccountUnsizedInit4": 19303, + "boxedAccountUnsized4": 2135, + "boxedAccountUnsizedInit8": 37770, + "boxedAccountUnsized8": 3948, + "boxedInterfaceAccountMint1": 2085, + "boxedInterfaceAccountMint2": 3726, + "boxedInterfaceAccountMint4": 6991, + "boxedInterfaceAccountMint8": 13562, + "boxedInterfaceAccountToken1": 2015, + "boxedInterfaceAccountToken2": 3585, + "boxedInterfaceAccountToken4": 6712, + "boxedInterfaceAccountToken8": 13003, + "interfaceAccountMint1": 2174, + "interfaceAccountMint2": 4057, + "interfaceAccountMint4": 7823, + "interfaceAccountMint8": 15357, + "interfaceAccountToken1": 2101, + "interfaceAccountToken2": 3909, + "interfaceAccountToken4": 7522, + "interface1": 630, + "interface2": 813, + "interface4": 1174, + "interface8": 1905, + "program1": 630, + "program2": 813, + "program4": 1176, + "program8": 1905, + "signer1": 564, + "signer2": 776, + "signer4": 1195, + "signer8": 2035, + "systemAccount1": 618, + "systemAccount2": 882, + "systemAccount4": 1406, + "systemAccount8": 2460, + "uncheckedAccount1": 546, + "uncheckedAccount2": 738, + "uncheckedAccount4": 1115, + "uncheckedAccount8": 1877 }, "stackMemory": { "account_info1": 128, "account_info2": 128, "account_info4": 128, "account_info8": 128, - "account_empty_init1": 320, - "account_empty_init2": 400, - "account_empty_init4": 448, - "account_empty_init8": 640, + "account_empty_init1": 176, + "account_empty_init2": 208, + "account_empty_init4": 208, + "account_empty_init8": 240, "account_empty1": 128, "account_empty2": 128, "account_empty4": 128, "account_empty8": 128, - "account_sized_init1": 328, - "account_sized_init2": 416, - "account_sized_init4": 480, - "account_sized_init8": 704, + "account_sized_init1": 208, + "account_sized_init2": 256, + "account_sized_init4": 240, + "account_sized_init8": 304, "account_sized1": 128, "account_sized2": 128, "account_sized4": 128, "account_sized8": 128, - "account_unsized_init1": 344, - "account_unsized_init2": 448, - "account_unsized_init4": 544, - "account_unsized_init8": 832, + "account_unsized_init1": 224, + "account_unsized_init2": 296, + "account_unsized_init4": 304, + "account_unsized_init8": 432, "account_unsized1": 128, - "account_unsized2": 128, + "account_unsized2": 144, "account_unsized4": 128, "account_unsized8": 128, "boxed_account_empty_init1": 176, "boxed_account_empty_init2": 208, - "boxed_account_empty_init4": 288, - "boxed_account_empty_init8": 320, + "boxed_account_empty_init4": 208, + "boxed_account_empty_init8": 240, "boxed_account_empty1": 128, - "boxed_account_empty2": 144, + "boxed_account_empty2": 128, "boxed_account_empty4": 144, - "boxed_account_empty8": 128, + "boxed_account_empty8": 144, "boxed_account_sized_init1": 176, "boxed_account_sized_init2": 208, - "boxed_account_sized_init4": 288, - "boxed_account_sized_init8": 320, + "boxed_account_sized_init4": 208, + "boxed_account_sized_init8": 240, "boxed_account_sized1": 128, - "boxed_account_sized2": 144, + "boxed_account_sized2": 128, "boxed_account_sized4": 144, - "boxed_account_sized8": 128, - "boxed_account_unsized_init1": 280, - "boxed_account_unsized_init2": 320, - "boxed_account_unsized_init4": 288, - "boxed_account_unsized_init8": 320, - "boxed_account_unsized1": 152, + "boxed_account_sized8": 144, + "boxed_account_unsized_init1": 176, + "boxed_account_unsized_init2": 208, + "boxed_account_unsized_init4": 208, + "boxed_account_unsized_init8": 240, + "boxed_account_unsized1": 128, "boxed_account_unsized2": 144, - "boxed_account_unsized4": 176, - "boxed_account_unsized8": 192, + "boxed_account_unsized4": 128, + "boxed_account_unsized8": 128, "boxed_interface_account_mint1": 128, - "boxed_interface_account_mint2": 144, + "boxed_interface_account_mint2": 128, "boxed_interface_account_mint4": 144, - "boxed_interface_account_mint8": 128, + "boxed_interface_account_mint8": 144, "boxed_interface_account_token1": 128, - "boxed_interface_account_token2": 144, + "boxed_interface_account_token2": 128, "boxed_interface_account_token4": 144, - "boxed_interface_account_token8": 128, + "boxed_interface_account_token8": 144, "interface_account_mint1": 128, "interface_account_mint2": 128, "interface_account_mint4": 128, @@ -557,4 +557,4 @@ } } } -} +} \ No newline at end of file