POC Porter implementation for /get_treasure_map, /publish_treasure_map, and /get_ursulas (unaffected by TMapConKFrags work)#2717
Conversation
|
For NOTE: the list of Ursulas returned will vary every time the following is run so other values need to be modified eg. include/exclude lists. Federated Example
In [1]: import requests
In [2]: payload = {"bob_encrypting_key": "026d1f4ce5b2474e0dae499d6737a8d987ed3c9ab1a55e00f57ad2d8e81fe9e9ac", "treasure_map_id": "f6ec73c93084ce91d5542a4ba6070071f5565112fe19b26ae9c960f9d658903a"}
In [3]: r = requests.get("http://localhost:9155/get_treasure_map", json=payload)
# no treasure map available since not published as yet
In [5]: r.text
Out[5]: 'Asked 12 nodes, but none had map f6ec73c93084ce91d5542a4ba6070071f5565112fe19b26ae9c960f9d658903a'
In [6]: r
Out[6]: <Response [500]>
# publish treasure map
In [7]: payload_publish = {"bob_encrypting_key": "026d1f4ce5b2474e0dae499d6737a8d987ed3c9ab1a55e00f57ad2d8e81fe9e9ac", "treasure_map": "Qld7S8sbKFCv2B8KxfJo4oxiTOjZ4VPyqTK5K1xK6DND6TbLg2hvlGaMV69aiiC5QfadB82w/5q1Sw+SNFHN2esWgAbs38QuUVUGCzDoWzQAAAGIAuhw12ZiPMNV8LaeWV8uUN+au2HGOjWilqtKsaP9fmnLAzFiTUAu9/VCxOLOQE88BPoWk1H7OxRLDEhnBVYyflpifKbOYItwLLTtWYVFRY90LtNSAzS8d3vNH4c3SHSZwYsCKY+5LvJ68GD0CqhydSxCcGckh0unttHrYGSOQsURUI4AAAEBsSMlukjA1WyYA+FouqkuRtk8bVHcYLqRUkK2n6dShEUGMuY1SzcAbBINvJYmQp+hhzK5m47AzCl463emXepYZQC/evytktG7yXxd3k8Ak+Qr7T4+G2VgJl4YrafTpIT6wowd+8u/SMSrrf/M41OhtLeBC4uDKjO3rYBQfVLTpEAgiX/9jxB80RtNMeCwgcieviAR5tlw2IlxVTEhxXbFeopcOZmfEuhVWqgBUfIakqsNCXkkubV0XS2l5G1vtTM8oNML0rP8PyKd4+0M5N6P/EQqFkHH93LCDD0IQBq9usm3MoJp0eT8N3m5gprI05drDh2xe/W6qnQfw3YXnjdvf2A="}
In [8]: r_pub = requests.post("http://localhost:9155/publish_treasure_map", json=payload_publish)
In [9]: r_pub
Out[9]: <Response [200]>
In [10]: r_pub.json()
Out[10]: {'result': {}, 'version': '5.2.0'}
# now that it is published try getting it again
In [11]: r = requests.get("http://localhost:9155/get_treasure_map", json=payload)
In [12]: r
Out[12]: <Response [200]>
In [13]: r.json()
Out[13]:
{'result': {'treasure_map': 'Qld7S8sbKFCv2B8KxfJo4oxiTOjZ4VPyqTK5K1xK6DND6TbLg2hvlGaMV69aiiC5QfadB82w/5q1Sw+SNFHN2esWgAbs38QuUVUGCzDoWzQAAAGIAuhw12ZiPMNV8LaeWV8uUN+au2HGOjWilqtKsaP9fmnLAzFiTUAu9/VCxOLOQE88BPoWk1H7OxRLDEhnBVYyflpifKbOYItwLLTtWYVFRY90LtNSAzS8d3vNH4c3SHSZwYsCKY+5LvJ68GD0CqhydSxCcGckh0unttHrYGSOQsURUI4AAAEBsSMlukjA1WyYA+FouqkuRtk8bVHcYLqRUkK2n6dShEUGMuY1SzcAbBINvJYmQp+hhzK5m47AzCl463emXepYZQC/evytktG7yXxd3k8Ak+Qr7T4+G2VgJl4YrafTpIT6wowd+8u/SMSrrf/M41OhtLeBC4uDKjO3rYBQfVLTpEAgiX/9jxB80RtNMeCwgcieviAR5tlw2IlxVTEhxXbFeopcOZmfEuhVWqgBUfIakqsNCXkkubV0XS2l5G1vtTM8oNML0rP8PyKd4+0M5N6P/EQqFkHH93LCDD0IQBq9usm3MoJp0eT8N3m5gprI05drDh2xe/W6qnQfw3YXnjdvf2A='},
'version': '5.2.0'} |
/get_treasure_map and /publish_treasure_map/get_treasure_map, /publish_treasure_map, and /get_ursulas
/get_treasure_map, /publish_treasure_map, and /get_ursulas/get_treasure_map, /publish_treasure_map, and /get_ursulas
|
For NOTE: the list of Ursulas returned will vary every time the following is run so other values need to be modified eg. include/exclude lists. Federated Example
In [1]: import requests
In [2]: payload = {"quantity": 5, "duration_periods": 4}
In [3]: r = requests.get("http://localhost:9155/get_ursulas", json=payload)
In [4]: r
Out[4]: <Response [200]>
In [5]: r.content
Out[5]: b'{"result": {"ursulas": [{"encrypting_key": "03440a4c53bd8a215334694ff9e262bff2bdd015afb9b00e3bb60341b220166198", "checksum_address": "0xee94Bdb476510F447D2697A821E159CbcC7Db3d9", "ip_address": "https://127.0.0.1:11507"}, {"encrypting_key": "0341b821ad2e7fc814ccecc770d66ac67fc116f8ca01f0a077010498e408b485db", "checksum_address": "0x39Dbe2270780aaB9d20a8E58f62d441851AB96cD", "ip_address": "https://127.0.0.1:11511"}, {"encrypting_key": "026d9a993e37370d135867bd8c8108e7533def19e70ff26b7127cf2ad8bf3c5674", "checksum_address": "0x519A5EF6c5f66527d6888caf1221f52d64eD7C34", "ip_address": "https://127.0.0.1:11504"}, {"encrypting_key": "026ddd7ed9f8b7e649ad2f0a994894332688421cd64bb7eabdc506ec1ead48aa71", "checksum_address": "0x226f652aE5BD2A07097085729b7109EF62D16388", "ip_address": "https://127.0.0.1:11509"}, {"encrypting_key": "03add66a40607f44525aeed31e9c8979601704e3aba23d1e6378d89dffc5262eca", "checksum_address": "0x2b49d8a024CEc7e5E4D1fB953624ADEa9308ca9F", "ip_address": "https://127.0.0.1:11500"}]}, "version": "5.2.0"}'
In [6]: include_ursulas = ["0x7b5D8E3ADf81F53c815B731295E4677D28137935", "0x519A5EF6c5f66527d6888caf1221f52d64eD7C34"]
In [7]: payload["include_ursulas"] = include_ursulas
In [8]: r = requests.get("http://localhost:9155/get_ursulas", json=payload)
In [9]: r
Out[9]: <Response [200]>
In [10]: r.content
Out[10]: b'{"result": {"ursulas": [{"encrypting_key": "02f1999d954d88745ce9f4f9b8e7348e0a8ccda05711d14e5dc206bd272bdf0493", "checksum_address": "0x64FaCbb9AD35f1E5f6aAd2Dc5f626f3A38E2247f", "ip_address": "https://127.0.0.1:11501"}, {"encrypting_key": "021bad03835961be222e7d6b9ea161a2ba902545e8a796528308dad19f073dbf45", "checksum_address": "0x41f5f375521259E8377775DEEE045E5F6eA3fC35", "ip_address": "https://127.0.0.1:11510"}, {"encrypting_key": "026d9a993e37370d135867bd8c8108e7533def19e70ff26b7127cf2ad8bf3c5674", "checksum_address": "0x519A5EF6c5f66527d6888caf1221f52d64eD7C34", "ip_address": "https://127.0.0.1:11504"}, {"encrypting_key": "030fa280e84ff8c2e10b63bc32d1f4bb487beb98a8e8949a756f254c97f2052982", "checksum_address": "0x7b5D8E3ADf81F53c815B731295E4677D28137935", "ip_address": "https://127.0.0.1:11506"}, {"encrypting_key": "03ee7b66057b75f97f8b7ea51d0c2bfb5ab3838ef66a3c1c4dfe4014a0dd9d59a0", "checksum_address": "0x1f31F8F2988f1313c4B36CE211E708c946c66fee", "ip_address": "https://127.0.0.1:11505"}]}, "version": "5.2.0"}'
In [11]: exclude_ursulas = ["0x1f31F8F2988f1313c4B36CE211E708c946c66fee", "0x64FaCbb9AD35f1E5f6aAd2Dc5f626f3A38E2247f", "0x8fEE90e395a47cfB3f4e8ce96306337B701A6ca8", "0x39Dbe2270780aaB9d20a8E58f62d441851AB96cD"]
In [12]: payload["exclude_ursulas"] = exclude_ursulas
In [13]: r = requests.get("http://localhost:9155/get_ursulas", json=payload)
In [14]: r
Out[14]: <Response [200]>
In [15]: r.content
Out[15]: b'{"result": {"ursulas": [{"encrypting_key": "026d9a993e37370d135867bd8c8108e7533def19e70ff26b7127cf2ad8bf3c5674", "checksum_address": "0x519A5EF6c5f66527d6888caf1221f52d64eD7C34", "ip_address": "https://127.0.0.1:11504"}, {"encrypting_key": "0350d0ec52ffa63691d4a71748b0e5a6fe7c8aa751bedb8873c52ad43684b51fa0", "checksum_address": "0x538D64a582C8a3A6A2b8480c5e4c231b85B747f9", "ip_address": "https://127.0.0.1:11508"}, {"encrypting_key": "030fa280e84ff8c2e10b63bc32d1f4bb487beb98a8e8949a756f254c97f2052982", "checksum_address": "0x7b5D8E3ADf81F53c815B731295E4677D28137935", "ip_address": "https://127.0.0.1:11506"}, {"encrypting_key": "020faf809b76ef4ee45ced7929f0d7697aed958e39327d31ceb7275dbe9307e751", "checksum_address": "0x14c1c069216e2b1Fd7aB41f7e21a6d9dc9D631Bc", "ip_address": "https://127.0.0.1:11503"}, {"encrypting_key": "026ddd7ed9f8b7e649ad2f0a994894332688421cd64bb7eabdc506ec1ead48aa71", "checksum_address": "0x226f652aE5BD2A07097085729b7109EF62D16388", "ip_address": "https://127.0.0.1:11509"}]}, "version": "5.2.0"}'
In [16]: r = requests.get("http://localhost:9155/get_ursulas", json=payload)
In [17]: r
Out[17]: <Response [200]>
In [18]: r.content
Out[18]: b'{"result": {"ursulas": [{"encrypting_key": "0350d0ec52ffa63691d4a71748b0e5a6fe7c8aa751bedb8873c52ad43684b51fa0", "checksum_address": "0x538D64a582C8a3A6A2b8480c5e4c231b85B747f9", "ip_address": "https://127.0.0.1:11508"}, {"encrypting_key": "026ddd7ed9f8b7e649ad2f0a994894332688421cd64bb7eabdc506ec1ead48aa71", "checksum_address": "0x226f652aE5BD2A07097085729b7109EF62D16388", "ip_address": "https://127.0.0.1:11509"}, {"encrypting_key": "030fa280e84ff8c2e10b63bc32d1f4bb487beb98a8e8949a756f254c97f2052982", "checksum_address": "0x7b5D8E3ADf81F53c815B731295E4677D28137935", "ip_address": "https://127.0.0.1:11506"}, {"encrypting_key": "026d9a993e37370d135867bd8c8108e7533def19e70ff26b7127cf2ad8bf3c5674", "checksum_address": "0x519A5EF6c5f66527d6888caf1221f52d64eD7C34", "ip_address": "https://127.0.0.1:11504"}, {"encrypting_key": "020faf809b76ef4ee45ced7929f0d7697aed958e39327d31ceb7275dbe9307e751", "checksum_address": "0x14c1c069216e2b1Fd7aB41f7e21a6d9dc9D631Bc", "ip_address": "https://127.0.0.1:11503"}]}, "version": "5.2.0"}'Decentralized Example
In [1]: import requests
In [2]: payload = {"quantity": 5, "duration_periods": 4}
In [3]: r = requests.get("http://localhost:9155/get_ursulas", json=payload)
In [4]: r
Out[4]: <Response [200]>
In [5]: r.content
Out[5]: b'{"result": {"ursulas": [{"encrypting_key": "025a335eca37edce8191d43c156e7bc6b451b21e5258759966bbfe0e6ce44543cb", "checksum_address": "0x5cF1703A1c99A4b42Eb056535840e93118177232", "ip_address": "https://3.236.144.36:9151"}, {"encrypting_key": "02b0a0099ee180b531b4937bd7446972296447b2479ca6259cb6357ed98b90da3a", "checksum_address": "0x7fff551249D223f723557a96a0e1a469C79cC934", "ip_address": "https://54.218.83.166:9151"}, {"encrypting_key": "02761c765e2f101df39a5f680f3943d0d993ef9576de8a3e0e5fbc040d6f8c15a5", "checksum_address": "0x9C7C824239D3159327024459Ad69bB215859Bd25", "ip_address": "https://92.53.84.156:9151"}, {"encrypting_key": "0258b7c79fe73f3499de91dd5a5341387184035d0555b10e6ac762d211a39684c0", "checksum_address": "0x9919C9f5CbBAA42CB3bEA153E14E16F85fEA5b5D", "ip_address": "https://3.36.66.164:9151"}, {"encrypting_key": "02e43a623c24db4f62565f82b6081044c1968277edfdca494a81c8fd0826e0adf6", "checksum_address": "0xfBeb3368735B3F0A65d1F1E02bf1d188bb5F5BE6", "ip_address": "https://128.199.124.254:9151"}]}, "version": "5.2.0"}'
In [6]: include_ursulas = ["0x5cF1703A1c99A4b42Eb056535840e93118177232", "0x7fff551249D223f723557a96a0e1a469C79cC934"]
In [7]: payload["include_ursulas"] = include_ursulas
In [8]: r = requests.get("http://localhost:9155/get_ursulas", json=payload)
In [9]: r
Out[9]: <Response [200]>
In [10]: r.content
Out[10]: b'{"result": {"ursulas": [{"encrypting_key": "030b29c5bbcba278a962e76cbb0f404b74ef8c50892dd33664a24c8b079369fa41", "checksum_address": "0xCef1B4Bf8F05F623A2A688b56d9dA679D302EBa7", "ip_address": "https://54.39.181.135:9151"}, {"encrypting_key": "039397a359f537a34e72859c55563ea224433ecfb02bf030da46485197868e66fc", "checksum_address": "0x02D4Fe8f98129F578fb2e160404033B8e4627A36", "ip_address": "https://54.39.190.30:9151"}, {"encrypting_key": "025a335eca37edce8191d43c156e7bc6b451b21e5258759966bbfe0e6ce44543cb", "checksum_address": "0x5cF1703A1c99A4b42Eb056535840e93118177232", "ip_address": "https://3.236.144.36:9151"}, {"encrypting_key": "02b0a0099ee180b531b4937bd7446972296447b2479ca6259cb6357ed98b90da3a", "checksum_address": "0x7fff551249D223f723557a96a0e1a469C79cC934", "ip_address": "https://54.218.83.166:9151"}, {"encrypting_key": "0389b7552f5724bd831cb7dc3d2e8ba8389575b52d544d2b091a8a65dbeffa287e", "checksum_address": "0xB04FcDF9327f65AB0107Ea95b78BB200C07FA752", "ip_address": "https://18.210.24.63:9151"}]}, "version": "5.2.0"}'
In [11]: exclude_ursulas = ["0xB04FcDF9327f65AB0107Ea95b78BB200C07FA752", "0xCef1B4Bf8F05F623A2A688b56d9dA679D302EBa7", "0x02D4Fe8f98129F578fb2e160404033B8e4627A36", "0x9C7C824239D3159327024459Ad69bB215859Bd25", "0x9919C9f5CbBAA42CB3bEA153E14E16F85fEA5b5D", "0xfBeb3368735B3F0A65d1F1E02bf1d188bb5F5BE6"]
In [12]: payload['exclude_ursulas'] = exclude_ursulas
In [13]: r = requests.get("http://localhost:9155/get_ursulas", json=payload)
In [14]: r
Out[14]: <Response [200]>
In [15]: r.content
Out[15]: b'{"result": {"ursulas": [{"encrypting_key": "025a335eca37edce8191d43c156e7bc6b451b21e5258759966bbfe0e6ce44543cb", "checksum_address": "0x5cF1703A1c99A4b42Eb056535840e93118177232", "ip_address": "https://3.236.144.36:9151"}, {"encrypting_key": "02b0a0099ee180b531b4937bd7446972296447b2479ca6259cb6357ed98b90da3a", "checksum_address": "0x7fff551249D223f723557a96a0e1a469C79cC934", "ip_address": "https://54.218.83.166:9151"}, {"encrypting_key": "030b41e643823db37ca98f69362e8665dc2b7dbfa3aa412993665795afcecc2d9b", "checksum_address": "0xbdA6Ba3Ad624582495C55451A1840e563fc16389", "ip_address": "https://34.209.206.31:9151"}, {"encrypting_key": "029efc301b857e184da14fcb29b55d8a38bf28d906763c811cc641b4c916fd423b", "checksum_address": "0x93EC08943257DC1abeFb46875C7AAF92aeE0ecC6", "ip_address": "https://44.235.74.191:9151"}, {"encrypting_key": "02921281b5b0ca222a9bf5e5c6d6525381677b7ed429e2deab79eb245b6461a472", "checksum_address": "0x42D2875a71Cb25DDcF05Dbed55490cB905498Bac", "ip_address": "https://13.212.162.22:9151"}]}, "version": "5.2.0"}'
In [16]: r = requests.get("http://localhost:9155/get_ursulas", json=payload)
In [17]: r
Out[17]: <Response [200]>
In [18]: r.content
Out[18]: b'{"result": {"ursulas": [{"encrypting_key": "025a335eca37edce8191d43c156e7bc6b451b21e5258759966bbfe0e6ce44543cb", "checksum_address": "0x5cF1703A1c99A4b42Eb056535840e93118177232", "ip_address": "https://3.236.144.36:9151"}, {"encrypting_key": "02f80e41b8269c4a57a8b8dfb3787746fcea620883e5a0a09b2c8c89cae4488bc1", "checksum_address": "0xFb626333099A91Ab677BCd5e9C71bc4Dbe0238a8", "ip_address": "https://34.209.70.116:9151"}, {"encrypting_key": "02b0a0099ee180b531b4937bd7446972296447b2479ca6259cb6357ed98b90da3a", "checksum_address": "0x7fff551249D223f723557a96a0e1a469C79cC934", "ip_address": "https://54.218.83.166:9151"}, {"encrypting_key": "029efc301b857e184da14fcb29b55d8a38bf28d906763c811cc641b4c916fd423b", "checksum_address": "0x93EC08943257DC1abeFb46875C7AAF92aeE0ecC6", "ip_address": "https://44.235.74.191:9151"}, {"encrypting_key": "027bb2220dfd1f9d02c0ccf973678b9d811806daf0e6e4439c253854746c393c77", "checksum_address": "0xb011b6794F271B1d8D2328eDf332535343CB4D44", "ip_address": "https://138.197.186.215:9151"}]}, "version": "5.2.0"}' |
/get_treasure_map, /publish_treasure_map, and /get_ursulas/get_treasure_map, /publish_treasure_map, and /get_ursulas
/get_treasure_map, /publish_treasure_map, and /get_ursulas/get_treasure_map, /publish_treasure_map, and /get_ursulas (unaffected by TMapConKFrags work)
…publish_treasure_map for Porter. Added federated functionality to Porter.
Remove unused 'publish_treasure_map' parameter from _enact() function. Loosen validation on treasure map id which can be 32 bytes (federated) or 16 bytes (non-federated). Probably only care about non-federated but for ease of testing, federated really helps.
…or federated mode (not changed for rest api).
Added rpc and web control tests for porter.
…th to be specified.
nucypher/utilities/porter/control/specifications/fields/treasuremapid.py
Outdated
Show resolved
Hide resolved
nucypher/utilities/porter/control/specifications/fields/treasuremapid.py
Outdated
Show resolved
Hide resolved
… map id length. Co-authored-by: David Núñez <david@nucypher.com>
KPrasch
left a comment
There was a problem hiding this comment.
This is the meant and potatoes of Porter, nice work. There's also some excellent code reorg in here that introduces a higher degree of testability. Still looking it over, but left a few comments and questions while I get my head around this somewhat large changeset.
nucypher/characters/control/specifications/fields/treasuremap.py
Outdated
Show resolved
Hide resolved
nucypher/characters/lawful.py
Outdated
| return map_id | ||
|
|
||
| def get_treasure_map_from_known_ursulas(self, network_middleware, map_identifier, timeout=3): | ||
| def get_treasure_map_from_known_ursulas(self, map_identifier, timeout=3): |
There was a problem hiding this comment.
This method is intentionally name shadowing the one on the treasure map? Also, let's get some type annotations in here.
There was a problem hiding this comment.
I wanted to keep the calls into this original function in Bob the same and then pass through the call to the common function in treasuremap.py. It felt ok, since the function is on Bob, and Bob's encrypting key is needed anyway. Who better to pass it than Bob himself, and original callers don't have to worry about getting the encryption key themselves.
The function in treasuremap.py has the same name but can be changed if desired.
| bob_enc_key = UmbralPublicKey.from_bytes(bob_encrypting_key) | ||
| treasure_map = self.implementer.get_treasure_map(map_identifier=treasure_map_id, | ||
| bob_encrypting_key=bob_enc_key) | ||
| response_data = {'treasure_map': treasure_map} |
There was a problem hiding this comment.
Might be good to include a dummy versioning field local to the map here in anticipation of map versioning introduced in PR #2687.
There was a problem hiding this comment.
Perhaps I'll wait for that to be fleshed out and address it in a different PR. Without fully understanding what's in there now, presumably the version is in the treasuremap itself, and the version may not matter with respect to obtaining it via Porter.
nucypher/utilities/porter/control/specifications/fields/treasuremapid.py
Show resolved
Hide resolved
| You should have received a copy of the GNU Affero General Public License | ||
| along with nucypher. If not, see <https://www.gnu.org/licenses/>. | ||
| """ | ||
| from constant_sorrow.constants import NO_CONTROL_PROTOCOL |
There was a problem hiding this comment.
Porter living inside a utilities module is short-selling it's greatness, and a case in favor of moving to a separate repo IMO (while I still do greatly appreciate the benefits of a unified CI).
There was a problem hiding this comment.
@derekpierre and I talked about this a while ago and we agreed that a separate repo is indeed a potential outcome. We also discussed the difficulties that we've seen with nucypher-monitor living in a separate repo in terms of synchronization. I'd personally lean towards keeping it inside the same repo, potentially relocated to a more prominent namespace.
There was a problem hiding this comment.
Definitely pros and cons that are up for debate, but something we can address in a separate PR.
… treasure maps provided as bytes in the `/publish_treasure_map` endpoint. The context information is provided either at construction time of the TreasureMap field, or via the parent Schema context.
Type of PR:
Required reviews:
Issues fixed/closed:
Related to #2703, #2704.
Why it's needed:
Simple POC implementation for Porter functions
/get_treasure_map(Bob),/publish_treasure_map(Alice), and/get_ursulas(Alice) that are unaffected by the work to be completed for TMapConKFrags.Outstanding questions for reviewers:
NotStakingwasn't caught before when trying to get a treasure map from nodes? I added it to the refactored common code here - https://github.com/derekpierre/nucypher/blob/porter-impl/nucypher/characters/utils.py#L56