:: Re: [Libbitcoin] Master libbitcoin-…
Top Page
Delete this message
Reply to this message
Author: Eric Voskuil
Date:  
To: Police Terror, libbitcoin
Subject: Re: [Libbitcoin] Master libbitcoin-server on testnet
On 10/21/2016 07:36 AM, Police Terror wrote:
> Looking at libbitcoin/src/utility/random.cpp, I see that
> nonzero_pseudo_random() is throwing. Why isn't that an assert instead?


(1) In a !NDEBUG build the assert would not execute. The result would
have to be either a zero value return, other (fixed) value or an
infinite loop - any of which is catostrophic. A failure return could be
allowed, but it would push the hard failure out to each caller, creating
failure-handling complexity without any means to resolve the failure
(except calling again, which is where we are with the loop).

(2) In a DEBUG build the result is the same as the throw, it terminates
the process.

Asserts are useful for checking developer assumptions, but are not
useful in validating inputs from public interfaces or resolving
unrecoverable failures.

> terminate called after throwing an instance of 'std::runtime_error'
> what(): random_device::random_device(const std::string&)


It does look like the error is being handled exactly as intended. If the
RNG returns a value of zero 100 times in a row, the only thing one can
do is try longer. The question is why this is happening. My best guess
is lack of thread safety. Otherwise you might want to inspect your
platform for "enhancements" :).

e

> https://github.com/libbitcoin/libbitcoin/blob/master/src/utility/random.cpp#L46
>
> Here is the backtrace:
>
> #9  libbitcoin::pseudo_random () at src/utility/random.cpp:39
> #10 0x00007ffff5a3d48d in libbitcoin::network::hosts::fetch
> (this=this@entry=0x657310,
>     out=...) at src/collections/hosts.cpp:76
> #11 0x00007ffff5a27e7a in
> libbitcoin::network::p2p::fetch_address(std::function<void
> (std::error_code const&, libbitcoin::message::network_address const&)>)
> const (this=0x656ad0,
>     handler=...) at src/p2p.cpp:430
> #12 0x00007ffff5a5ae5f in
> libbitcoin::network::session::fetch_address(std::function<void
> (std::error_code const&, libbitcoin::config::authority const&)>) const (
>     this=this@entry=0x7fff280d6330, handler=...) at
> src/sessions/session.cpp:83
> #13 0x00007ffff5a6064e in
> libbitcoin::network::session_batch::new_connect(std::shared_ptr<libbitcoin::network::connector>,
> std::function<void (std::error_code const&,
> std::shared_ptr<libbitcoin::network::channel>)>)
> (this=this@entry=0x7fff280d6330,
>     connect=std::shared_ptr (count 115, weak 1) 0x7ffef03f5760, handler=...)
>     at src/sessions/session_batch.cpp:70
> #14 0x00007ffff5a60b53 in
> libbitcoin::network::session_batch::connect(std::shared_ptr<libbitcoin::network::connector>,
> std::function<void (std::error_code const&,
> std::shared_ptr<libbitcoin::network::channel>)>) (this=0x7fff280d6330,
>     connect=std::shared_ptr (count 115, weak 1) 0x7ffef03f5760, handler=...)
>     at src/sessions/session_batch.cpp:56
> #15 0x00007ffff5a6f335 in
> libbitcoin::network::session_outbound::new_connection (
>     this=this@entry=0x7fff280d6330,
>     connect=std::shared_ptr (count 115, weak 1) 0x7ffef03f5760)
>     at src/sessions/session_outbound.cpp:87
> #16 0x00007ffff5a6f7d1 in
> libbitcoin::network::session_outbound::handle_connect (
>     this=0x7fff280d6330, ec=..., channel=...,
>     connect=std::shared_ptr (count 115, weak 1) 0x7ffef03f5760)
>     at src/sessions/session_outbound.cpp:97