Skip to content

回复:Bitcoind ​

首次公开证据

打开首次公开证据
查看 1 个交叉存档
来源说明

Published on GitHub in February 2024 as part of Martti Malmi's testimony in the COPA v. Wright trial

其实,请改用这个,这样更正确:

c
void ParseString(const string& str, char c, vector<string>& v)
{
     string::size_type i1 = 0;
     string::size_type i2;
     loop
     {
         i2 = str.find(c, i1);
         if (i2 == str.npos)
         {
             v.push_back(str.substr(i1));
             return;
         }
         v.push_back(str.substr(i1, i2-i1));
         i1 = i2+1;
     }
}

问题在 util.c 的 ParseString 中。我猜是类型“unsigned int”和 str.npos 的类型 size_type 不兼容。

尝试把两个“unsigned int”改成“size_type”。

旧版: void ParseString(const string& str, char c, vector<string>& v) { unsigned int i1 = 0; unsigned int i2; do { i2 = str.find(c, i1); v.push_back(str.substr(i1, i2-i1)); i1 = i2+1; } while (i2 != str.npos); }

新版: void ParseString(const string& str, char c, vector<string>& v) { size_type i1 = 0; size_type i2; do { i2 = str.find(c, i1); v.push_back(str.substr(i1, i2-i1)); i1 = i2+1; } while (i2 != str.npos); }

这是我用 gdb 调试时得到的另一次测试运行 debug.log。程序在调试行“irc 8”之后开始吞噬内存,几秒钟内就因“terminate called after throwing an instance of 'std::bad_alloc'”崩溃了。

问题在 RecvUntil 中,但我仍然看不出有什么不对。我能想到的唯一可能是套接字正在接收大量字符。

试试这个 irc.cpp。debug.log 可能会快速增长,准备好终止它。

debug.log 已附上

这就缩小了很多范围。debug.log 中没有打印任何 IRC 活动,所以我猜它没能越过 RecvUntil。仔细看我没发现明显问题。我猜可能是在 ConnectSocket 或 RecvUntil 中。

用附上的 irc.cpp 和 net.cpp 试试,并把 debug.log 发来。

或者你可以在 gdb 中运行它,并逐步执行 ThreadIRCSeed gdb --args bitcoin [switches] b ThreadIRCSeed run step 或用 u 跳过并从例程中向上退出。

无论有没有 getinfo,我都会遇到错误。注释掉 ThreadIRCSeed 就解决了问题。

如果你不执行 getinfo,仍然会这样吗?

你可以注释掉下面列出的 CreateThread,然后逐个重新启用,直到问题再次出现。这样我们就能知道问题在哪个线程中。

net.cpp,在 // Start threads 下: CreateThread(ThreadIRCSeed, NULL) CreateThread(ThreadSocketHandler, NULL, true) CreateThread(ThreadOpenConnections, NULL) CreateThread(ThreadMessageHandler, NULL)

init.cpp: CreateThread(ThreadRPCServer, NULL);

出现了。我忘了提崩溃错误消息: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc

你能把 debug.log 发给我吗?

我尝试用 ddd 调试器调试我构建的 bitcoind,但还不太成功。它总是最终耗尽系统内存并崩溃。你能再把最新的 64 位 bitcoind 构建发给我吗?这样我可以看看问题是否出在我的构建上。

英文原文 ​

展开英文原文

Actually, please try this instead, this is more correct:

c
void ParseString(const string& str, char c, vector<string>& v)
{
     string::size_type i1 = 0;
     string::size_type i2;
     loop
     {
         i2 = str.find(c, i1);
         if (i2 == str.npos)
         {
             v.push_back(str.substr(i1));
             return;
         }
         v.push_back(str.substr(i1, i2-i1));
         i1 = i2+1;
     }
}

It's in util.c ParseString. I'm guessing the problem is incompatibility between the type "unsigned int" and the type of str.npos, which is size_type.

Try changing the two "unsigned int"s to "size_type".

old: void ParseString(const string& str, char c, vector<string>& v) { unsigned int i1 = 0; unsigned int i2; do { i2 = str.find(c, i1); v.push_back(str.substr(i1, i2-i1)); i1 = i2+1; } while (i2 != str.npos); }

new: void ParseString(const string& str, char c, vector<string>& v) { size_type i1 = 0; size_type i2; do { i2 = str.find(c, i1); v.push_back(str.substr(i1, i2-i1)); i1 = i2+1; } while (i2 != str.npos); }

Here's another test run debug.log I got when debugging with gdb. The program started eating memory after the debug line "irc 8" and within a few seconds crashed with "terminate called after throwing an instance of 'std::bad_alloc'".

It's in RecvUntil, but I still can't see anything wrong with it. The only thing I can think of is if the socket is receiving a spew of characters.

Try this irc.cpp. debug.log may grow rapidly so be ready to kill it.

debug.log attached

That narrows it down a lot. It didn't print any IRC activity in debug.log, so I guess it couldn't have gotten past the RecvUntil. Eyeballing it I don't see anything obvious. I guess it would have to be either in ConnectSocket or RecvUntil.

Try it with the attached irc.cpp and net.cpp and send me the debug.log.

Or you could run it in gdb and step through ThreadIRCSeed gdb --args bitcoin [switches] b ThreadIRCSeed run step or u to step over and up out of routines.

I get the error regardless of the getinfo. Commenting out ThreadIRCSeed fixed the problem.

Does it still do it if you didn't do getinfo?

You could comment out the CreateThreads listed below, then re-enable them one at a time until it does it again. Then we would know which thread the problem is in.

net.cpp, under // Start threads CreateThread(ThreadIRCSeed, NULL) CreateThread(ThreadSocketHandler, NULL, true) CreateThread(ThreadOpenConnections, NULL) CreateThread(ThreadMessageHandler, NULL)

init.cpp: CreateThread(ThreadRPCServer, NULL);

Here goes. I forgot to mention the crash error message:

terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc

Could you send me the debug.log?

I tried debugging my build of bitcoind with ddd debugger, but didn't have much success yet. It always ends up taking all the system's memory and finally crashes. Could you please send me again the latest 64 bit build of bitcoind, so I can see if the problem is about my build?

为历史保存,为中文读者整理。每篇档案均附来源与英文原文。