Skip to content

Commit 17a74d4

Browse files
authored
Merge pull request #551 from bandprotocol/adjust-time
Change GuaranteeBlockTime for feeds module from 3 to 1 sec.
2 parents 415d192 + f759334 commit 17a74d4

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

x/feeds/keeper/keeper_price.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -284,28 +284,32 @@ func CheckMissReport(
284284
blockHeight int64,
285285
gracePeriod int64,
286286
) bool {
287-
// During the grace period, if the block time exceeds MaxGuaranteeBlockTime, it will be capped at MaxGuaranteeBlockTime.
288-
// This means that in cases of slow block time, the validator will not be deactivated
289-
// as long as the block height does not exceed the equivalent of assumed MaxGuaranteeBlockTime of block time.
290-
lastTime := lastUpdateTimestamp + gracePeriod
291-
lastBlock := lastUpdateBlock + gracePeriod/types.MaxGuaranteeBlockTime
292-
293-
if valInfo.Status.Since.Unix()+gracePeriod > lastTime {
294-
lastTime = valInfo.Status.Since.Unix() + gracePeriod
287+
// Calculate the deadline time and block height for the validator to report.
288+
// During the grace period, if the block time exceeds ExpectedBlockTime, it will be capped at ExpectedBlockTime.
289+
// This prevents validator deactivation due to slower block times, as long as the block height remains within the threshold.
290+
deadlineTime := lastUpdateTimestamp + gracePeriod
291+
deadlineBlock := lastUpdateBlock + gracePeriod/types.ExpectedBlockTime
292+
293+
// Extend deadline if the validator just became active.
294+
if valInfo.Status.Since.Unix()+gracePeriod > deadlineTime {
295+
deadlineTime = valInfo.Status.Since.Unix() + gracePeriod
295296
}
296297

298+
// Extend deadline if the validator has a valid price within the feed interval.
297299
if valPrice.SignalPriceStatus != types.SIGNAL_PRICE_STATUS_UNSPECIFIED {
298-
if valPrice.Timestamp+feed.Interval > lastTime {
299-
lastTime = valPrice.Timestamp + feed.Interval
300+
// Extend deadline time based on the price timestamp.
301+
if valPrice.Timestamp+feed.Interval > deadlineTime {
302+
deadlineTime = valPrice.Timestamp + feed.Interval
300303
}
301304

302-
if valPrice.BlockHeight+feed.Interval/types.MaxGuaranteeBlockTime > lastBlock {
303-
lastBlock = valPrice.BlockHeight + feed.Interval/types.MaxGuaranteeBlockTime
305+
// Extend deadline block based on the price block height.
306+
if valPrice.BlockHeight+feed.Interval/types.ExpectedBlockTime > deadlineBlock {
307+
deadlineBlock = valPrice.BlockHeight + feed.Interval/types.ExpectedBlockTime
304308
}
305309
}
306310

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

311315
// checkHavePrice checks if a validator has a price feed within interval range.

x/feeds/keeper/keeper_price_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ func (suite *KeeperTestSuite) TestCheckMissReport() {
537537
},
538538
},
539539
blockTime: time.Unix(1300, 0),
540-
blockHeight: 350,
540+
blockHeight: 389,
541541
gracePeriod: 120,
542542
expectedResult: true, // Should get miss report
543543
},

x/feeds/types/constant.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const (
44
// MaxSignalIDCharacters defines the maximum number of characters allowed in a signal ID.
55
MaxSignalIDCharacters uint64 = 32
66

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

0 commit comments

Comments
 (0)