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 2894 #2895

Merged
merged 4 commits into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Changelog
=========

* :bug:`2894` Raiden will no longer miss confirmation blocks at restart and will emit the block state change only for confirmed blocks.
* :feature:`2857` Respect the ``--environment-type`` for private chain setup.
* :feature:`2858` Changed contract address argument names to be consistent with the names of the contracts in the contracts repository.

Expand Down
7 changes: 4 additions & 3 deletions raiden/raiden_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ def _callback_new_block(self, latest_block):
latest_block_number = latest_block['number']
confirmation_blocks = self.config['blockchain']['confirmation_blocks']
confirmed_block_number = latest_block_number - confirmation_blocks
confirmed_block = self.chain.client.web3.eth.getBlock(confirmed_block_number)

# handle testing private chains
confirmed_block_number = max(GENESIS_BLOCK_NUMBER, confirmed_block_number)
Expand All @@ -550,9 +551,9 @@ def _callback_new_block(self, latest_block):
# been processed but the Block state change has not been
# dispatched.
state_change = Block(
block_number=latest_block_number,
gas_limit=latest_block['gasLimit'],
block_hash=bytes(latest_block['hash']),
block_number=confirmed_block_number,
gas_limit=confirmed_block['gasLimit'],
block_hash=bytes(confirmed_block['hash']),
)
self.handle_state_change(state_change)

Expand Down
3 changes: 2 additions & 1 deletion raiden/tests/integration/api/test_pythonapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from raiden.api.python import RaidenAPI
from raiden.exceptions import DepositMismatch, UnknownTokenAddress
from raiden.settings import DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS
from raiden.tests.utils.events import must_contain_entry
from raiden.tests.utils.geth import wait_until_block
from raiden.tests.utils.transfer import get_channelstate
Expand Down Expand Up @@ -159,7 +160,7 @@ def test_channel_lifecycle(raiden_network, token_addresses, deposit, transport_c
channel12.settle_timeout +
10 # arbitrary number of additional blocks, used to wait for the settle() call
)
wait_until_block(node1.raiden.chain, settlement_block)
wait_until_block(node1.raiden.chain, settlement_block + DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS)

state_changes = node1.raiden.wal.storage.get_statechanges_by_identifier(
from_identifier=0,
Expand Down
7 changes: 6 additions & 1 deletion raiden/tests/integration/test_integration_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from raiden.constants import GENESIS_BLOCK_NUMBER
from raiden.network.blockchain_service import BlockChainService
from raiden.settings import DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS
from raiden.tests.utils.events import must_have_event
from raiden.tests.utils.geth import wait_until_block
from raiden.tests.utils.network import CHAIN
Expand Down Expand Up @@ -538,7 +539,11 @@ def test_secret_revealed(raiden_chain, deposit, settle_timeout, token_addresses)
channel_state2_1.partner_state.balance_proof,
)

settle_expiration = app0.raiden.chain.block_number() + settle_timeout
settle_expiration = (
app0.raiden.chain.block_number() +
settle_timeout +
DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS
)
wait_until_block(app0.raiden.chain, settle_expiration)

assert_synced_channel_state(
Expand Down
34 changes: 34 additions & 0 deletions raiden/tests/integration/test_service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import pytest

from raiden.messages import Ping
from raiden.settings import DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS
from raiden.tests.utils.events import must_contain_entry
from raiden.tests.utils.geth import wait_until_block
from raiden.transfer import state, views
from raiden.transfer.state_change import Block


@pytest.mark.parametrize('number_of_nodes', [2])
Expand Down Expand Up @@ -57,3 +61,33 @@ def test_udp_ping_pong_unreachable_node(raiden_network, skip_if_not_udp):
app1.raiden.address,
)
assert network_state is state.NODE_NETWORK_UNREACHABLE


@pytest.mark.parametrize('number_of_nodes', [1])
@pytest.mark.parametrize('channels_per_node', [0])
@pytest.mark.parametrize('number_of_tokens', [1])
def test_raiden_service_callback_new_block(raiden_network):
""" Regression test for: https://github.com/raiden-network/raiden/issues/2894 """
app0 = raiden_network[0]

app0.raiden.alarm.stop()
target_block_num = app0.raiden.chain.block_number() + DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS + 1
wait_until_block(
app0.raiden.chain,
target_block_num,
)

latest_block = app0.raiden.chain.get_block(block_identifier='latest')
app0.raiden._callback_new_block(latest_block=latest_block)

app0_state_changes = app0.raiden.wal.storage.get_statechanges_by_identifier(
from_identifier=0,
to_identifier='latest',
)

assert must_contain_entry(app0_state_changes, Block, {
'block_number': target_block_num - DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS,
})
assert not must_contain_entry(app0_state_changes, Block, {
'block_number': latest_block['number'],
})