Skip to content

Commit

Permalink
pub rand as param
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Oct 25, 2024
1 parent d2d9e49 commit 323eaa5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
8 changes: 8 additions & 0 deletions cmd/datagen/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
totalStakersFlag = "total-stakers"
babylonPathFlag = "babylon-path"
totalDelegationsFlag = "total-delegations"
numPubRandFlag = "num-public-randomness"
)

// CommandGenerate generates data
Expand All @@ -30,6 +31,7 @@ func CommandGenerate() *cobra.Command {
f.Int(totalFpFlag, 3, "Number of finality providers to run (optional)")
f.Int(totalDelegationsFlag, 0, "Number of delegations to run this cmd, after it we will exit. (optional, 0 for indefinite)")
f.Int(totalStakersFlag, 100, "Number of stakers to run (optional)")
f.Uint32(numPubRandFlag, 150_000, "Number of pub randomness to commit, should be a high value (optional)")

return cmd
}
Expand All @@ -56,7 +58,13 @@ func cmdGenerate(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("failed to read flag %s: %w", totalStakersFlag, err)
}

numPubRand, err := flags.GetUint32(numPubRandFlag)
if err != nil {
return fmt.Errorf("failed to read flag %s: %w", numPubRandFlag, err)
}

cfg := config.Config{
NumPubRand: numPubRand,
TotalStakers: totalStakers,
TotalFinalityProviders: totalFps,
TotalDelegations: totalDelegations,
Expand Down
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import "fmt"

type Config struct {
NumPubRand uint32
TotalStakers int
TotalFinalityProviders int
TotalDelegations int
Expand All @@ -22,5 +23,9 @@ func (c *Config) Validate() error {
return fmt.Errorf("max number of total delegations has to be between [0, 10m]")
}

if c.NumPubRand > 10_000_000 {
return fmt.Errorf("max numbe for pub randomness 10m")
}

return nil
}
2 changes: 1 addition & 1 deletion harness/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func startHarness(ctx context.Context, cfg config.Config) error {
vig.Start(ctx)

fpMgr := NewFinalityProviderManager(tm, fpmSender, zap.NewNop(), numFinalityProviders, fpMgrHome, eotsDir) // todo(lazar); fp count cfg
if err = fpMgr.Initialize(ctx); err != nil {
if err = fpMgr.Initialize(ctx, cfg.NumPubRand); err != nil {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions harness/finalityprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (fpm *FinalityProviderManager) Start(ctx context.Context) {
}

// Initialize creates finality provider instances and EOTS manager
func (fpm *FinalityProviderManager) Initialize(ctx context.Context) error {
func (fpm *FinalityProviderManager) Initialize(ctx context.Context, numPubRand uint32) error {
db, err := lib.NewBackend(fpm.eotsDb)
if err != nil {
return err
Expand Down Expand Up @@ -138,7 +138,7 @@ func (fpm *FinalityProviderManager) Initialize(ctx context.Context) error {
fpm.localEOTS = eots

fmt.Printf("🎲 Starting to commit randomness\n")
if err := fpm.commitRandomness(ctx); err != nil {
if err := fpm.commitRandomness(ctx, numPubRand); err != nil {
return err
}

Expand Down Expand Up @@ -197,9 +197,9 @@ func (fpm *FinalityProviderManager) submitFinalitySigForever(ctx context.Context
}
}

func (fpm *FinalityProviderManager) commitRandomness(ctx context.Context) error {
func (fpm *FinalityProviderManager) commitRandomness(ctx context.Context, numPubRand uint32) error {
startHeight := uint64(1) // todo(lazar): configure
npr := uint32(150_000)
npr := numPubRand
for _, fp := range fpm.finalityProviders {
pubRandList, err := fpm.getPubRandList(startHeight, npr, *fp.btcPk)
if err != nil {
Expand Down

0 comments on commit 323eaa5

Please sign in to comment.