Skip to content

Commit

Permalink
Merge branch 'sanaz/adds-timeouts-to-endblock-abci' of github.com:cel…
Browse files Browse the repository at this point in the history
…estiaorg/celestia-core into sanaz/adds-timeouts-to-endblock-abci
  • Loading branch information
evan-forbes committed Oct 14, 2024
2 parents 12639d4 + 85e92f3 commit e772715
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
12 changes: 6 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,11 +1058,11 @@ func (cfg *ConsensusConfig) Propose(round int32) time.Duration {
// ProposeWithCustomTimeout is identical to Propose. However,
// it calculates the amount of time to wait for a proposal using the supplied
// customTimeout.
// If customTimeout is 0, the default TimeoutCommit is used.
// If customTimeout is 0, the TimeoutPropose from cfg is used.
func (cfg *ConsensusConfig) ProposeWithCustomTimeout(round int32, customTimeout time.Duration) time.Duration {
// this is to capture any unforeseen cases where the customTimeout is 0
var timeoutPropose time.Duration
if customTimeout == 0 {
var timeoutPropose = customTimeout
if timeoutPropose == 0 {
// falling back to default timeout
timeoutPropose = cfg.TimeoutPropose
}
Expand Down Expand Up @@ -1090,11 +1090,11 @@ func (cfg *ConsensusConfig) Commit(t time.Time) time.Time {
}

// CommitWithCustomTimeout is identical to Commit. However, it calculates the time for commit using the supplied customTimeout.
// If customTimeout is 0, the default TimeoutCommit is used.
// If customTimeout is 0, the TimeoutCommit from cfg is used.
func (cfg *ConsensusConfig) CommitWithCustomTimeout(t time.Time, customTimeout time.Duration) time.Time {
// this is to capture any unforeseen cases where the customTimeout is 0
var timeoutCommit time.Duration
if customTimeout == 0 {
var timeoutCommit = customTimeout
if timeoutCommit == 0 {
// falling back to default timeout
timeoutCommit = cfg.TimeoutCommit
}
Expand Down
29 changes: 23 additions & 6 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"fmt"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -192,12 +191,30 @@ func TestInstrumentationConfigValidateBasic(t *testing.T) {
assert.Error(t, cfg.ValidateBasic())
}

func TestDebug(t *testing.T) {
cfg := DefaultConfig()
func TestProposeWithCustomTimeout(t *testing.T) {
cfg := DefaultConsensusConfig()

// customTimeout is 0, should fallback to default timeout
round := int32(1)
expectedTimeout := time.Duration(cfg.TimeoutPropose.Nanoseconds()+cfg.TimeoutProposeDelta.Nanoseconds()*int64(round)) * time.Nanosecond
assert.Equal(t, expectedTimeout, cfg.ProposeWithCustomTimeout(round, time.Duration(0)))

// customTimeout is not 0
customTimeout := 2 * time.Second
expectedTimeout = time.Duration(customTimeout.Nanoseconds()+cfg.TimeoutProposeDelta.Nanoseconds()*int64(round)) * time.Nanosecond
assert.Equal(t, expectedTimeout, cfg.ProposeWithCustomTimeout(round, customTimeout))
}

timeout := cfg.Consensus.ProposeWithCustomTimeout(1, time.Second*10)
func TestCommitWithCustomTimeout(t *testing.T) {
cfg := DefaultConsensusConfig()

pt := cfg.Consensus.Propose(1)
// customTimeout is 0, should fallback to default timeout
inputTime := time.Now()
expectedTime := inputTime.Add(cfg.TimeoutCommit)
assert.Equal(t, expectedTime, cfg.CommitWithCustomTimeout(inputTime, time.Duration(0)))

fmt.Println(timeout, pt)
// customTimeout is not 0
customTimeout := 2 * time.Second
expectedTime = inputTime.Add(customTimeout)
assert.Equal(t, expectedTime, cfg.CommitWithCustomTimeout(inputTime, customTimeout))
}

0 comments on commit e772715

Please sign in to comment.