Skip to content

Commit

Permalink
allowed 'historical replay' of the noncustodial issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Nguyen authored and oten91 committed Sep 22, 2022
1 parent 6c03e41 commit 72a3eb7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

const (
AppVersion = "BETA-0.9.1"
AppVersion = "BETA-0.9.1.1"
)

// NewPocketCoreApp is a constructor function for PocketCoreApp
Expand Down
25 changes: 13 additions & 12 deletions codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ var (
)

const (
UpgradeCodecHeight = int64(30024)
CodecChainHaltHeight = int64(30334)
ValidatorSplitHeight = int64(45353)
UpgradeCodecUpdateKey = "CODEC"
ValidatorSplitUpdateKey = "SPLIT"
NonCustodialUpdateKey = "NCUST"
TxCacheEnhancementKey = "REDUP"
MaxRelayProtKey = "MREL"
ReplayBurnKey = "REPBR"
BlockSizeModifyKey = "BLOCK"
RSCALKey = "RSCAL"
VEDITKey = "VEDIT"
UpgradeCodecHeight = int64(30024)
CodecChainHaltHeight = int64(30334)
ValidatorSplitHeight = int64(45353)
NonCustodial1RollbackHeight = int64(69583)
UpgradeCodecUpdateKey = "CODEC"
ValidatorSplitUpdateKey = "SPLIT"
NonCustodialUpdateKey = "NCUST"
TxCacheEnhancementKey = "REDUP"
MaxRelayProtKey = "MREL"
ReplayBurnKey = "REPBR"
BlockSizeModifyKey = "BLOCK"
RSCALKey = "RSCAL"
VEDITKey = "VEDIT"
)

func GetCodecUpgradeHeight() int64 {
Expand Down
21 changes: 19 additions & 2 deletions x/nodes/keeper/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,38 @@ import (

// RewardForRelays - Award coins to an address (will be called at the beginning of the next block)
func (k Keeper) RewardForRelays(ctx sdk.Ctx, relays sdk.BigInt, address sdk.Address) sdk.BigInt {
// feature flags
isAfterRSCAL := k.Cdc.IsAfterNamedFeatureActivationHeight(ctx.BlockHeight(), codec.RSCALKey)
isAfterNonCustodial := k.Cdc.IsAfterNonCustodialUpgrade(ctx.BlockHeight())

// The conditions of the original non-custodial issue:
isDuringNonCustodialIssue := isAfterNonCustodial && isAfterRSCAL && ctx.BlockHeight() <= codec.NonCustodial1RollbackHeight

// get validator
validator, found := k.GetValidator(ctx, address)
if !found {
ctx.Logger().Error(fmt.Errorf("no validator found for address %s; at height %d\n", address.String(), ctx.BlockHeight()).Error())
return sdk.ZeroInt()
}

if k.Cdc.IsAfterNonCustodialUpgrade(ctx.BlockHeight()) {
if isAfterNonCustodial {
address = k.GetOutputAddressFromValidator(validator)
}

// This simulates the issue that happened between the original non-custodial rollout and the rollback height
// This code is needed to allow a 'history replay' of the issue during sync-from-scratch
if isDuringNonCustodialIssue {
_, found := k.GetValidator(ctx, address)
if !found {
ctx.Logger().Error(fmt.Errorf("no validator found for address %s; at height %d\n", address.String(), ctx.BlockHeight()).Error())
return sdk.ZeroInt()
}
}

var coins sdk.BigInt

//check if PIP22 is enabled, if so scale the rewards
if k.Cdc.IsAfterNamedFeatureActivationHeight(ctx.BlockHeight(), codec.RSCALKey) {
if isAfterRSCAL {
stake := validator.GetTokens()
//floorstake to the lowest bin multiple or take ceiling, whicherver is smaller
flooredStake := sdk.MinInt(stake.Sub(stake.Mod(k.ServicerStakeFloorMultiplier(ctx))), k.ServicerStakeWeightCeiling(ctx).Sub(k.ServicerStakeWeightCeiling(ctx).Mod(k.ServicerStakeFloorMultiplier(ctx))))
Expand Down

0 comments on commit 72a3eb7

Please sign in to comment.