-
Notifications
You must be signed in to change notification settings - Fork 202
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
feat: stable block time #2422
base: main
Are you sure you want to change the base?
feat: stable block time #2422
Conversation
copied from berachain#2280 * [PBTS](https://docs.cometbft.com/v1.0/explanation/core/proposer-based-timestamps) is used, which can't be attacked by 1/3+ of malicious validators (time warp attack). * `InitialTime` (genesis time) is persisted across restarts to preserve the desired block cadence. The algorithm is as follows (assuming the target block cadence (configurable) is 2s): ```go targetBlockTime = InitialTime + 2s * blockHeight if actualBlockTime >= targetBlockTime { ABCI.FinalizeBlockResponse.NextBlockDelay = 0 } else { ABCI.FinalizeBlockResponse.NextBlockDelay = targetBlockTime - actualBlockTime } ```
func SetTargetBlockTime[ | ||
LoggerT log.AdvancedLogger[LoggerT], | ||
](t time.Duration) func(*Service[LoggerT]) { | ||
return func(bs *Service[LoggerT]) { bs.setTargetBlockTime(t) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that we do enforce some floor on timeouts in
func validateConfig(cfg *cmtcfg.Config) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I will factor this in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unclear to me how to do it from the API perspective. Do you have any suggestions @abi87?
Signed-off-by: Anton Kaliaev <[email protected]>
|
||
// ToBytes converts the blockDelay to bytes. | ||
func (d *blockDelay) ToBytes() []byte { | ||
bz, err := json.Marshal(d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably sub-optimal
InitialTime
InitialTime
to the latest block time if the network doesn't commit a block (any block because of downtime) for a configurable period of timeNextBlockDelay
feat: stable block time #2422 (comment)