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

WIP: monero.dart support #818

Merged
merged 19 commits into from
Apr 11, 2024
Merged

Conversation

MrCyjaneK
Copy link

@MrCyjaneK MrCyjaneK commented Mar 20, 2024

This PR includes

  • Initial monero.dart support
  • wallet creation
  • wallet restore
  • receiving address
  • transaction history (partial)
  • polyseed support
  • transaction creation (crash - but "the code is there")

Build instructions:

  • "The usual" ./build_all.sh
  • extra: libwallet2_api_c.so has to be in /usr/lib or in the app's lib folder (1st one is recommended).
# before executing make sure that 'gcc g++ gperf' are installed (e.g. apt install -y gcc g++ gperf)
pushd $(mktemp -d)
git clone --recursive --branch rewrite-wip https://git.mrcyjanek.net/mrcyjanek/monero_c
pushd monero
git submodule update --init --force
popd
./apply_patches.sh
./build_single.sh $(gcc -dumpmachine) -j$(nproc)
unxz ./release/$(gcc -dumpmachine)_libwallet2_api_c.so.xz
sudo mv ./release/$(gcc -dumpmachine)_libwallet2_api_c.so /usr/lib/libwallet2_api_c.so
popd

or just grab it from https://static.mrcyjanek.net/monero_c/v0.18.3.3-RC10

x86_64 linux

sudo wget https://static.mrcyjanek.net/monero_c/v0.18.3.3-RC12/monero/x86_64-linux-gnu_libwallet2_api_c.so.xz -O /usr/lib/monero_libwallet2_api_c.so.xz
sudo unxz -f /usr/lib/monero_libwallet2_api_c.so.xz
sudo wget https://static.mrcyjanek.net/monero_c/v0.18.3.3-RC12/wownero/x86_64-linux-gnu_libwallet2_api_c.so.xz -O /usr/lib/wownero_libwallet2_api_c.so.xz
sudo unxz -f /usr/lib/wownero_libwallet2_api_c.so.xz

Features roadmap:

@codecov-commenter
Copy link

codecov-commenter commented Mar 20, 2024

Codecov Report

Attention: Patch coverage is 5.12821% with 37 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (monerodart@368c405). Click here to learn what that means.

Files Patch % Lines
lib/utilities/enums/coin_enum.dart 0.00% 22 Missing ⚠️
lib/utilities/constants.dart 18.18% 9 Missing ⚠️
lib/themes/color_theme.dart 0.00% 2 Missing ⚠️
lib/themes/stack_colors.dart 0.00% 2 Missing ⚠️
lib/utilities/amount/amount_unit.dart 0.00% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff              @@
##             monerodart     #818   +/-   ##
=============================================
  Coverage              ?   41.27%           
=============================================
  Files                 ?       54           
  Lines                 ?     4625           
  Branches              ?        0           
=============================================
  Hits                  ?     1909           
  Misses                ?     2716           
  Partials              ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sneurlax sneurlax marked this pull request as draft March 22, 2024 22:09
@MrCyjaneK
Copy link
Author

MrCyjaneK commented Mar 30, 2024

I've reinstalled my vm and switched from ubuntu 20.04 to kubuntu 20.04, and there was a crash in one of plugins, in this linux/flutter/ephemeral/.plugin_symlinks/devicelocale/linux directory.

Patch with backtrace
From e0510a18c61f9fabf27ac290d693fe62784f3814 Mon Sep 17 00:00:00 2001
From: Czarek Nakamoto <cyjan@mrcyjanek.net>
Date: Sat, 30 Mar 2024 08:29:43 +0100
Subject: [PATCH] FIX: double free or corruption in devicelocale_plugin.cc

(gdb) bt
0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
1  0x00007ffff4357859 in __GI_abort () at abort.c:79
2  0x00007ffff43c226e in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff44ec298 "%s\n") at ../sysdeps/posix/libc_fatal.c:155
3  0x00007ffff43ca2fc in malloc_printerr (str=str@entry=0x7ffff44ee690 "double free or corruption (!prev)") at malloc.c:5347
4  0x00007ffff43cbfac in _int_free (av=0x7ffff4521b80 <main_arena>, p=0x2012e20, have_lock=<optimized out>) at malloc.c:4317
5  0x00007ffff7f0fd37 in get_category_locale(int) (category=6)
    at /home/user/stack_wallet/linux/flutter/ephemeral/.plugin_symlinks/devicelocale/linux/devicelocale_plugin.cc:52
{...}

After simply commenting out the line there were no more issues, and
stack_wallet continued to work as expected.

Issue occurs on kubuntu 20.04 (didn't occur on ubuntu 20.04).
---
 devicelocale_plugin.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/devicelocale_plugin.cc b/devicelocale_plugin.cc
index c484d53..49fcf61 100644
--- a/devicelocale_plugin.cc
+++ b/devicelocale_plugin.cc
@@ -49,7 +49,7 @@ static gchar *get_category_locale(int category)
     bool no_locale = locale == nullptr
         || strncmp(locale, "LC_", sizeof("LC_") - 1) == 0;
     if (no_locale) {
-        g_free(locale);
+        // g_free(locale);
         return nullptr;
     } else {
         return locale;

MrCyjaneK pushed a commit to MrCyjaneK/monero_c that referenced this pull request Mar 31, 2024
So basically: when we open the .so file, we define some
symbols, and it appears that if we load something else,
with the same symbols, under the same thread we cause
some funky behaviour - like calling function a wownero
function MONERO_Wallet_address() resulting in a monero
address being generated.
Needless to say, this is undesired, and a blocker for
cypherstack/stack_wallet#818

I'm afraid that this may not solve all of our issues (but
will solve some significant roadblocks), because of the
"genesis block" issue, as output of
nm -gDC release/wownero/x86_64-linux-gnu_libwallet2_api_c.so | grep genesis
indicate that these functions may share *something* in
common across both WOW and XMR libraries.
In a case in which this fix won't be sufficient, I think that
the way forward would be to close the dynamic libraries,
but before we do that I want to check if maybe there is
a change to run multiple wallets at once.
MrCyjaneK added a commit to MrCyjaneK/monero_c that referenced this pull request Mar 31, 2024
So basically: when we open the .so file, we define some
symbols, and it appears that if we load something else,
with the same symbols, under the same thread we cause
some funky behaviour - like calling function a wownero
function MONERO_Wallet_address() resulting in a monero
address being generated.
Needless to say, this is undesired, and a blocker for
cypherstack/stack_wallet#818

I'm afraid that this may not solve all of our issues (but
will solve some significant roadblocks), because of the
"genesis block" issue, as output of
nm -gDC release/wownero/x86_64-linux-gnu_libwallet2_api_c.so | grep genesis
indicate that these functions may share *something* in
common across both WOW and XMR libraries.
In a case in which this fix won't be sufficient, I think that
the way forward would be to close the dynamic libraries,
but before we do that I want to check if maybe there is
a change to run multiple wallets at once.
@MrCyjaneK
Copy link
Author

Current version is working with monero and wownero, upon receiving a transaction however it decided to be less cooperative and failed, however it did so with a backtrace:

* thread #38, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000160031fac wownero_libwallet2_api_c.dylib`Monero::Wallet2CallbackImpl::on_unconfirmed_money_received(unsigned long long, crypto::hash const&, cryptonote::transaction const&, unsigned long long, cryptonote::subaddress_index const&) + 1056
    frame #1: 0x00000001600d40fc wownero_libwallet2_api_c.dylib`tools::wallet2::process_new_transaction(crypto::hash const&, cryptonote::transaction const&, std::__1::vector<unsigned long long, std::__1::allocator<unsigned long long>> const&, unsigned long long, unsigned char, unsigned long long, bool, bool, bool, tools::wallet2::tx_cache_data const&, std::__1::map<std::__1::pair<unsigned long long, unsigned long long>, unsigned long, std::__1::less<std::__1::pair<unsigned long long, unsigned long long>>, std::__1::allocator<std::__1::pair<std::__1::pair<unsigned long long, unsigned long long> const, unsigned long>>>*, bool) + 38080
    frame #2: 0x00000001600f7bfc wownero_libwallet2_api_c.dylib`tools::wallet2::process_pool_state(std::__1::vector<std::__1::tuple<cryptonote::transaction, crypto::hash, bool>, std::__1::allocator<std::__1::tuple<cryptonote::transaction, crypto::hash, bool>>> const&) + 512
    frame #3: 0x00000001600f17d4 wownero_libwallet2_api_c.dylib`tools::wallet2::refresh(bool, unsigned long long, unsigned long long&, bool&, bool, bool, unsigned long long) + 5308
    frame #4: 0x00000001600d98c4 wownero_libwallet2_api_c.dylib`tools::wallet2::refresh(bool) + 60
    frame #5: 0x000000016001f038 wownero_libwallet2_api_c.dylib`Monero::WalletImpl::doRefresh() + 564
    frame #6: 0x000000016002f408 wownero_libwallet2_api_c.dylib`Monero::WalletImpl::refreshThreadFunc() + 2800
    frame #7: 0x000000016041e424 wownero_libwallet2_api_c.dylib`boost::(anonymous namespace)::thread_proxy(param=<unavailable>) at thread.cpp:177:34 [opt]
    frame #8: 0x0000000193f2ef94 libsystem_pthread.dylib`_pthread_start + 136

That leads me to believe that we are not at fault here (we as in monero_c code), I'd put blame on wownero patches? Maybe? This is just an idea, I'll actually test receiving transaction on linux

@MrCyjaneK
Copy link
Author

MrCyjaneK commented Apr 2, 2024

https://git.wownero.com/wownero/wownero/issues/484 the crash from above is resolved, monero_c code is also updated to reflect that change, and with this changes it works exactly the same on all (currently supported) platforms, that is

  • Windows
  • Linux
  • MacOS
  • Android

But that being said, the libraries are not packaged, I've workarounded xcode signing by symlinking the libraries and copying it to the right place as a xcode step, to make sure that they work use monero_c release v0.18.3.3-RC14 or newer, I'll most likely leave it as is, and just point to correct directory after adjusting build_all.sh script. (thanks @malik1004x for helping me out and pointing to a correct way to load a dylib on macos, if not for your help I'd most likely still be stuck learning how it works).

27f7465#diff-41c84f65620ae5e6d1f5708be89d2d7ca5b7f264127faccf746620036391e05c

I think that the code is ready for some initial review/testing/insight, things like syncing/creation/restore/sending should work across all platforms.

@MrCyjaneK
Copy link
Author

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: HiveError: Cannot read, unknown typeId: 46. Did you forget to register an adapter?

@MrCyjaneK MrCyjaneK marked this pull request as ready for review April 4, 2024 06:02
@sneurlax sneurlax deleted the branch cypherstack:monerodart April 9, 2024 19:08
@sneurlax sneurlax closed this Apr 9, 2024
@sneurlax sneurlax reopened this Apr 9, 2024
@sneurlax
Copy link
Member

sneurlax commented Apr 9, 2024

Excuse me @MrCyjaneK, that was an accident. I pushed my own local copy of cypherstack:monerodart back, but you might want to push again (and feel free to force push--though you may not be allowed) and/or double-check commit shas etc.

Takes another note to set up commit signing

My apologies for any inconvenience.

@sneurlax
Copy link
Member

sneurlax commented Apr 9, 2024

Anyways, this is ready to merge to cypherstack:monerodart. The more important merge is into cypherstack:staging (or main, if we want to eschew staging because of its current FROSTiness.

Copy link
Member

@sneurlax sneurlax left a comment

Choose a reason for hiding this comment

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

I approve these changes for merging into cypherstack:monerodart (not staging or main) as lightly reviewed and tested on:

  • Linux
  • macOS
  • iOS
  • Android
  • Windows

I will need to more fully review the code before approving these changes for inclusion in staging/main. I mostly just tested it and quickly looked over most code

@rehrar rehrar merged commit adab5e4 into cypherstack:monerodart Apr 11, 2024
0 of 2 checks passed
sneurlax added a commit that referenced this pull request May 3, 2024
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.

None yet

4 participants