From ed6f91790634477bf8fe597f144ad623ebcd1aff Mon Sep 17 00:00:00 2001 From: Lazar <12626340+Lazar955@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:18:11 +0100 Subject: [PATCH] chore(headers): batch headers (#32) * batch headers * longer timeout --- e2e/e2e_test.go | 2 +- harness/app.go | 2 +- harness/babylonclient.go | 2 +- harness/btcstaker.go | 7 +++---- harness/finalityprovider.go | 1 - harness/headergenerator.go | 10 ++++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 02c0690..e0e6d18 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -10,7 +10,7 @@ import ( ) func TestCreatesDelegations(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) defer cancel() cfg := config.Config{ diff --git a/harness/app.go b/harness/app.go index 81fb49e..c983891 100644 --- a/harness/app.go +++ b/harness/app.go @@ -25,7 +25,7 @@ func startHarness(cmdCtx context.Context, cfg config.Config) error { numStakers := cfg.TotalStakers numFinalityProviders := cfg.TotalFinalityProviders - const numMatureOutputs = uint32(1500) + const numMatureOutputs = uint32(6000) stopChan := make(chan struct{}) // for stopping when we reach totalDelegations tm, err := StartManager(ctx, numMatureOutputs, 5, cfg) diff --git a/harness/babylonclient.go b/harness/babylonclient.go index 94d2cd9..99b4be6 100644 --- a/harness/babylonclient.go +++ b/harness/babylonclient.go @@ -197,7 +197,7 @@ func ToProviderMsgs(msgs []sdk.Msg) []pv.RelayerMessage { } func (s *SenderWithBabylonClient) InsertBTCHeadersToBabylon(ctx context.Context, headers []*wire.BlockHeader) (*pv.RelayerTxResponse, error) { - var headersBytes []bbntypes.BTCHeaderBytes + headersBytes := make([]bbntypes.BTCHeaderBytes, 0, len(headers)) for _, h := range headers { headersBytes = append(headersBytes, bbntypes.NewBTCHeaderBytesFromBlockHeader(h)) diff --git a/harness/btcstaker.go b/harness/btcstaker.go index 76dfa88..205ae14 100644 --- a/harness/btcstaker.go +++ b/harness/btcstaker.go @@ -88,11 +88,10 @@ func (s *BTCStaker) runForever(ctx context.Context, stakerAddress btcutil.Addres fmt.Printf("🚫 Err getting staking params %v\n", err) continue } - err = s.buildAndSendStakingTransaction(ctx, stakerAddress, stakerPk, ¶msResp.Params) - if err != nil { - fmt.Printf("🚫 Err in BTC Staker (%s), err: %v\n", s.client.BabylonAddress.String(), err) - if strings.Contains(strings.ToLower(err.Error()), "insufficient funds") { + if err = s.buildAndSendStakingTransaction(ctx, stakerAddress, stakerPk, ¶msResp.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") { if s.requestFunding(ctx) { fmt.Printf("✅ Received funding for %s\n", s.client.BabylonAddress.String()) } else { diff --git a/harness/finalityprovider.go b/harness/finalityprovider.go index ab62d96..2828ce0 100644 --- a/harness/finalityprovider.go +++ b/harness/finalityprovider.go @@ -600,6 +600,5 @@ func (fpi *FinalityProviderInstance) submitFinalitySigForever(ctx context.Contex if err = fpi.submitFinalitySignature(ctx, blocks); err != nil { fmt.Printf("🚫 Err submitting fin signature: %v\n", err) } - } } diff --git a/harness/headergenerator.go b/harness/headergenerator.go index 1d64de6..342022c 100644 --- a/harness/headergenerator.go +++ b/harness/headergenerator.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" + "slices" ) type BTCHeaderGenerator struct { @@ -33,7 +34,7 @@ func (s *BTCHeaderGenerator) CatchUpBTCLightClient(ctx context.Context) error { } btclcHeight := tipResp.Header.Height - var headers []*wire.BlockHeader + headers := make([]*wire.BlockHeader, 0, btcHeight) for i := int(btclcHeight + 1); i <= int(btcHeight); i++ { hash, err := s.tm.TestRpcClient.GetBlockHash(int64(i)) if err != nil { @@ -46,9 +47,10 @@ func (s *BTCHeaderGenerator) CatchUpBTCLightClient(ctx context.Context) error { headers = append(headers, header) } - _, err = s.client.InsertBTCHeadersToBabylon(ctx, headers) - if err != nil { - return err + for headersChunk := range slices.Chunk(headers, 1500) { + if _, err = s.client.InsertBTCHeadersToBabylon(ctx, headersChunk); err != nil { + return err + } } return nil