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 29, 2023
1 parent 1ba798b commit 1346d98
Show file tree
Hide file tree
Showing 2 changed files with 14 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
14 changes: 8 additions & 6 deletions dpos/manager/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"sort"
"testing"
"time"

"github.com/elastos/Elastos.ELA/utils/test"
)

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 +31,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 +52,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 +78,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 +112,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 +138,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 1346d98

Please sign in to comment.