Skip to content

Commit 9c1d567

Browse files
committed
Revert upstream PR mimblewimble#3810
This removes changes introducd by mimblewimble#3810 (AI-generated slop), keeping only my own message size logging modifications.
1 parent 5dc569e commit 9c1d567

File tree

11 files changed

+19
-338
lines changed

11 files changed

+19
-338
lines changed

core/src/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ pub fn get_chain_type() -> ChainTypes {
197197
CHAIN_TYPE.with(|chain_type| match chain_type.get() {
198198
None => {
199199
if !GLOBAL_CHAIN_TYPE.is_init() {
200-
std::panic!("GLOBAL_CHAIN_TYPE and CHAIN_TYPE unset. Consider set_local_chain_type() in tests.");
200+
panic!("GLOBAL_CHAIN_TYPE and CHAIN_TYPE unset. Consider set_local_chain_type() in tests.");
201201
}
202202
let chain_type = GLOBAL_CHAIN_TYPE.borrow();
203203
set_local_chain_type(chain_type);

core/src/ser.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,6 @@ impl ProtocolVersion {
361361
PROTOCOL_VERSION
362362
}
363363

364-
/// Default implementation that returns the current protocol version
365-
pub fn default() -> ProtocolVersion {
366-
PROTOCOL_VERSION
367-
}
368-
369364
/// We need to specify a protocol version for our local database.
370365
/// Regardless of specific version used when sending/receiving data between peers
371366
/// we need to take care with serialization/deserialization of data locally in the db.

doc/macros.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

doc/pool/transaction_pool.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

grin/p2p/src/msg.rs

Lines changed: 0 additions & 43 deletions
This file was deleted.

p2p/src/msg.rs

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use crate::types::{
3434
};
3535
use crate::util::secp::pedersen::RangeProof;
3636
use bytes::Bytes;
37-
use log::{info, warn};
3837
use num::FromPrimitive;
3938
use std::fs::File;
4039
use std::io::{Read, Write};
@@ -98,7 +97,7 @@ fn default_max_msg_size() -> u64 {
9897
}
9998

10099
// Max msg size for each msg type.
101-
pub fn max_msg_size(msg_type: Type) -> u64 {
100+
fn max_msg_size(msg_type: Type) -> u64 {
102101
match msg_type {
103102
Type::Error => 0,
104103
Type::Hand => 128,
@@ -173,7 +172,7 @@ impl Msg {
173172
///
174173
/// Note: We return a MsgHeaderWrapper here as we may encounter an unknown msg type.
175174
///
176-
pub fn read_header<R: std::io::Read>(
175+
pub fn read_header<R: Read>(
177176
stream: &mut R,
178177
version: ProtocolVersion,
179178
) -> Result<MsgHeaderWrapper, Error> {
@@ -187,7 +186,7 @@ pub fn read_header<R: std::io::Read>(
187186
/// Read a single item from the provided stream, always blocking until we
188187
/// have a result (or timeout).
189188
/// Returns the item and the total bytes read.
190-
pub fn read_item<T: Readable, R: std::io::Read>(
189+
pub fn read_item<T: Readable, R: Read>(
191190
stream: &mut R,
192191
version: ProtocolVersion,
193192
) -> Result<(T, u64), Error> {
@@ -198,7 +197,7 @@ pub fn read_item<T: Readable, R: std::io::Read>(
198197

199198
/// Read a message body from the provided stream, always blocking
200199
/// until we have a result (or timeout).
201-
pub fn read_body<T: Readable, R: std::io::Read>(
200+
pub fn read_body<T: Readable, R: Read>(
202201
h: &MsgHeader,
203202
stream: &mut R,
204203
version: ProtocolVersion,
@@ -209,14 +208,14 @@ pub fn read_body<T: Readable, R: std::io::Read>(
209208
}
210209

211210
/// Read (an unknown) message from the provided stream and discard it.
212-
pub fn read_discard<R: std::io::Read>(msg_len: u64, stream: &mut R) -> Result<(), Error> {
211+
pub fn read_discard<R: Read>(msg_len: u64, stream: &mut R) -> Result<(), Error> {
213212
let mut buffer = vec![0u8; msg_len as usize];
214213
stream.read_exact(&mut buffer)?;
215214
Ok(())
216215
}
217216

218217
/// Reads a full message from the underlying stream.
219-
pub fn read_message<T: Readable, R: std::io::Read>(
218+
pub fn read_message<T: Readable, R: Read>(
220219
stream: &mut R,
221220
version: ProtocolVersion,
222221
msg_type: Type,
@@ -323,24 +322,6 @@ impl Writeable for MsgHeader {
323322
}
324323
}
325324

326-
impl MsgHeader {
327-
/// Read a message header from the provided reader
328-
pub fn read<R: std::io::Read>(reader: &mut R) -> Result<MsgHeader, Error> {
329-
let mut head = vec![0u8; MsgHeader::LEN];
330-
reader.read_exact(&mut head)?;
331-
let header: MsgHeaderWrapper = ser::deserialize(
332-
&mut &head[..],
333-
ProtocolVersion::local(),
334-
DeserializationMode::default(),
335-
)?;
336-
337-
match header {
338-
MsgHeaderWrapper::Known(header) => Ok(header),
339-
MsgHeaderWrapper::Unknown(_, _) => Err(Error::BadMessage),
340-
}
341-
}
342-
}
343-
344325
impl Readable for MsgHeaderWrapper {
345326
fn read<R: Reader>(reader: &mut R) -> Result<MsgHeaderWrapper, ser::Error> {
346327
let m = magic();
@@ -1005,41 +986,3 @@ impl fmt::Debug for Consumed {
1005986
}
1006987
}
1007988
}
1008-
1009-
impl Message {
1010-
pub fn read<R: std::io::Read>(
1011-
reader: &mut R,
1012-
msg_type: Option<Type>,
1013-
) -> Result<Vec<u8>, Error> {
1014-
use log::{info, warn};
1015-
let header = MsgHeader::read(reader)?;
1016-
let msg_len = header.msg_len;
1017-
1018-
match msg_type {
1019-
Some(msg_type) => {
1020-
let max_len = max_msg_size(msg_type);
1021-
let current_max_len = max_len * 4; // Current 4x limit
1022-
if msg_len > current_max_len {
1023-
return Err(Error::MsgTooLarge(msg_len as usize, current_max_len));
1024-
}
1025-
info!(
1026-
"Received {:?} message: size={} bytes, 1x limit={} bytes, 4x limit={} bytes",
1027-
msg_type, msg_len, max_len, current_max_len
1028-
);
1029-
if msg_len > max_len {
1030-
warn!(
1031-
"Message size ({} bytes) exceeds 1x limit ({} bytes) for type {:?}",
1032-
msg_len, max_len, msg_type
1033-
);
1034-
}
1035-
}
1036-
None => {
1037-
info!("Received unknown message type: size={} bytes", msg_len);
1038-
}
1039-
}
1040-
1041-
let mut payload = vec![0u8; msg_len as usize];
1042-
reader.read_exact(&mut payload)?;
1043-
std::result::Result::Ok(payload)
1044-
}
1045-
}

p2p/src/types.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ pub enum Error {
9090
PeerNotBanned,
9191
PeerException,
9292
Internal,
93-
MsgTooLarge(usize, u64), // Message size, maximum allowed size
9493
}
9594

9695
impl From<ser::Error> for Error {
@@ -114,38 +113,6 @@ impl From<io::Error> for Error {
114113
}
115114
}
116115

117-
impl fmt::Display for Error {
118-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
119-
match self {
120-
Error::Serialization(ref e) => write!(f, "Serialization error: {}", e),
121-
Error::Connection(ref e) => write!(f, "Connection error: {}", e),
122-
Error::BadMessage => write!(f, "Bad message"),
123-
Error::UnexpectedMessage => write!(f, "Unexpected message"),
124-
Error::MsgLen => write!(f, "Wrong message length"),
125-
Error::Banned => write!(f, "Peer banned"),
126-
Error::ConnectionClose => write!(f, "Connection closed"),
127-
Error::Timeout => write!(f, "Connection timed out"),
128-
Error::Store(ref e) => write!(f, "Store error: {}", e),
129-
Error::Chain(ref e) => write!(f, "Chain error: {}", e),
130-
Error::PeerWithSelf => write!(f, "Connect to self"),
131-
Error::NoDandelionRelay => write!(f, "No Dandelion relay"),
132-
Error::GenesisMismatch { us, peer } => {
133-
write!(f, "Genesis mismatch: our={}, peer={}", us, peer)
134-
}
135-
Error::Send(ref s) => write!(f, "Send error: {}", s),
136-
Error::PeerNotFound => write!(f, "Peer not found"),
137-
Error::PeerNotBanned => write!(f, "Peer not banned"),
138-
Error::PeerException => write!(f, "Peer exception"),
139-
Error::Internal => write!(f, "Internal error"),
140-
Error::MsgTooLarge(size, max) => write!(
141-
f,
142-
"Message too large: {} bytes, maximum: {} bytes",
143-
size, max
144-
),
145-
}
146-
}
147-
}
148-
149116
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
150117
pub struct PeerAddr(pub SocketAddr);
151118

servers/src/grin/server.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,7 @@ impl Server {
577577
// this call is blocking and makes sure all peers stop, however
578578
// we can't be sure that we stopped a listener blocked on accept, so we don't join the p2p thread
579579
self.p2p.stop();
580-
// let _ = self.lock_file.unlock();
581-
let _ = fs2::FileExt::unlock(&*self.lock_file);
580+
let _ = self.lock_file.unlock();
582581
warn!("Shutdown complete");
583582
}
584583

src/main.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)