Skip to content

Commit 5349098

Browse files
committed
change InboundUpgrade function to use new rpcs. fmt. add test for LightClientFinalityUpdate
1 parent 8ffe1a7 commit 5349098

File tree

11 files changed

+167
-75
lines changed

11 files changed

+167
-75
lines changed

beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use std::marker::PhantomData;
1616
use std::sync::Arc;
1717
use tokio_util::codec::{Decoder, Encoder};
1818
use types::{
19-
LightClientBootstrap, EthSpec, ForkContext, ForkName, Hash256,
20-
LightClientFinalityUpdate, LightClientOptimisticUpdate, SignedBeaconBlock,
21-
SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockMerge, SignedBeaconBlockCapella,
19+
EthSpec, ForkContext, ForkName, Hash256, LightClientBootstrap, LightClientFinalityUpdate,
20+
LightClientOptimisticUpdate, SignedBeaconBlock, SignedBeaconBlockAltair, SignedBeaconBlockBase,
21+
SignedBeaconBlockCapella, SignedBeaconBlockMerge,
2222
};
2323
use unsigned_varint::codec::Uvi;
2424

@@ -488,12 +488,10 @@ fn handle_v1_request<T: EthSpec>(
488488
root: Hash256::from_ssz_bytes(decoded_buffer)?,
489489
},
490490
))),
491-
Protocol::LightClientOptimisticUpdate => Ok(Some(
492-
InboundRequest::LightClientOptimisticUpdate,
493-
)),
494-
Protocol::LightClientFinalityUpdate => Ok(Some(
495-
InboundRequest::LightClientFinalityUpdate,
496-
)),
491+
Protocol::LightClientOptimisticUpdate => {
492+
Ok(Some(InboundRequest::LightClientOptimisticUpdate))
493+
}
494+
Protocol::LightClientFinalityUpdate => Ok(Some(InboundRequest::LightClientFinalityUpdate)),
497495
// MetaData requests return early from InboundUpgrade and do not reach the decoder.
498496
// Handle this case just for completeness.
499497
Protocol::MetaData => {

beacon_node/lighthouse_network/src/rpc/config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ impl FromStr for OutboundRateLimiterConfig {
141141
Protocol::MetaData => meta_data_quota = meta_data_quota.or(quota),
142142
Protocol::LightClientBootstrap
143143
| Protocol::LightClientOptimisticUpdate
144-
| Protocol::LightClientFinalityUpdate => return Err("Lighthouse does not send LightClient requests. Quota should not be set."),
144+
| Protocol::LightClientFinalityUpdate => {
145+
return Err(
146+
"Lighthouse does not send LightClient requests. Quota should not be set.",
147+
)
148+
}
145149
}
146150
}
147151
Ok(OutboundRateLimiterConfig {

beacon_node/lighthouse_network/src/rpc/methods.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use std::sync::Arc;
1313
use strum::IntoStaticStr;
1414
use superstruct::superstruct;
1515
use types::{
16-
LightClientBootstrap, Epoch, EthSpec, Hash256,
17-
LightClientFinalityUpdate, LightClientOptimisticUpdate, SignedBeaconBlock, Slot,
16+
Epoch, EthSpec, Hash256, LightClientBootstrap, LightClientFinalityUpdate,
17+
LightClientOptimisticUpdate, SignedBeaconBlock, Slot,
1818
};
1919

2020
/// Maximum number of blocks in a single request.

beacon_node/lighthouse_network/src/rpc/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@ pub(crate) use protocol::InboundRequest;
2424

2525
pub use codec::{BaseOutboundCodec, OutboundCodec, SSZSnappyOutboundCodec};
2626
pub use handler::{
27-
HandlerErr, HandlerEvent, HandlerState,
28-
OutboundInfo, OutboundSubstreamState, RPCHandler, SubstreamId,
27+
HandlerErr, HandlerEvent, HandlerState, OutboundInfo, OutboundSubstreamState, RPCHandler,
28+
SubstreamId,
2929
};
3030
pub use methods::{
31-
BlocksByRangeRequest, BlocksByRootRequest, GoodbyeReason, LightClientBootstrapRequest, MaxRequestBlocks,
32-
RPCResponseErrorCode, ResponseTermination, StatusMessage, MAX_REQUEST_BLOCKS,
31+
BlocksByRangeRequest, BlocksByRootRequest, GoodbyeReason, LightClientBootstrapRequest,
32+
MaxRequestBlocks, RPCResponseErrorCode, ResponseTermination, StatusMessage, MAX_REQUEST_BLOCKS,
3333
};
3434
pub use outbound::OutboundFramed;
3535
pub use outbound::OutboundRequest;
36-
pub use protocol::{
37-
max_rpc_size, Encoding, Protocol, ProtocolId, RPCError, RPCProtocol, Version,
38-
};
36+
pub use protocol::{max_rpc_size, Encoding, Protocol, ProtocolId, RPCError, RPCProtocol, Version};
3937

4038
use self::config::OutboundRateLimiterConfig;
4139
use self::self_limiter::SelfRateLimiter;

beacon_node/lighthouse_network/src/rpc/outbound.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ impl<TSpec: EthSpec> OutboundRequest<TSpec> {
122122
OutboundRequest::Ping(_) => Protocol::Ping,
123123
OutboundRequest::MetaData(_) => Protocol::MetaData,
124124
OutboundRequest::LightClientBootstrap(_) => Protocol::LightClientBootstrap,
125-
OutboundRequest::LightClientOptimisticUpdate => {
126-
Protocol::LightClientOptimisticUpdate
127-
}
125+
OutboundRequest::LightClientOptimisticUpdate => Protocol::LightClientOptimisticUpdate,
128126
OutboundRequest::LightClientFinalityUpdate => Protocol::LightClientFinalityUpdate,
129127
}
130128
}

beacon_node/lighthouse_network/src/rpc/protocol.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ use tokio_util::{
2222
};
2323
use types::{
2424
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockCapella, BeaconBlockMerge,
25-
EmptyBlock, EthSpec, ForkContext, ForkName, Hash256, MainnetEthSpec, Signature,
26-
SignedBeaconBlock, LightClientFinalityUpdate, LightClientOptimisticUpdate, LightClientBootstrap,
25+
EmptyBlock, EthSpec, ForkContext, ForkName, Hash256, LightClientBootstrap,
26+
LightClientFinalityUpdate, LightClientOptimisticUpdate, MainnetEthSpec, Signature,
27+
SignedBeaconBlock,
2728
};
2829

2930
lazy_static! {
@@ -444,6 +445,12 @@ where
444445
// MetaData requests should be empty, return the stream
445446
match protocol_name {
446447
Protocol::MetaData => Ok((InboundRequest::MetaData(PhantomData), socket)),
448+
Protocol::LightClientOptimisticUpdate => {
449+
Ok((InboundRequest::LightClientOptimisticUpdate, socket))
450+
}
451+
Protocol::LightClientFinalityUpdate => {
452+
Ok((InboundRequest::LightClientFinalityUpdate, socket))
453+
}
447454
_ => {
448455
match tokio::time::timeout(
449456
Duration::from_secs(REQUEST_TIMEOUT),

beacon_node/lighthouse_network/src/rpc/self_limiter.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ impl<Id: ReqId, TSpec: EthSpec> SelfRateLimiter<Id, TSpec> {
7373
// inbound and outbound requests, and the LightClientBootstrap is an only inbound
7474
// protocol.
7575
.one_every(Protocol::LightClientBootstrap, Duration::from_secs(10))
76-
.one_every(Protocol::LightClientOptimisticUpdate, Duration::from_secs(10))
76+
.one_every(
77+
Protocol::LightClientOptimisticUpdate,
78+
Duration::from_secs(10),
79+
)
7780
.one_every(Protocol::LightClientFinalityUpdate, Duration::from_secs(10))
7881
.build()?;
7982

beacon_node/lighthouse_network/src/service/api_types.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::sync::Arc;
22

33
use libp2p::core::connection::ConnectionId;
44
use types::{
5-
LightClientBootstrap, EthSpec, LightClientFinalityUpdate,
6-
LightClientOptimisticUpdate, SignedBeaconBlock,
5+
EthSpec, LightClientBootstrap, LightClientFinalityUpdate, LightClientOptimisticUpdate,
6+
SignedBeaconBlock,
77
};
88

99
use crate::rpc::{
@@ -57,12 +57,8 @@ impl<TSpec: EthSpec> std::convert::From<Request> for OutboundRequest<TSpec> {
5757
})
5858
}
5959
Request::LightClientBootstrap(b) => OutboundRequest::LightClientBootstrap(b),
60-
Request::LightClientOptimisticUpdate => {
61-
OutboundRequest::LightClientOptimisticUpdate
62-
}
63-
Request::LightClientFinalityUpdate => {
64-
OutboundRequest::LightClientFinalityUpdate
65-
}
60+
Request::LightClientOptimisticUpdate => OutboundRequest::LightClientOptimisticUpdate,
61+
Request::LightClientFinalityUpdate => OutboundRequest::LightClientFinalityUpdate,
6662
Request::Status(s) => OutboundRequest::Status(s),
6763
}
6864
}

beacon_node/lighthouse_network/tests/common/mock_light_client.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use futures::future::BoxFuture;
44
use futures::prelude::*;
55
use libp2p::core::connection::ConnectionId;
66
use libp2p::core::upgrade::{NegotiationError, ProtocolError};
7-
use libp2p::core::{UpgradeError, UpgradeInfo, PeerId};
7+
use libp2p::core::{PeerId, UpgradeError, UpgradeInfo};
88
use libp2p::multiaddr::{Multiaddr, Protocol as MProtocol};
99
use libp2p::swarm::handler::SubstreamProtocol;
1010
use libp2p::swarm::{
@@ -15,13 +15,12 @@ use libp2p::swarm::{NotifyHandler, PollParameters, SwarmBuilder, SwarmEvent};
1515
use libp2p::OutboundUpgrade;
1616
use lighthouse_network::rpc::methods::RPCCodedResponse;
1717
use lighthouse_network::rpc::{
18-
max_rpc_size, BaseOutboundCodec, Encoding, GoodbyeReason,
19-
HandlerErr, HandlerEvent, HandlerState,
20-
OutboundCodec, OutboundFramed, OutboundInfo, OutboundRequest, OutboundSubstreamState, Protocol,
21-
ProtocolId, RPCError, RPCMessage, RPCProtocol, RPCReceived, RPCSend,
22-
ReqId, SSZSnappyOutboundCodec, SubstreamId, Version,
18+
max_rpc_size, BaseOutboundCodec, Encoding, GoodbyeReason, HandlerErr, HandlerEvent,
19+
HandlerState, OutboundCodec, OutboundFramed, OutboundInfo, OutboundRequest,
20+
OutboundSubstreamState, Protocol, ProtocolId, RPCError, RPCMessage, RPCProtocol, RPCReceived,
21+
RPCSend, ReqId, SSZSnappyOutboundCodec, SubstreamId, Version,
2322
};
24-
use lighthouse_network::{error, Request, NetworkConfig};
23+
use lighthouse_network::{error, NetworkConfig, Request};
2524
use slog::{crit, debug, o, trace};
2625
use smallvec::SmallVec;
2726
use std::collections::hash_map::Entry;
@@ -35,7 +34,7 @@ use tokio::time::Instant as TInstant;
3534
use tokio_util::{codec::Framed, compat::FuturesAsyncReadCompatExt, time::DelayQueue};
3635
use types::{EthSpec, ForkContext};
3736

38-
use lighthouse_network::{build_transport, Context as ServiceContext, };
37+
use lighthouse_network::{build_transport, Context as ServiceContext};
3938

4039
/// The time (in seconds) before a substream that is awaiting a response from the user times out.
4140
pub const RESPONSE_TIMEOUT: u64 = 10;
@@ -470,7 +469,7 @@ where
470469
match rpc_event {
471470
RPCSend::Request(id, req) => self.send_request(id, req),
472471
RPCSend::Shutdown(id, reason) => self.shutdown(Some((id, reason))),
473-
_ => {},
472+
_ => {}
474473
}
475474
// In any case, we need the handler to process the event.
476475
if let Some(waker) = &self.waker {

0 commit comments

Comments
 (0)