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

chore: fp distribution #34

Merged
merged 1 commit into from
Nov 22, 2024
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
8 changes: 4 additions & 4 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ func (m *Manager) RunBabylondResource(
"--covenant-quorum=1 --covenant-pks=%s "+
"--min-signed-per-window=0 && "+ // never jail sluggish fps
"chmod -R 777 /home && "+
"sed -i -e 's/iavl-cache-size = 781250/iavl-cache-size = 50000/' /home/node0/babylond/config/app.toml && "+ // disable the cache otherwise we go OOM
//"sed -i -e 's/iavl-disable-fastnode = false/iavl-disable-fastnode = true/' /home/node0/babylond/config/app.toml && "+
"sed -i -e 's/iavl-cache-size = 781250/iavl-cache-size = 0/' /home/node0/babylond/config/app.toml && "+ // disable the cache otherwise we go OOM
"sed -i -e 's/iavl-disable-fastnode = false/iavl-disable-fastnode = true/' /home/node0/babylond/config/app.toml && "+
`sed -i -e 's/timeout_commit = "5s"/timeout_commit = "2s"/' /home/node0/babylond/config/config.toml &&`+
"babylond start --home=/home/node0/babylond --rpc.pprof_laddr=0.0.0.0:6060",
epochInterval, slashingPkScript, baseHeaderHex, bbn.NewBIP340PubKeyFromBTCPK(CovenantPubKey).MarshalHex()),
Expand Down Expand Up @@ -279,8 +279,8 @@ func (m *Manager) RunBabylondResource(
cmd2 := []string{
"sh", "-c", fmt.Sprintf(
"chmod -R 777 /home && ls -la &&" +
"sed -i -e 's/iavl-cache-size = 781250/iavl-cache-size = 50000/' /home/node1/babylond/config/app.toml && " + // disable the cache otherwise we go OOM
//"sed -i -e 's/iavl-disable-fastnode = false/iavl-disable-fastnode = true/' /home/node1/babylond/config/app.toml && " +
"sed -i -e 's/iavl-cache-size = 781250/iavl-cache-size = 0/' /home/node1/babylond/config/app.toml && " + // disable the cache otherwise we go OOM
"sed -i -e 's/iavl-disable-fastnode = false/iavl-disable-fastnode = true/' /home/node1/babylond/config/app.toml && " +
`sed -i -e 's/timeout_commit = "5s"/timeout_commit = "2s"/' /home/node1/babylond/config/config.toml &&` +
"babylond start --home=/home/node1/babylond --rpc.pprof_laddr=0.0.0.0:6060",
),
Expand Down
5 changes: 4 additions & 1 deletion harness/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ func startHarness(cmdCtx context.Context, cfg config.Config) error {
if err != nil {
return err
}
stakers = append(stakers, NewBTCStaker(tm, stakerSender, fpMgr.randomFp().btcPk.MustToBTCPK(), tm.fundingRequests, tm.fundingResponse))

rndFpChunk := fpMgr.getRandomChunk(3)

stakers = append(stakers, NewBTCStaker(tm, stakerSender, rndFpChunk, tm.fundingRequests, tm.fundingResponse))
}

// periodically check if we need to fund the staker
Expand Down
15 changes: 13 additions & 2 deletions harness/btcstaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ type BTCStaker struct {
tm *TestManager
client *SenderWithBabylonClient
fpPK *btcec.PublicKey
fpPKChunk []*btcec.PublicKey
fundingRequest chan sdk.AccAddress
fundingResponse chan sdk.AccAddress
}

func NewBTCStaker(
tm *TestManager,
client *SenderWithBabylonClient,
finalityProviderPublicKey *btcec.PublicKey,
finalityProvidersPublicKey []*btcec.PublicKey,
fundingRequest chan sdk.AccAddress,
fundingResponse chan sdk.AccAddress,
) *BTCStaker {
return &BTCStaker{
tm: tm,
client: client,
fpPK: finalityProviderPublicKey,
fpPKChunk: finalityProvidersPublicKey,
fundingRequest: fundingRequest,
fundingResponse: fundingResponse,
}
Expand Down Expand Up @@ -89,6 +90,9 @@ func (s *BTCStaker) runForever(ctx context.Context, stakerAddress btcutil.Addres
continue
}

// each round rnd FP to delegate
s.fpPK = s.randomFpPK()

if err = s.buildAndSendStakingTransaction(ctx, stakerAddress, stakerPk, &paramsResp.Params); err != nil {
fmt.Printf("🚫 Err in BTC Staker (%s), err: %v\n", s.client.BabylonAddress.String(), err)
if strings.Contains(err.Error(), "insufficient funds") {
Expand Down Expand Up @@ -584,3 +588,10 @@ func bbnPksToBtcPks(pks []bbn.BIP340PubKey) ([]*btcec.PublicKey, error) {
}
return btcPks, nil
}

func (s *BTCStaker) randomFpPK() *btcec.PublicKey {
r.Seed(time.Now().UnixNano())
randomIndex := r.Intn(len(s.fpPKChunk))

return s.fpPKChunk[randomIndex]
}
29 changes: 26 additions & 3 deletions harness/finalityprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,32 @@ func (fpi *FinalityProviderInstance) hasVotingPower(ctx context.Context, b *Bloc
return true, nil
}

func (fpm *FinalityProviderManager) randomFp() *FinalityProviderInstance {
randomIndex := r.Intn(len(fpm.finalityProviders))
func (fpm *FinalityProviderManager) getRandomChunk(chunkSize int) []*btcec.PublicKey {
if len(fpm.finalityProviders) == 0 {
return []*btcec.PublicKey{}
}

if chunkSize >= len(fpm.finalityProviders) || len(fpm.finalityProviders) == 1 {
return fpiToBtcPks(fpm.finalityProviders)
}

r.Seed(time.Now().UnixNano())

startIndex := r.Intn(len(fpm.finalityProviders) - chunkSize + 1)

chunk := fpm.finalityProviders[startIndex : startIndex+chunkSize]

return fpiToBtcPks(chunk)
}

func fpiToBtcPks(fpi []*FinalityProviderInstance) []*btcec.PublicKey {
fpPKs := make([]*btcec.PublicKey, 0, len(fpi))

for _, fp := range fpi {
fpPKs = append(fpPKs, fp.btcPk.MustToBTCPK())
}

return fpm.finalityProviders[randomIndex]
return fpPKs
}

func (fpm *FinalityProviderManager) queryFinalizedBlockForever(ctx context.Context) {
Expand Down Expand Up @@ -582,6 +604,7 @@ func (fpi *FinalityProviderInstance) submitFinalitySigForever(ctx context.Contex
}

if !hasVp {
time.Sleep(500 * time.Millisecond)
continue
}

Expand Down