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

Add stake controlled governance contract #51

Merged
merged 105 commits into from
Oct 17, 2023
Merged

Conversation

eloylp
Copy link
Member

@eloylp eloylp commented Aug 29, 2023

Referenced issue

Closes #36

Summary of changes

  • A stake controlled governance contract (See linked issue for more details)
  • Adaptations to the current voting contract.

Reviewer recommendations

Currenttly this is a WIP, reviewers can check the stream of commits as they go.
The author will try to commit small and early.

EDIT - A initial POC was reached. Reviewer is ecouraged to:

  • Read this comment for context before review. This is highly encouraged.
  • The changes of the governance contracts are prefixed with [GC]
  • The changes of the governance contracts are prefixed with [VC]
  • Commits should be atomic enough for an easy, incremental review.

@vercel
Copy link

vercel bot commented Aug 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eiger-nebula ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 16, 2023 5:21pm

@eloylp eloylp changed the title [GC] Added initial scaffolding of the governance contract Add stake controlled governance contract Aug 29, 2023
@eloylp eloylp force-pushed the add-governance-contract branch from 51ed8cd to a8b8913 Compare August 31, 2023 09:07
@eloylp eloylp force-pushed the add-governance-contract branch from a8b8913 to 827766f Compare August 31, 2023 09:08
@eloylp eloylp force-pushed the add-governance-contract branch from be39adf to 143f000 Compare September 1, 2023 22:04
@eloylp eloylp force-pushed the add-governance-contract branch from a2eadd2 to 39f693f Compare September 6, 2023 16:27
@eloylp eloylp force-pushed the add-governance-contract branch from 8d3d2ea to 76e2312 Compare September 9, 2023 11:46
eloylp added 7 commits October 5, 2023 19:07
…t clients for cross contract interactions.

Sharing types in cross contract interactions with contractimport! causes a false sense of interoperability, as they work in unit tests but not in futurenet. The error was:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: MissingEntry("ProposalPayload")'

The solution reached here was to:
1. Create a third crate "shared" that will hold the shared structures per contract until we find a better solution.
2. Remove the use of contract clients for cross contract interactions. Now we need to convert all the types to `Val` before interacting with the dependent contract and sending them through env.invoke_contract(...)
Now that we are using a third crate for sharing common types across contracts, we are allowed to access the types implementations (methods) . That allows us to reduce calls among contracts, since we can directly return that types and use their methods.
@mariopil
Copy link
Member

mariopil commented Oct 9, 2023

I'm having problems with integration tests:

[cargo-make] INFO - Running Task: invoke_init
2023-10-09T08:42:34.279065Z ERROR soroban_cli::log::diagnostic_event: 0: "AAAAAAAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAAPAAAABGluaXQAAAAQAAAAAQAAAAUAAAASAAAAAAAAAAAZBisi/w+3Ls+TCbj0Rnum3idac9ln9om6jCwcrqNOLAAAABIAAAABfcHs35M1GZ/JkY2+DHMs4dEUaqjynMnDYK/Gp0eulN8AAAAFAAAAAAAADhAAAAADAAATiAAAAA0AAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAO8="
2023-10-09T08:42:34.279511Z ERROR soroban_cli::log::diagnostic_event: 1: "AAAAAAAAAAAAAAABZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAACAAAAAAAAAAMAAAAPAAAAB2ZuX2NhbGwAAAAADQAAACBERVWYP/MPT5tnobJ2SVA+DUl1y81j0G+KF7bXd8aSRAAAAA8AAAAEaW5pdAAAABAAAAABAAAABQAAABIAAAABZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAAFAAAAAAAADhAAAAADAAATiAAAAAn/////////////////////AAAAAAAAAAE="
2023-10-09T08:42:34.279522Z ERROR soroban_cli::log::diagnostic_event: 2: "AAAAAAAAAAAAAAABREVVmD/zD0+bZ6GydklQPg1JdcvNY9Bvihe213fGkkQAAAACAAAAAAAAAAIAAAAPAAAABWVycm9yAAAAAAAAAgAAAAEAAAAHAAAAEAAAAAEAAAACAAAADgAAAC1WTSBjYWxsIGZhaWxlZDogRnVuYyhNaXNtYXRjaGluZ1BhcmFtZXRlckxlbikAAAAAAAAPAAAABGluaXQ="
2023-10-09T08:42:34.279542Z ERROR soroban_cli::log::diagnostic_event: 3: "AAAAAAAAAAAAAAABZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAACAAAAAAAAAAIAAAAPAAAABWVycm9yAAAAAAAAAgAAAAEAAAAHAAAAEAAAAAEAAAADAAAADgAAABRjb250cmFjdCBjYWxsIGZhaWxlZAAAAA8AAAAEaW5pdAAAABAAAAABAAAABQAAABIAAAABZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAAFAAAAAAAADhAAAAADAAATiAAAAAn/////////////////////AAAAAAAAAAE="
2023-10-09T08:42:34.279551Z ERROR soroban_cli::log::diagnostic_event: 4: "AAAAAAAAAAAAAAABZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAACAAAAAAAAAAIAAAAPAAAABWVycm9yAAAAAAAAAgAAAAEAAAAHAAAADgAAAEBlc2NhbGF0aW5nIGVycm9yIHRvIFZNIHRyYXAgZnJvbSBmYWlsZWQgaG9zdCBmdW5jdGlvbiBjYWxsOiBjYWxs"
2023-10-09T08:42:34.279557Z ERROR soroban_cli::log::diagnostic_event: 5: "AAAAAAAAAAAAAAABZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAACAAAAAAAAAAEAAAAPAAAAA2xvZwAAAAAQAAAAAQAAAAMAAAAOAAAAHlZNIGNhbGwgdHJhcHBlZCB3aXRoIEhvc3RFcnJvcgAAAAAADwAAAARpbml0AAAAAgAAAAEAAAAH"
error: transaction simulation failed: host invocation failed

Caused by:
    HostError: Error(WasmVm, InternalError)

    Event log (newest first):
       0: [Diagnostic Event] contract:65539f4a5b4a3e176481bade497438159ad0dd430ae2c148948e63c5d9bd6923, topics:[error, Error(WasmVm, InternalError)], data:"escalating error to VM trap from failed host function call: call"
       1: [Diagnostic Event] contract:65539f4a5b4a3e176481bade497438159ad0dd430ae2c148948e63c5d9bd6923, topics:[error, Error(WasmVm, InternalError)], data:["contract call failed", init, [Address(Contract(65539f4a5b4a3e176481bade497438159ad0dd430ae2c148948e63c5d9bd6923)), 3600, 5000, 340282366920938463463374607431768211455, true]]
       2: [Failed Diagnostic Event (not emitted)] contract:444555983ff30f4f9b67a1b27649503e0d4975cbcd63d06f8a17b6d777c69244, topics:[error, Error(WasmVm, InternalError)], data:["VM call failed: Func(MismatchingParameterLen)", init]
       3: [Diagnostic Event] contract:65539f4a5b4a3e176481bade497438159ad0dd430ae2c148948e63c5d9bd6923, topics:[fn_call, Bytes(444555983ff30f4f9b67a1b27649503e0d4975cbcd63d06f8a17b6d777c69244), init], data:[Address(Contract(65539f4a5b4a3e176481bade497438159ad0dd430ae2c148948e63c5d9bd6923)), 3600, 5000, 340282366920938463463374607431768211455, true]
       4: [Diagnostic Event] topics:[fn_call, Bytes(65539f4a5b4a3e176481bade497438159ad0dd430ae2c148948e63c5d9bd6923), init], data:[Address(Account(19062b22ff0fb72ecf9309b8f4467ba6de275a73d967f689ba8c2c1caea34e2c)), Address(Contract(7dc1ecdf9335199fc9918dbe0c732ce1d1146aa8f29cc9c360afc6a747ae94df)), 3600, 5000, Bytes(00000000000000000000000000000000000000000000000000000000000000ef)]

    Backtrace (newest first):
       0: soroban_wasmi::engine::EngineExecutor::execute_wasm_func
       1: soroban_wasmi::engine::EngineInner::execute_func
       2: soroban_wasmi::func::Func::call
       3: soroban_env_host::vm::Vm::invoke_function_raw
       4: soroban_env_host::host::frame::<impl soroban_env_host::host::Host>::with_frame
       5: soroban_env_host::host::frame::<impl soroban_env_host::host::Host>::call_n_internal
       6: soroban_env_host::host::frame::<impl soroban_env_host::host::Host>::invoke_function
       7: preflight::preflight::preflight_invoke_hf_op
       8: preflight::preflight_invoke_hf_op::{{closure}}
       9: core::ops::function::FnOnce::call_once{{vtable.shim}}
      10: preflight::catch_preflight_panic
      11: _cgo_0b49d6ed4a0b_Cfunc_preflight_invoke_hf_op
                 at tmp/go-build/cgo-gcc-prolog:103:11
      12: runtime.asmcgocall
                 at ./runtime/asm_amd64.s:848


[cargo-make] ERROR - Error while executing command, exit code: 1
[cargo-make] WARN - Build Failed.

@eloylp
Copy link
Member Author

eloylp commented Oct 16, 2023

I'm having problems with integration tests:

[cargo-make] INFO - Running Task: invoke_init
2023-10-09T08:42:34.279065Z ERROR soroban_cli::log::diagnostic_event: 0: "AAAAAAAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAAPAAAABGluaXQAAAAQAAAAAQAAAAUAAAASAAAAAAAAAAAZBisi/w+3Ls+TCbj0Rnum3idac9ln9om6jCwcrqNOLAAAABIAAAABfcHs35M1GZ/JkY2+DHMs4dEUaqjynMnDYK/Gp0eulN8AAAAFAAAAAAAADhAAAAADAAATiAAAAA0AAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAO8="
2023-10-09T08:42:34.279511Z ERROR soroban_cli::log::diagnostic_event: 1: "AAAAAAAAAAAAAAABZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAACAAAAAAAAAAMAAAAPAAAAB2ZuX2NhbGwAAAAADQAAACBERVWYP/MPT5tnobJ2SVA+DUl1y81j0G+KF7bXd8aSRAAAAA8AAAAEaW5pdAAAABAAAAABAAAABQAAABIAAAABZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAAFAAAAAAAADhAAAAADAAATiAAAAAn/////////////////////AAAAAAAAAAE="
2023-10-09T08:42:34.279522Z ERROR soroban_cli::log::diagnostic_event: 2: "AAAAAAAAAAAAAAABREVVmD/zD0+bZ6GydklQPg1JdcvNY9Bvihe213fGkkQAAAACAAAAAAAAAAIAAAAPAAAABWVycm9yAAAAAAAAAgAAAAEAAAAHAAAAEAAAAAEAAAACAAAADgAAAC1WTSBjYWxsIGZhaWxlZDogRnVuYyhNaXNtYXRjaGluZ1BhcmFtZXRlckxlbikAAAAAAAAPAAAABGluaXQ="
2023-10-09T08:42:34.279542Z ERROR soroban_cli::log::diagnostic_event: 3: "AAAAAAAAAAAAAAABZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAACAAAAAAAAAAIAAAAPAAAABWVycm9yAAAAAAAAAgAAAAEAAAAHAAAAEAAAAAEAAAADAAAADgAAABRjb250cmFjdCBjYWxsIGZhaWxlZAAAAA8AAAAEaW5pdAAAABAAAAABAAAABQAAABIAAAABZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAAFAAAAAAAADhAAAAADAAATiAAAAAn/////////////////////AAAAAAAAAAE="
2023-10-09T08:42:34.279551Z ERROR soroban_cli::log::diagnostic_event: 4: "AAAAAAAAAAAAAAABZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAACAAAAAAAAAAIAAAAPAAAABWVycm9yAAAAAAAAAgAAAAEAAAAHAAAADgAAAEBlc2NhbGF0aW5nIGVycm9yIHRvIFZNIHRyYXAgZnJvbSBmYWlsZWQgaG9zdCBmdW5jdGlvbiBjYWxsOiBjYWxs"
2023-10-09T08:42:34.279557Z ERROR soroban_cli::log::diagnostic_event: 5: "AAAAAAAAAAAAAAABZVOfSltKPhdkgbreSXQ4FZrQ3UMK4sFIlI5jxdm9aSMAAAACAAAAAAAAAAEAAAAPAAAAA2xvZwAAAAAQAAAAAQAAAAMAAAAOAAAAHlZNIGNhbGwgdHJhcHBlZCB3aXRoIEhvc3RFcnJvcgAAAAAADwAAAARpbml0AAAAAgAAAAEAAAAH"
error: transaction simulation failed: host invocation failed

Caused by:
    HostError: Error(WasmVm, InternalError)

    Event log (newest first):
       0: [Diagnostic Event] contract:65539f4a5b4a3e176481bade497438159ad0dd430ae2c148948e63c5d9bd6923, topics:[error, Error(WasmVm, InternalError)], data:"escalating error to VM trap from failed host function call: call"
       1: [Diagnostic Event] contract:65539f4a5b4a3e176481bade497438159ad0dd430ae2c148948e63c5d9bd6923, topics:[error, Error(WasmVm, InternalError)], data:["contract call failed", init, [Address(Contract(65539f4a5b4a3e176481bade497438159ad0dd430ae2c148948e63c5d9bd6923)), 3600, 5000, 340282366920938463463374607431768211455, true]]
       2: [Failed Diagnostic Event (not emitted)] contract:444555983ff30f4f9b67a1b27649503e0d4975cbcd63d06f8a17b6d777c69244, topics:[error, Error(WasmVm, InternalError)], data:["VM call failed: Func(MismatchingParameterLen)", init]
       3: [Diagnostic Event] contract:65539f4a5b4a3e176481bade497438159ad0dd430ae2c148948e63c5d9bd6923, topics:[fn_call, Bytes(444555983ff30f4f9b67a1b27649503e0d4975cbcd63d06f8a17b6d777c69244), init], data:[Address(Contract(65539f4a5b4a3e176481bade497438159ad0dd430ae2c148948e63c5d9bd6923)), 3600, 5000, 340282366920938463463374607431768211455, true]
       4: [Diagnostic Event] topics:[fn_call, Bytes(65539f4a5b4a3e176481bade497438159ad0dd430ae2c148948e63c5d9bd6923), init], data:[Address(Account(19062b22ff0fb72ecf9309b8f4467ba6de275a73d967f689ba8c2c1caea34e2c)), Address(Contract(7dc1ecdf9335199fc9918dbe0c732ce1d1146aa8f29cc9c360afc6a747ae94df)), 3600, 5000, Bytes(00000000000000000000000000000000000000000000000000000000000000ef)]

    Backtrace (newest first):
       0: soroban_wasmi::engine::EngineExecutor::execute_wasm_func
       1: soroban_wasmi::engine::EngineInner::execute_func
       2: soroban_wasmi::func::Func::call
       3: soroban_env_host::vm::Vm::invoke_function_raw
       4: soroban_env_host::host::frame::<impl soroban_env_host::host::Host>::with_frame
       5: soroban_env_host::host::frame::<impl soroban_env_host::host::Host>::call_n_internal
       6: soroban_env_host::host::frame::<impl soroban_env_host::host::Host>::invoke_function
       7: preflight::preflight::preflight_invoke_hf_op
       8: preflight::preflight_invoke_hf_op::{{closure}}
       9: core::ops::function::FnOnce::call_once{{vtable.shim}}
      10: preflight::catch_preflight_panic
      11: _cgo_0b49d6ed4a0b_Cfunc_preflight_invoke_hf_op
                 at tmp/go-build/cgo-gcc-prolog:103:11
      12: runtime.asmcgocall
                 at ./runtime/asm_amd64.s:848


[cargo-make] ERROR - Error while executing command, exit code: 1
[cargo-make] WARN - Build Failed.

Hello @mariopil , in tried to replicate this error by executing:

$ cargo make run_test

At least three times, but without problems. Could it be a futurenet transient problem ? I am at commit 8f1b8eb

Maybe its a matter of having the voting contract outdated (the resulting wasm file) . Could you try again with:

$ cargo clean
$ soroban contract build --package voting
$ soroban contract build --package governance
$ cargo make run_test

Sometimes happened to me i did not update the voting contract compilation, on which depends the governance one.

@mariopil
Copy link
Member

Hmm, after cleaning everything and rebuilding it works now...

Copy link
Contributor

@geofmureithi geofmureithi left a comment

Choose a reason for hiding this comment

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

Just a few notes.

pub fn init(
env: Env,
admin: Address,
voting_period_secs: u64,
target_approval_rate_bps: u32,
total_voters: u32,
participation: u128,
admin_mode: bool,
) {
let storage = env.storage().persistent();

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you suggested we use:

if storage
            .get::<_, ()>(&DataKey::AlreadyInitialized)
            .is_some()

instead of

if storage
            .get::<_, bool>(&DataKey::AlreadyInitialized)
            .is_some()

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed at f191d32

proposer: Address,
id: u64,
payload: ProposalPayload,
) -> Result<(), Error> {
let storage = env.storage().persistent();
Copy link
Contributor

Choose a reason for hiding this comment

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

Check initialization?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed at 3182bee

@eloylp eloylp merged commit 6b30196 into main Oct 17, 2023
14 checks passed
@eloylp eloylp deleted the add-governance-contract branch October 17, 2023 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build a basic stake controlled governance contract
3 participants