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

Fix bug settled channel #512

Merged
merged 6 commits into from
Aug 9, 2019

Conversation

palango
Copy link
Contributor

@palango palango commented Aug 9, 2019

The problem was that we changed the last_known_block in the Context from an independent value towards a a property returning the value of latest_known_block of BlockchainState, which is only updated when all events for a given block range are processed.

This led to the following condition to always be False.

settle_period_end_block = event.block_number + channel.settle_timeout
    settle_period_over = settle_period_end_block < context.latest_confirmed_block
    if not settle_period_over:
       ....

This in turn let the MS to try to send an update to the blockchain for a closed channel.

We have tests for that behavior, however we wrongly updated the BlockchainState as well, which led to the tests not catching this.

This also includes some cleanups I did while fixing the bug.
Fixes #511

The problem was that we changed the `last_known_block` in the `Context`
from an independent value towards a a property returning the value of
`latest_known_block` of `BlockchainState`, which is only updated when
all events for a given block range are processed.

This led to the following condition to always be `False`.
```py
settle_period_end_block = event.block_number + channel.settle_timeout
    settle_period_over = settle_period_end_block < context.latest_confirmed_block
    if not settle_period_over:
       ...
```

This in turn let the MS to try to send an update to the blockchain for a
closed channel.

We have tests for that behavior, however we wrongly updated the
`BlockchainState` as well, which led to the tests not catching this.
In `monitor` and `claim` we don't convert to hex addresses either.
- Add some type annotations
- reorder some functions
- Rename some variables
@palango palango requested a review from karlb August 9, 2019 11:45
@codecov
Copy link

codecov bot commented Aug 9, 2019

Codecov Report

Merging #512 into master will increase coverage by 0.1%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #512     +/-   ##
=========================================
+ Coverage   91.21%   91.31%   +0.1%     
=========================================
  Files          36       36             
  Lines        2255     2258      +3     
  Branches      287      287             
=========================================
+ Hits         2057     2062      +5     
+ Misses        149      148      -1     
+ Partials       49       48      -1
Impacted Files Coverage Δ
src/monitoring_service/service.py 90% <100%> (ø) ⬆️
src/pathfinding_service/service.py 91.84% <100%> (ø) ⬆️
src/raiden_libs/database.py 91.3% <100%> (+2.89%) ⬆️
src/raiden_libs/states.py 100% <100%> (ø) ⬆️
src/raiden_libs/blockchain.py 96.05% <100%> (ø) ⬆️
src/monitoring_service/handlers.py 85.85% <100%> (+0.21%) ⬆️
src/monitoring_service/database.py 100% <100%> (ø) ⬆️
src/pathfinding_service/database.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d495279...7f1f326. Read the comment docs.

@@ -41,16 +41,23 @@
class Context:
ms_state: MonitoringServiceState
db: Database
w3: Web3
web3: Web3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rename is something I also wanted to do for a while.

src/monitoring_service/handlers.py Show resolved Hide resolved
@karlb
Copy link
Contributor

karlb commented Aug 9, 2019

I relied to much an the tests when doing the change. Can you suggest a new test to catch this?

@palango
Copy link
Contributor Author

palango commented Aug 9, 2019

I relied to much an the tests when doing the change. Can you suggest a new test to catch this?

Yeah, so if I undo the change at https://github.com/raiden-network/raiden-services/pull/512/files#diff-6d7bdd065a1e0f2407c94540508e8707R123 then actually the test test_channel_closed_event_handler_ignores_existing_channel_after_timeout fails. It was unlucky that we changed the committed block at the same time.

That's why I chose not to add more tests, but we could do something like test_first_allowed_monitoring with a settled channel.

@karlb
Copy link
Contributor

karlb commented Aug 9, 2019

Yeah, so if I undo the change at https://github.com/raiden-network/raiden-services/pull/512/files#diff-6d7bdd065a1e0f2407c94540508e8707R123 then actually the test test_channel_closed_event_handler_ignores_existing_channel_after_timeout fails. It was unlucky that we changed the committed block at the same time.

OK, that's a really unlucky case. Then the tests are probably fine as they are.

@palango palango merged commit de562c2 into raiden-network:master Aug 9, 2019
@palango palango deleted the fix-bug-settled-channel branch August 9, 2019 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could not identify the intended function with name firstBlockAllowedToMonitor
2 participants