-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parametrize timespan constants. #965
Conversation
src/chain/header.cpp
Outdated
@@ -41,7 +41,7 @@ using wall_clock = std::chrono::system_clock; | |||
//----------------------------------------------------------------------------- | |||
|
|||
header::header() | |||
: header(0, null_hash, null_hash, 0, 0, 0) | |||
: header(0, null_hash, null_hash, 0, 0, 0, settings{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
header::header()
is used by the factory functions below. I added this dummy value such that we can have the discussion here based on the code. I'd fix this by adding a settings
parameter to this constructor and the factory functions. @evoskuil what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, require the parameter until all other repos have been updated, so that you do not end up missing the necessary settings passage. But at that point you can also add a defaulted construction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I have propagated the settings
as a parameter wherever needed. This blew up the PR to some extend. Now, I know what you meant by this refactoring being "pervasive" :) Pushing new version now.
@@ -124,24 +125,26 @@ class BC_API chain_state | |||
}; | |||
|
|||
/// Checkpoints must be ordered by height with greatest at back. | |||
static map get_map(size_t height, const checkpoints& checkpoints, | |||
map get_map(size_t height, const checkpoints& checkpoints, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep this static and parameterize necessary settings (or settings object).
@@ -181,29 +184,29 @@ class BC_API chain_state | |||
|
|||
static activations activation(const data& values, uint32_t forks); | |||
static uint32_t median_time_past(const data& values, uint32_t forks); | |||
static uint32_t work_required(const data& values, uint32_t forks); | |||
uint32_t work_required(const data& values, uint32_t forks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep this static and parameterize necessary settings (or settings object).
src/chain/header.cpp
Outdated
@@ -41,7 +41,7 @@ using wall_clock = std::chrono::system_clock; | |||
//----------------------------------------------------------------------------- | |||
|
|||
header::header() | |||
: header(0, null_hash, null_hash, 0, 0, 0) | |||
: header(0, null_hash, null_hash, 0, 0, 0, settings{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, require the parameter until all other repos have been updated, so that you do not end up missing the necessary settings passage. But at that point you can also add a defaulted construction.
src/chain/header.cpp
Outdated
{ | ||
} | ||
|
||
header::header(uint32_t version, hash_digest&& previous_block_hash, | ||
hash_digest&& merkle, uint32_t timestamp, uint32_t bits, uint32_t nonce) | ||
hash_digest&& merkle, uint32_t timestamp, uint32_t bits, uint32_t nonce, const settings& settings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: honor the 80 character line limit (more above and below).
include/bitcoin/bitcoin/settings.hpp
Outdated
uint32_t work_limit(bool retarget=true) const | ||
{ | ||
return retarget ? retarget_proof_of_work_limit : no_retarget_proof_of_work_limit; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move implementation to cpp.
include/bitcoin/bitcoin/settings.hpp
Outdated
// The target number of blocks for 2 weeks of work (2016 blocks). | ||
size_t retargeting_interval; | ||
|
||
uint32_t work_limit(bool retarget=true) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: move declaration above fields.
include/bitcoin/bitcoin/settings.hpp
Outdated
{ | ||
return retarget ? retarget_proof_of_work_limit : no_retarget_proof_of_work_limit; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: remove blank line.
include/bitcoin/bitcoin/settings.hpp
Outdated
class BC_API settings | ||
{ | ||
|
||
private: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: private after public: https://github.com/libbitcoin/libbitcoin/wiki/Style-Guide#hpp-format
include/bitcoin/bitcoin/settings.hpp
Outdated
/// Common database configuration settings, properties not thread safe. | ||
class BC_API settings | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: remove blank line: https://github.com/libbitcoin/libbitcoin/wiki/Style-Guide#hpp-format
I'm still postponing to fix the tests until I know that the main changes are ok. |
examples/main.cpp
Outdated
@@ -45,7 +45,8 @@ int bc::main(int argc, char* argv[]) | |||
#endif | |||
|
|||
// Extracting Satoshi's words from genesis block. | |||
const auto block = bc::chain::block::genesis_mainnet(); | |||
const auto block = | |||
bc::chain::block::genesis_mainnet(libbitcoin::settings()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use bc::settings()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The genesis block needs to itself become a setting, meaning that genesis_mainnet
will no longer exist. The genesis block will be deserialized from the base16-encoded setting stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the genesis block is on my todo list. I prefer to approach the migration of the constants iteratively. Once this is merged I'd open a new PR where the genesis block becomes a setting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
static uint32_t work_required_retarget(const data& values); | ||
static uint32_t retarget_timespan(const chain_state::data& values); | ||
static uint32_t work_required_retarget(const data& values, | ||
const settings& settings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistency here, pass retarget_proof_of_work_limit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you check the implementation then you can see that actually four values from settings
are used in work_required_retarget()
:
settings.retarget_proof_of_work_limit
settings.min_timespan
settings.max_timespan
settings.target_timespan_seconds
.
I'm happy to pass them individually but my judgement was that they would bloat the function signature. Your call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, these aren't always obvious calls. I've tried for a consistent approach whereby classes are constructed with the the settings object given sufficient use, but functions (including static members) are parameterized so as to avoid a dependency on the setting object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, let's go for consistency here. Will adapt.
src/message/compact_block.cpp
Outdated
} | ||
|
||
bool compact_block::from_data(uint32_t version, reader& source) | ||
bool compact_block::from_data(uint32_t version, reader& source, const settings& settings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: 80 char line length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
See warnings:
|
@evoskuil I was wondering why I didn't see those warnings. Turns out that they are enabled for C only, i.e. they're assigned to |
See the Travis builds for the warnings. |
My point was that the warnings are raised in the Travis builds - they are not limited to C sources. |
gotcha 👍 |
@toxeus The warnings (in fact errors) were the result of field ordering in the header file. Fields are initialized in the header order, not in the order listed in the constructor initializers. I always try to keep these orders the same to avoid this type of failure. The errors were resolved in the most recent build by moving the initialization of these values into the constructor body. There should not be private fields in the settings class. Making these public and matching the declaration order to the initialization order will resolve the issue properly. |
@evoskuil ok, I'm happy to fix the initialization issue the way you've suggested instead of moving it to the constructor body. But what about the build systemt's bug where it doesn't enable warnings for cpp files? Do you prefer me to open an issue for that? |
@toxeus I’m not seeing the issue you are describing. These warnings are in a cpp file. But if you want to open an issue with explanation the libbitcoin-build repository is the best place to do it. Thanks! |
@evoskuil I gave you a curl command to see the issue I'm describing. I'll open an issue in the repo you've suggested. Thanks! |
@toxeus I pointed out above the the warnings do appear in the Travis builds. The specific builds from the curl script did not have the warnings only because you inadvertently resolved them. |
@evoskuil the curl script fetches the logs for the commit where the warnings should have been present. Visit the travis build link and then click on commit. |
@toxeus I already investigated this, which is how I discovered the inadvertent fix. The previous builds do have the warnings. In fact the Travis builds are the only place where I have seen the warnings as I haven’t been building locally. |
@evoskuil Strange. Maybe travis overwrites the logs. |
Just look back at previous builds, the warnings are there in the logs. |
@evoskuil wrote:
Actually, it's not in the previous build but in the next one. Now, I remember how this all came about!
The fix is correct if private member variables are used and the libbitcoin header file style is adhered to. |
Great, thanks for tracking it down. I was only looking at the clang builds. I'll check out the -build issue. |
Time to update the tests and get it passing. |
@evoskuil I've fixed the test. Will start work on the PRs for the other repos. |
{ | ||
} | ||
|
||
uint32_t settings::work_limit(bool retarget) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move this function out of settings and into chain::header (see chain::header::proof). Prob should do that in an independent commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Independent commit as in independent PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evoskuil I've been now looking into moving this function into chain::header as you've suggested. The problem is that it is also used in chain::chain_state where there's no access to a header
object. However, there's a comment which states that bits.self
is unused. If this assignment can be removed then moving work_limit()
becomes trivial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you can set it to zero in that case. Self has no purpose in the context of a pool chain state and when the pool state is upgraded to a block the blocks bits are re-populated.
BOOST_REQUIRE(!instance.from_data(data)); | ||
BOOST_REQUIRE(!instance.is_valid()); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(block__genesis__mainnet__valid_structure) | ||
{ | ||
const auto genesis = bc::chain::block::genesis_mainnet(); | ||
const auto genesis = bc::chain::block::genesis_mainnet(settings()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use consistent style (settings() and settings{}).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My style is very consistent. I always use settings()
except for cases where the vexing parse occurs.
@@ -0,0 +1,55 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add tests for settings class (see other repos).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course! The big refactoring work did distract my attention from the tests.
The constants are parametrized such that libbitcoin can be used by various altcoins by solely editing the config file.
Rebased and fixed conflicts. |
The constants are parametrized such that libbitcoin can be used by various altcoins by solely editing the config file.
Further constants will be parametrized in upcoming pull requests.
As soon as this patch is in a satisfactory state I'll fix the unit tests and will open PRs in other libbitcoin repos to propagate these changes. Please comment.