Skip to content

Use nonce ranges#287

Merged
LefterisJP merged 9 commits into
raiden-network:masterfrom
czepluch:use_nonce_ranges
Dec 21, 2016
Merged

Use nonce ranges#287
LefterisJP merged 9 commits into
raiden-network:masterfrom
czepluch:use_nonce_ranges

Conversation

@czepluch

Copy link
Copy Markdown
Contributor

This PR adds nonce ranges to the netting channels. This makes sure that once #191 allows for channels to be reopened, the same transfers cannot be used again.

Tests for reopening a channel and for nonce ranges have also been added, but they are marked as xfail until #191 is done.

With this PR I believe that #39 can be closed

Comment thread raiden/channel.py Outdated

# use nonce ranges
self.our_state.nonce = our_state.nonce * (external_state.opened_block * (2 ** 32))
self.partner_state.nonce = partner_state.nonce * (external_state.opened_block * (2 ** 32))

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.

IMHO these statements should be part of ChannelEndState constructor, and then we can move the nonce initialization to the assetmanager.py

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.

Do you have an argument for why this would be preferred?

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 constructor is the place to initialize an object, without passing nonce in the constructor we end up with a object improperly initialized (eg. it will produce the wrong behavior)


@pytest.mark.xfail
def test_reopen_channel(tester_state, tester_channelmanager, tester_channels, settle_timeout,
netting_channel_abi):

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, one argument per line :)

@hackaugusto

Copy link
Copy Markdown
Contributor

Do we need to merge first #191 and then #287 or it doesnt matter?

@czepluch

Copy link
Copy Markdown
Contributor Author

@hackaugusto It doesn't really do anything before #191 is merged, but this could be merged without #191. I believe I could get #191 ready pretty fast with a temporary fix until #232 is ready.

I will make the changes from your comments.

address2 = tester.a2

# We need to close the channel before it can be deleted, to do so we need
# one transfer to call closeSingleTransfer(0

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.

typo here: closeSingleTransfer(0 -> closeSingleTransfer()

)
tester_state.mine(number_of_blocks=settle_timeout + 1)

# delete the channel needs to update the manager's 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.

delete -> deleting


tester_state.mine(1)

# now a single new channel can be open

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.

open -> opened

@czepluch

Copy link
Copy Markdown
Contributor Author

Whoops. Introduced some errors with last commit. Looking into fixing them.

@czepluch czepluch added this to the MVP milestone Dec 19, 2016
Comment thread raiden/channel.py Outdated
# 0 is used in the netting contract to represent the lack of a
# transfer, so this value must start at 1
if isinstance(get_block_number, int):
# if get_block_number == 0:

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 don't leave commented code inside a commit. Amend the commit and remove it.

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.

Removed with latest commit. Please approve when checks are done.

@LefterisJP LefterisJP modified the milestones: Sprint 1, MVP Dec 20, 2016
Comment thread raiden/assetmanager.py Outdated
our_state = ChannelEndState(
channel_details['our_address'],
channel_details['our_balance'],
self.raiden.chain.block_number,

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 believe this should be the opened block instead of the current block.

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.

This was already done when you reviewed this, no? At least it's done in my latest commit from before you made the comment.

Comment thread raiden/channel.py Outdated
@@ -282,7 +282,7 @@ def __init__(self, participant_address, participant_balance):
# sequential nonce, current value has not been used.
# 0 is used in the netting contract to represent the lack of a
# transfer, so this value must start at 1

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.

we should update this comment.

, so this value must start at 1

to something like:

the nonce value must inside netting channel allowed range that is defined in terms of the opened block

Comment thread raiden/channel.py Outdated
# do not call settle if already settled, the event polling
# might be lagging behind.
# do not call settle if already settled, the settle_event might
# not be set if the LogListener is lagging behind.

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.

Vim fucked up somehow and did update the file correctly when fetching. So these lines are included in the commit, but I didn't write them.

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.

Then amend the commit, delete them, and force push in your branch.

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.

Cool. I didn't know the --amend command before now. The other times you've said amend the commit, I thought it was meant literally.

@LefterisJP LefterisJP Dec 21, 2016

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.

argh I see! That's why you had so many commits in other times. Good to see you know it now. Generally a lot of small commits is nice but not too many. If you just append something to a previous commit you should generally amend it and force push (only if it's your own feature branch ofcourse)

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.

3 participants