Skip to content

Commit

Permalink
Merge pull request #509 from iotaledger/future-bounded-delegation-end…
Browse files Browse the repository at this point in the history
…-epoch

Calculate Delegation End Epoch from the Future Bounded Commitment Index
  • Loading branch information
PhilippGackstatter authored Nov 9, 2023
2 parents 2be0c46 + 57a3ed3 commit ac23b39
Showing 1 changed file with 7 additions and 4 deletions.
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

0 comments on commit ac23b39

Please sign in to comment.