Skip to content

Commit

Permalink
feat: adjusted claimPrimarySlot method in Authorship class
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgi Grigorov committed Oct 29, 2024
1 parent 7b8ef9a commit 2303112
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/main/java/com/limechain/babe/Authorship.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.limechain.babe;

import com.limechain.babe.predigest.BabePreDigest;
import com.limechain.babe.predigest.PreDigestType;
import com.limechain.utils.LittleEndianUtils;
import com.limechain.utils.math.BigRational;
import com.limechain.chain.lightsyncstate.Authority;
Expand All @@ -17,15 +19,14 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Authorship {

//TODO: Replace return type with PreDigest
public static Object claimPrimarySlot(final byte[] randomness,
final long slotNumber,
final long epochNumber,
final Schnorrkel.KeyPair keyPair,
final int authorityIndex,
final BigInteger threshold) {
public static BabePreDigest claimPrimarySlot(final byte[] randomness,
final BigInteger slotNumber,
final long epochNumber,
final Schnorrkel.KeyPair keyPair,
final int authorityIndex,
final BigInteger threshold) {

var transcript = makeTranscript(randomness, slotNumber, epochNumber);
var transcript = makeTranscript(randomness, slotNumber.longValue(), epochNumber);

Schnorrkel schnorrkel = Schnorrkel.getInstance();
VrfOutputAndProof vrfOutputAndProof = schnorrkel.vrfSign(keyPair, transcript);
Expand All @@ -38,8 +39,13 @@ public static Object claimPrimarySlot(final byte[] randomness,
var isBelowThreshold = LittleEndianUtils.fromLittleEndianByteArray(vrfBytes).compareTo(threshold) < 0;

if (isBelowThreshold) {
//TODO: Return PreDigest
return null;
return new BabePreDigest(
PreDigestType.BABE_PRIMARY,
authorityIndex,
slotNumber,
vrfOutputAndProof.getOutput(),
vrfOutputAndProof.getProof()
);
}

return null;
Expand Down Expand Up @@ -99,7 +105,7 @@ private static double getBabeConstant(@NotNull Pair<BigInteger, BigInteger> cons
return c;
}

private static TranscriptData makeTranscript(byte[] randomness, Long slotNumber, Long epochNumber) {
private static TranscriptData makeTranscript(byte[] randomness, long slotNumber, long epochNumber) {
var transcript = new TranscriptData("BABE".getBytes());
transcript.appendMessage("slot number", LittleEndianUtils.longToLittleEndianBytes(slotNumber));
transcript.appendMessage("current epoch", LittleEndianUtils.longToLittleEndianBytes(epochNumber));
Expand Down

0 comments on commit 2303112

Please sign in to comment.