Skip to content

Commit

Permalink
Merge pull request #6446 from onflow/petera/allow-faster-view-times-t…
Browse files Browse the repository at this point in the history
…estnet

[Benchnet] Allow configuring view times faster than 1s
  • Loading branch information
jordanschalm authored Nov 13, 2024
2 parents acbc34f + e0cc4c6 commit a764d3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions integration/localnet/builder/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (
numViewsInStakingPhase uint64
numViewsInDKGPhase uint64
numViewsEpoch uint64
numViewsPerSecond uint64
epochCommitSafetyThreshold uint64
profiler bool
profileUploader bool
Expand All @@ -88,6 +89,7 @@ func init() {
flag.Uint64Var(&numViewsInStakingPhase, "epoch-staking-phase-length", 2000, "number of views in epoch staking phase")
flag.Uint64Var(&numViewsInDKGPhase, "epoch-dkg-phase-length", 2000, "number of views in epoch dkg phase")
flag.Uint64Var(&epochCommitSafetyThreshold, "epoch-commit-safety-threshold", 1000, "number of views for safety threshold T (assume: one finalization occurs within T blocks)")
flag.Uint64Var(&numViewsPerSecond, "target-view-rate", 1, "target number of views per second")
flag.BoolVar(&profiler, "profiler", DefaultProfiler, "whether to enable the auto-profiler")
flag.BoolVar(&profileUploader, "profile-uploader", DefaultProfileUploader, "whether to upload profiles to the cloud")
flag.BoolVar(&tracing, "tracing", DefaultTracing, "whether to enable low-overhead tracing in flow")
Expand Down Expand Up @@ -127,6 +129,9 @@ func main() {
if numViewsEpoch != 0 {
flowNetworkOpts = append(flowNetworkOpts, testnet.WithViewsInEpoch(numViewsEpoch))
}
if numViewsPerSecond != 0 {
flowNetworkOpts = append(flowNetworkOpts, testnet.WithViewsPerSecond(numViewsPerSecond))
}
if numViewsInStakingPhase != 0 {
flowNetworkOpts = append(flowNetworkOpts, testnet.WithViewsInStakingAuction(numViewsInStakingPhase))
}
Expand Down
16 changes: 14 additions & 2 deletions integration/testnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const (
DefaultViewsInStakingAuction uint64 = 5
DefaultViewsInDKGPhase uint64 = 50
DefaultViewsInEpoch uint64 = 200
DefaultViewsPerSecond uint64 = 1
DefaultEpochCommitSafetyThreshold uint64 = 20
DefaultEpochExtensionViewCount uint64 = 50

Expand Down Expand Up @@ -430,6 +431,7 @@ type NetworkConfig struct {
ViewsInDKGPhase uint64
ViewsInStakingAuction uint64
ViewsInEpoch uint64
ViewsPerSecond uint64
EpochCommitSafetyThreshold uint64
KVStoreFactory func(epochStateID flow.Identifier) (protocol_state.KVStoreAPI, error)
}
Expand All @@ -444,6 +446,7 @@ func NewNetworkConfig(name string, nodes NodeConfigs, opts ...NetworkConfigOpt)
ViewsInStakingAuction: DefaultViewsInStakingAuction,
ViewsInDKGPhase: DefaultViewsInDKGPhase,
ViewsInEpoch: DefaultViewsInEpoch,
ViewsPerSecond: DefaultViewsPerSecond,
EpochCommitSafetyThreshold: DefaultEpochCommitSafetyThreshold,
KVStoreFactory: func(epochStateID flow.Identifier) (protocol_state.KVStoreAPI, error) {
return kvstore.NewDefaultKVStore(DefaultEpochCommitSafetyThreshold, DefaultEpochExtensionViewCount, epochStateID)
Expand Down Expand Up @@ -483,6 +486,12 @@ func WithViewsInEpoch(views uint64) func(*NetworkConfig) {
}
}

func WithViewsPerSecond(views uint64) func(*NetworkConfig) {
return func(config *NetworkConfig) {
config.ViewsPerSecond = views
}
}

func WithViewsInDKGPhase(views uint64) func(*NetworkConfig) {
return func(config *NetworkConfig) {
config.ViewsInDKGPhase = views
Expand Down Expand Up @@ -1161,6 +1170,9 @@ func BootstrapNetwork(networkConf NetworkConfig, bootstrapDir string, chainID fl

dkgOffsetView := rootHeader.View + networkConf.ViewsInStakingAuction - 1

// target number of seconds in epoch
targetDuration := networkConf.ViewsInEpoch / networkConf.ViewsPerSecond

// generate epoch service events
epochSetup := &flow.EpochSetup{
Counter: epochCounter,
Expand All @@ -1172,8 +1184,8 @@ func BootstrapNetwork(networkConf NetworkConfig, bootstrapDir string, chainID fl
Participants: participants.ToSkeleton(),
Assignments: clusterAssignments,
RandomSource: randomSource,
TargetDuration: networkConf.ViewsInEpoch, // 1view/s
TargetEndTime: uint64(time.Now().Unix()) + networkConf.ViewsInEpoch,
TargetDuration: targetDuration,
TargetEndTime: uint64(time.Now().Unix()) + targetDuration,
}

epochCommit := &flow.EpochCommit{
Expand Down

0 comments on commit a764d3e

Please sign in to comment.