Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions sim/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ const (
)

var (
defaultBaseChain gpbft.ECChain
defaultBeacon = []byte("beacon")
defaultLatencyModel latency.Model
defaultBaseChain gpbft.ECChain
defaultBeacon = []byte("beacon")
)

func init() {
Expand All @@ -27,10 +26,6 @@ func init() {
if err != nil {
panic("failed to instantiate default simulation base chain")
}
defaultLatencyModel, err = latency.NewLogNormal(time.Now().UnixMilli(), time.Second*5)
if err != nil {
panic("failed to instantiate default simulation latency model")
}
}

type Option func(*options) error
Expand Down Expand Up @@ -69,7 +64,7 @@ func newOptions(o ...Option) (*options, error) {
opts.honestCount = defaultHonestCount
}
if opts.latencyModel == nil {
opts.latencyModel = defaultLatencyModel
opts.latencyModel = latency.None
}
if opts.signingBacked == nil {
opts.signingBacked = signing.NewFakeBackend()
Expand Down
13 changes: 12 additions & 1 deletion sim/sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (s *Simulation) Run(instanceCount uint64, maxRounds uint64) error {
if s.decisions.err != nil {
return fmt.Errorf("error in decision: %w", s.decisions.err)
}
if s.participants[0].CurrentRound() >= maxRounds {
if s.getMaxRound() > maxRounds {
return fmt.Errorf("reached maximum number of %d rounds", maxRounds)
}
// Verify the current instance as soon as it completes.
Expand Down Expand Up @@ -181,3 +181,14 @@ func (s *Simulation) GetInstance(i int) *ECInstance {
}
return s.ec.Instances[i]
}

func (s *Simulation) getMaxRound() uint64 {
var maxRound uint64
for _, participant := range s.participants {
currentRound := participant.CurrentRound()
if currentRound > maxRound {
maxRound = currentRound
}
}
return maxRound
}