|
| 1 | +const std = @import("std"); |
| 2 | +const primitives = @import("../../primitives/types.zig"); |
| 3 | +const consensus = @import("../../consensus/types.zig"); |
| 4 | +const configs = @import("../../configs/config.zig"); |
| 5 | +const constants = @import("../../primitives/constants.zig"); |
| 6 | +const preset = @import("../../presets/preset.zig"); |
| 7 | +const phase0 = @import("../../consensus/phase0/types.zig"); |
| 8 | +const altair = @import("../../consensus/altair/types.zig"); |
| 9 | +const electra = @import("../../consensus/electra/types.zig"); |
| 10 | +const epoch_helper = @import("../../consensus/helpers/epoch.zig"); |
| 11 | +const shuffle_helper = @import("../../consensus/helpers/shuffle.zig"); |
| 12 | +const balance_helper = @import("../../consensus/helpers/balance.zig"); |
| 13 | +const committee_helper = @import("../../consensus/helpers/committee.zig"); |
| 14 | + |
| 15 | +// pub fn weighJustificationAndFinalization( |
| 16 | +// state: *consensus.BeaconState, |
| 17 | +// total_active_balance: primitives.Gwei, |
| 18 | +// previous_epoch_target_balance: primitives.Gwei, |
| 19 | +// current_epoch_target_balance: primitives.Gwei, |
| 20 | +// ) void { |
| 21 | +// const previous_epoch = epoch_helper.getPreviousEpoch(state); |
| 22 | +// const current_epoch = epoch_helper.getCurrentEpoch(state); |
| 23 | +// const old_previous_justified_checkpoint = state.p; |
| 24 | +// const old_current_justified_checkpoint = state.current_justified_checkpoint; |
| 25 | +// |
| 26 | +// // Process justifications |
| 27 | +// state.previous_justified_checkpoint = state.current_justified_checkpoint; |
| 28 | +// |
| 29 | +// // Shift justification bits |
| 30 | +// var i: usize = constants.JUSTIFICATION_BITS_LENGTH - 1; |
| 31 | +// while (i > 0) : (i -= 1) { |
| 32 | +// state.justification_bits[i] = state.justification_bits[i - 1]; |
| 33 | +// } |
| 34 | +// state.justification_bits[0] = 0; |
| 35 | +// |
| 36 | +// if (previous_epoch_target_balance * 3 >= total_active_balance * 2) { |
| 37 | +// state.current_justified_checkpoint = consensus.Checkpoint{ |
| 38 | +// .epoch = previous_epoch, |
| 39 | +// .root = getBlockRoot(state, previous_epoch), |
| 40 | +// }; |
| 41 | +// state.justification_bits[1] = 1; |
| 42 | +// } |
| 43 | +// |
| 44 | +// if (current_epoch_target_balance * 3 >= total_active_balance * 2) { |
| 45 | +// state.current_justified_checkpoint = Checkpoint{ |
| 46 | +// .epoch = current_epoch, |
| 47 | +// .root = getBlockRoot(state, current_epoch), |
| 48 | +// }; |
| 49 | +// state.justification_bits[0] = 1; |
| 50 | +// } |
| 51 | +// |
| 52 | +// // Process finalizations |
| 53 | +// const bits = state.justification_bits; |
| 54 | +// |
| 55 | +// // The 2nd/3rd/4th most recent epochs are justified, the 2nd using the 4th as source |
| 56 | +// if (allBitsSet(bits[1..4]) and old_previous_justified_checkpoint.epoch + 3 == current_epoch) { |
| 57 | +// state.finalized_checkpoint = old_previous_justified_checkpoint; |
| 58 | +// } |
| 59 | +// // The 2nd/3rd most recent epochs are justified, the 2nd using the 3rd as source |
| 60 | +// if (allBitsSet(bits[1..3]) and old_previous_justified_checkpoint.epoch + 2 == current_epoch) { |
| 61 | +// state.finalized_checkpoint = old_previous_justified_checkpoint; |
| 62 | +// } |
| 63 | +// // The 1st/2nd/3rd most recent epochs are justified, the 1st using the 3rd as source |
| 64 | +// if (allBitsSet(bits[0..3]) and old_current_justified_checkpoint.epoch + 2 == current_epoch) { |
| 65 | +// state.finalized_checkpoint = old_current_justified_checkpoint; |
| 66 | +// } |
| 67 | +// // The 1st/2nd most recent epochs are justified, the 1st using the 2nd as source |
| 68 | +// if (allBitsSet(bits[0..2]) and old_current_justified_checkpoint.epoch + 1 == current_epoch) { |
| 69 | +// state.finalized_checkpoint = old_current_justified_checkpoint; |
| 70 | +// } |
| 71 | +// } |
| 72 | + |
| 73 | +fn allBitsSet(bits: []const bool) bool { |
| 74 | + return !std.mem.containsAtLeast(bool, bits, 1, false); |
| 75 | +} |
0 commit comments