Skip to content

Commit

Permalink
CAP-46-09: Updated and formalized the configuration settings proposal. (
Browse files Browse the repository at this point in the history
#1291)

This has been moved from CAP-0046-02 in order to separate configuration and contract lifecycle specification.

The main difference is the proposal to store only the hash of the upgrade set in `SCPValue`. Otherwise, this expands on the details omitted from the original proposal.

Co-authored-by: Siddharth Suresh <[email protected]>
  • Loading branch information
dmkozh and sisuresh authored Nov 4, 2022
1 parent c1e770a commit 97802bb
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 52 deletions.
21 changes: 11 additions & 10 deletions core/cap-0046-02.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protocol.
### XDR

See the XDR diffs in the Soroban overview CAP, specifically those covering
config settings, new envelope types, and new ledger header flags.
`InvokeHostFunctionOp`.

## Semantics

Expand Down Expand Up @@ -98,15 +98,16 @@ fn create_contract_from_contract(contract: Vec<u8>, salt: Vec<u8>) -> ContractID

TODO: How does this work with the new fee model?

### Configuration settings using Ledger Upgrades
This CAP also adds a mechanism for validators to store and update configuration
options using ledger upgrades. The maximum WASM contract size will be set during
the protocol upgrade using a new `ConfigurationEntry`, with `ConfigSettingID` ==
`CONFIG_TYPE_CONTRACT_MAX_SIZE`, and `ConfigSetting.uint32Val` == `16384`. This
new entry can be updated using a `LedgerUpgrade`. This mechanism is generalized
to allow validators to update any configuration settings we add. Note that
validators cannot add or remove configuration settings using `LedgerUpgrades`.
New configurations need to be added during the protocol upgrade.
### Max contract size setting

The maximum WASM contract size will be introduced as a `ConfigSettingEntry`(see
[CAP-0046-09]
(https://github.com/stellar/stellar-protocol/blob/master/core/cap-0046-09.md)
for details on config entries).

It is set during the protocol version upgrade using a new `ConfigSettingEntry`,
with `configSettingID` == `CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES`, and
`contractMaxSizeBytes` == `16384`.

### Validator override
This proposal adds two new `LedgerHeader` flags that can disable the create and
Expand Down
152 changes: 152 additions & 0 deletions core/cap-0046-09.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
## Preamble

```
CAP: 0046-09
Title: Network Configuration Ledger Entries
Working Group:
Owner: Dmytro Kozhevin <@dmkozh>
Authors: Dmytro Kozhevin <@dmkozh>
Consulted:
Status: Draft
Created: 2022-11-01
Discussion:
Protocol version: TBD
```

## Simple Summary

This proposal defines a new ledger entry type to store various network-wide
configuration and a way to upgrade such configuration entries.

## Motivation and Goals Alignment

See the Soroban overview CAP for overall Soroban motivation.

The configuration entries in particular are motivated by the need to store a
large amount of Soroban-related configuration, such as the host function
metering data, contract fee structure, contract size limits etc. Currently the
network-wide configuration is only stored in the `LedgerHeader`, which would be
infeasible to use given that the Soroban-related information may require tens
of kilobytes of space to be stored.


## Abstract

This CAP introduces a special type of configuration `LedgerEntry` that can only
be modified via a protocol upgrade. It also specifies the general rules for
adding and modifying these entries.

## Specification

### XDR

See the XDR diffs in the Soroban overview CAP, specifically those referring to
the `ConfigSettingEntry` and `ConfigUpgradeSet`.

### Configuration settings entries

This CAP adds a general mechanism for validators to store and update
configuration settings using ledger upgrades. The smart contracts require a
significant amount of configuration related to fees and metering and hence this
CAP accounts for large and complex configuration settings.

In order to prevent bloating of the `LedgerHeader` the settings are stored in
the ledger as a new type of `LedgerEntry`: `ConfigSettingEntry`. Every
`ConfigSettingEntry` is uniquely identified by its type (`ConfigSettingID`) and
hence at most one entry of each type may exist in the ledger. Setting entries
are represented by arbitrary XDR.

`ConfigSettingID` and its corresponding payload should correspond to an 'atomic'
set of configuration settings, i.e. those that are expected to be used and
upgraded together. For example, contract size limit, metering data and fee data
would all be represented by the separate entries (or more granular entries if
needed).

#### Adding and removing setting etnries

New settings may only be introduced during the protocol version upgrades. Every
CAP introducing the new setting must also define its default value to be used
during the protocol version upgrade. When the upgrade happens, all the new
settings defined for the upgrade are created in the ledger with respective
default values.

Removal of the setting types could happen during the protocol version upgrade
too. However, given that the footprint of a single ledger entry is negligible
at the scale of ledger, there is really no need to maintain the removal
mechanism. Not being able to remove the setting by accident is also safer, as
the settings are fundamental components to any functionality needing them.
Hence this CAP assumes the settings are always persisted in the ledger after
they are introduced (similar to e.g. `LedgerHeader` parameters).

### Configuration upgrade mechanism

Every configuration setting entry is considered to be atomic for the sake of the
upgrade, i.e. an upgrade must provide the full XDR of the setting, even if it
is only being partially updated. This is done to simplify the upgrade format
(otherwise we'd need to introduce some key-value mechanism of specifying
upgraded fields).

Multiple configuration setting entries may be upgraded at once using
`ConfigUpgradeSet` struct that contrains all the updated `ConfigSettingEntry`
entries. Similar to the transaction sets, the network needs to agree on hash of
the `ConfigUpgradeSet`, hence only hash is added to `SCPValue`. While upgrades
are rare events, the size of the setting entry is not bounded and the number of
`SCPValues` in the network is large enough (thousands of messages per node as
of writing this) to have a risk of significantly reducing the network bandwidth
during the upgrade.

The actual upgrade set contents are pulled from the peers in a similar fashion
to the transaction sets (if needed at all; ideally all the validators would
have exactly the same upgrade set).

#### `ConfigUpgradeSet` validation

`ConfigUpgradeSet` is considered valid when:

- all the `updatedEntry` values have unique `configSettingID` values
- `updateEntry` are ordered by the integer values of the `ConfigSettingID` enum
- every `updatedEntry` is valid itself

Individual config settings are validated in the way defined by the CAPs
introducing them.

#### `ConfigUpgradeSet` acceptance

In order to vote for the config upgrade set, besides validating the
`ConfigUpgradeSet` contents, validators also need to be able to accept them
according to their own scheduled upgrades.

The validator will accept a valid nominated `ConfigUpgradeSet` when it can
accept every updated entry in it. As a general rule, the validator should
accept a given updated `ConfigSettingEntry` when the validator has exactly the
same upgrade scheduled. However, the acceptance rules can be adjusted by the
CAP introducing the config entry. For example, if entries describe CPU costs of
executing a host function, it could be viable to allow any of the nominated
upgrade values to be within 1% of the scheduled upgrade.

If there are ever multiple valid `ConfigUpgradeSet`s that validator can accept,
the one that has the most entries should be picked. Ties are resolved in favor
of the lowest hash value.

Note, that unlike with regular ledger upgrades, the network won't try to build a
viable set of upgrades if only some of the entries are valid or accepted. So
the whole `ConfigUpgradeSet` can be considered to be atomic from the upgrade
standpoint.

## Resource Utilization

No substantial changes to resource utilization are expected, including the
upgrade events.

## Security Concerns

Compared to the existing ledger upgrades that normally are limited to very
simple changes like bumping the protocol version, the configuration upgrades to
schedule are much harder to review from the validator perspective. It's also
not plausible that every validator would do complex operations like host
function cost calibration. Hence the upgrade sets to nominate have to be
distributed via the trusted and secure channels. Both these issues increase the
risks of applying a malicious upgrade to the network (for example by
distributing it to validators as an impersonated trusted party). Although the
influence scope of such a malicious upgrade would be reasonably limited and
likely concern only the Smart Contracts.
106 changes: 64 additions & 42 deletions core/cap-0046.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ the following sub-CAPs:
rather than their relationship to the rest of the network. This mostly
relates to the new XDR files below, rather than the diffs.
- [CAP-0046-02 (ex-0047) - Smart Contract Lifecycle](./cap-0046-02.md) covers
the mechanism for creating smart contracts _and_ changes to the ledger to
store global configuration parameters.
the mechanism for creating smart contracts.
- CAPs 0048, 0049 and 0050 are abandoned explorations of interoperability
between smart contracts and existing assets on the Stellar network.
- [CAP-0046-03 (ex-0051) - Smart Contract Host Functions](./cap-0046-03.md)
Expand All @@ -98,6 +97,9 @@ the following sub-CAPs:
- [CAP-0046-08 (ex-0056) - Smart Contract Logging](./cap-0046-08.md) covers
changes to the transaction result, metadata, and ledger close metadata XDR
to capture a new set of "events" emitted during smart contract execution.
- [CAP-0046-09 - Network Configuration Ledger Entries](./cap-0046-09.md)
introduces configuration ledger entries and specifies the protocol upgrade
process for such entries.

### XDR changes

Expand All @@ -115,16 +117,16 @@ The diff showing the updates is therefore not generated by `git diff`, but by
running the following command:

```
diff -ruN --exclude='*.h' --exclude='.git*' --exclude='*.md' src/protocol-{curr,next}/xdr
diff -ru --exclude='*.h' --exclude='.git*' --exclude='*.md' src/protocol-{curr,next}/xdr
```

That calculates the following difference between the `src/protocol-curr` and
`src/protocol-next` directories:

```diff mddiffcheck.ignore=true
diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xdr/Stellar-ledger-entries.x src/protocol-next/xdr/Stellar-ledger-entries.x
--- src/protocol-curr/xdr/Stellar-ledger-entries.x 2022-08-27 21:13:20.829335365 -0700
+++ src/protocol-next/xdr/Stellar-ledger-entries.x 2022-10-27 19:22:02.594346104 -0700
--- src/protocol-curr/xdr/Stellar-ledger-entries.x 2022-11-01 19:19:35.769341600 -0400
+++ src/protocol-next/xdr/Stellar-ledger-entries.x 2022-11-01 17:03:53.669248500 -0400
@@ -3,11 +3,11 @@
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

Expand All @@ -149,7 +151,7 @@ diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xd
};

struct Signer
@@ -491,6 +493,41 @@
@@ -491,6 +493,23 @@
body;
};

Expand All @@ -159,39 +161,21 @@ diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xd
+ SCVal val;
+};
+
+enum ConfigSettingType
+{
+ CONFIG_SETTING_TYPE_UINT32 = 0
+};
+
+union ConfigSetting switch (ConfigSettingType type)
+{
+case CONFIG_SETTING_TYPE_UINT32:
+ uint32 uint32Val;
+};
+
+enum ConfigSettingID
+{
+ CONFIG_SETTING_CONTRACT_MAX_SIZE = 0
+ CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES = 0
+};
+
+struct ConfigSettingEntry
+union ConfigSettingEntry switch (ConfigSettingID configSettingID)
+{
+ union switch (int v)
+ {
+ case 0:
+ void;
+ }
+ ext;
+
+ ConfigSettingID configSettingID;
+ ConfigSetting setting;
+case CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES:
+ uint32 contractMaxSizeBytes;
+};
+
struct LedgerEntryExtensionV1
{
SponsorshipDescriptor sponsoringID;
@@ -521,6 +558,10 @@
@@ -521,6 +540,10 @@
ClaimableBalanceEntry claimableBalance;
case LIQUIDITY_POOL:
LiquidityPoolEntry liquidityPool;
Expand All @@ -202,7 +186,7 @@ diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xd
}
data;

@@ -575,6 +616,17 @@
@@ -575,6 +598,17 @@
{
PoolID liquidityPoolID;
} liquidityPool;
Expand All @@ -220,7 +204,7 @@ diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xd
};

// list of all envelope types used in the application
@@ -589,6 +641,10 @@
@@ -589,6 +623,10 @@
ENVELOPE_TYPE_SCPVALUE = 4,
ENVELOPE_TYPE_TX_FEE_BUMP = 5,
ENVELOPE_TYPE_OP_ID = 6,
Expand All @@ -233,8 +217,8 @@ diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xd
};
}
diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xdr/Stellar-ledger.x src/protocol-next/xdr/Stellar-ledger.x
--- src/protocol-curr/xdr/Stellar-ledger.x 2022-08-27 21:13:20.829335365 -0700
+++ src/protocol-next/xdr/Stellar-ledger.x 2022-09-13 22:22:47.489578095 -0700
--- src/protocol-curr/xdr/Stellar-ledger.x 2022-11-01 19:19:35.769341600 -0400
+++ src/protocol-next/xdr/Stellar-ledger.x 2022-11-01 17:03:53.670267500 -0400
@@ -47,13 +47,17 @@
ext;
};
Expand Down Expand Up @@ -270,11 +254,11 @@ diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xd
case LEDGER_UPGRADE_FLAGS:
uint32 newFlags; // update flags
+case LEDGER_UPGRADE_CONFIG:
+ struct
+ {
+ ConfigSettingID id; // id to update
+ ConfigSetting setting; // new value
+ } configSetting;
+ Hash configUpgradeSetHash;
+};
+
+struct ConfigUpgradeSet {
+ ConfigSettingEntry updatedEntry<>;
};

/* Entries used to define the bucket list */
Expand Down Expand Up @@ -416,9 +400,47 @@ diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xd
+ LedgerCloseMetaV2 v2;
};
}
diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xdr/Stellar-overlay.x src/protocol-next/xdr/Stellar-overlay.x
--- src/protocol-curr/xdr/Stellar-overlay.x 2022-11-01 19:19:35.770344000 -0400
+++ src/protocol-next/xdr/Stellar-overlay.x 2022-11-01 17:04:28.632486900 -0400
@@ -83,7 +83,7 @@
uint32 numFailures;
};

-// Next ID: 18
+// Next ID: 20
enum MessageType
{
ERROR_MSG = 0,
@@ -113,7 +113,11 @@

SEND_MORE = 16,
FLOOD_ADVERT = 18,
- FLOOD_DEMAND = 19
+ FLOOD_DEMAND = 19,
+
+ // Configuration upgrades
+ GET_CONFIG_UPGRADE_SET = 20,
+ CONFIG_UPGRADE_SET = 21
};

struct DontHave
@@ -243,6 +247,11 @@
case SURVEY_RESPONSE:
SignedSurveyResponseMessage signedSurveyResponseMessage;

+case GET_CONFIG_UPGRADE_SET:
+ uint256 configUgradeSetHash;
+case CONFIG_UPGRADE_SET:
+ ConfigUpgradeSet configUpgradeSet;
+
// SCP
case GET_SCP_QUORUMSET:
uint256 qSetHash;
Only in src/protocol-curr/xdr: Stellar-overlay.x.bak
diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xdr/Stellar-transaction.x src/protocol-next/xdr/Stellar-transaction.x
--- src/protocol-curr/xdr/Stellar-transaction.x 2022-08-27 21:13:20.829335365 -0700
+++ src/protocol-next/xdr/Stellar-transaction.x 2022-10-27 19:22:02.594346104 -0700
--- src/protocol-curr/xdr/Stellar-transaction.x 2022-11-01 19:19:35.771360700 -0400
+++ src/protocol-next/xdr/Stellar-transaction.x 2022-11-01 17:03:53.520503800 -0400
@@ -2,6 +2,7 @@
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
Expand Down Expand Up @@ -551,8 +573,8 @@ diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xd
tr;
case opBAD_AUTH:
diff -ru '--exclude=*.h' '--exclude=.git*' '--exclude=*.md' src/protocol-curr/xdr/Stellar-types.x src/protocol-next/xdr/Stellar-types.x
--- src/protocol-curr/xdr/Stellar-types.x 2022-08-27 21:13:20.829335365 -0700
+++ src/protocol-next/xdr/Stellar-types.x 2022-10-27 19:22:02.598346064 -0700
--- src/protocol-curr/xdr/Stellar-types.x 2022-11-01 19:19:35.771360700 -0400
+++ src/protocol-next/xdr/Stellar-types.x 2022-11-01 17:03:53.520503800 -0400
@@ -79,6 +79,7 @@
typedef opaque SignatureHint[4];

Expand Down

0 comments on commit 97802bb

Please sign in to comment.