Skip to content

Commit

Permalink
feat(bpos): vote proposal after change view
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Jun 28, 2023
1 parent 1ba798b commit 0d0fb6f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions dpos/manager/dposnormalhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func (h *DPOSNormalHandler) ProcessProposal(id peer.PID, p *payload.DPOSProposal
func (h *DPOSNormalHandler) ChangeView(firstBlockHash *common.Uint256) {
log.Info("[OnViewChanged] clean proposal")
h.proposalDispatcher.CleanProposals(true)
// sign proposal with same view offset to me
for _, v := range h.proposalDispatcher.precociousProposals {
if h.consensus.GetViewOffset() == v.ViewOffset {
h.proposalDispatcher.ProcessProposal(peer.PID{}, v, false)
}
}
}

func (h *DPOSNormalHandler) TryStartNewConsensus(b *types.Block) bool {
Expand Down
13 changes: 7 additions & 6 deletions dpos/manager/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package manager

import (
"fmt"
"github.com/elastos/Elastos.ELA/utils/test"
"math"
"math/rand"
"sort"
Expand All @@ -10,7 +11,7 @@ import (
)

func TestView_ChangeViewV1(t *testing.T) {
testing.Short()
test.SkipShort(t)
print("[")
for step := uint32(1); step <= 50; step++ {
for i := 0; i < 100; i++ {
Expand All @@ -29,7 +30,7 @@ func TestView_ChangeViewV1(t *testing.T) {
}

func TestView_ChangeViewV2(t *testing.T) {
testing.Short()
test.SkipShort(t)
print("[")
for step := uint32(2); step <= 36; step++ {
for i := 0; i < 100; i++ {
Expand All @@ -50,7 +51,7 @@ func TestView_ChangeViewV2(t *testing.T) {
}

func TestView_ChangeViewV3(t *testing.T) {
testing.Short()
test.SkipShort(t)
addTime := uint32(1)
offsetTime := 60 * time.Second
arbitersCount := 36
Expand All @@ -76,7 +77,7 @@ func TestView_ChangeViewV3(t *testing.T) {
}

func TestView_ChangeViewV3_Special(t *testing.T) {
testing.Short()
test.SkipShort(t)
addTime := uint32(1)
offsetTime := 60 * time.Second
arbitersCount := 36
Expand Down Expand Up @@ -110,7 +111,7 @@ func TestView_ChangeViewV3_Special(t *testing.T) {
}

func TestView_ChangeViewV4(t *testing.T) {
testing.Short()
test.SkipShort(t)
addTime := uint32(1)
offsetTime := 3600 * time.Second
arbitersCount := 36
Expand All @@ -136,7 +137,7 @@ func TestView_ChangeViewV4(t *testing.T) {
}

func TestView_ChangeViewV4_Special(t *testing.T) {
testing.Short()
test.SkipShort(t)
addTime := uint32(3)
offsetTime := 7200 * time.Second
arbitersCount := 36
Expand Down

0 comments on commit 0d0fb6f

Please sign in to comment.