Skip to content

Commit

Permalink
fix const param
Browse files Browse the repository at this point in the history
  • Loading branch information
ybensacq committed Sep 23, 2024
1 parent ce4200b commit efe885e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/network/protocol/messages/getblocks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub const GetblocksMessage = struct {
/// Returns the message checksum
///
/// Computed as `Sha256(Sha256(self.serialize()))[0..4]`
pub fn checksum(self: GetblocksMessage) [4]u8 {
pub fn checksum(self: *const GetblocksMessage) [4]u8 {
var digest: [32]u8 = undefined;
var hasher = Sha256.init(.{});
const writer = hasher.writer();
Expand All @@ -40,9 +40,7 @@ pub const GetblocksMessage = struct {

/// Free the `header_hashes`
pub fn deinit(self: GetblocksMessage, allocator: std.mem.Allocator) void {
if (self.header_hashes.len > 0) {
allocator.free(self.header_hashes);
}
allocator.free(self.header_hashes);
}

/// Serialize the message as bytes and write them to the Writer.
Expand Down
2 changes: 1 addition & 1 deletion src/network/wire/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn sendMessage(allocator: std.mem.Allocator, w: anytype, protocol_version: i
const payload_len: u32 = @intCast(payload.len);

// Calculate total message size
const precomputed_total_size = 18; // network (4 bytes) + command (12 bytes) + payload size (4 bytes) + checksum (4 bytes)
const precomputed_total_size = 24; // network (4 bytes) + command (12 bytes) + payload size (4 bytes) + checksum (4 bytes)
const total_message_size = precomputed_total_size + payload_len;

if (total_message_size > MAX_SIZE) {
Expand Down

0 comments on commit efe885e

Please sign in to comment.