Skip to content

Commit

Permalink
chore: add wait group to send finality sig together
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Jan 30, 2025
1 parent d48499c commit e5c8ffc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
58 changes: 35 additions & 23 deletions test/e2e/btc_rewards_distribution_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math"
"math/rand"
"strings"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -259,42 +260,53 @@ func (s *BtcRewardsDistribution) Test4CommitPublicRandomnessAndSealed() {
fp2CommitPubRandList.Sig,
)

n1.WaitForNextBlock()
n2.WaitForNextBlock()
n1.WaitUntilCurrentEpochIsSealedAndFinalized(1)

fp1CommitPubRand := n1.QueryListPubRandCommit(fp1CommitPubRandList.FpBtcPk)
s.Require().Equal(fp1CommitPubRand[commitStartHeight].NumPubRand, numPubRand)
fp2CommitPubRand := n2.QueryListPubRandCommit(fp2CommitPubRandList.FpBtcPk)
s.Require().Equal(fp2CommitPubRand[commitStartHeight].NumPubRand, numPubRand)

n1.WaitUntilCurrentEpochIsSealedAndFinalized(1)

s.finalityBlockHeightVoted = n1.WaitFinalityIsActivated()

// submit finality signature
s.finalityIdx = s.finalityBlockHeightVoted - commitStartHeight

appHash := n1.AddFinalitySignatureToBlock(
s.fp1BTCSK,
s.fp1.BtcPk,
s.finalityBlockHeightVoted,
s.fp1RandListInfo.SRList[s.finalityIdx],
&s.fp1RandListInfo.PRList[s.finalityIdx],
*s.fp1RandListInfo.ProofList[s.finalityIdx].ToProto(),
fmt.Sprintf("--from=%s", wFp1),
)

n2.AddFinalitySignatureToBlock(
s.fp2BTCSK,
s.fp2.BtcPk,
s.finalityBlockHeightVoted,
s.fp2RandListInfo.SRList[s.finalityIdx],
&s.fp2RandListInfo.PRList[s.finalityIdx],
*s.fp2RandListInfo.ProofList[s.finalityIdx].ToProto(),
fmt.Sprintf("--from=%s", wFp2),
n1.WaitForNextBlockWithSleep50ms()
var (
wg sync.WaitGroup
appHash bytes.HexBytes
)
wg.Add(2)

go func() {
defer wg.Done()
appHash = n1.AddFinalitySignatureToBlock(
s.fp1BTCSK,
s.fp1.BtcPk,
s.finalityBlockHeightVoted,
s.fp1RandListInfo.SRList[s.finalityIdx],
&s.fp1RandListInfo.PRList[s.finalityIdx],
*s.fp1RandListInfo.ProofList[s.finalityIdx].ToProto(),
fmt.Sprintf("--from=%s", wFp1),
)
}()

go func() {
defer wg.Done()
n2.AddFinalitySignatureToBlock(
s.fp2BTCSK,
s.fp2.BtcPk,
s.finalityBlockHeightVoted,
s.fp2RandListInfo.SRList[s.finalityIdx],
&s.fp2RandListInfo.PRList[s.finalityIdx],
*s.fp2RandListInfo.ProofList[s.finalityIdx].ToProto(),
fmt.Sprintf("--from=%s", wFp2),
)
}()

n2.WaitForNextBlock()
wg.Wait()
n1.WaitForNextBlockWithSleep50ms()

// ensure vote is eventually cast
var finalizedBlocks []*ftypes.IndexedBlock
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/initialization/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ func updateBtccheckpointGenesis(btccheckpointGenState *btccheckpointtypes.Genesi

func updateFinalityGenesis(finalityGenState *finalitytypes.GenesisState) {
finalityGenState.Params = finalitytypes.DefaultParams()
finalityGenState.Params.FinalityActivationHeight = 1
finalityGenState.Params.FinalitySigTimeout = 5
finalityGenState.Params.FinalityActivationHeight = 0
finalityGenState.Params.FinalitySigTimeout = 4
finalityGenState.Params.SignedBlocksWindow = 300
}

Expand Down

0 comments on commit e5c8ffc

Please sign in to comment.