Skip to content

Commit

Permalink
chore(headers): batch headers (#32)
Browse files Browse the repository at this point in the history
* batch headers

* longer timeout
  • Loading branch information
Lazar955 authored Nov 19, 2024
1 parent 35b3e6c commit ed6f917
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion harness/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion harness/babylonclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 3 additions & 4 deletions harness/btcstaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &paramsResp.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, &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") {
if s.requestFunding(ctx) {
fmt.Printf("✅ Received funding for %s\n", s.client.BabylonAddress.String())
} else {
Expand Down
1 change: 0 additions & 1 deletion harness/finalityprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
}
10 changes: 6 additions & 4 deletions harness/headergenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"slices"
)

type BTCHeaderGenerator struct {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit ed6f917

Please sign in to comment.