Skip to content

Commit 9ee4175

Browse files
authored
[PSL-1247] pasteld: port PSL-1223 to the master branch (#264)
* [PSL-1247] pasteld: port PSL-1223 to the master branch * compilation fixes
1 parent a23f62c commit 9ee4175

File tree

16 files changed

+551
-382
lines changed

16 files changed

+551
-382
lines changed

build-aux/vs2022/libbitcoin_util/libbitcoin_util.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<ClCompile Include="..\..\..\src\utils\bech32.cpp" />
110110
<ClCompile Include="..\..\..\src\utils\datacompressor.cpp" />
111111
<ClCompile Include="..\..\..\src\utils\hash.cpp" />
112+
<ClCompile Include="..\..\..\src\utils\logmanager.cpp" />
112113
<ClCompile Include="..\..\..\src\utils\ping_util.cpp" />
113114
<ClCompile Include="..\..\..\src\utils\random.cpp" />
114115
<ClCompile Include="..\..\..\src\utils\scheduler.cpp" />
@@ -146,6 +147,7 @@
146147
<ClInclude Include="..\..\..\src\utils\enum_util.h" />
147148
<ClInclude Include="..\..\..\src\utils\fs.h" />
148149
<ClInclude Include="..\..\..\src\utils\hash.h" />
150+
<ClInclude Include="..\..\..\src\utils\logmanager.h" />
149151
<ClInclude Include="..\..\..\src\utils\map_types.h" />
150152
<ClInclude Include="..\..\..\src\utils\numeric_range.h" />
151153
<ClInclude Include="..\..\..\src\utils\ping_util.h" />

build-aux/vs2022/libbitcoin_util/libbitcoin_util.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
<ClCompile Include="..\..\..\src\utils\hash.cpp">
101101
<Filter>Source Files\utils</Filter>
102102
</ClCompile>
103+
<ClCompile Include="..\..\..\src\utils\logmanager.cpp">
104+
<Filter>Source Files\utils</Filter>
105+
</ClCompile>
103106
</ItemGroup>
104107
<ItemGroup>
105108
<ClInclude Include="..\..\..\src\compat\byteswap.h">
@@ -249,5 +252,8 @@
249252
<ClInclude Include="..\..\..\src\utils\hash.h">
250253
<Filter>Source Files\utils</Filter>
251254
</ClInclude>
255+
<ClInclude Include="..\..\..\src\utils\logmanager.h">
256+
<Filter>Source Files\utils</Filter>
257+
</ClInclude>
252258
</ItemGroup>
253259
</Project>

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ AC_PREREQ([2.60])
33
define(_CLIENT_VERSION_MAJOR, 2)
44
define(_CLIENT_VERSION_MINOR, 2)
55
define(_CLIENT_VERSION_REVISION, 7)
6-
define(_CLIENT_VERSION_BUILD, 0)
6+
define(_CLIENT_VERSION_BUILD, 1)
77
define(_ZC_BUILD_VAL,
88
m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, m4_incr(_CLIENT_VERSION_BUILD),
99
m4_eval(_CLIENT_VERSION_BUILD < 50), 1,

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ UTILS_CPP = \
252252
utils/bech32.cpp \
253253
utils/datacompressor.cpp \
254254
utils/hash.cpp \
255+
utils/logmanager.cpp \
255256
utils/ping_util.cpp \
256257
utils/random.cpp \
257258
utils/scheduler.cpp \
@@ -272,6 +273,7 @@ UTILS_H = \
272273
utils/enum_util.h \
273274
utils/fs.h \
274275
utils/hash.h \
276+
utils/logmanager.h \
275277
utils/map_types.h \
276278
utils/numeric_range.h \
277279
utils/ping_util.h \

src/clientversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define CLIENT_VERSION_MAJOR 2
1818
#define CLIENT_VERSION_MINOR 2
1919
#define CLIENT_VERSION_REVISION 7
20-
#define CLIENT_VERSION_BUILD 0
20+
#define CLIENT_VERSION_BUILD 1
2121

2222
//! Set to true for release, false for prerelease or test build
2323
#define CLIENT_VERSION_IS_RELEASE true

src/compat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#ifdef _WIN32_WINNT
1313
#undef _WIN32_WINNT
1414
#endif
15-
#define _WIN32_WINNT 0x0501
15+
#define _WIN32_WINNT 0x0601
1616
#ifndef WIN32_LEAN_AND_MEAN
1717
#define WIN32_LEAN_AND_MEAN 1
1818
#endif

src/httpserver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <thread>
1313
#include <functional>
1414

15+
#include <compat.h>
16+
1517
#include <event2/buffer.h>
1618
#include <event2/event.h>
1719
#include <event2/http.h>

src/init.cpp

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,32 @@ class CCoinsViewErrorCatcher : public CCoinsViewBacked
169169
// Writes do not need similar protection, as failure to write is handled by the caller.
170170
};
171171

172+
class CLogRotationManager : public CStoppableServiceThread
173+
{
174+
public:
175+
CLogRotationManager() :
176+
CStoppableServiceThread("logrt")
177+
{}
178+
static constexpr auto LOG_ROTATION_INTERVAL = chrono::minutes(10);
179+
180+
void execute() override
181+
{
182+
// check if debug log needs to be rotated every 10 minutes
183+
while (!shouldStop())
184+
{
185+
unique_lock lock(m_mutex);
186+
if (m_condVar.wait_for(lock, LOG_ROTATION_INTERVAL) == cv_status::timeout)
187+
{
188+
if (gl_LogMgr)
189+
gl_LogMgr->ShrinkDebugLogFile();
190+
}
191+
}
192+
}
193+
};
194+
172195
static unique_ptr<CCoinsViewDB> gl_pCoinsDbView;
173196
static unique_ptr<CCoinsViewErrorCatcher> pCoinsCatcher;
197+
static shared_ptr<CLogRotationManager> gl_LogRotationManager;
174198

175199
void Interrupt(CServiceThreadGroup& threadGroup, CScheduler &scheduler)
176200
{
@@ -180,6 +204,8 @@ void Interrupt(CServiceThreadGroup& threadGroup, CScheduler &scheduler)
180204
InterruptREST();
181205
threadGroup.stop_all();
182206
scheduler.stop(false);
207+
if (gl_LogRotationManager)
208+
gl_LogRotationManager->stop();
183209
}
184210

185211
void Shutdown(CServiceThreadGroup& threadGroup, CScheduler &scheduler)
@@ -197,6 +223,9 @@ void Shutdown(CServiceThreadGroup& threadGroup, CScheduler &scheduler)
197223
RenameThread("psl-shutoff");
198224
mempool.AddTransactionsUpdated(1);
199225

226+
if (gl_LogRotationManager)
227+
gl_LogRotationManager->waitForStop();
228+
200229
StopHTTPRPC();
201230
StopREST();
202231
StopRPC();
@@ -213,8 +242,12 @@ void Shutdown(CServiceThreadGroup& threadGroup, CScheduler &scheduler)
213242
#endif
214243
#endif
215244
StopNode();
245+
LogFnPrintf("Waiting for Pastel threads to exit...");
216246
threadGroup.join_all();
247+
LogFnPrintf("...done");
248+
LogFnPrintf("Waiting for scheduler threads to exit...");
217249
scheduler.join_all();
250+
LogFnPrintf("...done");
218251
UnregisterNodeSignals(GetNodeSignals());
219252

220253
if (fFeeEstimatesInitialized)
@@ -290,7 +323,8 @@ void HandleSIGTERM(int)
290323

291324
void HandleSIGHUP(int)
292325
{
293-
fReopenDebugLog = true;
326+
if (gl_LogMgr)
327+
gl_LogMgr->ScheduleReopenDebugLog();
294328
}
295329

296330
bool static InitError(const string &str)
@@ -796,6 +830,9 @@ bool AppInit2(CServiceThreadGroup& threadGroup, CScheduler& scheduler)
796830
{
797831
string strError;
798832

833+
if (!gl_LogMgr)
834+
return InitError("Error: Log Manager is not initialized");
835+
799836
// ********************************************************* Step 1: setup
800837
#ifdef _MSC_VER
801838
// Turn off Microsoft heap dump noise
@@ -866,7 +903,7 @@ bool AppInit2(CServiceThreadGroup& threadGroup, CScheduler& scheduler)
866903

867904
// Set this early so that parameter interactions go to console
868905
string error;
869-
if (!SetPrintToConsoleMode(error))
906+
if (!gl_LogMgr->SetPrintToConsoleMode(error))
870907
return InitError(error);
871908
fLogTimestamps = GetBoolArg("-logtimestamps", true);
872909
fLogIPs = GetBoolArg("-logips", false);
@@ -1194,10 +1231,15 @@ bool AppInit2(CServiceThreadGroup& threadGroup, CScheduler& scheduler)
11941231
CreatePidFile(GetPidFile(), getpid());
11951232
#endif
11961233
if (GetBoolArg("-shrinkdebugfile", !fDebug))
1197-
ShrinkDebugFile();
1234+
gl_LogMgr->ShrinkDebugLogFile(true);
11981235

1199-
if (fPrintToDebugLog)
1200-
OpenDebugLog();
1236+
gl_LogMgr->OpenDebugLogFile();
1237+
if (!gl_LogRotationManager)
1238+
{
1239+
gl_LogRotationManager = make_unique<CLogRotationManager>();
1240+
if (threadGroup.add_thread(error, gl_LogRotationManager, true) == INVALID_THREAD_OBJECT_ID)
1241+
return InitError(translate("Failed to create log rotation thread. ") + error);
1242+
}
12011243

12021244
LogPrintf("Using OpenSSL version %s\n", OpenSSL_version(OPENSSL_VERSION_STRING));
12031245
#ifdef ENABLE_WALLET
@@ -1226,7 +1268,7 @@ bool AppInit2(CServiceThreadGroup& threadGroup, CScheduler& scheduler)
12261268

12271269
if (!chainparams.IsRegTest() &&
12281270
GetBoolArg("-showmetrics", isatty(STDOUT_FILENO)) &&
1229-
!IsPrintToConsole() && !GetBoolArg("-daemon", false))
1271+
!gl_LogMgr->IsPrintToConsole() && !GetBoolArg("-daemon", false))
12301272
{
12311273
// Start the persistent metrics interface
12321274
ConnectMetricsScreen();
@@ -1240,6 +1282,7 @@ bool AppInit2(CServiceThreadGroup& threadGroup, CScheduler& scheduler)
12401282
libsnark::inhibit_profiling_counters = true;
12411283

12421284
// Initialize Zcash circuit parameters
1285+
uiInterface.InitMessage(translate("Initializing chain parameters..."));
12431286
ZC_LoadParams(chainparams);
12441287

12451288
/* Start the RPC server already. It will be started in "warmup" mode

src/net.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
#include <algorithm>
1313
#include <functional>
1414
#include <random>
15+
16+
#include <compat.h>
17+
1518
#ifdef WIN32
1619
#include <string.h>
17-
#include <winsock2.h>
18-
#include <ws2tcpip.h>
1920
#include <iphlpapi.h>
2021
#include <wininet.h>
21-
#else
22-
#include <fcntl.h>
23-
#include <ifaddrs.h>
2422
#endif
2523

2624
#include <extlibs/scope_guard.hpp>

src/pasteld.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ void WaitForShutdown(CServiceThreadGroup& threadGroup, CScheduler &scheduler)
5858
//
5959
bool AppInit(int argc, char* argv[])
6060
{
61+
if (!gl_LogMgr)
62+
gl_LogMgr = make_unique<CLogManager>();
63+
6164
CServiceThreadGroup threadGroup;
6265
CScheduler scheduler("scheduler");
6366

@@ -180,6 +183,12 @@ bool AppInit(int argc, char* argv[])
180183
WaitForShutdown(threadGroup, scheduler);
181184
Shutdown(threadGroup, scheduler);
182185

186+
if (gl_LogMgr)
187+
{
188+
LogPrintf("Shutdown: log file closed\n");
189+
gl_LogMgr->CloseDebugLogFile();
190+
gl_LogMgr.reset();
191+
}
183192
return fRet;
184193
}
185194

0 commit comments

Comments
 (0)