Bitcoin full node and query server

September 2019

Archive of the libbitcoin Slack #general channel.

Monday, September 2, 2019

evoskuil21:56
@jungly I've been thinking that an easy compromise solution for the store's hard shutdown issue would be to implement an alternative database driver. The database itself is trivial, just a small set of templates. We even substitute it in text cases as you know, using just a std::vector. The memory map is optimal for server scenarios - specifically rapid query, therefore optimized for mining and validation. Providing a database driver would allow for compromise in the desktop/wallet scenario where these performance characteristics are not required.
jungly22:22
Thanks @evoskuil. I really like the drivers idea. It gives us some freedom to experiment as well. I went down the rabbit hole of in memory databases, reading a bunch of papers from here - https://15721.courses.cs.cmu.edu/spring2019/schedule.html It's amazing how much work is being done in the area. It seems Microsoft's hekaton SQL server engine is doing a lot of excellent stuff. We can pick some good ideas from these projects, if and when needed. The drivers approach is really cool. Will give us an easy way to experiment. Btw, I also ran a small experiment of measuring the amount of data going to disk per second during IBD. Want to plot it on a chart before sharing.
CMU 15-721
Course schedule with slides, lecture notes, and videos.
Microsoft Research
Hekaton is a new database engine optimized for memory resident data and OLTP workloads. Hekaton is fully integrated into SQL Server; it is not a separate system. To take advantage of Hekaton, a user simply declares a table memory optimized. Hekaton tables are fully transactional and durable and accessed using T-SQL in the same way …
evoskuil22:29
My last work in blockchain was block caching during sync, so that a large memory machine could cache blocks received out of order up to the size of the entire chain, eliminating the block read required for validation purposes. The other remaining optimization to complete is minimizing the scope of confirmation updates.
(edited)
23 replies · jungly, evoskuil · last Sep 09, 2019
jungly22:37
Yup. Totally get that. It's just a to measure things, so we can know how things are improving etc. I was curious to know how much io was coming due to vm paging effort. I went for a 256 GB ram and 12 virtual cores wth nvme SSD machine. It looked interesting how there were no real page faults up to a certain amount of memory usage and then they go up quiet rapidly (kind of expected). But I'll share the results soon so we can look interpret them properly.
evoskuil22:39
excellent, thanks.
jungly14:14
Hey @evoskuil. Here's a first pass on the experiments I ran to see how disk and virtual memory was being used when running IBD. If nothing, hopefully this provides us a way to keep measuring as we keep improving the system. Let me know if should have done anything differently, I can have another go, or improve what we capture for the next time.
PDFreport.pdfPDF · 346.6 KB
evoskuil06:28
Blocks start to go from ~1kb to ~1mb as you get around 300,000, 3 orders of magnitude increase.
jungly06:29
Yes. Of course! Thanks. It's not doing that bad then.
jungly06:30
The increase in the reads is also as you expected.
evoskuil06:33
Also note that resource usage is maximized in terms of RAM, CPU and network. So the more work there is to do, the more we use, limited by what the operating system will offer. The optimization is for speed.
evoskuil06:34
Header download is not optimized, as it intends to allow slow peers in the interest of ensuring that fast peers don't always provide the chain.
jungly06:39
It seems disk wasn't the bottle neck. Right?
evoskuil06:45
Reading is clearly dominating performance, it's causing writes to decline as read cost slows down validation.
evoskuil06:47
Am I reading correctly that you downloaded all blocks in less than 4 minutes with swap?
jungly06:52
Yes. That was a bit mad.
evoskuil06:54
That's the optimized part. As you can see, if we can conquer the read cost it can make a big difference.
evoskuil06:57
I've implemented an in-memory cache (height-ordered circular buffer hash table) of downloads to preclude re-reading each block for validation. With enough memory this can contain the entire chain, reducing reads to much less than writes.
jungly07:02
There is a cache in master,iirc. I left the default settings for it. Or is there a new one not in master?
evoskuil07:07
The master cache is a dynamic blind cache of unspent outputs, which populates by height following validation, and is indexed by tx hash. It's useful on low memory machines, but will actually reuduce performance on high memory machines, since there's a population cost but no benefit.
evoskuil07:26
The download cache can be very helpful, but not so great after a restart following a large set of downloads.
evoskuil07:28
The worst case is where it's faster to download in order off the network than it is to read from the disk. That seems like an unlikely scenario, in which case, as long as the initial parallel download is fast enough to be negligible it would always be faster even to read after downloading.
(edited)
evoskuil07:29
That's the premise of the design, we'll see 🙂
jungly08:51
The worry would be if the cache itself gets paged out to disk. Maybe we will have to consider mlock on cache and indexes? I am sure you thought about it, any reason we don't do it yet for things like indexes? Are they too large for small memory machines?
evoskuil12:03
I don’t think we want to try and stop paging if the OS thinks it’s optimal. I think mlock could cause more significant problems. Given that indexes are more frequently accessed and small they should tend to be retained.
(edited)
evoskuil12:04
It’s a design principle to allow the OS to optimize resource usage, which is its function.
evoskuil12:04
We just try and use all resources, without wasting any of course.
evoskuil22:30
So you will see much more reading and some more writing now than is ideal.
I did a lot of work to fully templatize and isolate the database primitives so that we could test cleanly, but it allows for a fairly simple replacement, and by mapping calls to a standard query language, SQL or otherwise, a driver model should provide easy access to any store.
👍 1
There are no joins, so a simpler query abstraction may be simpler and more efficient.
(edited)
We'd still retain constant time, just a higher constant.
This is really the only significant issue in terms of desktop/wallet support.
I would prefer to provide an integral reliable database, with the possibility of external stores being a secondary concern.
This implies licensing considerations. If we can't find something that we can integrate, we'd want to provide a conditional build dependency.
jungly22:44
I didn't realise you were open to the idea of using an integrable store. I can check if any of the existing in memory stores are 1) stable enough, 2) do what we want and 3) have a license we can use. Though I also think, our use case is so application specific, we really don't need all the bloat a generic store will come with, as they try to be generic, by definition. It might be interesting to measure how using such a store performs or if they are usable at all.
evoskuil22:45
Really all we would be after is the shutdown guarantee (to the extent that is possible).
(edited)
However if it performs as poorly as our full write-flushing it would be for nothing.
jungly22:46
That really is the first and the most important goal.
evoskuil22:46
I believe it's the only advantage we require.
jungly22:47
Get that thing to shutdown restart properly, without to much of a slowdown :)
evoskuil22:48
Yup, I believe we will always outperform on other measures.
jungly22:48
👍🏾
evoskuil22:48
At least on an SSD.
jungly22:49
Yeah. That's an assumption I am convinced is totally sane.
👍 1

Wednesday, September 4, 2019

R
RaGa19:21
does this URL: https://libbitcoin.org reachable?
pmienk19:22
@RaGa, timeout for me
R
RaGa19:23
been getting that for quite a while....
pmienk19:25
What were you looking for?
I ask, as I'm not aware what it hosts.
R
RaGa19:26
for the website
I mean what sorta information does it host or stuff like that
pmienk19:27
What information were you looking for? I'm not sure what's on libbitcoin.org as I thought everything was hosted in github. I was hoping to be able to direct you to something useful for your purposes.
R
RaGa19:28
Mostly looking for what applications have been built using libbitcoin toolkit
may be out of date. may even be what libbitcoin.org redirects to. not sure if that ever got set up
evoskuil19:43
that's way out of date, not the same
@narodnik Could you please talk to your admin to see if he can get the site up? I contacted him but no response. It's been down for a very long time. We can move to libbitcoin.net if he's not able.
R
RaGa19:53
@pmienk TY, Watched the Airbitz video,I have started out with bitcoin during my spare time, so things are bit distorted to me now.....may be i should focus on understanding the satoshi's reference implementation first.
👀 1
Slackbot19:53
👻
pmienk19:57
@RaGa I guess it's all about what your goals are. In general I would argue for a logical understanding of the protocol independent of an implementation. What specifically are you trying to do?
evoskuil20:00
If you want to understand Bitcoin generally, libbitcoin is much easier than the Satoshi prototype. The website doesn’t contain any information you would need, it’s all in github. Info about libbitcoin is also in the Bitcoin Wiki: https://en.bitcoin.it/wiki/Libbitcoin
Slackbot20:00
👻
R
RaGa20:01
primarily I want to contribute as I see bitcoin is kinda revolutionary, so will try to make some contributions, plus, will help other people ( who are new to bitcoin or never heard of bitcoin) to understand what it is or does.
@evoskuil TY, I will go through it.
(edited)
pmienk20:04
Well, I know we would welcome contributions. I agree with @evoskuil that I believe that our codebase is more readable as it was developed with the purpose of providing a developer api as opposed to the prototype
though admittedly, bias 🙂
R
RaGa20:06
What do you mean by admittedly bias?
evoskuil20:06
It also puts a much strong emphasis on readability and code self-documentation.
pmienk20:07
well, i've contributed to this one, so it's not surprising i think its easier to understand
👍 1
It also hasn't had to evolve into multithreading. I think that single-threaded aspect may be what's confused some people's understanding of the protocol.
evoskuil20:09
Libbitcoin also avoids a lot of unnecessary implementation optimizations that have been implemented in the Satoshi prototype to overcome architectural issues.
Slackbot20:09
👻
R
RaGa20:11
ok, thanks I will catch up.

Friday, September 6, 2019

N
narodnik10:51
@evoskuil did you see they are making new hard drives which are key-value stores (in hardware)?
evan15:02
Way cool

Tuesday, September 10, 2019

R
RaGa14:58
Hi, Hope thing are going good. I've been building libbitcoin-system repo, faced couple of issues, resolved some and finally stuck here CXX examples/examples_libbitcoin_system_examples-main.o CXXLD src/libbitcoin-system.la copying selected object files to avoid basename conflicts... ar: u' modifier ignored since D' is the default (see U')` CXXLD examples/libbitcoin-system-examples src/.libs/libbitcoin-system.so: undefined reference to secp256k1_ecdsa_recover'` src/.libs/libbitcoin-system.so: undefined reference to secp256k1_ecdsa_sign_recoverable'` src/.libs/libbitcoin-system.so: undefined reference to secp256k1_ecdsa_recoverable_signature_serialize_compact'` src/.libs/libbitcoin-system.so: undefined reference to secp256k1_ecdsa_recoverable_signature_parse_compact'` collect2: error: ld returned 1 exit status Makefile:2438: recipe for target 'examples/libbitcoin-system-examples' failed make: *** [examples/libbitcoin-system-examples] Error 1 I've secp256k1 library in /usr/local/include/ and headers are stashed at /usr/local/include/include/ Changed the Makefile like below secp256k1_BUILD_CPPFLAGS = -I/usr/local/include/include secp256k1_CFLAGS = -I/usr/local/include/include secp256k1_CPPFLAGS = -I/usr/local/include/include secp256k1_ISYS_CPPFLAGS = -isystem/usr/local/include secp256k1_LIBS = -L/usr/local/lib -lsecp256k1 Any help is much appreciated.
I always recommend using the install.sh script though, which takes care of the required configure option mentioned there.
R
RaGa15:51
Thanks, What do you think the problem I am facing? I really don't wanna install libbitcoin, yet wanna compile source, clearly I am getting linker error
neillm15:52
Looks like you're missing the --enable-module-recovery configure option on secp256k1
👍 1
R
RaGa15:53
I did build libbitcoin/secp256k1 with that switch too
(edited)
neillm15:53
Then it's not being detected in the proper location, or is finding a version without it built
evoskuil15:54
Yup, that’s definitely the issue.
R
RaGa15:54
I did make clean, re configure on both...
neillm15:55
This is a matter of where you installed to, and if it's being detected
evoskuil15:55
Nevertheless, that’s definitely the issue :)
R
RaGa15:55
ok, I will check
neillm15:55
If you add --prefix=/some/dir on both secp256k1 and then do make install and do the same for libbitcoin-system, it should work
Pretty much exactly what install.sh does, but also can provide other missing deps if needed
(edited)
evoskuil15:56
Or just use install.sh :)
R
RaGa15:57
hold on, should I install secp256k1?
(edited)
neillm15:57
It's required by libbitcoin-system, so yes
R
RaGa15:57
that is the part I missed, because I thought it is optional
neillm15:57
Check that link I sent, it's all stated clearly 🙂
R
RaGa15:59
"A minimal libbitcoin build requires boost and libsecp256k1. The libbitcoin/secp256k1 repository is forked from bitcoin-core/secp256k1 in order to control for changes and to incorporate the necessary Visual Studio build. The original repository can be used directly but recent changes to the public interface may cause build breaks. The --enable-module-recovery switch is required."
will install it
R
RaGa16:13
@neillm and @evoskuil Thank you, built successfully!!
And I think under Autotools (advanced users) some wordings like "build and install secp256k1" would be needed, because when I see a dependency libbitcoin/secp256k1, I clicked on it and the followed instruction given in that repo, which is libsecp256k1 is built using autotools: $ ./autogen.sh $ ./configure $ make $ ./tests $ sudo make install # optional
evoskuil16:17
Gotta read the readme.
The requirement for libsecp is very explicitly presented.
R
RaGa16:21
OK

Wednesday, September 11, 2019

N
narodnik12:15
@Mlmikael check your PM
L
is mbetls a new dependency of libbitcoin-protocol?
evoskuil17:44
I believe it’s a conditional dependency, for ssl/tls support.
(edited)
L
dependency of which package? only libbitcoin-protocol? but it is also a part of libbitcoin-system's install.sh
pmienk17:57
I don't believe you're correct. The only reference to mbedtls in -system install.sh is a check against an undefined MBEDTLS_ARCHIVE variable.
not that that's good, MBEDTLS_ARCHIVE should be defined so the check will always fail, but it's not the same as taking a dependency
the things installed by install.sh are listed in the build_all() function
(btw, the check will still always fail, i just don't like undefined references)
L
@pmienk I didn't say mbetls was a dependency of libbitcoin-system :). I just wanted to know which libbitcoin packages need this dependency and that it is present (mentioned) in the install.sh script of libbitcoin-system
@pmienk ok :)
pmienk18:04
well, the question was 'dependency of which package?' But to resolve this, I believe mbedtls was included to facilitate an integrated web server. I believe if it's utilized that would be by -server
L
https://github.com/libbitcoin/libbitcoin-protocol/blob/master/install.sh Script options: # --with-mbedtls Compile with MbedTLS Support
I see
neillm18:07
@pmienk is correct that it's required for SSL support on the server. It's in protocol because that's where the code is used, but server is the user of that.
pmienk18:07
its possible that all functionality could be accomplished at the protocol layer
neillm18:07
If you want to run the server without ssl support, it's not needed
evoskuil18:32
@pmienk I think it’s all in -protocol, but the server install has protocol as a dependency on -protocol, so it is incorporated into the server install. Unless I misunderstand what you meant by “protocol level”.
pmienk18:33
@evoskuil I hadn't seen neil's message and was speculating that all changes were in libbitcoin-protocol
evoskuil18:35
Yeah, should all be in there except inclusion of the full decency graph in the upstream installers.
evoskuil18:40
At least we got rid of the web dependency, with Neill implementing it. I’m planning to rebase it on ASIO, which would greatly simplify it, if I can get my head around it again.
neillm18:42
👍

Friday, September 13, 2019

L
I'm trying to understand the libbitcoin's dependency chain. I will talk about the client stack. Libbitcoin-explorer has libbitcoin-system as a (indirect) dependency, which in turn has another (optional) icu dependency. For this reason I can build libbitcoin-explorer with icu option, it makes sense. Let's say I just want to build only the libbitcoin-network. The libbitcoin-network build (same for protocol and client) doesn't provide the icu option. Do I understand it correctly, that it was meant that way? In other words the libbitcoin-network (as well as protocol and client) doesn't use any icu features of libbitcoin-system and that is the reason I shouldn't build libbitcoin-network with icu option, right? (ICU was just an example, you can replace it with another optional dependency like png).
pmienk18:05
@ldz the install script does not facilitate that option, correct.
@ldz If the resulting library would not be effected by the options presence or absence, I don't believe it's surfaced in the script.
neillm18:41
Yes, that's correct. For ICU in particular, only system and explorer use features from it (optionally). So while there are optional method in -system, -explorer is the only other part of the stack that needs those (also optionally).
While you could have -system installed with ICU support, -network won't use any of those features (at least at the moment).
L
thanks

Saturday, September 21, 2019

evoskuil16:39
I don't expected network would ever use localization features. These are generally restricted to user interface, so bx and supporting functions in system would probably remain the only usage.
pmienk17:34
While network may not use localization, a developer utilizing network may wish to without depending upon explorer. The existing install.sh is not equipped for the development scenario.
evoskuil17:35
Which installer is that, system? The dependency is optional.
pmienk17:35
Network, as it will overwrite any installed system library
evoskuil17:36
There is no requirement to install into as a system library, and it's not recommended.
This same issue holds with all dev tools that install to system. Boost is a good example.
Boost can be installed without ICU support, then taking a dependency on it when it is required causes a failure.
Given the many conditional compilation options of boost it's practically unusable as a system library.
pmienk17:39
If I install to a prefix with the intention of developing a product which requires localization features of libbitcoin-system and libbitcoin-network no install.sh present provides me that functionality without also installing something bigger in the prefix ala libbitcoin-explorer
evoskuil17:40
Are you saying that network should expose the system option to install ICU?
pmienk17:40
Given that our continual refrain is "use the install script", I am solely pointing out that it is insufficient without explaining the need to over-install or use a different procedure
I'm saying that a developer may wish that functionality, while agreeing that a user or the ci system doesn't need that
evoskuil17:41
You are correct that the installer is not intended to create a general purpose dev environment. That can be done by installing the repos independently using conventional methods.
pmienk17:42
Total agreement.
Other use case differences are why I've been maintaining my own developer setup script.
evoskuil17:43
The installer serves four purposes. (1) reliable CI builds, (2) reliable end-user build, (3) reduces support load by demonstrating that the build succeeds, (4) memorializes the various workarounds necessary for developer to succeed.
If we could also provide support for incremental builds (which seems unlikely, given the conditionality of dependencies) and provide reliability against system dependencies (which also seems unlikely given our experience with boost and with ICU) that would be great, but it would seem that manual builds are ideal for experienced developers.
It would be nice to isolate the small number of workarounds we have so that they could be applied more easily in a manual build. The only one that comes to mind is the boost-icu installer bug.
pmienk17:52
The recent pull request by ldz has me again looking at the build project. I may try to expand what I've already done to expose the dependency issues in my own setup after I wrap on the database changes for 157
👍 2
It may also be worth it to put some version of your above mission statement for install.sh in it's help output

Friday, September 27, 2019

E
Edward Boggis-Rolfe08:58
Hi perhaps I am misunderstanding something, looking at elliptic_curve.hpp there is a lot of good stuff about signing, however is it possible to public/private key encrypt and decrypt data with this library too?
E
Edward Boggis-Rolfe09:19
I am planning to use this to transfer keys and small blobs of data, also what is the maximum size that the key can be?
pmienk09:49
All our elliptic curve work uses secp256k1 (https://github.com/bitcoin-core/secp256k1) which I don't believe supports arbitrary encryption of data.
E
Edward Boggis-Rolfe10:56
Thanks I came to that conclusion to that too, I may have to look at the openssl implementation, however I was trying to avoid that, do you know if the two systems are easily compatible when sharing keys?
pmienk18:28
I don't recall anything regarding openssl other than it was a large dependency we wished to avoid.

Sunday, September 29, 2019

N
narodnik14:49
isn't there AES symmetric encryption in libbitcoin?
I think I saw it maybe
He can use that together with symmetric crypto to share the seed
evoskuil23:51
void aes256_encrypt(const aes_secret& key, aes_block& block) void aes256_decrypt(const aes_secret& key, aes_block& block)
evoskuil23:57
encrypted_keys uses these ala BIP38
👍 1

Monday, September 30, 2019

skaht14:02
@evoskuil and @neillm - If libbitcoin bx HD tech is ever enhanced take a quick look at https://github.com/satoshilabs/slips/blob/master/slip-0010.md. The idea is to make BIP 32 to not only implicitly support secp256k1 elliptic curve but to support other cryptographic curves such as ed25519 and p-256. This request was driven by Prusnak’s answer to https://github.com/monero-project/monero/issues/5744
(edited)
ieeexplore.ieee.org
We show how to adapt the Bitcoin BIP32 proposal for deterministic key generation for the Ed25519 curve which has non-linear key space. We also demonstrate