Skip to content

Commit

Permalink
Merge pull request #551 from bandprotocol/adjust-time
Browse files Browse the repository at this point in the history
Change GuaranteeBlockTime for feeds module from 3 to 1 sec.
  • Loading branch information
RogerKSI authored Jan 13, 2025
2 parents 415d192 + f759334 commit 17a74d4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
32 changes: 18 additions & 14 deletions x/feeds/keeper/keeper_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,28 +284,32 @@ func CheckMissReport(
blockHeight int64,
gracePeriod int64,
) bool {
// During the grace period, if the block time exceeds MaxGuaranteeBlockTime, it will be capped at MaxGuaranteeBlockTime.
// This means that in cases of slow block time, the validator will not be deactivated
// as long as the block height does not exceed the equivalent of assumed MaxGuaranteeBlockTime of block time.
lastTime := lastUpdateTimestamp + gracePeriod
lastBlock := lastUpdateBlock + gracePeriod/types.MaxGuaranteeBlockTime

if valInfo.Status.Since.Unix()+gracePeriod > lastTime {
lastTime = valInfo.Status.Since.Unix() + gracePeriod
// Calculate the deadline time and block height for the validator to report.
// During the grace period, if the block time exceeds ExpectedBlockTime, it will be capped at ExpectedBlockTime.
// This prevents validator deactivation due to slower block times, as long as the block height remains within the threshold.
deadlineTime := lastUpdateTimestamp + gracePeriod
deadlineBlock := lastUpdateBlock + gracePeriod/types.ExpectedBlockTime

// Extend deadline if the validator just became active.
if valInfo.Status.Since.Unix()+gracePeriod > deadlineTime {
deadlineTime = valInfo.Status.Since.Unix() + gracePeriod
}

// Extend deadline if the validator has a valid price within the feed interval.
if valPrice.SignalPriceStatus != types.SIGNAL_PRICE_STATUS_UNSPECIFIED {
if valPrice.Timestamp+feed.Interval > lastTime {
lastTime = valPrice.Timestamp + feed.Interval
// Extend deadline time based on the price timestamp.
if valPrice.Timestamp+feed.Interval > deadlineTime {
deadlineTime = valPrice.Timestamp + feed.Interval
}

if valPrice.BlockHeight+feed.Interval/types.MaxGuaranteeBlockTime > lastBlock {
lastBlock = valPrice.BlockHeight + feed.Interval/types.MaxGuaranteeBlockTime
// Extend deadline block based on the price block height.
if valPrice.BlockHeight+feed.Interval/types.ExpectedBlockTime > deadlineBlock {
deadlineBlock = valPrice.BlockHeight + feed.Interval/types.ExpectedBlockTime
}
}

// Determine if the last action is too old, indicating a missed report
return lastTime < blockTime.Unix() && lastBlock < blockHeight
// Determine if the validator has missed the report based on the deadline time and block height.
return deadlineTime < blockTime.Unix() && deadlineBlock < blockHeight
}

// checkHavePrice checks if a validator has a price feed within interval range.
Expand Down
2 changes: 1 addition & 1 deletion x/feeds/keeper/keeper_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func (suite *KeeperTestSuite) TestCheckMissReport() {
},
},
blockTime: time.Unix(1300, 0),
blockHeight: 350,
blockHeight: 389,
gracePeriod: 120,
expectedResult: true, // Should get miss report
},
Expand Down
6 changes: 2 additions & 4 deletions x/feeds/types/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const (
// MaxSignalIDCharacters defines the maximum number of characters allowed in a signal ID.
MaxSignalIDCharacters uint64 = 32

// MaxGuaranteeBlockTime specifies the maximum capped block time (in seconds) during a grace period.
// If block times are slower, they will be capped at this value to prevent validator deactivation,
// as long as the block height remains within the calculated threshold for MaxGuaranteeBlockTime.
MaxGuaranteeBlockTime int64 = 3
// ExpectedBlockTime specifies the expected block time (in seconds).
ExpectedBlockTime int64 = 1
)

0 comments on commit 17a74d4

Please sign in to comment.