Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate Delegation End Epoch from the Future Bounded Commitment Index #509

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/protocol/engine/ledger/ledger/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ func (v *VM) ValidateSignatures(signedTransaction mempool.SignedTransaction, res

case *iotago.DelegationOutput:
delegationID := castOutput.DelegationID
delegationEnd := castOutput.EndEpoch

if delegationID.Empty() {
delegationID = iotago.DelegationIDFromOutputID(outputID)
}

delegationEnd := castOutput.EndEpoch
if delegationEnd == 0 {
delegationEnd = v.ledger.apiProvider.APIForSlot(commitmentInput.Slot).TimeProvider().EpochFromSlot(commitmentInput.Slot) - iotago.EpochIndex(1)
// If Delegation ID is zeroed, the output is in delegating state, which means its End Epoch is not set and we must use the
// "last epoch", which is the epoch index corresponding to the future bounded slot index minus 1.
apiForSlot := v.ledger.apiProvider.APIForSlot(commitmentInput.Slot)
futureBoundedSlotIndex := commitmentInput.Slot + apiForSlot.ProtocolParameters().MinCommittableAge()
delegationEnd = apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex) - iotago.EpochIndex(1)
}

reward, _, _, rewardErr := v.ledger.sybilProtection.DelegatorReward(castOutput.ValidatorAddress.AccountID(), castOutput.DelegatedAmount, castOutput.StartEpoch, delegationEnd)
Expand Down
Loading