Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ledger): flatten shred field nesting #332

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions src/ledger/meta.zig
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ pub const ErasureMeta = struct {

pub fn fromCodeShred(shred: CodeShred) ?Self {
return .{
.fec_set_index = shred.fields.common.fec_set_index,
.fec_set_index = shred.common.fec_set_index,
.config = ErasureConfig{
.num_data = shred.fields.custom.num_data_shreds,
.num_code = shred.fields.custom.num_code_shreds,
.num_data = shred.custom.num_data_shreds,
.num_code = shred.custom.num_code_shreds,
},
.first_code_index = shred.firstCodeIndex() catch return null,
.first_received_code_index = shred.fields.common.index,
.first_received_code_index = shred.common.index,
};
}

Expand Down Expand Up @@ -358,9 +358,9 @@ pub const MerkleRootMeta = struct {
// `None` for those cases in blockstore, as a later
// shred that contains a proper merkle root would constitute
// a valid duplicate shred proof.
.merkle_root = shred.fields.merkleRoot() catch null,
.first_received_shred_index = shred.fields.common.index,
.first_received_shred_type = shred.fields.common.variant.shred_type,
.merkle_root = shred.merkleRoot() catch null,
.first_received_shred_index = shred.common.index,
.first_received_shred_type = shred.common.variant.shred_type,
};
}
};
36 changes: 19 additions & 17 deletions src/ledger/reader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1970,11 +1970,11 @@ test "lowestSlot" {
const shred_slot = 10;
const shred_index = 10;

var shred = Shred{ .data = try DataShred.default(allocator) };
var shred = Shred{ .data = try DataShred.zeroedForTest(allocator) };
defer shred.deinit();

shred.data.fields.common.slot = shred_slot;
shred.data.fields.common.index = shred_index;
shred.data.common.slot = shred_slot;
shred.data.common.index = shred_index;

// insert a shred
var slot_meta = SlotMeta.init(allocator, shred_slot, null);
Expand Down Expand Up @@ -2020,11 +2020,11 @@ test "isShredDuplicate" {
const shred_payload = try allocator.alloc(u8, size);
defer allocator.free(shred_payload);

var shred = Shred{ .data = try DataShred.default(allocator) };
var shred = Shred{ .data = try DataShred.zeroedForTest(allocator) };
defer shred.deinit();
shred.data.fields.common.slot = shred_slot;
shred.data.fields.common.index = shred_index;
@memset(shred.data.fields.payload, 0);
shred.data.common.slot = shred_slot;
shred.data.common.index = shred_index;
@memset(shred.data.payload, 0);

// no duplicate
try std.testing.expectEqual(null, try reader.isShredDuplicate(shred));
Expand Down Expand Up @@ -2068,10 +2068,10 @@ test "findMissingDataIndexes" {
const shred_slot = 10;
const shred_index = 2;

var shred = Shred{ .data = try DataShred.default(allocator) };
var shred = Shred{ .data = try DataShred.zeroedForTest(allocator) };
defer shred.deinit();
shred.data.fields.common.slot = shred_slot;
shred.data.fields.common.index = shred_index;
shred.data.common.slot = shred_slot;
shred.data.common.index = shred_index;

// set the variant
const variant = sig.ledger.shred.ShredVariant{
Expand All @@ -2080,8 +2080,8 @@ test "findMissingDataIndexes" {
.chained = false,
.resigned = false,
};
shred.data.fields.common.variant = variant;
try shred.data.fields.writePayload(&(.{2} ** 100));
shred.data.common.variant = variant;
try shred.data.writePayload(&(.{2} ** 100));

var slot_meta = SlotMeta.init(allocator, shred_slot, null);
slot_meta.last_index = 4;
Expand Down Expand Up @@ -2133,10 +2133,10 @@ test "getCodeShred" {
&max_root,
);

var shred = Shred{ .code = try CodeShred.default(allocator) };
var shred = Shred{ .code = try CodeShred.zeroedForTest(allocator) };
defer shred.deinit();
shred.code.fields.common.slot = 10;
shred.code.fields.common.index = 10;
shred.code.common.slot = 10;
shred.code.common.index = 10;

try std.testing.expect(shred == .code);

Expand All @@ -2147,8 +2147,10 @@ test "getCodeShred" {
.chained = false,
.resigned = false,
};
shred.code.fields.common.variant = variant;
try shred.code.fields.writePayload(&(.{2} ** 100));
shred.code.common.variant = variant;
shred.code.custom.num_data_shreds = 1;
shred.code.custom.num_code_shreds = 1;
try shred.code.writePayload(&(.{2} ** 100));

const shred_slot = shred.commonHeader().slot;
const shred_index = shred.commonHeader().index;
Expand Down
Loading
Loading