Skip to content

Commit

Permalink
Add BeaconProposer.getCurrentSlotNumber()
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalinin committed Sep 26, 2018
1 parent a136fe3 commit 05ecebb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Expand Up @@ -60,11 +60,16 @@ public interface BeaconProposer {
long getTimestamp(long slotNumber);

/**
* Calculates a number of slot that given moment of time does fit to.
* Calculates a number of slot that given moment of time does fit into.
* Uses {@link BeaconGenesis#timestamp} and {@link #SLOT_DURATION}
*
* @param timestamp timestamp in milliseconds
* @return slot number
*/
long getSlotNumber(long timestamp);

/**
* Calculates a number of the slot that current moment it time does fit into.
*/
long getCurrentSlotNumber();
}
Expand Up @@ -112,4 +112,9 @@ public long getTimestamp(long slotNumber) {
public long getSlotNumber(long timestamp) {
return (timestamp - BeaconGenesis.instance().getTimestamp()) / SLOT_DURATION;
}

@Override
public long getCurrentSlotNumber() {
return getSlotNumber(System.currentTimeMillis());
}
}
Expand Up @@ -108,8 +108,7 @@ private void submitIfAssigned(Committee[][] committees) {
return;

// get number of the next slot that validator is eligible to propose
long slotNumber = calcNextProposingSlot(proposer.getSlotNumber(System.currentTimeMillis()),
index.getSlotOffset());
long slotNumber = calcNextProposingSlot(proposer.getCurrentSlotNumber(), index.getSlotOffset());

// not an obvious way of calculating proposer index,
// proposer = committee[X % len(committee)], X = slotNumber
Expand All @@ -123,8 +122,8 @@ private void submitIfAssigned(Committee[][] committees) {
public void submit(long slotNumber) {
if (proposerThread == null) return;

// skip slots that are in the past
if (slotNumber < proposer.getSlotNumber(System.currentTimeMillis()))
// skip slots that start in the past
if (slotNumber <= proposer.getCurrentSlotNumber())
return;

// always cancel current task and create a new one
Expand Down

0 comments on commit 05ecebb

Please sign in to comment.