Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Implementation of svm_transfer host function #419

Merged
merged 99 commits into from
Nov 30, 2021
Merged

Implementation of svm_transfer host function #419

merged 99 commits into from
Nov 30, 2021

Conversation

kobby-pentangeli
Copy link
Contributor

This PR addresses issue#406, i.e. introducing a new host function that sends coins from the current executing account to a destination account.

TODO:

  • Investigate why loading the source account succeeds, but doing same for the destination account fails.

@kobby-pentangeli kobby-pentangeli changed the title Implementation of svm_transfer host function Implementation of svm_transfer host function Nov 22, 2021
@neysofu
Copy link
Contributor

neysofu commented Nov 22, 2021

Reviewing :)

@neysofu
Copy link
Contributor

neysofu commented Nov 22, 2021

The loading of the destination account fails because the helper function create_account in vmcalls_tests.rs creates a new GlobalState::in_memory at every call. The two accounts effectively exist in two separate databases. I believe we've never had a test that required creating multiple accounts!

The solution is:

  1. Add a gs: &GlobalState parameter to create_account and .clone() it inside the function body if necessary. Cloning a GlobalState is relatively cheap because it's wrapped in an Arc.
  2. Put let gs = GlobalState::in_memory(); where necessary and pass it as an argument to create_account.

@neysofu neysofu marked this pull request as ready for review November 30, 2021 15:13
crates/runtime/src/runtime/runtime.rs Show resolved Hide resolved
crates/runtime/src/vmcalls/transfer.rs Outdated Show resolved Hide resolved
crates/runtime/src/vmcalls/transfer.rs Outdated Show resolved Hide resolved
crates/runtime/src/vmcalls/transfer.rs Outdated Show resolved Hide resolved
crates/runtime/src/vmcalls/transfer.rs Outdated Show resolved Hide resolved
crates/runtime/tests/vmcalls_tests.rs Show resolved Hide resolved
@neysofu neysofu merged commit 3bf41e7 into master Nov 30, 2021
@neysofu neysofu deleted the svm-transfer branch November 30, 2021 17:25
@neysofu neysofu restored the svm-transfer branch November 30, 2021 17:27
@neysofu neysofu deleted the svm-transfer branch November 30, 2021 17:27
@neysofu neysofu restored the svm-transfer branch November 30, 2021 17:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants