From eb2a7342b808a599a96d4d8f7c9469f85d2a7311 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 21 Mar 2023 09:40:55 +0000 Subject: [PATCH 1/4] link against libz on non Apple/Windows Needed by libcrypto at least --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97ccee6ad..0a3f79f9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1117,7 +1117,8 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "(SunOS|Solaris)") set(EXTRA_LIBRARIES socket nsl resolv) elseif(NOT MSVC AND NOT DEPENDS) find_library(RT rt) - set(EXTRA_LIBRARIES ${RT}) + find_library(Z z) + set(EXTRA_LIBRARIES ${RT} ${Z}) endif() list(APPEND EXTRA_LIBRARIES ${CMAKE_DL_LIBS}) From e2d02caf6774b8be8e03798944bbe16a971390f6 Mon Sep 17 00:00:00 2001 From: wowario Date: Tue, 11 Apr 2023 15:03:33 +0300 Subject: [PATCH 2/4] update checkpoints and bump version --- README.md | 2 +- src/blocks/checkpoints.dat | Bin 63684 -> 64580 bytes src/checkpoints/checkpoints.cpp | 2 ++ src/checkpoints/checkpoints.dat | Bin 63684 -> 64580 bytes src/cryptonote_core/blockchain.cpp | 2 +- src/version.cpp.in | 2 +- 6 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 98139b5d5..7daaba57e 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ Dates are provided in the format YYYY-MM-DD. | - | 2020-06-28 | Hallucinogenic Hypnotoad | v0.8.0.0 | v0.8.0.2 | Dandelion++ support | 253,999 | 2020-10-09 | Illiterate Illuminati | v0.9.0.0 | v0.9.3.3 | Dynamic coinbase unlock (up to 1 mo.), Deterministic unlock times, Enforce maximum coinbase amount, show_qr_code wallet command, CLSAG | 331,170 | 2021-07-04 | Junkie Jeff | v0.10.0.0 | v0.10.2.0 | Bulletproofs+, Miner Block Header Signing, Vote by Block, Change coinbase unlock time to 1 day, Reset difficulty and switch back to Monero's difficulty algorithm -| 514,000 | 2023-04-01 | Kunty Karen | v0.11.0.0 | v0.11.0.1 | View tags, fee changes, adjusted dynamic block weight algorithm, multisig security fixes, RPC broadcast node donation sub-address, Limit tx_extra max size to ~1kb, 12-hour difficulty adjustment window +| 514,000 | 2023-04-01 | Kunty Karen | v0.11.0.0 | v0.11.0.2 | View tags, fee changes, adjusted dynamic block weight algorithm, multisig security fixes, RPC broadcast node donation sub-address, Limit tx_extra max size to ~1kb, 12-hour difficulty adjustment window X's indicate that these details have not been determined as of commit date. diff --git a/src/blocks/checkpoints.dat b/src/blocks/checkpoints.dat index 32da1e63a070ebfefc3ccb9e26008b64f1693df3..47314925441b4c365a859d5feaea56a4ce0a2f0f 100644 GIT binary patch delta 916 zcmV;F18e-m@dL#80|D`|0mJxzk!c9Rw4WO4vKlr~ZyCPMX>vAoF>2Fu;jfL&o<_+b zquNres+Xd|Wf#2#3m_D3R_IK)8#tNjh<>up{%FeTtf01D%<5hh=i=6+9XjJuMNz;s z9dz!AdfXH3<2}$1+xGO97Je2?IHvI9n=oc#>ONaJ0#x&mJ2YRnkAtayf7pCaKA26* ztHgI5UK&=xrbRWY93WyDvLf7XSOe9d(jfI)np`w+6S8GJIf(X|VlVUYhz93$Zr%NMw4@v=<>*14}< zJ0(9oG$P&}UF5zN&@@?p`!tv>wXvwt@4%gqF`DxiBF?9fN zf55y!g2T!jt-~U(ca-?XWY}644YT8a&B=?r>_6VSs)5wv;Fy+q zrRr^bUj@gOyqN~VfV;aQ-)RPIaR{FmAjE{|jT}uL`qJVxnpuNvT+@;25i2P_ zx6J<>b#cwT`3zj9TeZ7Mjz8oDzNg*B_lt|B{Op1z3$jyHsi=H8ppzLc4#rcy#)Wpc zEuXq32&JljX;4r#;!LUI0UN8TcpZ6ZL? qrvAoF>2Fu;jfL&o<_+b zquNres+Xd|Wf#2#3m_D3R_IK)8#tNjh<>up{%FeTtf01D%<5hh=i=6+9XjJuMNz;s z9dz!AdfXH3<2}$1+xGO97Je2?IHvI9n=oc#>ONaJ0#x&mJ2YRnkAtayf7pCaKA26* ztHgI5UK&=xrbRWY93WyDvLf7XSOe9d(jfI)np`w+6S8GJIf(X|VlVUYhz93$Zr%NMw4@v=<>*14}< zJ0(9oG$P&}UF5zN&@@?p`!tv>wXvwt@4%gqF`DxiBF?9fN zf55y!g2T!jt-~U(ca-?XWY}644YT8a&B=?r>_6VSs)5wv;Fy+q zrRr^bUj@gOyqN~VfV;aQ-)RPIaR{FmAjE{|jT}uL`qJVxnpuNvT+@;25i2P_ zx6J<>b#cwT`3zj9TeZ7Mjz8oDzNg*B_lt|B{Op1z3$jyHsi=H8ppzLc4#rcy#)Wpc zEuXq32&JljX;4r#;!LUI0UN8TcpZ6ZL? qr Date: Mon, 27 Mar 2023 16:32:47 -0500 Subject: [PATCH 3/4] cryptonote core/protocol: don't drop peers for soft offenses Also: txs with tx_extra which is too large will not get published to ZMQ Co-authored-by: SChernykh --- src/cryptonote_basic/verification_context.h | 7 ++++++- src/cryptonote_core/cryptonote_core.cpp | 2 +- src/cryptonote_core/tx_pool.cpp | 2 ++ src/cryptonote_protocol/cryptonote_protocol_handler.inl | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cryptonote_basic/verification_context.h b/src/cryptonote_basic/verification_context.h index ffd07b27a..10a16a8c1 100644 --- a/src/cryptonote_basic/verification_context.h +++ b/src/cryptonote_basic/verification_context.h @@ -42,7 +42,12 @@ namespace cryptonote static_assert(unsigned(relay_method::none) == 0, "default m_relay initialization is not to relay_method::none"); relay_method m_relay; // gives indication on how tx should be relayed (if at all) - bool m_verifivation_failed; //bad tx, should drop connection + bool m_verifivation_failed; //bad tx, tx should not enter mempool and connection should be dropped unless m_no_drop_offense + // Do not add to mempool, do not relay, but also do not punish the peer for sending or drop + // connections to them. Used for low fees, tx_extra too big, "relay-only rules". Not to be + // confused with breaking soft fork rules, because tx could be later added to the chain if mined + // because it does not violate consensus rules. + bool m_no_drop_offense; bool m_verifivation_impossible; //the transaction is related with an alternative blockchain bool m_added_to_pool; bool m_low_mixin; diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 8d8ba198e..ba5005163 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -1103,7 +1103,7 @@ namespace cryptonote else if(tvc[i].m_verifivation_impossible) {MERROR_VER("Transaction verification impossible: " << results[i].hash);} - if(tvc[i].m_added_to_pool) + if(tvc[i].m_added_to_pool && results[i].tx.extra.size() <= MAX_TX_EXTRA_SIZE) { MDEBUG("tx added: " << results[i].hash); valid_events = true; diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 8380d79b6..6624bdc14 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -207,6 +207,7 @@ namespace cryptonote { tvc.m_verifivation_failed = true; tvc.m_fee_too_low = true; + tvc.m_no_drop_offense = true; return false; } @@ -225,6 +226,7 @@ namespace cryptonote LOG_PRINT_L1("transaction tx-extra is too big: " << tx_extra_size << " bytes, the limit is: " << MAX_TX_EXTRA_SIZE); tvc.m_verifivation_failed = true; tvc.m_tx_extra_too_big = true; + tvc.m_no_drop_offense = true; return false; } diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 01748195f..a80f07003 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -1020,7 +1020,7 @@ namespace cryptonote for (auto& tx : arg.txs) { tx_verification_context tvc{}; - if (!m_core.handle_incoming_tx({tx, crypto::null_hash}, tvc, tx_relay, true)) + if (!m_core.handle_incoming_tx({tx, crypto::null_hash}, tvc, tx_relay, true) && !tvc.m_no_drop_offense) { LOG_PRINT_CCONTEXT_L1("Tx verification failed, dropping connection"); drop_connection(context, false, false); From a2dc960250de01e4900e31ad804a4c10a6d1a7e4 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 29 Mar 2023 08:43:47 +0200 Subject: [PATCH 4/4] Fixed deadlock and crash when syncing with full dataset on Windows It's not allowed to use WaitForSingleObject with _beginthread, because the thread closes its own handle before exiting. So the wait function will either wait on an invalid handle, or on a different handle used by something else. Or, if it starts waiting before the thread exits, the behavior is undefined according to MS: "If this handle is closed while the wait is still pending, the function's behavior is undefined." In my test sync I observed threads getting stuck infinitely on WaitForSingleObject, and then rx_set_main_seedhash spamming new threads when RandomX seed changes again. Eventually the system ran out of resources, and monerod aborted with "Couldn't start RandomX seed thread" message. This PR fixes it by using `_beginthreadex` instead and explicitly closing the handle when it's safe. --- src/crypto/c_threads.h | 10 ++++++---- src/crypto/rx-slow-hash.c | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/crypto/c_threads.h b/src/crypto/c_threads.h index b4f773641..3457738b3 100644 --- a/src/crypto/c_threads.h +++ b/src/crypto/c_threads.h @@ -42,10 +42,11 @@ #define CTHR_RWLOCK_TRYLOCK_READ(x) TryAcquireSRWLockShared(&x) #define CTHR_THREAD_TYPE HANDLE -#define CTHR_THREAD_RTYPE void -#define CTHR_THREAD_RETURN return -#define CTHR_THREAD_CREATE(thr, func, arg) ((thr = (HANDLE)_beginthread(func, 0, arg)) != -1L) -#define CTHR_THREAD_JOIN(thr) WaitForSingleObject((HANDLE)thr, INFINITE) +#define CTHR_THREAD_RTYPE unsigned __stdcall +#define CTHR_THREAD_RETURN _endthreadex(0); return 0; +#define CTHR_THREAD_CREATE(thr, func, arg) ((thr = (HANDLE)_beginthreadex(0, 0, func, arg, 0, 0)) != 0L) +#define CTHR_THREAD_JOIN(thr) do { WaitForSingleObject(thr, INFINITE); CloseHandle(thr); } while(0) +#define CTHR_THREAD_CLOSE(thr) CloseHandle((HANDLE)thr); #else @@ -64,5 +65,6 @@ #define CTHR_THREAD_RETURN return NULL #define CTHR_THREAD_CREATE(thr, func, arg) (pthread_create(&thr, NULL, func, arg) == 0) #define CTHR_THREAD_JOIN(thr) pthread_join(thr, NULL) +#define CTHR_THREAD_CLOSE(thr) #endif diff --git a/src/crypto/rx-slow-hash.c b/src/crypto/rx-slow-hash.c index 14fb56e07..672144fcf 100644 --- a/src/crypto/rx-slow-hash.c +++ b/src/crypto/rx-slow-hash.c @@ -332,7 +332,7 @@ static void rx_init_dataset(size_t max_threads) { local_abort("Couldn't start RandomX seed thread"); } } - rx_seedthread(&si[n1]); + randomx_init_dataset(main_dataset, si[n1].si_cache, si[n1].si_start, si[n1].si_count); for (size_t i = 0; i < n1; ++i) CTHR_THREAD_JOIN(st[i]); CTHR_RWLOCK_UNLOCK_READ(main_cache_lock); @@ -402,6 +402,7 @@ void rx_set_main_seedhash(const char *seedhash, size_t max_dataset_init_threads) if (!CTHR_THREAD_CREATE(t, rx_set_main_seedhash_thread, info)) { local_abort("Couldn't start RandomX seed thread"); } + CTHR_THREAD_CLOSE(t); } void rx_slow_hash(const char *seedhash, const void *data, size_t length, char *result_hash) {