Skip to content

Latest commit

 

History

History
81 lines (49 loc) · 3.8 KB

cap-0055.md

File metadata and controls

81 lines (49 loc) · 3.8 KB
CAP: 0055
Title: Soroban streamlined linking
Working Group:
    Owner: Graydon Hoare <@graydon>
    Authors: Graydon Hoare <@graydon>
    Consulted: Jay Geng <@jayz22>, Dmytro Kozhevin <@dmkozh>
Status: Final
Created: 2024-03-13
Discussion: https://github.com/stellar/stellar-protocol/discussions/1460
Protocol version: 21

Simple Summary

Lower total costs by linking fewer host functions during VM instantiation in Soroban.

Working Group

As specified in the Preamble.

Motivation

To lower the CPU cost charged for each contract invocation transaction thereby admitting more such transactions per ledger and increasing total throughput.

Goals Alignment

This change is aligned with the goal of lowering the cost and increasing the scale of the network.

Abstract

CAP-0054 introduces a refined cost model for VM instantiation. This in turn enables a possible optimization to the VM instantiation process: linking fewer host functions.

Specification

The VM instantiation process adds a set of host functions into the VM's "linker" such that they are available for importing into a contract. There are over 100 host functions that can be added and at present they are all added for every contract. During profiling it has been observed that the set of host functions added to the linker is actually a source of significant cost.

This CAP therefore proposes limiting the set of host functions added to only those that are actually mentioned as imports in the contract. This set can easily be observed before the loop that adds functions to the linker, and doing so brings an immediate performance improvement.

This optimization is small and simple and without drawbacks. However, it depends on CAP-0054 in order to be reflected in a refined cost model, and therefore to influence the actual throughput of the system in terms of the cost model. So it is effectively a protocol change (or at least must co-occur with a protocol change).

XDR changes

There are no XDR changes beyond those proposed in CAP-0054.

Semantics

  • During parsing the host records which host functions are imported.
  • Only those functions that are imported are added to the linker.
  • As a result, less work is done in the host.
  • The performance benefit of doing less real work may or may not result in higher transaction throughput:
    • If the contract has a new refined cost model (as defined in CAP-0054), the new cost model will have terms reflecting the real number of imports, so the contract will incur lower model resources, allowing more transactions to fit in the same model resource budget for the enclosing transaction set.
    • Otherwise the old cost model is used, and the performance benefit is limited to real costs rather than those in the resource model: the transaction still completes more quickly than before, but no additional transactions will be admitted to the transaction set because the model does not yet reflect the lower real costs.

Design Rationale

This is a simple change to do less work, the rationale should be self-explanatory.

Protocol Upgrade Transition

Backwards Incompatibilities

The change is broadly backward compatible (new software can continue to process old data).

The only difference is that the same contracts will, if run under the new cost model of CAP-0054, incur lower costs. The change will therefore only be meaningful to end-users if part of that protocol change. It will be useful to validator-operators in any case.

Resource Utilization

The change strictly lowers real resource usage, though it might not lower model resource usage until contracts are upgraded.

Security Concerns

None apparent.

Test Cases

TBD

Implementation

A preliminary implementation is underway in the soroban-env-host repository