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

AEIP-14 State UTXO #1287

Merged
merged 23 commits into from
Nov 7, 2023

Conversation

bchamagne
Copy link
Member

@bchamagne bchamagne commented Oct 2, 2023

Description

Add a new kind of UTXO (Unspent Output) to store the state of smart contract.
See https://github.com/archethic-foundation/aeip/blob/main/AEIP-14.md

  • Documentation
  • Playground
  • Serialization of state algorithm
  • Fees calculation
  • Limiting the state size

Fixes #1217

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Many unit tests and this scenario:

(the authorized key is the StorageNoncePublicKey)

endpoint: local
access_seed: sc2
transaction_type: contract
smart_contract: |
  @version 1

  condition triggered_by: transaction, as: [
    content: get_count() < 10
  ]

  actions triggered_by: transaction do
    count = get_count()
    new_count = count + 1
    State.set("count", new_count)
  end


  export fun get_count() do
    State.get("count", 0)
  end
ownerships:
  - secret: sc2
    authorized_keys:
      - 0001AED84392F0AE24C0349F518271892A841A2205E0F0FB2C67D9FB72369DE22983
endpoint: local
access_seed: bastien
transaction_type: transfer
recipients:
  - to: 00002223BBD4EC3D64AE597696C7D7ADE1CEE65C639D885450AD2D7B75592AC76AFA

Tested with 1 node
Tested with 3 nodes

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@bchamagne bchamagne added smart contracts Involve smart contracts mining Involve transaction validation and mining DB Involve database replication AEIP labels Oct 2, 2023
@bchamagne bchamagne marked this pull request as draft October 2, 2023 14:06
@bchamagne bchamagne force-pushed the 1217-stateful-utxo branch 2 times, most recently from 926e68b to f267dd0 Compare October 10, 2023 09:39
@bchamagne bchamagne marked this pull request as ready for review October 10, 2023 09:39
@bchamagne
Copy link
Member Author

I've merged and retested 👍

lib/archethic/mining/smart_contract_validation.ex Outdated Show resolved Hide resolved
lib/archethic/mining/smart_contract_validation.ex Outdated Show resolved Hide resolved

case result do
%Contract.Result.Success{next_tx: expected_next_tx} ->
{Transaction.same_payload?(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also ensure the resulting state is the same. As if it's not we will have an invalid contract execution which is more accurate than an invalid unspent outputs

lib/archethic/replication/transaction_validator.ex Outdated Show resolved Hide resolved
lib/archethic/contracts.ex Outdated Show resolved Hide resolved
@bchamagne
Copy link
Member Author

LGTM

@bchamagne bchamagne merged commit 42125c9 into archethic-foundation:develop Nov 7, 2023
2 checks passed
@bchamagne bchamagne added the feature New feature request label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AEIP DB Involve database feature New feature request mining Involve transaction validation and mining replication smart contracts Involve smart contracts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement stateful UTXO (1)
2 participants