Skip to content
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
9 changes: 8 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ jobs:
needs:
- k8s-peers
- build-tests
# - build-tests-webrtc
- build-tests-webrtc
runs-on: ubuntu-20.04
container:
image: minaprotocol/mina-daemon:3.0.0-dc6bf78-focal-devnet
Expand All @@ -309,6 +309,7 @@ jobs:
- connection_discovery_rust_as_seed
- connection_discovery_rust_to_ocaml_via_seed
- connection_discovery_rust_to_ocaml
- webrtc_p2p_signaling
# - webrtc_single_node
# - webrtc_multi_node
fail-fast: false
Expand All @@ -331,6 +332,12 @@ jobs:
with:
pattern: tests*
merge-multiple: true

- name: Download tests
uses: actions/download-artifact@v4
with:
pattern: tests-webrtc*
merge-multiple: true

- name: Setup permissions
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
sudo apt install -y protobuf-compiler
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.79
toolchain: 1.81
components: rustfmt, clippy
default: true
- uses: actions-rs/cargo@v1
Expand All @@ -36,4 +36,4 @@ jobs:
name: clippy
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-targets -- -D warnings
args: --all-targets -- -D warnings --allow clippy::mutable_key_type --allow clippy::result_unit_err
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mina-p2p-messages/benches/gossip-binprot.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(unexpected_cfgs)]
#![cfg(benchmarks)]
#![feature(test)]

Expand Down
2 changes: 1 addition & 1 deletion mina-p2p-messages/tests/rpc-read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn debugger_to_wire() {
"v1/rpc/get-transition-knowledge",
"v1/rpc/get-ancestry",
] {
for_all_with_path(&PathBuf::from(d).join("response"), |encoded, path| {
for_all_with_path(PathBuf::from(d).join("response"), |encoded, path| {
let mut p = &encoded[1..];
let tag = BinprotTag::binprot_read(&mut p).unwrap().to_string_lossy();
let ver = Ver::binprot_read(&mut p).unwrap();
Expand Down
23 changes: 22 additions & 1 deletion node/common/src/service/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use std::collections::BTreeMap;
use node::{
core::channels::mpsc,
event_source::Event,
p2p::{connection::outgoing::P2pConnectionOutgoingInitOpts, PeerId},
p2p::{
connection::outgoing::P2pConnectionOutgoingInitOpts,
identity::{EncryptableType, PublicKey},
PeerId,
},
};
use rand::prelude::*;
#[cfg(feature = "p2p-libp2p")]
Expand Down Expand Up @@ -34,6 +38,23 @@ impl webrtc::P2pServiceWebrtc for NodeService {
fn peers(&mut self) -> &mut BTreeMap<PeerId, webrtc::PeerState> {
&mut self.p2p.webrtc.peers
}

fn encrypt<T: EncryptableType>(
&mut self,
other_pk: &PublicKey,
message: &T,
) -> Result<T::Encrypted, ()> {
let rng = &mut self.rng;
self.p2p.sec_key.encrypt(other_pk, rng, message)
}

fn decrypt<T: EncryptableType>(
&mut self,
other_pk: &PublicKey,
encrypted: &T::Encrypted,
) -> Result<T, ()> {
self.p2p.sec_key.decrypt(other_pk, encrypted)
}
}

impl webrtc_with_libp2p::P2pServiceWebrtcWithLibp2p for NodeService {
Expand Down
10 changes: 10 additions & 0 deletions node/common/src/service/rpc/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ impl State {
#[cfg(target_family = "wasm")]
#[cfg_attr(target_family = "wasm", wasm_bindgen)]
impl State {
pub async fn get(&self, filter: String) -> JsValue {
let res = self
.sender
.oneshot_request::<RpcStateGetResponse>(RpcRequest::StateGet(Some(filter)))
.await
.and_then(|v| v.ok());
res.map(|res| JsValue::from_serde(&res).unwrap_or_default())
.unwrap_or_default()
}

pub async fn peers(&self) -> JsValue {
let res = self
.sender
Expand Down
3 changes: 3 additions & 0 deletions node/native/src/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ pub async fn run(port: u16, rpc_sender: RpcSender) {
false => StatusCode::OK,
true => StatusCode::BAD_REQUEST,
},
P2pConnectionResponse::SignalDecryptionFailed => {
StatusCode::BAD_REQUEST
}
P2pConnectionResponse::InternalError => {
StatusCode::INTERNAL_SERVER_ERROR
}
Expand Down
142 changes: 141 additions & 1 deletion node/src/action_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ use crate::p2p::channels::best_tip::P2pChannelsBestTipAction;
use crate::p2p::channels::best_tip_effectful::P2pChannelsBestTipEffectfulAction;
use crate::p2p::channels::rpc::P2pChannelsRpcAction;
use crate::p2p::channels::rpc_effectful::P2pChannelsRpcEffectfulAction;
use crate::p2p::channels::signaling::discovery::P2pChannelsSignalingDiscoveryAction;
use crate::p2p::channels::signaling::discovery_effectful::P2pChannelsSignalingDiscoveryEffectfulAction;
use crate::p2p::channels::signaling::exchange::P2pChannelsSignalingExchangeAction;
use crate::p2p::channels::signaling::exchange_effectful::P2pChannelsSignalingExchangeEffectfulAction;
use crate::p2p::channels::snark::P2pChannelsSnarkAction;
use crate::p2p::channels::snark_effectful::P2pChannelsSnarkEffectfulAction;
use crate::p2p::channels::snark_job_commitment::P2pChannelsSnarkJobCommitmentAction;
Expand Down Expand Up @@ -209,6 +213,41 @@ pub enum ActionKind {
P2pChannelsRpcEffectfulInit,
P2pChannelsRpcEffectfulRequestSend,
P2pChannelsRpcEffectfulResponseSend,
P2pChannelsSignalingDiscoveryAnswerDecrypted,
P2pChannelsSignalingDiscoveryAnswerReceived,
P2pChannelsSignalingDiscoveryAnswerSend,
P2pChannelsSignalingDiscoveryDiscoveredAccept,
P2pChannelsSignalingDiscoveryDiscoveredAcceptReceived,
P2pChannelsSignalingDiscoveryDiscoveredReceived,
P2pChannelsSignalingDiscoveryDiscoveredReject,
P2pChannelsSignalingDiscoveryDiscoveredRejectReceived,
P2pChannelsSignalingDiscoveryDiscoveredSend,
P2pChannelsSignalingDiscoveryDiscoveryRequestReceived,
P2pChannelsSignalingDiscoveryDiscoveryRequestSend,
P2pChannelsSignalingDiscoveryInit,
P2pChannelsSignalingDiscoveryPending,
P2pChannelsSignalingDiscoveryReady,
P2pChannelsSignalingDiscoveryRequestReceived,
P2pChannelsSignalingDiscoveryRequestSend,
P2pChannelsSignalingDiscoveryEffectfulAnswerDecrypt,
P2pChannelsSignalingDiscoveryEffectfulInit,
P2pChannelsSignalingDiscoveryEffectfulMessageSend,
P2pChannelsSignalingDiscoveryEffectfulOfferEncryptAndSend,
P2pChannelsSignalingExchangeAnswerReceived,
P2pChannelsSignalingExchangeAnswerSend,
P2pChannelsSignalingExchangeInit,
P2pChannelsSignalingExchangeOfferDecryptError,
P2pChannelsSignalingExchangeOfferDecryptSuccess,
P2pChannelsSignalingExchangeOfferReceived,
P2pChannelsSignalingExchangeOfferSend,
P2pChannelsSignalingExchangePending,
P2pChannelsSignalingExchangeReady,
P2pChannelsSignalingExchangeRequestReceived,
P2pChannelsSignalingExchangeRequestSend,
P2pChannelsSignalingExchangeEffectfulAnswerEncryptAndSend,
P2pChannelsSignalingExchangeEffectfulInit,
P2pChannelsSignalingExchangeEffectfulMessageSend,
P2pChannelsSignalingExchangeEffectfulOfferDecrypt,
P2pChannelsSnarkInit,
P2pChannelsSnarkLibp2pBroadcast,
P2pChannelsSnarkLibp2pReceived,
Expand Down Expand Up @@ -618,7 +657,7 @@ pub enum ActionKind {
}

impl ActionKind {
pub const COUNT: u16 = 510;
pub const COUNT: u16 = 545;
}

impl std::fmt::Display for ActionKind {
Expand Down Expand Up @@ -1029,6 +1068,8 @@ impl ActionKindGet for P2pChannelsAction {
fn kind(&self) -> ActionKind {
match self {
Self::MessageReceived(a) => a.kind(),
Self::SignalingDiscovery(a) => a.kind(),
Self::SignalingExchange(a) => a.kind(),
Self::BestTip(a) => a.kind(),
Self::Transaction(a) => a.kind(),
Self::Snark(a) => a.kind(),
Expand Down Expand Up @@ -1069,6 +1110,8 @@ impl ActionKindGet for P2pNetworkAction {
impl ActionKindGet for P2pChannelsEffectfulAction {
fn kind(&self) -> ActionKind {
match self {
Self::SignalingDiscovery(a) => a.kind(),
Self::SignalingExchange(a) => a.kind(),
Self::BestTip(a) => a.kind(),
Self::Rpc(a) => a.kind(),
Self::Snark(a) => a.kind(),
Expand Down Expand Up @@ -1400,6 +1443,69 @@ impl ActionKindGet for P2pChannelsMessageReceivedAction {
}
}

impl ActionKindGet for P2pChannelsSignalingDiscoveryAction {
fn kind(&self) -> ActionKind {
match self {
Self::Init { .. } => ActionKind::P2pChannelsSignalingDiscoveryInit,
Self::Pending { .. } => ActionKind::P2pChannelsSignalingDiscoveryPending,
Self::Ready { .. } => ActionKind::P2pChannelsSignalingDiscoveryReady,
Self::RequestSend { .. } => ActionKind::P2pChannelsSignalingDiscoveryRequestSend,
Self::DiscoveryRequestReceived { .. } => {
ActionKind::P2pChannelsSignalingDiscoveryDiscoveryRequestReceived
}
Self::DiscoveredSend { .. } => ActionKind::P2pChannelsSignalingDiscoveryDiscoveredSend,
Self::DiscoveredRejectReceived { .. } => {
ActionKind::P2pChannelsSignalingDiscoveryDiscoveredRejectReceived
}
Self::DiscoveredAcceptReceived { .. } => {
ActionKind::P2pChannelsSignalingDiscoveryDiscoveredAcceptReceived
}
Self::AnswerSend { .. } => ActionKind::P2pChannelsSignalingDiscoveryAnswerSend,
Self::RequestReceived { .. } => {
ActionKind::P2pChannelsSignalingDiscoveryRequestReceived
}
Self::DiscoveryRequestSend { .. } => {
ActionKind::P2pChannelsSignalingDiscoveryDiscoveryRequestSend
}
Self::DiscoveredReceived { .. } => {
ActionKind::P2pChannelsSignalingDiscoveryDiscoveredReceived
}
Self::DiscoveredReject { .. } => {
ActionKind::P2pChannelsSignalingDiscoveryDiscoveredReject
}
Self::DiscoveredAccept { .. } => {
ActionKind::P2pChannelsSignalingDiscoveryDiscoveredAccept
}
Self::AnswerReceived { .. } => ActionKind::P2pChannelsSignalingDiscoveryAnswerReceived,
Self::AnswerDecrypted { .. } => {
ActionKind::P2pChannelsSignalingDiscoveryAnswerDecrypted
}
}
}
}

impl ActionKindGet for P2pChannelsSignalingExchangeAction {
fn kind(&self) -> ActionKind {
match self {
Self::Init { .. } => ActionKind::P2pChannelsSignalingExchangeInit,
Self::Pending { .. } => ActionKind::P2pChannelsSignalingExchangePending,
Self::Ready { .. } => ActionKind::P2pChannelsSignalingExchangeReady,
Self::RequestSend { .. } => ActionKind::P2pChannelsSignalingExchangeRequestSend,
Self::OfferReceived { .. } => ActionKind::P2pChannelsSignalingExchangeOfferReceived,
Self::OfferDecryptError { .. } => {
ActionKind::P2pChannelsSignalingExchangeOfferDecryptError
}
Self::OfferDecryptSuccess { .. } => {
ActionKind::P2pChannelsSignalingExchangeOfferDecryptSuccess
}
Self::AnswerSend { .. } => ActionKind::P2pChannelsSignalingExchangeAnswerSend,
Self::RequestReceived { .. } => ActionKind::P2pChannelsSignalingExchangeRequestReceived,
Self::OfferSend { .. } => ActionKind::P2pChannelsSignalingExchangeOfferSend,
Self::AnswerReceived { .. } => ActionKind::P2pChannelsSignalingExchangeAnswerReceived,
}
}
}

impl ActionKindGet for P2pChannelsBestTipAction {
fn kind(&self) -> ActionKind {
match self {
Expand Down Expand Up @@ -1652,6 +1758,40 @@ impl ActionKindGet for P2pNetworkRpcAction {
}
}

impl ActionKindGet for P2pChannelsSignalingDiscoveryEffectfulAction {
fn kind(&self) -> ActionKind {
match self {
Self::Init { .. } => ActionKind::P2pChannelsSignalingDiscoveryEffectfulInit,
Self::MessageSend { .. } => {
ActionKind::P2pChannelsSignalingDiscoveryEffectfulMessageSend
}
Self::OfferEncryptAndSend { .. } => {
ActionKind::P2pChannelsSignalingDiscoveryEffectfulOfferEncryptAndSend
}
Self::AnswerDecrypt { .. } => {
ActionKind::P2pChannelsSignalingDiscoveryEffectfulAnswerDecrypt
}
}
}
}

impl ActionKindGet for P2pChannelsSignalingExchangeEffectfulAction {
fn kind(&self) -> ActionKind {
match self {
Self::Init { .. } => ActionKind::P2pChannelsSignalingExchangeEffectfulInit,
Self::MessageSend { .. } => {
ActionKind::P2pChannelsSignalingExchangeEffectfulMessageSend
}
Self::OfferDecrypt { .. } => {
ActionKind::P2pChannelsSignalingExchangeEffectfulOfferDecrypt
}
Self::AnswerEncryptAndSend { .. } => {
ActionKind::P2pChannelsSignalingExchangeEffectfulAnswerEncryptAndSend
}
}
}
}

impl ActionKindGet for P2pChannelsBestTipEffectfulAction {
fn kind(&self) -> ActionKind {
match self {
Expand Down
19 changes: 18 additions & 1 deletion node/src/event_source/event_source_effects.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use p2p::channels::signaling::discovery::P2pChannelsSignalingDiscoveryAction;
use p2p::channels::signaling::exchange::P2pChannelsSignalingExchangeAction;
use p2p::channels::snark::P2pChannelsSnarkAction;
use p2p::channels::streaming_rpc::P2pChannelsStreamingRpcAction;
use p2p::channels::transaction::P2pChannelsTransactionAction;
Expand Down Expand Up @@ -158,6 +160,12 @@ pub fn event_source_effects<S: Service>(store: &mut Store<S>, action: EventSourc
error: P2pConnectionErrorResponse::Rejected(reason),
});
}
P2pConnectionResponse::SignalDecryptionFailed => {
store.dispatch(P2pConnectionOutgoingAction::AnswerRecvError {
peer_id,
error: P2pConnectionErrorResponse::SignalDecryptionFailed,
});
}
P2pConnectionResponse::InternalError => {
store.dispatch(P2pConnectionOutgoingAction::AnswerRecvError {
peer_id,
Expand Down Expand Up @@ -194,8 +202,17 @@ pub fn event_source_effects<S: Service>(store: &mut Store<S>, action: EventSourc
openmina_core::log::warn!(meta.time(); kind = "P2pChannelEvent::Opened", peer_id = peer_id.to_string(), error = err);
// TODO(binier): dispatch error action.
}
// TODO(binier): maybe dispatch success and then ready.
Ok(_) => match chan_id {
ChannelId::SignalingDiscovery => {
store.dispatch(P2pChannelsSignalingDiscoveryAction::Ready {
peer_id,
});
}
ChannelId::SignalingExchange => {
store.dispatch(P2pChannelsSignalingExchangeAction::Ready {
peer_id,
});
}
ChannelId::BestTipPropagation => {
store.dispatch(P2pChannelsBestTipAction::Ready { peer_id });
}
Expand Down
Loading
Loading