Skip to content

Commit ed646aa

Browse files
committed
fix: use var_str in 'reject' msgs
CommandString is (de)serialized as 12 bytes. However, BIP-61 defines the 'response-to-msg' (message that triggered the reject) field to be a var_str [1]. [1]: https://github.com/bitcoin/bips/blob/master/bip-0061.mediawiki#common-payload
1 parent 6f83e22 commit ed646aa

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/network/message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ mod test {
472472
NetworkMessage::GetCFCheckpt(GetCFCheckpt{filter_type: 17, stop_hash: hash([25u8; 32]).into()}),
473473
NetworkMessage::CFCheckpt(CFCheckpt{filter_type: 27, stop_hash: hash([77u8; 32]).into(), filter_headers: vec![hash([3u8; 32]).into(), hash([99u8; 32]).into()]}),
474474
NetworkMessage::Alert(vec![45,66,3,2,6,8,9,12,3,130]),
475-
NetworkMessage::Reject(Reject{message: CommandString::try_from("Test reject").unwrap(), ccode: RejectReason::Duplicate, reason: "Cause".into(), hash: hash([255u8; 32])}),
475+
NetworkMessage::Reject(Reject{message: "Test reject".into(), ccode: RejectReason::Duplicate, reason: "Cause".into(), hash: hash([255u8; 32])}),
476476
NetworkMessage::FeeFilter(1000),
477477
NetworkMessage::WtxidRelay,
478478
NetworkMessage::AddrV2(vec![AddrV2Message{ addr: AddrV2::Ipv4(Ipv4Addr::new(127, 0, 0, 1)), port: 0, services: ServiceFlags::NONE, time: 0 }]),

src/network/message_network.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use network::address::Address;
2626
use network::constants::{self, ServiceFlags};
2727
use consensus::{Encodable, Decodable, ReadExt};
2828
use consensus::encode;
29-
use network::message::CommandString;
3029
use hashes::sha256d;
3130

3231
/// Some simple messages
@@ -133,7 +132,7 @@ impl Decodable for RejectReason {
133132
#[derive(PartialEq, Eq, Clone, Debug)]
134133
pub struct Reject {
135134
/// message type rejected
136-
pub message: CommandString,
135+
pub message: Cow<'static, str>,
137136
/// reason of rejection as code
138137
pub ccode: RejectReason,
139138
/// reason of rejectection

0 commit comments

Comments
 (0)