|
1 | 1 | const std = @import("std"); |
2 | | -const Attestation = @import("consensus_types").deneb.Attestation; |
| 2 | +// TODO make this fork-agnostic |
| 3 | +const Attestation = @import("consensus_types").fulu.Attestation; |
| 4 | +const SignedBeaconBlock = @import("consensus_types").fulu.SignedBeaconBlock; |
3 | 5 | const ssz = @import("ssz"); |
4 | 6 | const zbench = @import("zbench"); |
| 7 | +const download_era_options = @import("download_era_options"); |
| 8 | +const era = @import("era"); |
| 9 | +const config = @import("config"); |
5 | 10 |
|
6 | 11 | // printf "Date: %s\nKernel: %s\nCPU: %s\nCPUs: %s\nMemory: %s\n" "$(date)" "$(uname -r)" "$(lscpu | grep 'Model name' | awk -F: '{print $2}' | xargs)" "$(lscpu | grep '^CPU(s):' | awk '{print $2}')" "$(free -h | grep Mem | awk '{print $2}')" |
7 | 12 | // Date: Fri Apr 25 10:07:24 AM EDT 2025 |
@@ -115,13 +120,28 @@ pub fn main() !void { |
115 | 120 | var bench = zbench.Benchmark.init(allocator, .{}); |
116 | 121 | defer bench.deinit(); |
117 | 122 |
|
118 | | - const attestation_file = try std.fs.cwd().openFile("bench/attestation.ssz", .{}); |
119 | | - defer attestation_file.close(); |
120 | | - const attestation_bytes = try attestation_file.readToEndAlloc(allocator, 1_000_000_000); |
| 123 | + const era_path = try std.fs.path.join( |
| 124 | + allocator, |
| 125 | + &[_][]const u8{ download_era_options.era_out_dir, download_era_options.era_files[1] }, |
| 126 | + ); |
| 127 | + defer allocator.free(era_path); |
121 | 128 |
|
122 | | - const attestation = allocator.create(Attestation.Type) catch unreachable; |
123 | | - attestation.* = Attestation.default_value; |
124 | | - Attestation.deserializeFromBytes(allocator, attestation_bytes, attestation) catch unreachable; |
| 129 | + var era_reader = try era.Reader.open(allocator, config.mainnet.config, era_path); |
| 130 | + defer era_reader.close(allocator); |
| 131 | + |
| 132 | + const block_slot = try era.era.computeStartBlockSlotFromEraNumber(era_reader.era_number) + 1; |
| 133 | + |
| 134 | + const block_bytes: []u8 = @constCast(try era_reader.readSerializedBlock(allocator, block_slot) orelse return error.InvalidEraFile); |
| 135 | + defer allocator.free(block_bytes); |
| 136 | + |
| 137 | + var block = SignedBeaconBlock.default_value; |
| 138 | + defer block.deinit(); |
| 139 | + try SignedBeaconBlock.deserializeFromBytes(allocator, block_bytes, &block); |
| 140 | + |
| 141 | + const attestation = &block.message.body.attestations.items[0]; |
| 142 | + const attestation_bytes = try allocator.alloc(u8, Attestation.serializedSize(attestation)); |
| 143 | + defer allocator.free(attestation_bytes); |
| 144 | + _ = Attestation.serializeIntoBytes(attestation, attestation_bytes); |
125 | 145 |
|
126 | 146 | const serialize_attestation = SerializeAttestation{ .attestation = attestation }; |
127 | 147 | try bench.addParam("serialize attestation", &serialize_attestation, .{}); |
|
0 commit comments