-
Notifications
You must be signed in to change notification settings - Fork 42
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
fix: e2e rewards test flaky #421
Open
RafilxTenfen
wants to merge
32
commits into
main
Choose a base branch
from
rafilx/tryfix-flunky-e2e-rwd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
80fba51
chore: add log
RafilxTenfen e970146
Merge branch 'main' of github.com:babylonlabs-io/babylon into rafilx/…
RafilxTenfen 5b2abca
Merge branch 'main' of github.com:babylonlabs-io/babylon into rafilx/…
RafilxTenfen 67d5abe
chore: add #421 to changelog and add checks for pub rand commit
RafilxTenfen f852a0b
fix: check of lenght pub rand commit
RafilxTenfen 0c17d55
Merge branch 'main' of github.com:babylonlabs-io/babylon into rafilx/…
RafilxTenfen b3b8f67
fix: check num pub rand
RafilxTenfen 5bef2ec
chore: add eventually check of rewards
RafilxTenfen f2ec45e
chore: reduce number of rwd blocks
RafilxTenfen efc9a26
chore: add more conditions to eventually run
RafilxTenfen d48499c
tryfix: modify finality params
RafilxTenfen e5c8ffc
chore: add wait group to send finality sig together
RafilxTenfen 559a654
chore: add checks for fps prior to epoch finalization and removed gas…
RafilxTenfen e233712
chore: rollback build testnet upgrade flag
RafilxTenfen 0231296
tryfix: add more balances to wallets
RafilxTenfen f972d6c
chore: add new function to better verify reward amounts
RafilxTenfen 37ec38f
chore: add check of existence rewards
RafilxTenfen 80f24c7
tryfix: coins withdraw
RafilxTenfen 1617511
fix: lint
RafilxTenfen f5ba76b
tryfix: ibc conn
RafilxTenfen 4c66241
chore: remove gas limit
RafilxTenfen 1dca41c
fix: avoid division by 0
RafilxTenfen 2f54c82
chore: increase amounts
RafilxTenfen e1324e5
chore: refactory ibc transfer testing
RafilxTenfen 69cc13f
fix: lint err wrapping
RafilxTenfen 7c8a1b4
fix: lint err check
RafilxTenfen 5783e52
chore: add back gas auto to wasm store
RafilxTenfen b679910
fix transfer ibc
RafilxTenfen 8cb7770
fix: addrB in transfer back
RafilxTenfen e19df9d
chore: refactory check of amounts in ibc transfers
RafilxTenfen 8f9b3bd
fix: node that queries tx
RafilxTenfen cbad0f4
fix: wait for one block to get the tx
RafilxTenfen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"math" | ||
"math/rand" | ||
"strings" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
|
@@ -126,10 +127,13 @@ func (s *BtcRewardsDistribution) Test1CreateFinalityProviders() { | |
n2, err := chainA.GetNodeAtIndex(2) | ||
s.NoError(err) | ||
|
||
n1.WaitForNextBlock() | ||
n2.WaitForNextBlock() | ||
|
||
s.fp1Addr = n1.KeysAdd(wFp1) | ||
s.fp2Addr = n2.KeysAdd(wFp2) | ||
|
||
n2.BankMultiSendFromNode([]string{s.fp1Addr, s.fp2Addr}, "100000ubbn") | ||
n2.BankMultiSendFromNode([]string{s.fp1Addr, s.fp2Addr}, "1000000ubbn") | ||
|
||
n2.WaitForNextBlock() | ||
|
||
|
@@ -164,7 +168,7 @@ func (s *BtcRewardsDistribution) Test2CreateFirstBtcDelegations() { | |
s.del1Addr = n2.KeysAdd(wDel1) | ||
s.del2Addr = n2.KeysAdd(wDel2) | ||
|
||
n2.BankMultiSendFromNode([]string{s.del1Addr, s.del2Addr}, "100000ubbn") | ||
n2.BankMultiSendFromNode([]string{s.del1Addr, s.del2Addr}, "1000000ubbn") | ||
|
||
n2.WaitForNextBlock() | ||
|
||
|
@@ -174,6 +178,9 @@ func (s *BtcRewardsDistribution) Test2CreateFirstBtcDelegations() { | |
s.CreateBTCDelegationAndCheck(n2, wDel2, s.fp1, s.del2BTCSK, s.del2Addr, s.fp1Del2StakingAmt) | ||
// fp2Del1 | ||
s.CreateBTCDelegationAndCheck(n2, wDel1, s.fp2, s.del1BTCSK, s.del1Addr, s.fp2Del1StakingAmt) | ||
|
||
resp := n2.QueryBtcDelegations(bstypes.BTCDelegationStatus_ANY) | ||
require.Len(s.T(), resp.BtcDelegations, 3) | ||
} | ||
|
||
// Test3SubmitCovenantSignature covenant approves all the 3 BTC delegation | ||
|
@@ -192,13 +199,13 @@ func (s *BtcRewardsDistribution) Test3SubmitCovenantSignature() { | |
} | ||
s.covenantWallets = covWallets | ||
|
||
n1.BankMultiSendFromNode(covAddrs, "100000ubbn") | ||
n1.BankMultiSendFromNode(covAddrs, "1000000ubbn") | ||
|
||
// tx bank send needs to take effect | ||
n1.WaitForNextBlock() | ||
|
||
pendingDelsResp := n1.QueryFinalityProvidersDelegations(s.fp1.BtcPk.MarshalHex(), s.fp2.BtcPk.MarshalHex()) | ||
s.Equal(len(pendingDelsResp), 3) | ||
s.Require().Equal(len(pendingDelsResp), 3) | ||
|
||
for _, pendingDelResp := range pendingDelsResp { | ||
pendingDel, err := ParseRespBTCDelToBTCDel(pendingDelResp) | ||
|
@@ -211,9 +218,9 @@ func (s *BtcRewardsDistribution) Test3SubmitCovenantSignature() { | |
|
||
// ensure the BTC delegation has covenant sigs now | ||
activeDelsSet := n1.QueryFinalityProvidersDelegations(s.fp1.BtcPk.MarshalHex(), s.fp2.BtcPk.MarshalHex()) | ||
s.Len(activeDelsSet, 3) | ||
s.Require().Len(activeDelsSet, 3) | ||
for _, activeDel := range activeDelsSet { | ||
s.True(activeDel.Active) | ||
s.Require().True(activeDel.Active) | ||
} | ||
} | ||
|
||
|
@@ -253,34 +260,87 @@ func (s *BtcRewardsDistribution) Test4CommitPublicRandomnessAndSealed() { | |
fp2CommitPubRandList.Sig, | ||
) | ||
|
||
n1.WaitUntilCurrentEpochIsSealedAndFinalized(1) | ||
// needs to wait for a block to make sure the pub rand is committed | ||
// prior to epoch finalization | ||
n2.WaitForNextBlockWithSleep50ms() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. important part, before the pub rand might not get included in the latest epoch and then it would not be finalized |
||
|
||
// check all FPs requirement to be active | ||
// TotalBondedSat > 0 | ||
// IsTimestamped | ||
// !IsJailed | ||
// !IsSlashed | ||
|
||
fp1CommitPubRand := n1.QueryListPubRandCommit(fp1CommitPubRandList.FpBtcPk) | ||
fp1PubRand := fp1CommitPubRand[commitStartHeight] | ||
s.Require().Equal(fp1PubRand.NumPubRand, numPubRand) | ||
|
||
fp2CommitPubRand := n2.QueryListPubRandCommit(fp2CommitPubRandList.FpBtcPk) | ||
fp2PubRand := fp2CommitPubRand[commitStartHeight] | ||
s.Require().Equal(fp2PubRand.NumPubRand, numPubRand) | ||
|
||
finalizedEpoch := n1.WaitUntilCurrentEpochIsSealedAndFinalized(1) | ||
s.Require().GreaterOrEqual(finalizedEpoch, fp1PubRand.EpochNum) | ||
s.Require().GreaterOrEqual(finalizedEpoch, fp2PubRand.EpochNum) | ||
|
||
fps := n2.QueryFinalityProviders() | ||
s.Require().Len(fps, 2) | ||
for _, fp := range fps { | ||
s.Require().False(fp.Jailed, "fp is jailed") | ||
s.Require().Zero(fp.SlashedBabylonHeight, "fp is slashed") | ||
fpDels := n2.QueryFinalityProviderDelegations(fp.BtcPk.MarshalHex()) | ||
if fp.BtcPk.Equals(s.fp1.BtcPk) { | ||
s.Require().Len(fpDels, 2) | ||
} else { | ||
s.Require().Len(fpDels, 1) | ||
} | ||
for _, fpDelStaker := range fpDels { | ||
for _, fpDel := range fpDelStaker.Dels { | ||
s.Require().True(fpDel.Active) | ||
s.Require().GreaterOrEqual(fpDel.TotalSat, uint64(0)) | ||
} | ||
} | ||
} | ||
|
||
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 | ||
|
@@ -328,6 +388,15 @@ func (s *BtcRewardsDistribution) Test5CheckRewardsFirstDelegations() { | |
s.True(del.Active) | ||
} | ||
|
||
// makes sure there is some reward there | ||
s.Eventually(func() bool { | ||
_, errFp1 := n2.QueryRewardGauge(s.fp1.Address()) | ||
_, errFp2 := n2.QueryRewardGauge(s.fp2.Address()) | ||
_, errDel1 := n2.QueryRewardGauge(sdk.MustAccAddressFromBech32(s.del1Addr)) | ||
_, errDel2 := n2.QueryRewardGauge(sdk.MustAccAddressFromBech32(s.del2Addr)) | ||
return errFp1 == nil && errFp2 == nil && errDel1 == nil && errDel2 == nil | ||
}, time.Minute*2, time.Second*3, "wait to have some rewards available in the gauge") | ||
|
||
// The rewards distributed for the finality providers should be fp1 => 3x, fp2 => 1x | ||
fp1DiffRewards, fp2DiffRewards, del1DiffRewards, del2DiffRewards := s.QueryRewardGauges(n2) | ||
s.AddFinalityVoteUntilCurrentHeight() | ||
|
@@ -413,8 +482,8 @@ func (s *BtcRewardsDistribution) Test7CheckRewards() { | |
// (del1) => 4_00000000 | ||
// (del2) => 10_00000000 | ||
|
||
// gets the difference in rewards in 8 blocks range | ||
fp1DiffRewards, fp2DiffRewards, del1DiffRewards, del2DiffRewards := s.GetRewardDifferences(8) | ||
// gets the difference in rewards in 4 blocks range | ||
fp1DiffRewards, fp2DiffRewards, del1DiffRewards, del2DiffRewards := s.GetRewardDifferences(4) | ||
|
||
// Check the difference in the finality providers | ||
// fp1 should receive ~75% of the rewards received by fp2 | ||
|
@@ -604,19 +673,31 @@ func (s *BtcRewardsDistribution) QueryRewardGauges(n *chain.NodeConfig) ( | |
|
||
g.Go(func() error { | ||
fp1RewardGauges, err = n.QueryRewardGauge(s.fp1.Address()) | ||
return err | ||
if err != nil { | ||
return fmt.Errorf("failed to query rewards for fp1: %w", err) | ||
} | ||
return nil | ||
}) | ||
g.Go(func() error { | ||
fp2RewardGauges, err = n.QueryRewardGauge(s.fp2.Address()) | ||
return err | ||
if err != nil { | ||
return fmt.Errorf("failed to query rewards for fp2: %w", err) | ||
} | ||
return nil | ||
}) | ||
g.Go(func() error { | ||
btcDel1RewardGauges, err = n.QueryRewardGauge(sdk.MustAccAddressFromBech32(s.del1Addr)) | ||
return err | ||
if err != nil { | ||
return fmt.Errorf("failed to query rewards for del1: %w", err) | ||
} | ||
return nil | ||
}) | ||
g.Go(func() error { | ||
btcDel2RewardGauges, err = n.QueryRewardGauge(sdk.MustAccAddressFromBech32(s.del2Addr)) | ||
return err | ||
if err != nil { | ||
return fmt.Errorf("failed to query rewards for del2: %w", err) | ||
} | ||
return nil | ||
}) | ||
s.NoError(g.Wait()) | ||
|
||
|
@@ -660,12 +741,13 @@ func CheckWithdrawReward( | |
n.WaitForNextBlockWithSleep50ms() | ||
|
||
delBalanceBeforeWithdraw, err := n.QueryBalances(delAddr) | ||
require.NoError(t, err) | ||
|
||
txHash := n.WithdrawReward(itypes.BTCDelegationType.String(), delWallet) | ||
|
||
n.WaitForNextBlock() | ||
|
||
_, txResp := n.QueryTx(txHash) | ||
require.NoError(t, err) | ||
|
||
delRwdGauge, errRwdGauge := n.QueryRewardGauge(accDelAddr) | ||
require.NoError(t, errRwdGauge) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would panic to quote as zero