Skip to content
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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

melekes
Copy link

@melekes melekes commented Jan 27, 2025

  • persist InitialTime
  • set InitialTime to the latest block time if the network doesn't commit a block (any block because of downtime) for a configurable period of time
  • tested manually + unit tests
  • enforce minimum for NextBlockDelay feat: stable block time #2422 (comment)

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) }
Copy link
Collaborator

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 {

Copy link
Author

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.

Copy link
Author

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?


// ToBytes converts the blockDelay to bytes.
func (d *blockDelay) ToBytes() []byte {
bz, err := json.Marshal(d)
Copy link
Author

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

consensus/cometbft/service/block_delay.go Outdated Show resolved Hide resolved
consensus/cometbft/service/service.go Show resolved Hide resolved
@abi87 abi87 linked an issue Feb 3, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(4788): Block Time Clock MVP
3 participants