Skip to content

Channel Withdraw#4130

Merged
rakanalh merged 52 commits into
raiden-network:developfrom
rakanalh:withdraw
Jun 12, 2019
Merged

Channel Withdraw#4130
rakanalh merged 52 commits into
raiden-network:developfrom
rakanalh:withdraw

Conversation

@rakanalh
Copy link
Copy Markdown
Contributor

@rakanalh rakanalh commented May 23, 2019

Resolves #1498

TODO

  • Rework proxy
  • Use contracts utils to fetch GAS_REQUIRED_FOR_WITHDRAW
  • Make Withdraw a confirmation for WithdrawRequest instead of relying on Processed
  • Lint errors
  • Unit tests
  • Add asserts on the balance in integration test_channel_withdraw
  • Add rest API integration test

Comment thread raiden/transfer/architecture.py Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2019

Codecov Report

Merging #4130 into develop will increase coverage by 0.24%.
The diff coverage is 86.02%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4130      +/-   ##
===========================================
+ Coverage    80.92%   81.16%   +0.24%     
===========================================
  Files          101      102       +1     
  Lines        12923    13366     +443     
  Branches      1983     2055      +72     
===========================================
+ Hits         10458    10849     +391     
- Misses        1869     1913      +44     
- Partials       596      604       +8
Impacted Files Coverage Δ
raiden/storage/serialization/types.py 68.18% <ø> (ø) ⬆️
raiden/exceptions.py 97.53% <100%> (+0.06%) ⬆️
raiden/transfer/token_network.py 98.38% <100%> (+1.29%) ⬆️
raiden/raiden_service.py 87.89% <100%> (+0.92%) ⬆️
raiden/message_handler.py 96.22% <100%> (+0.62%) ⬆️
raiden/utils/packing.py 100% <100%> (ø)
raiden/api/v1/encoding.py 91.32% <100%> (+0.03%) ⬆️
raiden/transfer/state.py 91.21% <100%> (+0.07%) ⬆️
raiden/network/proxies/payment_channel.py 86.48% <100%> (+0.37%) ⬆️
raiden/raiden_event_handler.py 86.59% <100%> (+1.25%) ⬆️
... and 31 more

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 316ca00...10b694c. Read the comment docs.

@rakanalh rakanalh marked this pull request as ready for review June 3, 2019 13:18
rakanalh added 6 commits June 6, 2019 12:54
This is done because we have introduced the WithdrawRequest and
Withdraw messages which need to be processed deterministicly and in
the order in which they were sent. This provides guarantees that a
certain withdraw request / confirmation will be validated according to
the latest balance proof previous to the withdraw message nonce
Also fixed typing and lint issues after rebase
@rakanalh rakanalh requested a review from hackaugusto June 7, 2019 12:28
Comment thread raiden/message_handler.py
Comment thread raiden/network/proxies/token_network.py Outdated
Comment thread raiden/network/proxies/token_network.py Outdated
Comment thread raiden/network/proxies/token_network.py Outdated
Comment thread raiden/network/proxies/token_network.py Outdated
Comment thread raiden/network/proxies/token_network.py Outdated
Copy link
Copy Markdown
Contributor

@konradkonrad konradkonrad left a comment

Choose a reason for hiding this comment

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

not fully through, but posting for visibility of comments. will continue from raiden/transfer/node.py

Comment thread raiden/network/proxies/token_network.py Outdated
Comment thread raiden/network/proxies/token_network.py Outdated
Comment thread raiden/network/proxies/token_network.py Outdated
Comment thread raiden/raiden_event_handler.py Outdated
Comment thread raiden/storage/sqlite.py Outdated
Comment thread raiden/transfer/channel.py
Comment thread raiden/transfer/channel.py Outdated
Comment thread raiden/transfer/channel.py Outdated
Comment thread raiden/transfer/channel.py Outdated
Comment thread raiden/transfer/events.py Outdated
Comment thread raiden/utils/packing.py Outdated
Comment thread raiden/utils/packing.py Outdated
Comment thread raiden/waiting.py
rakanalh added 3 commits June 12, 2019 10:45
Removed the part which mentions exception propagation which doesn't
really happen in the state machine.
Comment thread raiden/api/python.py Outdated
Comment thread raiden/transfer/node.py Outdated
Copy link
Copy Markdown
Contributor

@konradkonrad konradkonrad left a comment

Choose a reason for hiding this comment

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

some docstrings still need fixes, other than that LGTM!

@rakanalh rakanalh merged commit 3f1a78a into raiden-network:develop Jun 12, 2019
@rakanalh rakanalh deleted the withdraw branch June 12, 2019 12:21
Comment thread raiden/transfer/channel.py Outdated
Comment thread raiden/transfer/channel.py Outdated
block_hash = data["block_hash"]
channel_identifier = args["channel_identifier"]
token_network_address = event.originating_contract
participant = to_canonical_address(args["participant"])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please, implement the sandwich encoding, values should be converted from external representation to internal at the boundaries. In this case the address should be decode at decode_event_to_internal.

)
raiden.handle_and_track_state_change(withdraw_statechange)

chain_state = views.state_from_raiden(raiden)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is a race condition here, there is no synchronization among handle_and_track_state_change and state_from_raiden.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looking at the other blockchain event handlers, they all look pretty much the same so am not sure what i missed and what you mean by synchronisation? if i think i know what you're thinking, then that's something for another PR :)

Comment thread raiden/messages.py
channel_identifier: ChannelID
participant: Address
total_withdraw: WithdrawAmount
nonce: Nonce
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should have an ADR explaining why withdraw messages have a nonce.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

😱 😱 😱 😱 😱 😱

if not merkletree:
return None, None

nonce = get_next_nonce(sender_end_state)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this would be better at events_for_expired_lock (Which would be better named as send_expired_lock)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will change the name of the function. But the other part of your comment is to generate a new nonce and pass it as a parameter? Thats contradicts what we're doing in create_sendlockedtransfer so i am not sure i want to do that.

lock = transfer.lock
channel_state.our_state.balance_proof = transfer.balance_proof
channel_state.our_state.merkletree = merkletree
channel_state.our_state.nonce = transfer.balance_proof.nonce
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes the update in create unnecessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's no update. create_sendlockedtransfer only generates a new nonce but doesn't set it to the state. We only set the nonce here.

assert merkletree, "create_sendexpiredlock should return both message and merkle tree"
channel_state.our_state.merkletree = merkletree
channel_state.our_state.balance_proof = send_lock_expired.balance_proof
channel_state.our_state.nonce = send_lock_expired.balance_proof.nonce
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes the update in create unnecessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's no update, only generate

return TransitionResult(channel_state, events)


def handle_receive_withdraw(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe this should also have the _confirmation postfix?

else:
end_state = channel_state.partner_state

end_state.total_withdraw = state_change.total_withdraw
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not correct. E.g.:

  • A requests withdraw from B with total_withdraw=10
  • B confirms withdraw for A with total_withdraw=10
  • A sends withdraw to the chain
  • A requests withdraw from B with total_withdraw=20
  • The transaction for the first withdraw is confirmed, this will overwrite the total_withdraw
  • B confirms the total_withdraw=20, A will wrongly reject

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The value confirmed on-chain and the value request off-chain must be separated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, the value has to increase, if the value is lower it should be ignored.

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.

Implement channel withdraw logic for setTotalWithdraw

3 participants