-
Notifications
You must be signed in to change notification settings - Fork 378
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
Prepare publishing of blinded balance proofs #3452
Prepare publishing of blinded balance proofs #3452
Conversation
12bd0f5
to
f6aff08
Compare
This is still missing recovery at startup -- see #3454 |
One more comment: ideally publishing to the monitoring service would block further processing of the channel until the message was sent(received). The idea behind that is, that monitoring is needed for safety, and therefore the channel's protocol should not proceed until monitoring was successfully requested (note: current MS design does not give any feedback on a request). |
The question is what form of feedback would make sense since there should ideally be many monitoring services watching the broadcast channel. |
Codecov Report
@@ Coverage Diff @@
## master #3452 +/- ##
==========================================
+ Coverage 76.3% 76.44% +0.14%
==========================================
Files 102 102
Lines 13207 13257 +50
Branches 1855 1865 +10
==========================================
+ Hits 10077 10134 +57
+ Misses 2471 2465 -6
+ Partials 659 658 -1
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #3452 +/- ##
==========================================
+ Coverage 76.49% 76.53% +0.04%
==========================================
Files 103 103
Lines 13318 13366 +48
Branches 1881 1891 +10
==========================================
+ Hits 10187 10230 +43
- Misses 2472 2474 +2
- Partials 659 662 +3
Continue to review full report at Codecov.
|
This PR is probably the wrong place to discuss this. Nevertheless: In a long term view, I could see MS's publishing some batched "acknowledged balance_hashes" to the same room every once in a while (tbd.). Since MS's will compete in QoS, clients would whitelist some MS addresses and wait for N ack's before proceeding. |
10de2b2
to
c7d901b
Compare
raiden/transfer/architecture.py
Outdated
# Assuming, there is no transition None->new balance proof: | ||
if not hasattr(old_state, 'identifiers_to_paymentnetworks'): | ||
return | ||
for old_payment_network_identifier, current_payment_network_identifier in zip( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this works as you expect, identifiers_to_paymentnetworks
are dictionaries, and iterating over them returns the dict keys in order of insertion (python 3.6+):
>>> d = {1:1, 2:2}
>>> d2 = {2:2, 1:1}
>>> list(zip(d, d2))
[(1, 2), (2, 1)]
Which for all purposes is undefined at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is getting the new balance proofs, it just needs to get the keys from current_state.identifiers_to_paymentnetworks
, if there is no corresponding key in old_state.identifiers_to_paymentnetworks
then we know all BPs are new.
raiden/transfer/architecture.py
Outdated
if old_state == current_state: | ||
return | ||
# Assuming, there is no transition None->new balance proof: | ||
if not hasattr(old_state, 'identifiers_to_paymentnetworks'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking if the attribute exists is not sufficient, you should check if it's not None
, getattr(.., .., None)
is probably best here.
raiden/transfer/architecture.py
Outdated
@@ -272,6 +295,66 @@ def dispatch(self, state_change: StateChange) -> List[Event]: | |||
|
|||
return events | |||
|
|||
def detect_balance_proof_change(self, old_state, current_state): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, move this to the views module and add types
raiden/transfer/architecture.py
Outdated
self.current_state, | ||
iteration.new_state, | ||
): | ||
iteration.events.append(EventNewBalanceProofReceived(balance_proof)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no place for this logic, the state manager does all it needs to do already. You can just call detect_balance_proof_change
after a state change is processed.
e8c6ea1
to
417b4ba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks good to me (only made minor comments). But mostly, it's lacking a test which makes sure that the chain-state diff works. Could you please add a test for this?
def __init__(self, balance_proof): | ||
self.balance_proof = balance_proof | ||
|
||
def to_dict(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add return type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
@classmethod | ||
def from_dict(cls, data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data
param type and return type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
d31d30d
to
7dd2691
Compare
raiden/utils/typing.py
Outdated
T_EventNewBalanceProofReceived = TypeVar( | ||
'T_EventNewBalanceProofReceived', | ||
bound='raiden.transfer.mediated_transfer.events.EventNewBalanceProofReceived', | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please follow the conversation at #3374 (comment) and 69831a8
def from_dict( | ||
cls: Type[T_EventNewBalanceProofReceived], | ||
data: Dict, | ||
) -> T_EventNewBalanceProofReceived: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why you had to declare a type for this. The type would be EventNewBalanceProofReceived
, no need to declare yet another one in typing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please follow the conversation at #3374 (comment) and 69831a8
tldr; class is not available inside class definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of our other events / state changes / states declare this. Otherwise we would have lots of types. Please follow the same convention used in other events in the same file.
def __init__(self, balance_proof: BalanceProofSignedState) -> None: | ||
self.balance_proof = balance_proof | ||
|
||
def to_dict(self) -> Dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dict[str, Any]
class EventNewBalanceProofReceived(Event): | ||
""" Event for newly received balance proofs. Useful for notifying monitoring services. """ | ||
|
||
def __init__(self, balance_proof: BalanceProofSignedState) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for -> None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
@classmethod | ||
def from_dict( | ||
cls: Type[T_EventNewBalanceProofReceived], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't give a type for cls
and self
.
7dd2691
to
1430580
Compare
This event will be emitted when there are any newly received (and processed) balance proofs.
This adds an integration test that ensures that messages for EventNewBalanceProofReceived will create global messages from RaidenMonitoringEventHandler. Note: the special event handler needs to be enabled for this to work.
The previous implementation was short, but hard to read. This now uses a more explicit state traversal.
`make_room_alias` moved in the meantime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
changes were addressed and @rakanalh approved
This is progress towards #3273
The PR adds the necessary pieces to publish blinded balance proofs to the global matrix room
monitoring
.In particular:
EventNewBalanceProofReceived
StateManager.dispatch
method, and injects the new eventstransport.send_global
calls in theRaidenMonitoringEventHandler
EventNewBalanceProofReceived
totest_mediated_transfer_events
happy caseIt also changes the matrix transport behavior for
send_global
: previouslysend_global
would raiseAssertionError
, if a room target was not set up beforehand. Now the target room will be joined automatically. This is meant to avoid the overhead of checking for the room existence in sending code, or catching the Assertion. If this last change is contentious, we could add a non-assertingis_global_room_available(room_name)
method instead.