Skip to content

Commit

Permalink
State expiraiton rename
Browse files Browse the repository at this point in the history
  • Loading branch information
SirTyson committed Oct 20, 2023
1 parent 03a1aed commit 4413d0b
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 274 deletions.
2 changes: 1 addition & 1 deletion core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
| [CAP-0046-09](cap-0046-09.md) | Network Configuration Ledger Entries | Dmytro Kozhevin | Draft |
| [CAP-0046-10](cap-0046-10.md) | Smart Contract Budget Metering | Jay Geng | Draft |
| [CAP-0046-11](cap-0046-11.md) | Soroban Authorization Framework | Dmytro Kozhevin | Draft |
| [CAP-0046-12](cap-0046-12.md) | Soroban State Expiration Interface | Garand Tyson | Draft |
| [CAP-0046-12](cap-0046-12.md) | Soroban State Archival Interface | Garand Tyson | Draft |

### Rejected Proposals
| Number | Title | Author | Status |
Expand Down
12 changes: 6 additions & 6 deletions core/cap-0046-02.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ Contract instance consists of:

- A `ContractExecutable`.
- An optional `SCMap*` for users to store data
that should be tied to the lifetime of the instance (TODO: link to state
expiration CAP).
that should be tied to the lifetime of the instance (./cap-0046-02.md).

A contract instance may own an arbitrary amount of ledger entries attributed to
its identifier. Contracts that share the same source in no way may influence
Expand Down Expand Up @@ -223,12 +222,13 @@ functions that can be used for cross-contract invocations.

The `auth` vector must be properly filled with the required credentials and the correct invocation details. Refer to [Soroban Authorization Framework](./cap-0046-11.md) for details.

### Bump and restore contract
Both the contract instance and the contract code entry are persistent ledger entries which have finite, pre-specified lifetime.
### Extend and restore contract

We provide two additional operations `BumpFootprintExpirationOp` and `RestoreFootprintOp` for bumping and restoring entries.
Both the contract instance and the contract code entry are persistent ledger entries which have finite, pre-specified TTLs.

See [State Expiration Interface Cap](./CAP-TBD) for more details on expiration semantics and operations for bumping and restoring entries.
We provide two additional operations `ExtendFootprintTTLOp` and `RestoreFootprintOp` for extending TTL and restoring entries.

See [State Archival Interface Cap](./cap-0046-12.md) for more details on archival semantics and operations for extending and restoring entries.

## Design Rationale

Expand Down
14 changes: 7 additions & 7 deletions core/cap-0046-03.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ With that, we now present the host functions.
(func $get_current_contract_address (result i64))
;; Returns the max ledger sequence that an entry can live to (inclusive).
(func $get_max_expiration_ledger (result i64))
(func $get_max_live_until_ledger (result i64))
```

### "Integer" host functions (mod `i`)
Expand Down Expand Up @@ -345,14 +345,14 @@ With that, we now present the host functions.
;; Replaces the executable of the current contract with the provided Wasm code identified by a hash. Wasm entry corresponding to the hash has to already be present in the ledger. The update happens only after the current contract invocation has successfully finished, so this can be safely called in the middle of a function.
(func $update_current_contract_wasm (param $hash_bytes_object i64) (result i64))
;; Bumps the expiration ledger of the key specified so the entry will live for `min` ledgers from now. If the current expiration ledger is already large enough to live at least `min` more ledgers, then nothing happens.
(func $bump_contract_data (param $k_val i64) (param $t_storage_type i64) (param $min_u32_val u64) (result i64))
;; If the entry's TTL is below `threshold` ledgers, extend `live_until_ledger_seq` such that TTL == `extend_to`, where TTL is defined as `live_until_ledger_seq - current ledger`.
(func $extend_contract_data (param $k_val i64) (param $t_storage_type i64) (param $threshold_val u64) (param $extend_to_val u64) (result i64))
;; Bumps the expiration ledger the current contract instance and code (if applicable), so they will live for at least `min` ledgers from the current ledger (not including it).
(func $bump_current_contract_instance_and_code (param $min_u32_val u64) (result i64))
;; If the TTL for the current contract instance and code (if applicable) is below `threshold` ledgers, extend `live_until_ledger_seq` such that TTL == `extend_to`, where TTL is defined as `live_until_ledger_seq - current ledger`.
(func $extend_current_contract_instance_and_code (param $threshold_val u64) (param $extend_to_val u64) (result i64))
;; Bumps the expiration ledger the instance and code (if applicable) of the provided contract, so they will live for at least `min` ledgers from the current ledger (not including it).
(func $bump_contract_instance_and_code (param $contract_address_object i64) (param $min_u32_val u64) (result i64))
;; If the TTL for the provided contract instance and code (if applicable) is below `threshold` ledgers, extend `live_until_ledger_seq` such that TTL == `extend_to`, where TTL is defined as `live_until_ledger_seq - current ledger`.
(func $extend_contract_instance_and_code (param $contract_address_object i64) (param $threshold_val u64) (param $extend_to_val u64) (result i64))
;; Get the id of a contract without creating it. `deployer` is address of the contract deployer. `salt` is used to create a unique contract id. Returns the address of the would-be contract.
(func $get_contract_id (param $deployer_address_object i64) (param $salt_bytes_object i64) (result i64))
Expand Down
2 changes: 1 addition & 1 deletion core/cap-0046-05.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ These semantics should be considered in the light of the strict serializability
- Each write is visible immediately within the issuing transaction, but not to any other transaction, until the writing transaction commits
- All reads and writes are observable to transactions as they would be if the transactions executed sequentially in transaction-set application order

The durability of each write is controlled by the expiration strategy described in CAP-0046-TBD state expiration.
The durability of each write is controlled by the archival strategy described in CAP-0046-12 state archival.

## Design Rationale

Expand Down
22 changes: 11 additions & 11 deletions core/cap-0046-07.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,23 +361,23 @@ Rent fee has to be paid if operation increases the lifetime of the ledger entrie

Rent fee is computed only at transaction application time and it depends on the state of the ledger entries before and after the transaction has been applied.

Fee: `Rent_fee = sum(rent_fee_per_entry_change(entry_before, entry_after)) + expiration_write_fee` for all the ledger entry changes.
Fee: `Rent_fee = sum(rent_fee_per_entry_change(entry_before, entry_after)) + ttl_write_fee` for all the ledger entry changes.

Entry rent fee consists of two components: fee for renting new ledgers with the new entry size and fee for renting the old ledgers with increased size. If `entry_before` does not exist, we treat its size as `0` and expiration ledger as `0` for the sake of this formula.
Entry rent fee consists of two components: fee for renting new ledgers with the new entry size and fee for renting the old ledgers with increased size. If `entry_before` does not exist, we treat its size as `0` and `live_until_ledger` as `0` for the sake of this formula.

```
rent_fee_per_entry_change(entry_before_entry_after) =
if (entry_after.expiration_ledger > entry_before.expiration_ledger,
if (entry_after.live_until_ledger > entry_before.live_until_ledger,
rent_fee_for_size_and_ledgers(
entry_after.is_persistent,
size(entry_after),
new_expiration_ledger - max(entry_before.expiration_ledger, current_ledger - 1)),
new_live_until_ledger - max(entry_before.live_until_ledger, current_ledger - 1)),
0) +
if (exists(entry_before) && size(entry_after) > size(entry_before),
rent_fee_for_size_and_ledgers(
entry_after.is_persistent,
size(entry_after) - size(entry_before),
entry_before.expiration_ledger - current_ledger + 1),
entry_before.live_until_ledger - current_ledger + 1),
0)
```

Expand All @@ -391,17 +391,17 @@ rent_fee_for_size_and_ledgers(is_persistent, S, L) = round_up(
)
```

Settings values come from `StateExpirationSettings`.
Settings values come from `StateArchivalSettings`.

Additionally, we charge for the `ExpirationEntry` writes of entries that had `expirationLedger` changed using the same rate as for any other entry write:
Additionally, we charge for the `TTLEntry` writes of entries that had `liveUntilLedgerSeq` changed using the same rate as for any other entry write:

```
expiration_write_fee =
num_expiration_updates * feeWriteLedgerEntry +
round_up(write_fee_per_1kb(BucketListSize) * EXPIRATION_ENTRY_SIZE / 1024)
ttl_write_fee =
num_ttl_updates * feeWriteLedgerEntry +
round_up(write_fee_per_1kb(BucketListSize) * TTL_ENTRY_SIZE / 1024)
```

where `num_expiration_updates` is the number of ledger entries that had expiration ledger updated and `EXPIRATION_ENTRY_SIZE` is size of `ExpirationEntry` with its key and is set to `68` bytes.
where `num_ttl_updates` is the number of ledger entries that had `live_until_ledger` updated and `TTL_ENTRY_SIZE` is size of `TTLEntry` with its key and is set to `68` bytes.

Validity constraints: _None_

Expand Down
6 changes: 3 additions & 3 deletions core/cap-0046-11.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ considered expired and authorization fails.
allowed expiration ledger, signature is considered to be too early and
authorization fails. Maximum allowed expiration ledger is determined by the
network configuration and computed as
`currentLedgerSequence + stateExpirationSettings.maxEntryExpiration - 1`, where
`stateExpirationSettings` is the value from `CONFIG_SETTING_STATE_EXPIRATION`
`currentLedgerSequence + stateArchivalSettings.maxEntryTTL - 1`, where
`stateArchivalSettings` is the value from `CONFIG_SETTING_STATE_ARCHIVAL`
`ConfigSettingEntry`.

##### Nonce Consumption
Expand All @@ -485,7 +485,7 @@ allowed to create contract data entries with this key.
- `durability` is set to `TEMPORARY`
- `body` is set to `DATA_ENTRY` with `data.val` set to `SCV_VOID` `SCVal` and
`data.flags` are `0`.
- `expirationLedgerSeq` is set to the `signatureExpirationLedger` from the
- `liveUntilLedgerSeq` is set to the `signatureExpirationLedger` from the
credentials.

Before trying to consume the nonce host checks if it already exists in the
Expand Down
Loading

0 comments on commit 4413d0b

Please sign in to comment.