Skip to content
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: added test case for points #207

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,25 @@ genesis:
max_voting_power_per_pool: "1"
pool_count: "1"
pool_list:
- config: "{\"network\":\"kyve-1\",\"rpc\":\"https://rpc.kyve.network\"}"
- config: "{\"network\":\"archway-1\",\"rpc\":\"http://ovh-protocol-4:21002\"}"
current_compression_id: "1"
current_index: "0"
current_key: ""
current_storage_provider_id: "3"
current_summary: ""
id: "0"
logo: "ar://WOiYR7qF7G_dp6eO0bFC7AorS7601qgek3X_IeAZook"
logo: "ar://hKb8dVx4E1NCUJ_BlhNOcyfQEta5r38SBXqsfPnAsWE"
max_bundle_size: "100"
min_delegation: "100000000"
name: "KYVE"
name: "Archway"
inflation_share_weight: "1"
disabled: false
runtime: '@kyvejs/tendermint'
start_key: "1"
start_key: "5626500"
total_bundles: "0"
upload_interval: "60"
protocol:
version: "1.1.6"
version: "1.2.0"
binaries: "{\"kyve-linux-arm64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint%401.1.6/kyve-linux-arm64.zip\",\"kyve-linux-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint%401.1.6/kyve-linux-x64.zip\",\"kyve-macos-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint%401.1.6/kyve-macos-x64.zip\"}"
last_upgrade: "0"
upgrade_plan:
Expand Down Expand Up @@ -224,4 +224,4 @@ validators:
config:
consensus:
timeout_commit: "2s"
timeout_propose: "2s"
timeout_propose: "2s"
16 changes: 16 additions & 0 deletions x/bundles/keeper/msg_server_skip_uploader_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ func (k msgServer) SkipUploaderRole(goCtx context.Context, msg *types.MsgSkipUpl
// reset points of uploader as node has proven to be active
k.resetPoints(ctx, msg.PoolId, msg.Staker)

// If previous bundle was dropped just skip uploader role
// No previous round needs to be evaluated
if bundleProposal.StorageId == "" {
nextUploader := k.chooseNextUploader(ctx, msg.PoolId)

// Register empty bundle with next uploader
bundleProposal = types.BundleProposal{
PoolId: msg.PoolId,
NextUploader: nextUploader,
UpdatedAt: uint64(ctx.BlockTime().Unix()),
}
k.SetBundleProposal(ctx, bundleProposal)

return &types.MsgSkipUploaderRoleResponse{}, nil
}

// Previous round contains a bundle which needs to be validated now
result, err := k.tallyBundleProposal(ctx, bundleProposal, msg.PoolId)
if err != nil {
Expand Down
49 changes: 48 additions & 1 deletion x/bundles/keeper/msg_server_skip_uploader_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
stakertypes "github.com/KYVENetwork/chain/x/stakers/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"slices"
)

/*
Expand Down Expand Up @@ -160,6 +161,16 @@ var _ = Describe("msg_server_skip_uploader_role.go", Ordered, func() {
// check that the bundle is not finalized
_, found = s.App().BundlesKeeper.GetFinalizedBundle(s.Ctx(), 0, 0)
Expect(found).To(BeFalse())

// check that no validator got a point for the second round
valaccounts := s.App().StakersKeeper.GetAllValaccountsOfPool(s.Ctx(), 0)
for _, valaccount := range valaccounts {
if valaccount.Staker == i.STAKER_0 {
Expect(valaccount.Points).To(BeZero())
} else {
Expect(valaccount.Points).To(Equal(uint64(1))) // from the first round
}
}
})

It("Skip uploader on data bundle after uploader role has already been skipped", func() {
Expand Down Expand Up @@ -203,12 +214,22 @@ var _ = Describe("msg_server_skip_uploader_role.go", Ordered, func() {
Expect(bundleProposal.VotersInvalid).To(BeEmpty())
Expect(bundleProposal.VotersAbstain).To(BeEmpty())

// here the next uploader should be always be different after skipping
// here the next uploader should always be different after skipping
Expect(bundleProposal.NextUploader).NotTo(Equal(i.STAKER_0))

// check that the bundle is not finalized
_, found = s.App().BundlesKeeper.GetFinalizedBundle(s.Ctx(), 0, 0)
Expect(found).To(BeFalse())

// check that no validator got a point for the second round
valaccounts := s.App().StakersKeeper.GetAllValaccountsOfPool(s.Ctx(), 0)
for _, valaccount := range valaccounts {
if valaccount.Staker == i.STAKER_0 {
Expect(valaccount.Points).To(BeZero())
} else {
Expect(valaccount.Points).To(Equal(uint64(2))) // from the first and second round
}
}
})

It("Skip uploader role on dropped bundle", func() {
Expand Down Expand Up @@ -252,6 +273,16 @@ var _ = Describe("msg_server_skip_uploader_role.go", Ordered, func() {
// check that the bundle is not finalized
_, found = s.App().BundlesKeeper.GetFinalizedBundle(s.Ctx(), 0, 0)
Expect(found).To(BeFalse())

// check that no validator got a point for the second round
valaccounts := s.App().StakersKeeper.GetAllValaccountsOfPool(s.Ctx(), 0)
for _, valaccount := range valaccounts {
if valaccount.Staker == i.STAKER_0 {
Expect(valaccount.Points).To(BeZero())
} else {
Expect(valaccount.Points).To(Equal(uint64(1))) // from the first round
}
}
})

It("Skip uploader role on data bundle with current round containing a valid bundle", func() {
Expand Down Expand Up @@ -300,6 +331,16 @@ var _ = Describe("msg_server_skip_uploader_role.go", Ordered, func() {

Expect(finalizedBundle.PoolId).To(Equal(uint64(0)))
Expect(finalizedBundle.Uploader).To(Equal(i.STAKER_0))

// check if no validator got a point for the second round
valaccounts := s.App().StakersKeeper.GetAllValaccountsOfPool(s.Ctx(), 0)
for _, valaccount := range valaccounts {
if slices.Contains([]string{i.STAKER_0, i.STAKER_1}, valaccount.Staker) {
Expect(valaccount.Points).To(BeZero())
} else {
Expect(valaccount.Points).To(Equal(uint64(1))) // from the first round
}
}
})

It("Skip uploader role on data bundle with current round containing an invalid bundle", func() {
Expand Down Expand Up @@ -352,5 +393,11 @@ var _ = Describe("msg_server_skip_uploader_role.go", Ordered, func() {
// check that the bundle is not finalized
_, found = s.App().BundlesKeeper.GetFinalizedBundle(s.Ctx(), 0, 0)
Expect(found).To(BeFalse())

// check that no validator got a point
valaccounts := s.App().StakersKeeper.GetAllValaccountsOfPool(s.Ctx(), 0)
for _, valaccount := range valaccounts {
Expect(valaccount.Points).To(BeZero())
}
})
})
Loading