Skip to content

Commit

Permalink
feat: edge case of 99%
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Nov 12, 2024
1 parent 41378a7 commit 3cab2b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions aggsender/epoch_notifier_per_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ func (e *EpochNotifierPerBlock) percentEpoch(currentBlock uint64) float64 {
func (e *EpochNotifierPerBlock) isNotificationRequired(currentBlock, lastEpochNotified uint64) (bool, uint64) {
percentEpoch := e.percentEpoch(currentBlock)
thresholdPercent := float64(e.Config.EpochNotificationPercentage) / 100.0

Check failure on line 172 in aggsender/epoch_notifier_per_block.go

View workflow job for this annotation

GitHub Actions / lint

Magic number: 100.0, in <operation> detected (mnd)
maxTresholdPercent := float64(e.Config.NumBlockPerEpoch-1) / float64(e.Config.NumBlockPerEpoch)
if thresholdPercent > maxTresholdPercent {
thresholdPercent = maxTresholdPercent
}
if percentEpoch < thresholdPercent {
e.logger.Debugf("Block %d is at %f%% of the epoch no notify", currentBlock, percentEpoch*100)

Check failure on line 178 in aggsender/epoch_notifier_per_block.go

View workflow job for this annotation

GitHub Actions / lint

Magic number: 100, in <argument> detected (mnd)
return false, e.epochNumber(currentBlock)
Expand Down
18 changes: 18 additions & 0 deletions aggsender/epoch_notifier_per_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ func TestStartingBlockEpoch(t *testing.T) {
require.Equal(t, uint64(19), testData.sut.startingBlockEpoch(2))
}

func TestEpochNotifyPercentageEdgeCase0(t *testing.T) {
testData := newNotifierPerBlockTestData(t, nil)
testData.sut.Config.EpochNotificationPercentage = 0
notify, epoch := testData.sut.isNotificationRequired(9, 0)
require.True(t, notify)
require.Equal(t, uint64(1), epoch)
}

// if percent is 99 means at end of epoch, so in a config 0, epoch-size=10,
// 99% means last block of epoch
func TestEpochNotifyPercentageEdgeCase99(t *testing.T) {
testData := newNotifierPerBlockTestData(t, nil)
testData.sut.Config.EpochNotificationPercentage = 99
notify, epoch := testData.sut.isNotificationRequired(9, 0)
require.True(t, notify)
require.Equal(t, uint64(1), epoch)
}

func TestEpochStep(t *testing.T) {
testData := newNotifierPerBlockTestData(t, &ConfigEpochNotifierPerBlock{
StartingEpochBlock: 9,
Expand Down

0 comments on commit 3cab2b3

Please sign in to comment.