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

Refactor ping pong encrypted example #1007

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

plebhash
Copy link
Collaborator

@plebhash plebhash commented Jun 26, 2024

similarly to #977, this PR is refactoring the examples/ping-pong-with-noise example into examples/ping-pong-encrypted.

I wrote it from scratch as an exercise to get familiar with protocols crates.

The overall idea is quite similar to the previous implementation, but with some simplifications to make the example easier to understand.


ping-pong-encrypted is an example of how to do encrypted SV2 traffic while leveraging the following crates:

We establish a simple Ping-Pong protocol with a server and a client communicating over a TCP socket.

The server expects to receive a Ping message encoded as a SV2 binary frame.
The Ping message contains a nonce, which is a u8 generated randomly by the client.

The client expects to get a Pong message in response, also encoded as a SV2 binary frame, with the same nonce.

The messages are assigned arbitrary values for binary encoding:

pub const PING_MSG_TYPE: u8 = 0xfe;
pub const PONG_MSG_TYPE: u8 = 0xff;

All communication is encrypted with SV2 Noise Protocol.

@plebhash plebhash force-pushed the refactor-ping-pong-encrypted branch from 56af371 to d228ec2 Compare June 26, 2024 20:34
Copy link
Contributor

github-actions bot commented Jun 26, 2024

🐰Bencher

ReportSun, July 28, 2024 at 20:36:18 UTC
ProjectStratum v2 (SRI)
Branchrefactor-ping-pong-encrypted
Testbedsv2
Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns) | (Δ%)
Latency Upper Boundary
nanoseconds (ns) | (%)
client_sv2_handle_message_common✅ (view plot)44.87 (+0.69%)45.25 (99.16%)
client_sv2_handle_message_mining✅ (view plot)74.78 (+2.61%)80.41 (93.00%)
client_sv2_mining_message_submit_standard✅ (view plot)14.66 (+0.04%)14.69 (99.78%)
client_sv2_mining_message_submit_standard_serialize✅ (view plot)270.91 (+2.37%)284.44 (95.24%)
client_sv2_mining_message_submit_standard_serialize_deserialize✅ (view plot)599.18 (+0.80%)627.97 (95.42%)
client_sv2_open_channel✅ (view plot)168.47 (+1.48%)173.54 (97.08%)
client_sv2_open_channel_serialize✅ (view plot)274.99 (-2.82%)293.43 (93.72%)
client_sv2_open_channel_serialize_deserialize✅ (view plot)377.55 (-0.21%)423.91 (89.06%)
client_sv2_setup_connection✅ (view plot)171.04 (+4.12%)175.19 (97.63%)
client_sv2_setup_connection_serialize✅ (view plot)451.86 (-4.65%)506.78 (89.16%)
client_sv2_setup_connection_serialize_deserialize✅ (view plot)966.76 (-0.45%)1,039.00 (93.05%)

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

Copy link
Contributor

github-actions bot commented Jun 26, 2024

🐰Bencher

ReportSun, July 28, 2024 at 20:36:27 UTC
ProjectStratum v2 (SRI)
Branchrefactor-ping-pong-encrypted
Testbedsv2

🚨 11 ALERTS: Threshold Boundary Limits exceeded!
BenchmarkMeasure (units)ViewValueLower BoundaryUpper Boundary
client_sv2_mining_message_submit_standardL2 Accesses (accesses)🚨 (view plot | view alert)26.00 (+47.32%)23.31 (111.55%)
client_sv2_mining_message_submit_standard_serializeL2 Accesses (accesses)🚨 (view plot | view alert)55.00 (+15.97%)52.78 (104.21%)
client_sv2_mining_message_submit_standard_serialize_deserializeInstructions (instructions)🚨 (view plot | view alert)10,585.00 (+0.40%)10,567.30 (100.17%)
client_sv2_mining_message_submit_standard_serialize_deserializeL1 Accesses (accesses)🚨 (view plot | view alert)15,400.00 (+0.38%)15,373.90 (100.17%)
client_sv2_mining_message_submit_standard_serialize_deserializeL2 Accesses (accesses)🚨 (view plot | view alert)90.00 (+7.36%)89.73 (100.30%)
client_sv2_open_channel_serialize_deserializeInstructions (instructions)🚨 (view plot | view alert)8,027.00 (+0.53%)8,009.69 (100.22%)
client_sv2_open_channel_serialize_deserializeL1 Accesses (accesses)🚨 (view plot | view alert)11,673.00 (+0.50%)11,648.71 (100.21%)
client_sv2_open_channel_serialize_deserializeL2 Accesses (accesses)🚨 (view plot | view alert)84.00 (+14.29%)82.57 (101.73%)
client_sv2_setup_connectionL2 Accesses (accesses)🚨 (view plot | view alert)15.00 (+63.31%)13.96 (107.42%)
client_sv2_setup_connection_serialize_deserializeInstructions (instructions)🚨 (view plot | view alert)14,855.00 (+0.29%)14,837.01 (100.12%)
client_sv2_setup_connection_serialize_deserializeL1 Accesses (accesses)🚨 (view plot | view alert)21,812.00 (+0.28%)21,785.52 (100.12%)

Click to view all benchmark results
BenchmarkEstimated CyclesEstimated Cycles Results
estimated cycles | (Δ%)
Estimated Cycles Upper Boundary
estimated cycles | (%)
InstructionsInstructions Results
instructions | (Δ%)
Instructions Upper Boundary
instructions | (%)
L1 AccessesL1 Accesses Results
accesses | (Δ%)
L1 Accesses Upper Boundary
accesses | (%)
L2 AccessesL2 Accesses Results
accesses | (Δ%)
L2 Accesses Upper Boundary
accesses | (%)
RAM AccessesRAM Accesses Results
accesses | (Δ%)
RAM Accesses Upper Boundary
accesses | (%)
client_sv2_handle_message_common✅ (view plot)2,077.00 (+1.32%)2,127.28 (97.64%)✅ (view plot)473.00 (+0.49%)486.40 (97.25%)✅ (view plot)732.00 (-0.02%)755.23 (96.92%)✅ (view plot)10.00 (+42.86%)10.89 (91.86%)✅ (view plot)37.00 (+0.96%)38.56 (95.97%)
client_sv2_handle_message_mining✅ (view plot)8,219.00 (+0.27%)8,336.65 (98.59%)✅ (view plot)2,137.00 (+0.46%)2,171.37 (98.42%)✅ (view plot)3,159.00 (+0.46%)3,216.13 (98.22%)✅ (view plot)39.00 (+1.20%)43.61 (89.43%)✅ (view plot)139.00 (+0.11%)141.98 (97.90%)
client_sv2_mining_message_submit_standard✅ (view plot)6,282.00 (+0.10%)6,388.45 (98.33%)✅ (view plot)1,750.00 (+0.03%)1,763.19 (99.25%)✅ (view plot)2,547.00 (-0.26%)2,575.91 (98.88%)🚨 (view plot | view alert)26.00 (+47.32%)23.31 (111.55%)✅ (view plot)103.00 (-0.78%)106.90 (96.35%)
client_sv2_mining_message_submit_standard_serialize✅ (view plot)14,623.00 (-1.01%)15,034.91 (97.26%)✅ (view plot)4,694.00 (+0.01%)4,707.19 (99.72%)✅ (view plot)6,753.00 (-0.02%)6,775.28 (99.67%)🚨 (view plot | view alert)55.00 (+15.97%)52.78 (104.21%)✅ (view plot)217.00 (-2.39%)230.03 (94.33%)
client_sv2_mining_message_submit_standard_serialize_deserialize✅ (view plot)27,435.00 (-0.15%)27,843.64 (98.53%)🚨 (view plot | view alert)10,585.00 (+0.40%)10,567.30 (100.17%)🚨 (view plot | view alert)15,400.00 (+0.38%)15,373.90 (100.17%)🚨 (view plot | view alert)90.00 (+7.36%)89.73 (100.30%)✅ (view plot)331.00 (-1.12%)345.31 (95.86%)
client_sv2_open_channel✅ (view plot)4,417.00 (-1.64%)4,611.35 (95.79%)✅ (view plot)1,461.00 (+0.06%)1,474.45 (99.09%)✅ (view plot)2,157.00 (+0.20%)2,173.04 (99.26%)✅ (view plot)11.00 (-8.05%)15.23 (72.23%)✅ (view plot)63.00 (-3.21%)68.19 (92.39%)
client_sv2_open_channel_serialize✅ (view plot)14,006.00 (-1.46%)14,464.68 (96.83%)✅ (view plot)5,064.00 (+0.02%)5,077.45 (99.74%)✅ (view plot)7,321.00 (+0.04%)7,339.34 (99.75%)✅ (view plot)42.00 (+12.44%)42.27 (99.37%)✅ (view plot)185.00 (-3.49%)199.03 (92.95%)
client_sv2_open_channel_serialize_deserialize✅ (view plot)22,523.00 (-0.51%)23,023.79 (97.82%)🚨 (view plot | view alert)8,027.00 (+0.53%)8,009.69 (100.22%)🚨 (view plot | view alert)11,673.00 (+0.50%)11,648.71 (100.21%)🚨 (view plot | view alert)84.00 (+14.29%)82.57 (101.73%)✅ (view plot)298.00 (-2.12%)315.05 (94.59%)
client_sv2_setup_connection✅ (view plot)4,659.00 (-0.82%)4,765.03 (97.77%)✅ (view plot)1,502.00 (+0.05%)1,515.45 (99.11%)✅ (view plot)2,274.00 (-0.12%)2,299.70 (98.88%)🚨 (view plot | view alert)15.00 (+63.31%)13.96 (107.42%)✅ (view plot)66.00 (-2.73%)69.68 (94.72%)
client_sv2_setup_connection_serialize✅ (view plot)15,942.00 (-1.95%)16,503.87 (96.60%)✅ (view plot)5,963.00 (+0.01%)5,976.45 (99.77%)✅ (view plot)8,662.00 (+0.08%)8,677.81 (99.82%)✅ (view plot)49.00 (+9.61%)49.21 (99.57%)✅ (view plot)201.00 (-4.68%)217.96 (92.22%)
client_sv2_setup_connection_serialize_deserialize✅ (view plot)35,382.00 (-0.42%)35,749.07 (98.97%)🚨 (view plot | view alert)14,855.00 (+0.29%)14,837.01 (100.12%)🚨 (view plot | view alert)21,812.00 (+0.28%)21,785.52 (100.12%)✅ (view plot)110.00 (+10.20%)113.21 (97.16%)✅ (view plot)372.00 (-1.96%)384.91 (96.65%)

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

Copy link
Contributor

github-actions bot commented Jun 26, 2024

🐰Bencher

ReportSun, July 28, 2024 at 20:36:24 UTC
ProjectStratum v2 (SRI)
Branch1007/merge
Testbedsv1

🚨 1 ALERT: Threshold Boundary Limit exceeded!
BenchmarkMeasure (units)ViewValueLower BoundaryUpper Boundary
client-sv1-get-subscribe/client-sv1-get-subscribeLatency (nanoseconds (ns))🚨 (view plot | view alert)296.59 (+6.26%)293.24 (101.14%)

Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns) | (Δ%)
Latency Upper Boundary
nanoseconds (ns) | (%)
client-submit-serialize✅ (view plot)6,500.30 (-6.19%)7,349.35 (88.45%)
client-submit-serialize-deserialize✅ (view plot)7,470.10 (-4.84%)8,328.83 (89.69%)
client-submit-serialize-deserialize-handle/client-submit-serialize-deserialize-handle✅ (view plot)8,061.40 (-4.23%)8,839.34 (91.20%)
client-sv1-authorize-serialize-deserialize-handle/client-sv1-authorize-serialize-deserialize-handle✅ (view plot)889.16 (-1.01%)926.61 (95.96%)
client-sv1-authorize-serialize-deserialize/client-sv1-authorize-serialize-deserialize✅ (view plot)693.05 (-0.55%)717.83 (96.55%)
client-sv1-authorize-serialize/client-sv1-authorize-serialize✅ (view plot)245.98 (-0.85%)255.18 (96.40%)
client-sv1-get-authorize/client-sv1-get-authorize✅ (view plot)157.21 (+0.03%)162.46 (96.77%)
client-sv1-get-submit✅ (view plot)6,390.00 (-4.58%)7,134.55 (89.56%)
client-sv1-get-subscribe/client-sv1-get-subscribe🚨 (view plot | view alert)296.59 (+6.26%)293.24 (101.14%)
client-sv1-subscribe-serialize-deserialize-handle/client-sv1-subscribe-serialize-deserialize-handle✅ (view plot)765.45 (+2.41%)777.22 (98.49%)
client-sv1-subscribe-serialize-deserialize/client-sv1-subscribe-serialize-deserialize✅ (view plot)608.36 (-0.95%)637.59 (95.42%)
client-sv1-subscribe-serialize/client-sv1-subscribe-serialize✅ (view plot)203.19 (-1.66%)219.99 (92.36%)

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

Copy link
Contributor

github-actions bot commented Jun 26, 2024

🐰Bencher

ReportSun, July 28, 2024 at 20:36:20 UTC
ProjectStratum v2 (SRI)
Branchrefactor-ping-pong-encrypted
Testbedsv1

🚨 2 ALERTS: Threshold Boundary Limits exceeded!
BenchmarkMeasure (units)ViewValueLower BoundaryUpper Boundary
serialize_deserialize_authorizeRAM Accesses (accesses)🚨 (view plot | view alert)298.00 (+1.06%)297.85 (100.05%)
serialize_deserialize_handle_authorizeRAM Accesses (accesses)🚨 (view plot | view alert)369.00 (+1.40%)367.32 (100.46%)

Click to view all benchmark results
BenchmarkEstimated CyclesEstimated Cycles Results
estimated cycles | (Δ%)
Estimated Cycles Upper Boundary
estimated cycles | (%)
InstructionsInstructions Results
instructions | (Δ%)
Instructions Upper Boundary
instructions | (%)
L1 AccessesL1 Accesses Results
accesses | (Δ%)
L1 Accesses Upper Boundary
accesses | (%)
L2 AccessesL2 Accesses Results
accesses | (Δ%)
L2 Accesses Upper Boundary
accesses | (%)
RAM AccessesRAM Accesses Results
accesses | (Δ%)
RAM Accesses Upper Boundary
accesses | (%)
get_authorize✅ (view plot)8,504.00 (+0.81%)8,725.53 (97.46%)✅ (view plot)3,746.00 (+0.15%)3,855.71 (97.15%)✅ (view plot)5,249.00 (+0.08%)5,402.12 (97.17%)✅ (view plot)7.00 (-11.90%)10.40 (67.31%)✅ (view plot)92.00 (+2.18%)94.03 (97.84%)
get_submit✅ (view plot)95,475.00 (-0.08%)96,143.54 (99.30%)✅ (view plot)59,439.00 (-0.05%)59,779.65 (99.43%)✅ (view plot)85,360.00 (-0.05%)85,838.02 (99.44%)✅ (view plot)49.00 (-11.09%)62.58 (78.30%)✅ (view plot)282.00 (-0.03%)287.71 (98.01%)
get_subscribe✅ (view plot)7,957.00 (-0.25%)8,271.33 (96.20%)✅ (view plot)2,841.00 (+0.39%)2,940.12 (96.63%)✅ (view plot)3,972.00 (+0.46%)4,099.98 (96.88%)✅ (view plot)13.00 (-19.66%)19.82 (65.60%)✅ (view plot)112.00 (-0.56%)116.95 (95.77%)
serialize_authorize✅ (view plot)12,257.00 (+0.42%)12,503.93 (98.03%)✅ (view plot)5,317.00 (+0.11%)5,426.71 (97.98%)✅ (view plot)7,412.00 (+0.06%)7,565.46 (97.97%)✅ (view plot)10.00 (-7.41%)13.38 (74.73%)✅ (view plot)137.00 (+1.06%)140.24 (97.69%)
serialize_deserialize_authorize✅ (view plot)24,554.00 (+0.34%)24,709.48 (99.37%)✅ (view plot)9,898.00 (-0.02%)10,026.68 (98.72%)✅ (view plot)13,959.00 (-0.05%)14,151.77 (98.64%)✅ (view plot)33.00 (-9.79%)41.62 (79.29%)🚨 (view plot | view alert)298.00 (+1.06%)297.85 (100.05%)
serialize_deserialize_handle_authorize✅ (view plot)30,335.00 (+0.62%)30,348.92 (99.95%)✅ (view plot)12,101.00 (+0.05%)12,210.71 (99.10%)✅ (view plot)17,115.00 (-0.01%)17,280.53 (99.04%)✅ (view plot)61.00 (+3.71%)64.77 (94.18%)🚨 (view plot | view alert)369.00 (+1.40%)367.32 (100.46%)
serialize_deserialize_handle_submit✅ (view plot)126,406.00 (-0.00%)127,033.73 (99.51%)✅ (view plot)73,224.00 (-0.04%)73,621.57 (99.46%)✅ (view plot)104,946.00 (-0.04%)105,513.86 (99.46%)✅ (view plot)120.00 (-0.42%)131.31 (91.38%)✅ (view plot)596.00 (+0.19%)599.24 (99.46%)
serialize_deserialize_handle_subscribe✅ (view plot)27,503.00 (+0.17%)27,603.14 (99.64%)✅ (view plot)9,643.00 (+0.12%)9,742.12 (98.98%)✅ (view plot)13,638.00 (+0.11%)13,775.88 (99.00%)✅ (view plot)64.00 (-2.92%)73.80 (86.72%)✅ (view plot)387.00 (+0.31%)388.59 (99.59%)
serialize_deserialize_submit✅ (view plot)114,999.00 (-0.07%)115,655.20 (99.43%)✅ (view plot)68,001.00 (-0.08%)68,404.14 (99.41%)✅ (view plot)97,559.00 (-0.09%)98,152.61 (99.40%)✅ (view plot)65.00 (-6.39%)75.30 (86.32%)✅ (view plot)489.00 (+0.18%)492.39 (99.31%)
serialize_deserialize_subscribe✅ (view plot)22,888.00 (+0.06%)23,112.00 (99.03%)✅ (view plot)8,195.00 (+0.11%)8,297.86 (98.76%)✅ (view plot)11,543.00 (+0.12%)11,683.32 (98.80%)✅ (view plot)36.00 (-8.63%)44.09 (81.65%)✅ (view plot)319.00 (+0.15%)321.50 (99.22%)
serialize_submit✅ (view plot)99,792.00 (-0.10%)100,471.79 (99.32%)✅ (view plot)61,483.00 (-0.05%)61,829.06 (99.44%)✅ (view plot)88,207.00 (-0.05%)88,691.57 (99.45%)✅ (view plot)49.00 (-12.04%)62.30 (78.65%)✅ (view plot)324.00 (-0.21%)329.20 (98.42%)
serialize_subscribe✅ (view plot)11,294.00 (-0.29%)11,607.24 (97.30%)✅ (view plot)4,188.00 (+0.27%)4,287.12 (97.69%)✅ (view plot)5,829.00 (+0.29%)5,959.20 (97.82%)✅ (view plot)15.00 (-8.33%)18.98 (79.05%)✅ (view plot)154.00 (-0.78%)159.77 (96.39%)

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

@plebhash plebhash force-pushed the refactor-ping-pong-encrypted branch 8 times, most recently from 1da5329 to e37608e Compare June 26, 2024 21:12
Copy link
Contributor

@Shourya742 Shourya742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK e37608e. There are just a few nits.

examples/ping-pong-encrypted/src/server.rs Outdated Show resolved Hide resolved
examples/ping-pong-encrypted/src/client.rs Outdated Show resolved Hide resolved

// create Ping frame
let ping_frame =
StandardSv2Frame::<Message>::from_message(message.clone(), PING_MSG_TYPE, 0, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://stratumprotocol.org/specification/09-Extensions/
Is a 0 extension type unique in some way?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there are no extensions defined yet, using 0 is just the void/null case

Copy link
Contributor

@marathon-gary marathon-gary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@plebhash plebhash force-pushed the refactor-ping-pong-encrypted branch 2 times, most recently from aa1ad0c to 5f67449 Compare June 29, 2024 01:09
@plebhash plebhash marked this pull request as draft July 3, 2024 14:02
@plebhash
Copy link
Collaborator Author

plebhash commented Jul 3, 2024

reverting back to draft, since it could be affected by #903 (and other similar issues that are output from #845 )

@rrybarczyk
Copy link
Collaborator

Note: Wait to merge until the following is merged:

@plebhash plebhash force-pushed the refactor-ping-pong-encrypted branch from 5f67449 to 4aa8c14 Compare July 28, 2024 20:28
@plebhash plebhash removed this from the 1.1.0 milestone Aug 20, 2024
@plebhash plebhash changed the base branch from dev to main August 28, 2024 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo 📝
Development

Successfully merging this pull request may close these issues.

5 participants