Skip to content
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

Recalculate work from wallet #1895

Merged
merged 25 commits into from Apr 23, 2019

Conversation

@argakiig
Copy link
Collaborator

commented Apr 11, 2019

replaces #1860

blocks handled by the internal wallets will have work calculated using the active_difficulty if active_difficulty is greater
creates a thread in wallets to track these blocks and the time they were inserted, if they arent confirmed they are re inserted with an updated time.

@argakiig argakiig added this to the V19.0 milestone Apr 11, 2019

@argakiig argakiig requested review from clemahieu, wezrule and SergiySW Apr 11, 2019

@argakiig argakiig self-assigned this Apr 11, 2019

@argakiig argakiig requested a review from cryptocode Apr 11, 2019

@wezrule
Copy link
Collaborator

left a comment

What happens if the difficulty lowers while we are doing a recalculation. When we look to make a transaction, will it still use the stored work we have and if so it will it cancel the current work be generated?

Show resolved Hide resolved nano/lib/utility.cpp Outdated
Show resolved Hide resolved nano/node/wallet.cpp Outdated
Show resolved Hide resolved nano/node/wallet.cpp Outdated
Show resolved Hide resolved nano/node/nodeconfig.cpp Outdated
Show resolved Hide resolved nano/node/nodeconfig.hpp Outdated
Show resolved Hide resolved nano/node/wallet.cpp Outdated
Show resolved Hide resolved nano/node/wallet.cpp Outdated
Show resolved Hide resolved nano/core_test/wallet.cpp Outdated
Show resolved Hide resolved nano/node/wallet.cpp Outdated

@zhyatt zhyatt added this to CP3 (2019-04-10) in V19 Apr 11, 2019

Show resolved Hide resolved nano/node/wallet.cpp Outdated
Show resolved Hide resolved nano/node/wallet.cpp Outdated
Show resolved Hide resolved nano/node/wallet.cpp Outdated

@argakiig argakiig force-pushed the argakiig:recalculate_work_from_wallet branch 2 times, most recently from 97228b2 to 771d5d3 Apr 11, 2019

@argakiig argakiig requested review from wezrule and SergiySW Apr 16, 2019

Show resolved Hide resolved nano/lib/utility.cpp Outdated

argakiig added some commits Apr 10, 2019

Function to update work of block if below difficulty otherwise return…
… same block

Test to update difficulty if below active_difficulty
work recalc config option default 4 sec or 1/4 of announcement period
code cleanup and moving around
created thread to handle work regeneration
based on user configurable input
update election winner if hashes match
only recalc work if considered online, peer stake is greater than delta or min conf
Update nodeconfig.cpp
formatting

@argakiig argakiig force-pushed the argakiig:recalculate_work_from_wallet branch from e347555 to 7330f41 Apr 16, 2019

formatting and test cleanup
test was reworked block is generated and started to be processed
block is added to difficulty_reque
updated logic to handle test network
Show resolved Hide resolved nano/node/wallet.cpp Outdated
Show resolved Hide resolved nano/node/wallet.cpp Outdated
Show resolved Hide resolved nano/node/wallet.cpp Outdated
Show resolved Hide resolved nano/node/wallet.cpp Outdated
@SergiySW
Copy link
Collaborator

left a comment

Looking good, considering @cryptocode review changes

@SergiySW

This comment has been minimized.

Copy link
Collaborator

commented Apr 18, 2019

P.S. I guess for RC2 we may need to add some metrics to delay recalculation during network spam

argakiig added some commits Apr 20, 2019

update work action properly handles open blocks
do work regeneration drops junk blocks
make active_difficulty thread safe
pass lock into update_active_difficulty
missed active_difficulty reference from making threadsafe
moved transaction in do_work_regeneration outside loop to reuse
check active and ledger for confirmation multiple times
Show resolved Hide resolved nano/core_test/wallet.cpp Outdated
Show resolved Hide resolved nano/node/wallet.cpp Outdated

argakiig added some commits Apr 22, 2019

remove lock in test
repeat code to lambda
rename atomic_active_difficulty to properly reflect purpose
also should be fine as uint64_t since protected with mutex

argakiig and others added some commits Apr 22, 2019

In place of UB of mutex.try_lock(), check that we own the lock argume…
…nt and also the mutex matches the mutex we expect to be locked. This is the expected behavior.

Store a mapping of qualified_root -> state_block since we only regenerate work for state_blocks and saves some type checking and complexity.
The absence of the qualified_root in active_transactions indicates the block has been confirmed or it was a fork that was rejected, either way we don't need to generate more work for it, we don't need a different way to check if it's confirmed.
Remove items from generated_blocks before we iterate over it so we don't have to modify the container while iterating.
Fixed an issue where we were modifying a container while iterating over it with multimap::erase
Moving forward declarations to beginning of namespace declaration so they're all in one place.
Separating work_watcher from wallets since its sufficiently complex i.e. has its own mutex and condition variable.
Constify a lot of functions that aren't labeled as such but are.
update test
only evict block if we can ensure blocks are confirmed

@argakiig argakiig merged commit 67c3ef8 into nanocurrency:master Apr 23, 2019

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.