Skip to content

Commit

Permalink
tryfix: add fp voting every now and then
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Dec 18, 2024
1 parent 3c97ab1 commit 955c498
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
45 changes: 40 additions & 5 deletions test/e2e/btc_rewards_distribution_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
sdkmath "cosmossdk.io/math"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/chaincfg"
"github.com/cometbft/cometbft/libs/bytes"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -354,6 +355,8 @@ func (s *BtcRewardsDistribution) Test6ActiveLastDelegation() {
// fp2Del2
s.CreateBTCDelegationAndCheck(n2, wDel2, s.fp2, s.del2BTCSK, s.del2Addr, s.fp2Del2StakingAmt)

s.AddFinalityVote()

allDelegations := n2.QueryFinalityProvidersDelegations(s.fp1.BtcPk.MarshalHex(), s.fp2.BtcPk.MarshalHex())
s.Equal(len(allDelegations), 4)

Expand All @@ -374,6 +377,8 @@ func (s *BtcRewardsDistribution) Test6ActiveLastDelegation() {
// wait for a block so that above txs take effect
n1.WaitForNextBlock()

s.AddFinalityVote()

// ensure the BTC delegation has covenant sigs now
allDelegations = n1.QueryFinalityProvidersDelegations(s.fp1.BtcPk.MarshalHex(), s.fp2.BtcPk.MarshalHex())
s.Len(allDelegations, 4)
Expand All @@ -397,11 +402,10 @@ func (s *BtcRewardsDistribution) Test7FinalityVoteBlock() {
n1, err := chainA.GetNodeAtIndex(1)
s.NoError(err)

lastFinalizedEpoch, err := n1.QueryLastFinalizedEpoch()
s.NoError(err)
lastFinalizedEpoch++

n1.WaitUntilCurrentEpochIsSealedAndFinalized(lastFinalizedEpoch)
// lastFinalizedEpoch, err := n1.QueryLastFinalizedEpoch()
// s.NoError(err)
// lastFinalizedEpoch++
// n1.WaitUntilCurrentEpochIsSealedAndFinalized(lastFinalizedEpoch)

// submit finality signature
s.finalityIdx++
Expand Down Expand Up @@ -508,6 +512,37 @@ func (s *BtcRewardsDistribution) Test8CheckRewards() {

// TODO(rafilx): Slash a FP and expect rewards to be withdraw.

func (s *BtcRewardsDistribution) AddFinalityVote() (appHash bytes.HexBytes) {
chainA := s.configurer.GetChainConfig(0)
n2, err := chainA.GetNodeAtIndex(2)
s.NoError(err)
n1, err := chainA.GetNodeAtIndex(1)
s.NoError(err)

s.finalityIdx++
s.finalityBlockHeightVoted++

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(),
)

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(),
)

return appHash
}

// UpdateRewardGauges update the current reward gauges on the test suite
func (s *BtcRewardsDistribution) UpdateRewardGauges(n *chain.NodeConfig) {
s.fp1LastRewardGauge, s.fp2LastRewardGauge, s.btcDel1LastRewardGauge, s.btcDel2LastRewardGauge = s.QueryRewardGauges(n)
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/initialization/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ func updateBtccheckpointGenesis(btccheckpointGenState *btccheckpointtypes.Genesi
func updateFinalityGenesis(finalityGenState *finalitytypes.GenesisState) {
finalityGenState.Params = finalitytypes.DefaultParams()
finalityGenState.Params.FinalityActivationHeight = 0
finalityGenState.Params.SignedBlocksWindow = 2000
finalityGenState.Params.SignedBlocksWindow = 500
finalityGenState.Params.MinSignedPerWindow = sdkmath.LegacyMustNewDecFromStr("0.005000000000000000")
}

func updateGenUtilGenesis(c *internalChain) func(*genutiltypes.GenesisState) {
Expand Down

0 comments on commit 955c498

Please sign in to comment.