Skip to content

Modifications to support non-Linux OSes (tested on FreeBSD 14) #32

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

Merged
merged 6 commits into from
Jul 14, 2025

Conversation

21M4TW
Copy link
Contributor

@21M4TW 21M4TW commented Oct 23, 2024

-Modifying CMakeLists.txt to support non-Linux OSes that do not include epoll and argp. Using epoll-shim and the standalone argp libraries. Tested on FreeBSD 14
-Including <netiniet/in.h> in src/datum_protocol.c. This is required for compilation on FreeBSD 14

@luke-jr luke-jr added the portability Issues relating to running DATUM Gateway on new platforms label Mar 18, 2025
@luke-jr
Copy link
Contributor

luke-jr commented May 20, 2025

Do you plan to finish this? (Note argp-standalone is now supported in master)

@adozenlines
Copy link

I have added support for macOS to my fork; please feel free to modify it as needed. I have also added support for refreshing the status page. If it's something we can move into the main project, let me know.

TIA.

@21M4TW
Copy link
Contributor Author

21M4TW commented May 25, 2025

Do you plan to finish this? (Note argp-standalone is now supported in master)

Sorry yes I will look at it!

@21M4TW
Copy link
Contributor Author

21M4TW commented May 25, 2025

Do you plan to finish this? (Note argp-standalone is now supported in master)

So I modified CMakeLists.txt based on your recommendations. It almost works on FreeBSD, except for the fact that the calls to check_library_exists for both ARGP and EPOLL fail unless I replace the third argument by "/usr/local/lib", since this is where non-system libraries are installed on FreeBS. Do you have a suggestion on how to deal with this?

@luke-jr
Copy link
Contributor

luke-jr commented Jun 6, 2025

Sounds like a CMake bug? https://cmake.org/cmake/help/latest/module/CheckLibraryExists.html says the empty location should search default paths, which CMake devs say should include /usr/local on FreeBSD: https://gitlab.kitware.com/cmake/cmake/-/issues/21117

@21M4TW
Copy link
Contributor Author

21M4TW commented Jun 7, 2025

Sounds like a CMake bug? https://cmake.org/cmake/help/latest/module/CheckLibraryExists.html says the empty location should search default paths, which CMake devs say should include /usr/local on FreeBSD: https://gitlab.kitware.com/cmake/cmake/-/issues/21117

Yes I guess it is a bug on the CMake side, and can probably be ignored for here

@21M4TW
Copy link
Contributor Author

21M4TW commented Jun 7, 2025

Should be good now.

@luke-jr
Copy link
Contributor

luke-jr commented Jun 9, 2025

Do you want to add instructions to README and/or a CI task?

@luke-jr luke-jr added this to the v0.2.5 milestone Jun 9, 2025
@21M4TW
Copy link
Contributor Author

21M4TW commented Jun 10, 2025

Do you want to add instructions to README and/or a CI task?

I modified the README and started working on the CI task (in progress). I also modified CMakeLists.txt to add a workaround for the missing /usr/local/lib FreeBSD system directory in cmake, since it is also affecting the CI task. I will let you know once the CI task is finished. Currently it does builds datum and run it in the FreeBSD VM, so there is not much left to do.

@21M4TW 21M4TW force-pushed the master branch 2 times, most recently from f2a6c70 to a7a9971 Compare June 10, 2025 03:23
@21M4TW
Copy link
Contributor Author

21M4TW commented Jun 10, 2025

Do you want to add instructions to README and/or a CI task?

Ok the CI task should be working fine now

CMakeLists.txt Outdated
Comment on lines 80 to 81
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
check_library_exists(argp argp_parse "/usr/local/lib" ARGP)
Copy link
Contributor

Choose a reason for hiding this comment

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

This workaround will probably break normal usage once FreeBSD/CMake is fixed. :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why so? The directory for FreeBSD will not change so /usr/local/lib will remain valid even once the cmake port/package for FreeBSD fix the value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed the CI issue related to gcc. The lack of bash in the FreeBSD VM was causing it, so I changed the condition to be compatible with sh...

Copy link
Contributor

Choose a reason for hiding this comment

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

For example, if argp is moved to main, it would then be under /usr, not /usr/local. Or if someone forks FreeBSD to do that (or perhaps something more complicated).

Copy link
Contributor Author

@21M4TW 21M4TW Jun 10, 2025

Choose a reason for hiding this comment

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

All non-system libraries for FreeBSD are in /usr/local . It would only be in /usr/lib if argp was integrated into FreeBSD itself and the argp package disappeared, in which case the Datum README and the CI would need to be modified along with CMakeLists.txt? I just pushed a change that now looks in /usr/lib in addition to /usr/local/lib if this ever becomes the case. This will also look into subdirectories...

@21M4TW 21M4TW force-pushed the master branch 2 times, most recently from e2c3f05 to f08ddf8 Compare June 10, 2025 16:55
@21M4TW
Copy link
Contributor Author

21M4TW commented Jun 12, 2025

Sure this can also work, thanks. I committed it to the PR.

@luke-jr luke-jr changed the base branch from master to 0.2.x June 13, 2025 16:23
@luke-jr
Copy link
Contributor

luke-jr commented Jun 13, 2025

Rebased this to the 0.2.x branch and cleaned up the commit history. Can you confirm the new branch works fine on FreeBSD?

@BitcoinMechanic
Copy link
Contributor

Tested on Free-BSD - DATUM is unable to connect to OCEAN's prime servers.

@21M4TW
Copy link
Contributor Author

21M4TW commented Jul 7, 2025

Tested on Free-BSD - DATUM is unable to connect to OCEAN's prime servers.

Ok. I have only been solo mining with my setup, but I guess this is a good excuse to try this as well...

@21M4TW
Copy link
Contributor Author

21M4TW commented Jul 7, 2025

Tested on Free-BSD - DATUM is unable to connect to OCEAN's prime servers.

Do you get a seg fault and the following error?
2025-07-07 15:09:33.936 [ datum_protocol_client] ERROR: connect(...) error: Permission denied
2025-07-07 15:09:33.936 [ datum_protocol_client] ERROR: connect(...) error: Bad file descriptor

@BitcoinMechanic
Copy link
Contributor

No, this is what I get:

2025-07-07 12:40:56.703 [                         datum_protocol_init]  INFO: Our public keys:
2025-07-07 12:40:56.703 [                   datum_encrypt_log_pubkeys]  INFO: Signing Public Key:     90635b8ce5982a408080eb06b50f1ec88f32ace0c214c0ac247cca68966233cf
2025-07-07 12:40:56.703 [                   datum_encrypt_log_pubkeys]  INFO: Encryption Public Key:  3020dac6ccd9c13ae13e6e1705037695f7b9c8c8a0fdad5ab402ca5de1654a04
2025-07-07 12:40:56.703 [                         datum_protocol_init]  INFO: Pool's public keys: (You should periodically verify that these are what you expect!)
2025-07-07 12:40:56.703 [                   datum_encrypt_log_pubkeys]  INFO: Signing Public Key:     f21f2f0ef0aa1970468f22bad9bb7f4535146f8e4a8f646bebc93da3d89b1406
2025-07-07 12:40:56.703 [                   datum_encrypt_log_pubkeys]  INFO: Encryption Public Key:  f40d032f09a417d94dc068055df654937922d2c89522e3e8f6f0e649de473003
2025-07-07 12:40:56.703 [                                        main]  INFO: Waiting on DATUM server... 15
2025-07-07 12:40:56.704 [                            datum_api_thread]  INFO: API listening on port 7152
2025-07-07 12:40:57.707 [                                        main]  INFO: Waiting on DATUM server... 13
2025-07-07 12:40:58.730 [                                        main]  INFO: Waiting on DATUM server... 12
2025-07-07 12:40:59.737 [                                        main]  INFO: Waiting on DATUM server... 11
2025-07-07 12:41:00.746 [                                        main]  INFO: Waiting on DATUM server... 10
2025-07-07 12:41:01.757 [                                        main]  INFO: Waiting on DATUM server... 9
2025-07-07 12:41:02.767 [                                        main]  INFO: Waiting on DATUM server... 8
2025-07-07 12:41:03.783 [                                        main]  INFO: Waiting on DATUM server... 7
2025-07-07 12:41:04.787 [                                        main]  INFO: Waiting on DATUM server... 6
2025-07-07 12:41:05.797 [                                        main]  INFO: Waiting on DATUM server... 5
2025-07-07 12:41:06.806 [                                        main]  INFO: Waiting on DATUM server... 4
2025-07-07 12:41:07.817 [                                        main]  INFO: Waiting on DATUM server... 3
2025-07-07 12:41:08.826 [                                        main]  INFO: Waiting on DATUM server... 2
2025-07-07 12:41:09.838 [                                        main]  INFO: Waiting on DATUM server... 1
2025-07-07 12:41:10.847 [                                        main]  INFO: Waiting on DATUM server... 0
2025-07-07 12:41:11.858 [                                        main] ERROR: DATUM server connection could not be established.
2025-07-07 12:41:12.265 [               datum_gateway_template_thread]  INFO: NEW NETWORK BLOCK: 0000000000000000000114e217379a884094938054aef4120372f2bd4b1101cb (904496)
2025-07-07 12:41:12.284 [              datum_stratum_v1_socket_server]  INFO: Stratum V1 Server Init complete.
2025-07-07 12:41:12.284 [              datum_stratum_v1_socket_server]  INFO: Empty work send completed. Sent to 0 clients across 0 threads
2025-07-07 12:41:12.284 [               datum_gateway_listener_thread]  INFO: DATUM Socket listener thread active for 'Stratum V1 Server'
2025-07-07 12:41:12.286 [               datum_gateway_template_thread]  INFO: Updating priority stratum job for block 904496: 3.17727914 BTC, 4363 txns, 1505339 bytes (Sent to 0 stratum clients)
2025-07-07 12:41:27.188 [                                        main]  WARN: Configured for pooled mining only, and connection lost to DATUM server!  Shutting down Stratum v1 server until DATUM connection reestablished.
2025-07-07 12:41:27.188 [               datum_stratum_v1_shutdown_all]  INFO: Sent disconnect request for all stratum clients to 0 threads.

@21M4TW
Copy link
Contributor Author

21M4TW commented Jul 7, 2025

No, this is what I get:

2025-07-07 12:40:56.703 [                         datum_protocol_init]  INFO: Our public keys:
2025-07-07 12:40:56.703 [                   datum_encrypt_log_pubkeys]  INFO: Signing Public Key:     90635b8ce5982a408080eb06b50f1ec88f32ace0c214c0ac247cca68966233cf
2025-07-07 12:40:56.703 [                   datum_encrypt_log_pubkeys]  INFO: Encryption Public Key:  3020dac6ccd9c13ae13e6e1705037695f7b9c8c8a0fdad5ab402ca5de1654a04
2025-07-07 12:40:56.703 [                         datum_protocol_init]  INFO: Pool's public keys: (You should periodically verify that these are what you expect!)
2025-07-07 12:40:56.703 [                   datum_encrypt_log_pubkeys]  INFO: Signing Public Key:     f21f2f0ef0aa1970468f22bad9bb7f4535146f8e4a8f646bebc93da3d89b1406
2025-07-07 12:40:56.703 [                   datum_encrypt_log_pubkeys]  INFO: Encryption Public Key:  f40d032f09a417d94dc068055df654937922d2c89522e3e8f6f0e649de473003
2025-07-07 12:40:56.703 [                                        main]  INFO: Waiting on DATUM server... 15
2025-07-07 12:40:56.704 [                            datum_api_thread]  INFO: API listening on port 7152
2025-07-07 12:40:57.707 [                                        main]  INFO: Waiting on DATUM server... 13
2025-07-07 12:40:58.730 [                                        main]  INFO: Waiting on DATUM server... 12
2025-07-07 12:40:59.737 [                                        main]  INFO: Waiting on DATUM server... 11
2025-07-07 12:41:00.746 [                                        main]  INFO: Waiting on DATUM server... 10
2025-07-07 12:41:01.757 [                                        main]  INFO: Waiting on DATUM server... 9
2025-07-07 12:41:02.767 [                                        main]  INFO: Waiting on DATUM server... 8
2025-07-07 12:41:03.783 [                                        main]  INFO: Waiting on DATUM server... 7
2025-07-07 12:41:04.787 [                                        main]  INFO: Waiting on DATUM server... 6
2025-07-07 12:41:05.797 [                                        main]  INFO: Waiting on DATUM server... 5
2025-07-07 12:41:06.806 [                                        main]  INFO: Waiting on DATUM server... 4
2025-07-07 12:41:07.817 [                                        main]  INFO: Waiting on DATUM server... 3
2025-07-07 12:41:08.826 [                                        main]  INFO: Waiting on DATUM server... 2
2025-07-07 12:41:09.838 [                                        main]  INFO: Waiting on DATUM server... 1
2025-07-07 12:41:10.847 [                                        main]  INFO: Waiting on DATUM server... 0
2025-07-07 12:41:11.858 [                                        main] ERROR: DATUM server connection could not be established.
2025-07-07 12:41:12.265 [               datum_gateway_template_thread]  INFO: NEW NETWORK BLOCK: 0000000000000000000114e217379a884094938054aef4120372f2bd4b1101cb (904496)
2025-07-07 12:41:12.284 [              datum_stratum_v1_socket_server]  INFO: Stratum V1 Server Init complete.
2025-07-07 12:41:12.284 [              datum_stratum_v1_socket_server]  INFO: Empty work send completed. Sent to 0 clients across 0 threads
2025-07-07 12:41:12.284 [               datum_gateway_listener_thread]  INFO: DATUM Socket listener thread active for 'Stratum V1 Server'
2025-07-07 12:41:12.286 [               datum_gateway_template_thread]  INFO: Updating priority stratum job for block 904496: 3.17727914 BTC, 4363 txns, 1505339 bytes (Sent to 0 stratum clients)
2025-07-07 12:41:27.188 [                                        main]  WARN: Configured for pooled mining only, and connection lost to DATUM server!  Shutting down Stratum v1 server until DATUM connection reestablished.
2025-07-07 12:41:27.188 [               datum_stratum_v1_shutdown_all]  INFO: Sent disconnect request for all stratum clients to 0 threads.

Ok thanks. My environment is quite locked down. I might have to fix a few things first.

@21M4TW
Copy link
Contributor Author

21M4TW commented Jul 7, 2025

Ok I now get this in DEBUG mode, which seems to correspond to the issue you also have:
2025-07-07 17:06:10.876 [ datum_protocol_send_hello] DEBUG: Signing handshake 313 bytes
2025-07-07 17:06:10.876 [ datum_protocol_send_hello] DEBUG: Sending handshake init (425 bytes)
2025-07-07 17:06:10.881 [ datum_protocol_client] DEBUG: DATUM Protocol Thread is exiting.
2025-07-07 17:06:11.888 [ datum_protocol_start_connector] DEBUG: Starting DATUM v0.2.3-beta client...
2025-07-07 17:06:11.889 [ main] INFO: Waiting on DATUM server... 13

@21M4TW
Copy link
Contributor Author

21M4TW commented Jul 10, 2025

Ok, so I did some tests, and the issue is in datum_protocol_client (from datum_protocol.c). In the first iteration of the main while loop (when i is incremented to 1), epoll_wait times out while connect() is still in progress. By the time the second iteration in the main while loop occurs (when i is incremented to 2), server_out_buf is non-zero, so send() is called, but as connect() is still in progress, send() returns the error ENOTCONN.

Modifying the epoll_wait line by the following seems to fix the timing issue for me:
nfds = epoll_wait(epollfd, events, MAX_DATUM_CLIENT_EVENTS, (i>1? 5: 100)); // Wait for 5ms except for first loop

@21M4TW
Copy link
Contributor Author

21M4TW commented Jul 11, 2025

@BitcoinMechanic So I created the following branch in my fork with modified code that fixes the issue: https://github.com/21M4TW/datum_gateway/tree/fix_client_connect_in_progress . I tested it and it works for me. Would you like to test it as well before I submit a PR? Thanks

@luke-jr
Copy link
Contributor

luke-jr commented Jul 11, 2025

Probably makes sense to just add it to this PR? (Assuming it works)

@BitcoinMechanic
Copy link
Contributor

I can certainly test - gimme a bit

@luke-jr
Copy link
Contributor

luke-jr commented Jul 11, 2025

How about this?

--- a/src/datum_protocol.c
+++ b/src/datum_protocol.c
@@ -1629,7 +1629,7 @@ void *datum_protocol_client(void *args) {
                                        server_out_buf = 0;
                                }
                        } else {
-                               if (!(errno == EAGAIN || errno == EWOULDBLOCK)) {
+                               if (!(errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOTCONN)) {
                                        pthread_mutex_unlock(&datum_protocol_send_buffer_lock);
                                        break;
                                }

@BitcoinMechanic
Copy link
Contributor

@BitcoinMechanic So I created the following branch in my fork with modified code that fixes the issue: https://github.com/21M4TW/datum_gateway/tree/fix_client_connect_in_progress . I tested it and it works for me. Would you like to test it as well before I submit a PR? Thanks

This didn't work for me - same error as before.

@BitcoinMechanic
Copy link
Contributor

 || errno == ENOTCONN)) {

this works

…n ENOTCONN error when the connect() command was still in progress. This change prevents the main loop from exiting (it keeps trying to send the data) when such a situation occurs.
@21M4TW
Copy link
Contributor Author

21M4TW commented Jul 12, 2025

How about this?

--- a/src/datum_protocol.c
+++ b/src/datum_protocol.c
@@ -1629,7 +1629,7 @@ void *datum_protocol_client(void *args) {
                                        server_out_buf = 0;
                                }
                        } else {
-                               if (!(errno == EAGAIN || errno == EWOULDBLOCK)) {
+                               if (!(errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOTCONN)) {
                                        pthread_mutex_unlock(&datum_protocol_send_buffer_lock);
                                        break;
                                }

This worked for me as well. I added the change to this PR, as suggested.

@21M4TW 21M4TW requested a review from luke-jr July 13, 2025 01:18
@luke-jr luke-jr merged commit b4e9f6f into OCEAN-xyz:0.2.x Jul 14, 2025
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
portability Issues relating to running DATUM Gateway on new platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants