From 0e953314aa9766d90252200ab9c62324fe79e9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= <10921578+deanmlittle@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:24:51 +0800 Subject: [PATCH 01/14] Create XXXX-deprecate-rent-exemption-threshold.md --- ...XXXX-deprecate-rent-exemption-threshold.md | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 proposals/XXXX-deprecate-rent-exemption-threshold.md diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md new file mode 100644 index 00000000..a9c4880b --- /dev/null +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -0,0 +1,80 @@ +--- +simd: '0XXX' +title: Deprecate Rent Exemption Threshold +authors: + - Dean Little (@deanmlittle) + - Leonardo Donatacci (@L0STE) + - Febo (@0x_febo) +category: Standard/Meta +type: Core +status: Draft +created: 2024-11-13 +feature: (fill in with feature tracking issues once accepted) +--- + +## Summary + +Rename `lamports_per_byte_year` to `lamports_per_byte`, change default value from 3480 to 6960, change `exemption_threshold` to `1.0f64` and deprecate all `f64` math in all Rent-related SDKs and onchain programs moving forward. + +## Motivation + +Emulating floating point math is expensive inside of SVM due to the lack of native floating point number support. This makes calculating the rent exempt threshold cost >100 more CUs than it would if we were to simply use a u64. This is due to the `exemption_threshold`, which is currently set to `2.0` years. Since rent exemption is no longer time-based, we have the opportunity to make this commonly used calculation much more performant and simplify our tooling without affecting the existing API. It also simplifies any further changes we may want to make to Rent down the line. + +## New Terminology + +`lamports_per_byte` - the number of lamports required to pay for 1 byte of account storage. + +## Detailed Design + +Half the value of `DEFAULT_EXEMPTION_THRESHOLD` from `2.0` to `1.0`, and deprecate it from the protocol. + +```rs +pub const DEFAULT_EXEMPTION_THRESHOLD: f64 = 1.0; +``` + +Set `DEFAULT_LAMPORTS_PER_BYTE` from its current value of `3480` (the u64 value of `1_000_000_000 / 100 * 365 / (1024 * 1024)`), to `6960`; double its current u64 value, to counteract halving the exemption threshold above. + +```rs +pub const DEFAULT_LAMPORTS_PER_BYTE: u64 = 6960; +``` + +Rename `lamports_per_byte_year` in the Rent account to `lamports_per_byte` to reflect that Rent is no longer time-based. + +```rs +pub struct Rent { + pub lamports_per_byte: u64, + pub exemption_threshold: f64, + pub burn_percent: u8, +} +``` + +Officially deprecate `exemption_threshold` and remove all f64 math from Rent calculations in all SDKs and onchain programs moving forwards, replacing it with simple u64 math, ie: + +```rs +/// Minimum balance due for rent-exemption of a given account data size. +pub fn minimum_balance(&self, data_len: usize) -> u64 { + (ACCOUNT_STORAGE_OVERHEAD + data_len as u64) * self.lamports_per_byte_year +} +``` + +## Alternatives Considered + +- Leave things as they are. + +- Allow users to make the assumption that `2.0` will remain stable and do u64 math themselves at risk of the protocol changing on them. + +## Impact + +New onchain programs using updated SDKs will use far fewer CUs when caluclating rent exemption. Calculating rent exemption itself will become easier and more reliable. Existing programs will not be impacted. + +## Security Considerations + +None. + +## Drawbacks + +None. + +## Backwards Compatibility *(Optional)* + +This feature is backwards compatible. From 7e7bd8839cda2aef0799d788feda1de43fe0b5e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= <10921578+deanmlittle@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:28:20 +0800 Subject: [PATCH 02/14] Update XXXX-deprecate-rent-exemption-threshold.md --- proposals/XXXX-deprecate-rent-exemption-threshold.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md index a9c4880b..c019ed60 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -14,11 +14,11 @@ feature: (fill in with feature tracking issues once accepted) ## Summary -Rename `lamports_per_byte_year` to `lamports_per_byte`, change default value from 3480 to 6960, change `exemption_threshold` to `1.0f64` and deprecate all `f64` math in all Rent-related SDKs and onchain programs moving forward. +Rename `lamports_per_byte_year` to `lamports_per_byte`, change default value from 3480 to 6960, change `exemption_threshold` to `1.0f64` and deprecate it from the protocol, enabling us to remove `f64` math from all Rent-related SDKs in onchain programs moving forward. ## Motivation -Emulating floating point math is expensive inside of SVM due to the lack of native floating point number support. This makes calculating the rent exempt threshold cost >100 more CUs than it would if we were to simply use a u64. This is due to the `exemption_threshold`, which is currently set to `2.0` years. Since rent exemption is no longer time-based, we have the opportunity to make this commonly used calculation much more performant and simplify our tooling without affecting the existing API. It also simplifies any further changes we may want to make to Rent down the line. +Emulating floating point math is expensive inside of SVM due to the lack of native floating point number support. This makes calculating the rent exempt threshold cost ~248 more CUs than it would if we were to simply use a u64. This is due to the `exemption_threshold`, which is currently set to `2.0` years. Since rent exemption is no longer time-based, we have the opportunity to make this commonly used calculation much more performant and simplify our tooling without affecting the existing API. It also simplifies any further changes we may want to make to Rent down the line. ## New Terminology @@ -75,6 +75,6 @@ None. None. -## Backwards Compatibility *(Optional)* +## Backwards Compatibility This feature is backwards compatible. From f48562322bb4c7d13c715dfaafa341610867442b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= <10921578+deanmlittle@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:36:12 +0800 Subject: [PATCH 03/14] Update XXXX-deprecate-rent-exemption-threshold.md --- proposals/XXXX-deprecate-rent-exemption-threshold.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md index c019ed60..a7002adc 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -65,7 +65,7 @@ pub fn minimum_balance(&self, data_len: usize) -> u64 { ## Impact -New onchain programs using updated SDKs will use far fewer CUs when caluclating rent exemption. Calculating rent exemption itself will become easier and more reliable. Existing programs will not be impacted. +New onchain programs using updated SDKs will use far fewer CUs when calculating rent exemption. Calculating rent exemption itself will become simpler and more reliable. Existing programs will not be impacted. ## Security Considerations From 32216f567253f95d8b4d5def617ee88711deb55a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= <10921578+deanmlittle@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:36:35 +0800 Subject: [PATCH 04/14] Update XXXX-deprecate-rent-exemption-threshold.md --- proposals/XXXX-deprecate-rent-exemption-threshold.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md index a7002adc..b828bb5d 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -14,7 +14,7 @@ feature: (fill in with feature tracking issues once accepted) ## Summary -Rename `lamports_per_byte_year` to `lamports_per_byte`, change default value from 3480 to 6960, change `exemption_threshold` to `1.0f64` and deprecate it from the protocol, enabling us to remove `f64` math from all Rent-related SDKs in onchain programs moving forward. +Rename `lamports_per_byte_year` to `lamports_per_byte`, change default value from 3480 to 6960, change `exemption_threshold` to `1.0f64` and deprecate it from the protocol, enabling us to remove `f64` math from rent calculation and all rent-related SDKs in onchain programs moving forward. ## Motivation From 45110fe56a28dafbfa06156f4b53741098ccc005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= <10921578+deanmlittle@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:38:35 +0800 Subject: [PATCH 05/14] Update XXXX-deprecate-rent-exemption-threshold.md --- proposals/XXXX-deprecate-rent-exemption-threshold.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md index b828bb5d..ca6423e9 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -53,7 +53,7 @@ Officially deprecate `exemption_threshold` and remove all f64 math from Rent cal ```rs /// Minimum balance due for rent-exemption of a given account data size. pub fn minimum_balance(&self, data_len: usize) -> u64 { - (ACCOUNT_STORAGE_OVERHEAD + data_len as u64) * self.lamports_per_byte_year + (ACCOUNT_STORAGE_OVERHEAD + data_len as u64) * self.lamports_per_byte } ``` @@ -61,7 +61,11 @@ pub fn minimum_balance(&self, data_len: usize) -> u64 { - Leave things as they are. -- Allow users to make the assumption that `2.0` will remain stable and do u64 math themselves at risk of the protocol changing on them. +- Allow users to make the assumption that `2.0` will remain stable and do u64 math themselves at risk of the protocol changing. + +- Don't rename `lamports_per_byte_year` + +- Don't change `exemption_threshold` and instead ossify it at `2.0f64` ## Impact From c21074f70cf5f276c2596df773de969d1750a018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= <10921578+deanmlittle@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:40:35 +0800 Subject: [PATCH 06/14] Update XXXX-deprecate-rent-exemption-threshold.md --- proposals/XXXX-deprecate-rent-exemption-threshold.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md index ca6423e9..a56a134d 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -67,6 +67,8 @@ pub fn minimum_balance(&self, data_len: usize) -> u64 { - Don't change `exemption_threshold` and instead ossify it at `2.0f64` +- Bundle changes to rent values with existing rent change proposals to avoid multiple SIMDs + ## Impact New onchain programs using updated SDKs will use far fewer CUs when calculating rent exemption. Calculating rent exemption itself will become simpler and more reliable. Existing programs will not be impacted. From c6c60f4a0222036ab65f99df3c1860f8eca8b789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= <10921578+deanmlittle@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:42:27 +0800 Subject: [PATCH 07/14] Update XXXX-deprecate-rent-exemption-threshold.md --- proposals/XXXX-deprecate-rent-exemption-threshold.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md index a56a134d..7808c221 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -18,7 +18,7 @@ Rename `lamports_per_byte_year` to `lamports_per_byte`, change default value fro ## Motivation -Emulating floating point math is expensive inside of SVM due to the lack of native floating point number support. This makes calculating the rent exempt threshold cost ~248 more CUs than it would if we were to simply use a u64. This is due to the `exemption_threshold`, which is currently set to `2.0` years. Since rent exemption is no longer time-based, we have the opportunity to make this commonly used calculation much more performant and simplify our tooling without affecting the existing API. It also simplifies any further changes we may want to make to Rent down the line. +Emulating floating point math is expensive inside of SVM due to the lack of native floating point number support. This makes calculating the rent exempt threshold cost ~248 more CUs than it would if we were to simply use a u64. This is due to the `exemption_threshold`, which is currently set to `2.0` years. Since rent exemption is no longer time-based, we have the opportunity to make this commonly used calculation much more performant and simplify our tooling without affecting the existing API. It also simplifies any further changes we may want to make to rent down the line. ## New Terminology @@ -38,7 +38,7 @@ Set `DEFAULT_LAMPORTS_PER_BYTE` from its current value of `3480` (the u64 value pub const DEFAULT_LAMPORTS_PER_BYTE: u64 = 6960; ``` -Rename `lamports_per_byte_year` in the Rent account to `lamports_per_byte` to reflect that Rent is no longer time-based. +Rename `lamports_per_byte_year` in `Rent` to `lamports_per_byte` to reflect that rent is no longer time-based. ```rs pub struct Rent { @@ -48,7 +48,7 @@ pub struct Rent { } ``` -Officially deprecate `exemption_threshold` and remove all f64 math from Rent calculations in all SDKs and onchain programs moving forwards, replacing it with simple u64 math, ie: +Officially deprecate `exemption_threshold` and remove all f64 math from rent calculations in all SDKs and onchain programs moving forwards, replacing it with simple u64 math, ie: ```rs /// Minimum balance due for rent-exemption of a given account data size. From a1b1e03ac9b47eac0483e251c43adc4921047cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= <10921578+deanmlittle@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:54:31 +0800 Subject: [PATCH 08/14] Update XXXX-deprecate-rent-exemption-threshold.md --- proposals/XXXX-deprecate-rent-exemption-threshold.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md index 7808c221..0818b658 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -4,7 +4,7 @@ title: Deprecate Rent Exemption Threshold authors: - Dean Little (@deanmlittle) - Leonardo Donatacci (@L0STE) - - Febo (@0x_febo) + - Febo (@0febo) category: Standard/Meta type: Core status: Draft From 2183690b70217d0d811cdf2dee876ecaf3657d42 Mon Sep 17 00:00:00 2001 From: Fernando Otero Date: Thu, 14 Nov 2024 15:14:02 +0000 Subject: [PATCH 09/14] Minor edits --- ...XXXX-deprecate-rent-exemption-threshold.md | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md index 0818b658..79a0ca14 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -4,7 +4,7 @@ title: Deprecate Rent Exemption Threshold authors: - Dean Little (@deanmlittle) - Leonardo Donatacci (@L0STE) - - Febo (@0febo) + - febo (Anza) category: Standard/Meta type: Core status: Draft @@ -14,11 +14,15 @@ feature: (fill in with feature tracking issues once accepted) ## Summary -Rename `lamports_per_byte_year` to `lamports_per_byte`, change default value from 3480 to 6960, change `exemption_threshold` to `1.0f64` and deprecate it from the protocol, enabling us to remove `f64` math from rent calculation and all rent-related SDKs in onchain programs moving forward. +This proposal aims to eliminate the use of floating-point operations to +determine whether an account is rent exempt or not in programs by deprecating +the use of the `exempt_threshold` (`f64`) value. + +More specifically, rename `lamports_per_byte_year` to `lamports_per_byte`, change default value from `3480` to `6960`, change `exemption_threshold` to `1.0` and deprecate it from the protocol. This will enable us to remove `f64` math from all Rent-related SDKs and onchain programs moving forward. ## Motivation -Emulating floating point math is expensive inside of SVM due to the lack of native floating point number support. This makes calculating the rent exempt threshold cost ~248 more CUs than it would if we were to simply use a u64. This is due to the `exemption_threshold`, which is currently set to `2.0` years. Since rent exemption is no longer time-based, we have the opportunity to make this commonly used calculation much more performant and simplify our tooling without affecting the existing API. It also simplifies any further changes we may want to make to rent down the line. +Emulating floating point math is expensive inside of SVM due to the lack of native floating point number support. This makes calculating the rent exempt threshold cost `~248` more CUs than it would if we were to simply use a `u64`. This is due to the `exemption_threshold` (`f64`), which is currently set to `2.0` years. Since rent exemption is no longer time-based, we have the opportunity to make this commonly used calculation much more performant and simplify our tooling without affecting the existing API. It also simplifies any further changes we may want to make to Rent down the line. ## New Terminology @@ -26,52 +30,59 @@ Emulating floating point math is expensive inside of SVM due to the lack of nati ## Detailed Design -Half the value of `DEFAULT_EXEMPTION_THRESHOLD` from `2.0` to `1.0`, and deprecate it from the protocol. +Set the value of `DEFAULT_EXEMPTION_THRESHOLD` from `2.0` to `1.0`, and deprecate it from the protocol. ```rs pub const DEFAULT_EXEMPTION_THRESHOLD: f64 = 1.0; ``` -Set `DEFAULT_LAMPORTS_PER_BYTE` from its current value of `3480` (the u64 value of `1_000_000_000 / 100 * 365 / (1024 * 1024)`), to `6960`; double its current u64 value, to counteract halving the exemption threshold above. +Set `DEFAULT_LAMPORTS_PER_BYTE` from its current value of `3480` (the `u64` value of `1_000_000_000 / 100 * 365 / (1024 * 1024)`), to `6960`; double its current `u64` value, to counteract reducing the exemption threshold above. ```rs pub const DEFAULT_LAMPORTS_PER_BYTE: u64 = 6960; ``` -Rename `lamports_per_byte_year` in `Rent` to `lamports_per_byte` to reflect that rent is no longer time-based. +Rename `lamports_per_byte_year` in the Rent account to `lamports_per_byte` to reflect that Rent is no longer time-based and officially deprecate `exemption_threshold`. ```rs pub struct Rent { pub lamports_per_byte: u64, + #[deprecated(since = "2.X.X", note = "Use only `lamports_per_byte` instead")] pub exemption_threshold: f64, pub burn_percent: u8, } ``` -Officially deprecate `exemption_threshold` and remove all f64 math from rent calculations in all SDKs and onchain programs moving forwards, replacing it with simple u64 math, ie: + Remove all `f64` math from Rent calculations in all SDKs and onchain programs moving forwards, replacing it with simple `u64` math, ie: ```rs /// Minimum balance due for rent-exemption of a given account data size. pub fn minimum_balance(&self, data_len: usize) -> u64 { - (ACCOUNT_STORAGE_OVERHEAD + data_len as u64) * self.lamports_per_byte + (ACCOUNT_STORAGE_OVERHEAD + data_len as u64) * self.lamports_per_byte_year } ``` -## Alternatives Considered - -- Leave things as they are. +Validator implementations should stop using `exemption_threshold` and only use +the `lamports_per_byte` value. Any existing program using the current implementation will be unaffected. -- Allow users to make the assumption that `2.0` will remain stable and do u64 math themselves at risk of the protocol changing. +## Alternatives Considered -- Don't rename `lamports_per_byte_year` +* Leave things as they are. + - Calculating rent exemption on a program remains an +expensive operation. -- Don't change `exemption_threshold` and instead ossify it at `2.0f64` +* Allow users to make the assumption that `2.0` will remain stable and do `u64` math themselves. + - Risk of the protocol changing on them. -- Bundle changes to rent values with existing rent change proposals to avoid multiple SIMDs +* Perform the "conversion" ouside the VM and change the type of `exemption_threshold` to a `u64` using a new `RentV2` struct. + - Requires a new syscall and sysvar. ## Impact -New onchain programs using updated SDKs will use far fewer CUs when calculating rent exemption. Calculating rent exemption itself will become simpler and more reliable. Existing programs will not be impacted. +This change will significantly improve the compute unit (CU) consumption of +new onchain programs using updated SDKs programs that calculate the minimum lamports balance required for rent exemption. Currently, the calculation of the minimum balance for rent exemption +(`Rent::minimum_balance`) consumes approximately `256` CUs; with the proposed +change, this will be reduced to just `8` CUs. Existing programs will not be impacted. ## Security Considerations @@ -83,4 +94,4 @@ None. ## Backwards Compatibility -This feature is backwards compatible. +This feature is backwards compatible. It does not change the absolute value required for an account to be rent exempt and the current way of calculating the threshold will continue evaluate to the same value. Any deployed program will be unaffected. From 4cbf8cfc3bad0c618e5f522ffad1ad07d632ff0f Mon Sep 17 00:00:00 2001 From: febo Date: Thu, 14 Nov 2024 15:17:35 +0000 Subject: [PATCH 10/14] Wrap lines --- ...XXXX-deprecate-rent-exemption-threshold.md | 56 ++++++++++++++----- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md index 79a0ca14..7b0e21a0 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -18,42 +18,60 @@ This proposal aims to eliminate the use of floating-point operations to determine whether an account is rent exempt or not in programs by deprecating the use of the `exempt_threshold` (`f64`) value. -More specifically, rename `lamports_per_byte_year` to `lamports_per_byte`, change default value from `3480` to `6960`, change `exemption_threshold` to `1.0` and deprecate it from the protocol. This will enable us to remove `f64` math from all Rent-related SDKs and onchain programs moving forward. +More specifically, rename `lamports_per_byte_year` to `lamports_per_byte`, +change default value from `3480` to `6960`, change `exemption_threshold` to +`1.0` and deprecate it from the protocol. This will enable us to remove `f64` +math from all Rent-related SDKs and onchain programs moving forward. ## Motivation -Emulating floating point math is expensive inside of SVM due to the lack of native floating point number support. This makes calculating the rent exempt threshold cost `~248` more CUs than it would if we were to simply use a `u64`. This is due to the `exemption_threshold` (`f64`), which is currently set to `2.0` years. Since rent exemption is no longer time-based, we have the opportunity to make this commonly used calculation much more performant and simplify our tooling without affecting the existing API. It also simplifies any further changes we may want to make to Rent down the line. +Emulating floating point math is expensive inside of SVM due to the lack of +native floating point number support. This makes calculating the rent exempt +threshold cost `~248` more CUs than it would if we were to simply use a `u64`. +This is due to the `exemption_threshold` (`f64`), which is currently set to +`2.0` years. Since rent exemption is no longer time-based, we have the +opportunity to make this commonly used calculation much more performant and +simplify our tooling without affecting the existing API. It also simplifies any +further changes we may want to make to Rent down the line. ## New Terminology -`lamports_per_byte` - the number of lamports required to pay for 1 byte of account storage. +`lamports_per_byte` - the number of lamports required to pay for 1 byte of +account storage. ## Detailed Design -Set the value of `DEFAULT_EXEMPTION_THRESHOLD` from `2.0` to `1.0`, and deprecate it from the protocol. +Set the value of `DEFAULT_EXEMPTION_THRESHOLD` from `2.0` to `1.0`, and +deprecate it from the protocol. ```rs pub const DEFAULT_EXEMPTION_THRESHOLD: f64 = 1.0; ``` -Set `DEFAULT_LAMPORTS_PER_BYTE` from its current value of `3480` (the `u64` value of `1_000_000_000 / 100 * 365 / (1024 * 1024)`), to `6960`; double its current `u64` value, to counteract reducing the exemption threshold above. +Set `DEFAULT_LAMPORTS_PER_BYTE` from its current value of `3480` (the `u64` +value of `1_000_000_000 / 100 * 365 / (1024 * 1024)`), to `6960`; double its +current `u64` value, to counteract reducing the exemption threshold above. ```rs pub const DEFAULT_LAMPORTS_PER_BYTE: u64 = 6960; ``` -Rename `lamports_per_byte_year` in the Rent account to `lamports_per_byte` to reflect that Rent is no longer time-based and officially deprecate `exemption_threshold`. +Rename `lamports_per_byte_year` in the Rent account to `lamports_per_byte` to +reflect that Rent is no longer time-based and officially deprecate +`exemption_threshold`. ```rs pub struct Rent { pub lamports_per_byte: u64, - #[deprecated(since = "2.X.X", note = "Use only `lamports_per_byte` instead")] + #[deprecated(since = "2.X.X", note = "Use only `lamports_per_byte` +instead")] pub exemption_threshold: f64, pub burn_percent: u8, } ``` - Remove all `f64` math from Rent calculations in all SDKs and onchain programs moving forwards, replacing it with simple `u64` math, ie: + Remove all `f64` math from Rent calculations in all SDKs and onchain programs +moving forwards, replacing it with simple `u64` math, ie: ```rs /// Minimum balance due for rent-exemption of a given account data size. @@ -63,7 +81,8 @@ pub fn minimum_balance(&self, data_len: usize) -> u64 { ``` Validator implementations should stop using `exemption_threshold` and only use -the `lamports_per_byte` value. Any existing program using the current implementation will be unaffected. +the `lamports_per_byte` value. Any existing program using the current +implementation will be unaffected. ## Alternatives Considered @@ -71,18 +90,22 @@ the `lamports_per_byte` value. Any existing program using the current implementa - Calculating rent exemption on a program remains an expensive operation. -* Allow users to make the assumption that `2.0` will remain stable and do `u64` math themselves. +* Allow users to make the assumption that `2.0` will remain stable and do `u64` +math themselves. - Risk of the protocol changing on them. -* Perform the "conversion" ouside the VM and change the type of `exemption_threshold` to a `u64` using a new `RentV2` struct. +* Perform the "conversion" ouside the VM and change the type of +`exemption_threshold` to a `u64` using a new `RentV2` struct. - Requires a new syscall and sysvar. ## Impact This change will significantly improve the compute unit (CU) consumption of -new onchain programs using updated SDKs programs that calculate the minimum lamports balance required for rent exemption. Currently, the calculation of the minimum balance for rent exemption -(`Rent::minimum_balance`) consumes approximately `256` CUs; with the proposed -change, this will be reduced to just `8` CUs. Existing programs will not be impacted. +new onchain programs using updated SDKs programs that calculate the minimum +lamports balance required for rent exemption. Currently, the calculation of the +minimum balance for rent exemption (`Rent::minimum_balance`) consumes +approximately `256` CUs; with the proposed change, this will be reduced to +just `8` CUs. Existing programs will not be impacted. ## Security Considerations @@ -94,4 +117,7 @@ None. ## Backwards Compatibility -This feature is backwards compatible. It does not change the absolute value required for an account to be rent exempt and the current way of calculating the threshold will continue evaluate to the same value. Any deployed program will be unaffected. +This feature is backwards compatible. It does not change the absolute value +required for an account to be rent exempt and the current way of calculating +the threshold will continue evaluate to the same value. Any deployed program +will be unaffected. From 15f85fae5eb3a7bdf4d122e8aeda93e3c0f80a50 Mon Sep 17 00:00:00 2001 From: febo Date: Thu, 14 Nov 2024 15:23:41 +0000 Subject: [PATCH 11/14] Typos --- proposals/XXXX-deprecate-rent-exemption-threshold.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md index 7b0e21a0..68368762 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -76,7 +76,7 @@ moving forwards, replacing it with simple `u64` math, ie: ```rs /// Minimum balance due for rent-exemption of a given account data size. pub fn minimum_balance(&self, data_len: usize) -> u64 { - (ACCOUNT_STORAGE_OVERHEAD + data_len as u64) * self.lamports_per_byte_year + (ACCOUNT_STORAGE_OVERHEAD + data_len as u64) * self.lamports_per_byte } ``` @@ -103,7 +103,7 @@ math themselves. This change will significantly improve the compute unit (CU) consumption of new onchain programs using updated SDKs programs that calculate the minimum lamports balance required for rent exemption. Currently, the calculation of the -minimum balance for rent exemption (`Rent::minimum_balance`) consumes +minimum balance for rent exemption (`Rent::minimum_balance`) consumes approximately `256` CUs; with the proposed change, this will be reduced to just `8` CUs. Existing programs will not be impacted. @@ -117,7 +117,7 @@ None. ## Backwards Compatibility -This feature is backwards compatible. It does not change the absolute value -required for an account to be rent exempt and the current way of calculating +This feature is backwards compatible. It does not change the absolute value +required for an account to be rent exempt and the current way of calculating the threshold will continue evaluate to the same value. Any deployed program will be unaffected. From b979b31b7a37c266d2dbb89dec4706f80ccae5bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= <10921578+deanmlittle@users.noreply.github.com> Date: Thu, 14 Nov 2024 23:35:02 +0800 Subject: [PATCH 12/14] Update XXXX-deprecate-rent-exemption-threshold.md --- proposals/XXXX-deprecate-rent-exemption-threshold.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md index 68368762..ad523e5d 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -119,5 +119,5 @@ None. This feature is backwards compatible. It does not change the absolute value required for an account to be rent exempt and the current way of calculating -the threshold will continue evaluate to the same value. Any deployed program +the threshold will continue to evaluate to the same value. Any deployed program will be unaffected. From 48235b3d7eb5cf2877f7f2022d7e840f3f88359f Mon Sep 17 00:00:00 2001 From: Fernando Otero Date: Fri, 15 Nov 2024 12:01:49 +0000 Subject: [PATCH 13/14] Fix lint --- proposals/XXXX-deprecate-rent-exemption-threshold.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/XXXX-deprecate-rent-exemption-threshold.md index ad523e5d..74bc4787 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/XXXX-deprecate-rent-exemption-threshold.md @@ -86,15 +86,15 @@ implementation will be unaffected. ## Alternatives Considered -* Leave things as they are. +- Leave things as they are. - Calculating rent exemption on a program remains an expensive operation. -* Allow users to make the assumption that `2.0` will remain stable and do `u64` +- Allow users to make the assumption that `2.0` will remain stable and do `u64` math themselves. - Risk of the protocol changing on them. -* Perform the "conversion" ouside the VM and change the type of +- Perform the "conversion" ouside the VM and change the type of `exemption_threshold` to a `u64` using a new `RentV2` struct. - Requires a new syscall and sysvar. From e36946d6a1b76973dda8eacffe49ec0320bc49d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20=E5=88=A9=E8=BF=AA=E6=81=A9?= <10921578+deanmlittle@users.noreply.github.com> Date: Sun, 17 Nov 2024 01:21:16 +0900 Subject: [PATCH 14/14] Update and rename XXXX-deprecate-rent-exemption-threshold.md to 0194-deprecate-rent-exemption-threshold.md --- ...-threshold.md => 0194-deprecate-rent-exemption-threshold.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename proposals/{XXXX-deprecate-rent-exemption-threshold.md => 0194-deprecate-rent-exemption-threshold.md} (99%) diff --git a/proposals/XXXX-deprecate-rent-exemption-threshold.md b/proposals/0194-deprecate-rent-exemption-threshold.md similarity index 99% rename from proposals/XXXX-deprecate-rent-exemption-threshold.md rename to proposals/0194-deprecate-rent-exemption-threshold.md index 74bc4787..4fbae0ee 100644 --- a/proposals/XXXX-deprecate-rent-exemption-threshold.md +++ b/proposals/0194-deprecate-rent-exemption-threshold.md @@ -1,5 +1,5 @@ --- -simd: '0XXX' +simd: '0194' title: Deprecate Rent Exemption Threshold authors: - Dean Little (@deanmlittle)