Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

META - Backward Compatibility #1896

Open
piux2 opened this issue Apr 6, 2024 · 5 comments
Open

META - Backward Compatibility #1896

piux2 opened this issue Apr 6, 2024 · 5 comments

Comments

@piux2
Copy link
Contributor

piux2 commented Apr 6, 2024

We can use this as a starting point to track potential backward compatibility issues we need to be aware of, and devise solutions for each along the way.

1. Native function implementations.

Context

It's important to be aware that all native functions could have backward compatibility issues when we update their native implementation. This is not introduced by the new binding solution; instead, it makes the potential issue more apparent.

During contract execution, the functionValue.nativeBody,

fv.nativeBody = m.Store.GetNative(fv.NativePkg, fv.NativeName)

which is a func(*Machine) returned from iterating through nativeFuncs in stdlibs/native.go, by finding matching package and names,
var nativeFuncs = [...]nativeFunc{

returns a matching func(*Machine) when the VM executes the contract.

For example, in the standard contract stdlib/std/native.gno, PrevRealm() > getRealm(1), the nativeFuncs links Gno's getRealm(1)

func getRealm(height int) (address string, pkgPath string)

with the native implementation of X_getRealm().
func X_getRealm(m *gno.Machine, height int) (address string, pkgPath string) {

r0, r1 := libs_std.X_getRealm(

Backward compatibility issues:

updating the logic in stdlibs/std/native.go could cause existing contracts to fail to execute if contract developers assume the behaviors of PrevRealm have changed in a new release.

@piux2 piux2 added 📦 🤖 gnovm Issues or PRs gnovm related and removed 📦 🤖 gnovm Issues or PRs gnovm related labels Apr 6, 2024
@zivkovicmilos
Copy link
Member

cc @ajnavarro

@ajnavarro
Copy link
Contributor

Storage related backward-incompatibility problems

Serialization System Changes

Our backward compatibility is tied to the serialization format used to store data on disk. Any change to this format could introduce backward incompatibilities.

Payload Size Changes in Set Operations

Optimizations in the size of payloads stored during Set operations could lead to backward incompatibilities. Suppose the size of the data being stored in subsequent versions of the VM (even if that data is representing the same internal VM state, but is downsized using compression or similar) is reduced or altered for efficiency.

State format change

Any change to the internal VM state format could break backward compatibility. For instance, introducing a garbage collector (GC) or altering the way the VM represents its internal state could modify the amount of data stored.

Proposal

To mitigate the risk of backward-incompatible changes, I propose we decouple the storage costs from the exact byte size stored by the VM. Instead, each type—such as Interfaces, Structs, Ints, Strings, etc.—should be assigned a fixed cost based on properties intrinsic to the object itself.

For example, in the case of strings, we could calculate storage costs based on the length of the string (i.e., string length * X). This would ensure that the cost calculation is stable and not influenced by changes to how the VM stores data internally.

@Kouteki
Copy link
Contributor

Kouteki commented Oct 25, 2024

Conclusion of the team discussion:

  1. Use best judgement on a case-by-case basis
  2. Breaking compatility is not a deal breaker
  3. We'll rely on chain upgrades and snapshots when it comes to it
  4. YOLO

@Kouteki Kouteki moved this from Backlog to Todo in 🧙‍♂️gno.land core team Oct 28, 2024
@thehowl
Copy link
Member

thehowl commented Oct 30, 2024

It's important to be aware that all native functions could have backward compatibility issues when we update their native implementation. This is not introduced by the new binding solution; instead, it makes the potential issue more apparent.

Yes, furthermore they need to be reimplemented by any and all alternative VM implementations.

Native bindings are a necessary evil which make our lives simpler for writing static analysis tools, as we don't need to add shims or hardcode Gno's standard library functions, but they should still be kept to be as little as possible.

@thehowl
Copy link
Member

thehowl commented Oct 30, 2024

One general comment, additionally;

let's keep track of potential backward compatibility pitfalls, yes, but I'm looking more to have:

  • Strong tests which strictly verify our current expected behaviour.
  • "User Flow" integration test #2159 can help us try typical user flows and ensure they always work.
  • Portal loop CI testing against its genesis.json #2862 tries to prevent failures restarting the portal loop; I think eventually on mainnet we should have a long test (similar, conceptually, to this issue) which tries to replay the entire chain up to the point of the test with the modified code, showing us if the chain would fail with the updated code.

A collection like this can tell us where to look; proper tooling can help us point to real problems before they happen.

Also related: #2550

@thehowl thehowl changed the title Backward compatibility META - Backward Compatibility Oct 30, 2024
@Kouteki Kouteki moved this to Core in 🍜 Seoul triage Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Core
Development

No branches or pull requests

5 participants