Skip to content

Commit

Permalink
Await Accepted slot in issueCandidacy and issueValidationBlock in Tes…
Browse files Browse the repository at this point in the history
…t_ValidatorRewards
  • Loading branch information
jkrvivian committed May 15, 2024
1 parent fefbebc commit 1d03114
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
26 changes: 26 additions & 0 deletions tools/docker-network/tests/dockertestframework/awaits.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ func (d *DockerTestFramework) AwaitTransactionFailure(ctx context.Context, txID
})
}

func (d *DockerTestFramework) AwaitSlot(targetSlot iotago.SlotIndex) {
currentSlot := d.NodeStatus("V1").LatestAcceptedBlockSlot

if targetSlot <= currentSlot {
return
}

// we wait at max "targetSlot - currentSlot" times * slot duration
deadline := time.Duration(d.defaultWallet.Client.CommittedAPI().ProtocolParameters().SlotDurationInSeconds()) * time.Second
if currentSlot < targetSlot {
deadline *= time.Duration(targetSlot - currentSlot)
}

// give some extra time for peering etc
deadline += 30 * time.Second

d.EventuallyWithDurations(func() error {
latestAcceptedSlot := d.NodeStatus("V1").LatestAcceptedBlockSlot
if targetSlot > latestAcceptedSlot {
return ierrors.Errorf("current slot %d is not reached yet, current slot %d", targetSlot, latestAcceptedSlot)
}

return nil
}, deadline, 1*time.Second)
}

func (d *DockerTestFramework) AwaitCommitment(targetSlot iotago.SlotIndex) {
currentCommittedSlot := d.NodeStatus("V1").LatestCommitmentID.Slot()

Expand Down
17 changes: 2 additions & 15 deletions tools/docker-network/tests/rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func issueCandidacyAnnouncementsInBackground(ctx context.Context, d *dockertestf
}

// wait until the epoch start is reached
d.AwaitCommitment(d.DefaultWallet().Client.CommittedAPI().TimeProvider().EpochStart(epoch))
d.AwaitSlot(d.DefaultWallet().Client.CommittedAPI().TimeProvider().EpochStart(epoch))
if ctx.Err() != nil {
// context is canceled
return
Expand All @@ -307,12 +307,6 @@ func issueCandidacyAnnouncementsInBackground(ctx context.Context, d *dockertestf
fmt.Println("Issuing candidacy payload for account", wallet.BlockIssuer.AccountData.ID, "in epoch", epoch, "...")
committedAPI := d.DefaultWallet().Client.CommittedAPI()

// check if we are still in the epoch
currentCommittedSlot := d.NodeStatus("V1").LatestCommitmentID.Slot()
currentEpoch := committedAPI.TimeProvider().EpochFromSlot(currentCommittedSlot)

require.Equal(d.Testing, epoch, currentEpoch, "epoch mismatch")

// the candidacy announcement needs to be done before the nearing threshold
epochEndSlot := committedAPI.TimeProvider().EpochEnd(epoch)
maxRegistrationSlot := epochEndSlot - committedAPI.ProtocolParameters().EpochNearingThreshold()
Expand Down Expand Up @@ -342,19 +336,12 @@ func issueValidationBlocksInBackground(ctx context.Context, d *dockertestframewo
}

// wait until the slot is reached
d.AwaitCommitment(slot)
d.AwaitSlot(slot)
if ctx.Err() != nil {
// context is canceled
return
}

// check if we are still in the slot
currentCommittedSlot := d.NodeStatus("V1").LatestCommitmentID.Slot()
if slot < currentCommittedSlot {
// slot is already committed, no need to issue validation blocks
continue
}

ts := time.Now()
for validationBlockNr := range blocksPerSlot {
if ctx.Err() != nil {
Expand Down

0 comments on commit 1d03114

Please sign in to comment.