Skip to content

Commit

Permalink
Change RouteMetadata hash generation to canonicaljsonipy
Browse files Browse the repository at this point in the history
  • Loading branch information
ezdac committed Mar 25, 2021
1 parent 047af95 commit 13d363e
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 22 deletions.
18 changes: 11 additions & 7 deletions raiden/messages/metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass, field

import canonicaljson
import rlp
from eth_utils import keccak

Expand All @@ -24,13 +25,16 @@ class RouteMetadata:

@cached_property
def hash(self) -> bytes:
return keccak(self._rlp_serialize())

def _rlp_serialize(self) -> bytes:
return rlp.encode(
primitive_dict_to_nested_lists(
{"route": self.route, "address_metadata": self.address_metadata}
)
return keccak(self._serialize_canonicaljson())

def _serialize_canonicaljson(self) -> bytes:
route = [to_checksum_address(address) for address in self.route]
address_metadata = {
to_checksum_address(address): metadata
for address, metadata in self.address_metadata.items()
}
return canonicaljson.encode_canonical_json(
{"route": route, "address_metadata": address_metadata}
)

def __repr__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion raiden/tests/unit/serialized_messages/Delivered.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"delivered_message_identifier": "14089154938208861744",
"signature": "0x60672e5edb3b5684e74ac8c80d9e9715885e211a47fd638fd56fa8ffc7d0f8f7231066bf7a5896fde817b0d87704149f7b3053fa6b39aeea0ef17a50798d77fc1c",
"type": "Delivered"
}
}
2 changes: 1 addition & 1 deletion raiden/tests/unit/serialized_messages/LockExpired.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"token_network_address": "0x6e6574776f726b6e6574776f726b6e6574776f72",
"transferred_amount": "50",
"type": "LockExpired"
}
}
4 changes: 2 additions & 2 deletions raiden/tests/unit/serialized_messages/LockedTransfer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"nonce": "1",
"payment_identifier": "1",
"recipient": "0x7461726765747461726765747461726765747461",
"signature": "0xd6e5f4412d26aa3acca7277defeada0f1937ca5ab981ed504becc6b1cdca6b784a799f1647cb146745c1042b7b0ff2d5f95942f85ebf0bf07edb4f700ea2c8001c",
"signature": "0x997d411457b6f883d6e38c1c4c991eaae59e1f7cb7e64b251652d6c4dafb15363bc444ea2ece7418225349a28d3844f8d46b039799f2b00b365d2c9ddf9f26cf1b",
"target": "0x7461726765747461726765747461726765747461",
"token": "0x746f6b656e746f6b656e746f6b656e746f6b656e",
"token_network_address": "0x6e6574776f726b6e6574776f726b6e6574776f72",
"transferred_amount": "0",
"type": "LockedTransfer"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"updating_capacity": "83157032281535436592742485053875373772344953078307910801568052349361129029306",
"updating_nonce": "17118534853349346795",
"updating_participant": "0x383960255b4c58242a20366c4340207c2a794a3b"
}
}
2 changes: 1 addition & 1 deletion raiden/tests/unit/serialized_messages/PFSFeeUpdate.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"timestamp": "2000-01-01T00:00:00",
"type": "PFSFeeUpdate",
"updating_participant": "0x4e473d79783f3e7676372e2e6d49533a602a3e25"
}
}
2 changes: 1 addition & 1 deletion raiden/tests/unit/serialized_messages/Processed.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"message_identifier": "17841880388872081916",
"signature": "0x7cde765d5815eb67fd4e2b798f212580d487f051f05433058674490d225e43ca16a8d32d2e7d5a5dff3f136961c0c47790d97cbbdcecefbf8dd909cbb94fd3611c",
"type": "Processed"
}
}
2 changes: 1 addition & 1 deletion raiden/tests/unit/serialized_messages/RefundTransfer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
"token_network_address": "0x6e6574776f726b6e6574776f726b6e6574776f72",
"transferred_amount": "0",
"type": "RefundTransfer"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"reward_amount": "97425888683892750587945680783138836924292540737961888655734476399742293263563",
"signature": "0x80014a840660dbe04b3c67401c8e1ef1b9475a17f1560519e17e6b91e88fdcc9514c0348f3feeba527d35c4ea320117b301471dfb99cba549570cb0358e71ae31b",
"type": "RequestMonitoring"
}
}
2 changes: 1 addition & 1 deletion raiden/tests/unit/serialized_messages/RevealSecret.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"secret": "0x202467250c2a7153375a4b2b29702351214a52493027283c3b47572f33743e6d",
"signature": "0x195dbf16fce68b5513c960a9cb7849bba7607e77c0f402438c86966a33b0ea1d30c9a701c1e1c366cc6c8c0801f869d645570c8d61dd69d2b657077591b9ffc31b",
"type": "RevealSecret"
}
}
2 changes: 1 addition & 1 deletion raiden/tests/unit/serialized_messages/SecretRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"secrethash": "0x5b3d533720436772364439394443096b522b7767312a342e722b576c0c7b3c24",
"signature": "0x85042a09b9c3d3ac951b88650d4429b42b7ff77aa4a3f2f504ef8faf3fa61d4d47c73b606b64b1355329de2a2c6a65162965418afad38d7a567c4dc14a4f65161c",
"type": "SecretRequest"
}
}
2 changes: 1 addition & 1 deletion raiden/tests/unit/serialized_messages/Unlock.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"token_network_address": "0x6e6574776f726b6e6574776f726b6e6574776f72",
"transferred_amount": "50",
"type": "Unlock"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"token_network_address": "0x7c5c76770c385e5654297728552757314f486c78",
"total_withdraw": "43030000375053848483360010892688128125882955220842751483463799296695399817914",
"type": "WithdrawConfirmation"
}
}
2 changes: 1 addition & 1 deletion raiden/tests/unit/serialized_messages/WithdrawExpired.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"token_network_address": "0x6d4169287079442d0a775e566c284a2152660b71",
"total_withdraw": "81389322072213456958274814836804202981957383964284380743558564309315106239433",
"type": "WithdrawExpired"
}
}
2 changes: 1 addition & 1 deletion raiden/tests/unit/serialized_messages/WithdrawRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"token_network_address": "0x2b2765577a643542313b5c31625165356f752e52",
"total_withdraw": "35585354725113231262395347697090524356626150773896569326961510485817666774489",
"type": "WithdrawRequest"
}
}
1 change: 1 addition & 0 deletions raiden/tests/unit/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def test_message_identical() -> None:
# # pretty print for more readable diffs
# json_msg = json.dumps(json.loads(json_msg), indent=4, sort_keys=True)
# f.write(json_msg)
# f.write('\n')

with open(filename) as f:
saved_message_dict = JSONSerializer.deserialize(f.read())
Expand Down

0 comments on commit 13d363e

Please sign in to comment.