From 1346d988afc8bc531cf09932b4bf62fe3a9b3729 Mon Sep 17 00:00:00 2001 From: jiangzehua <1092431698@qq.com> Date: Wed, 28 Jun 2023 18:50:53 +0800 Subject: [PATCH] feat(bpos): vote proposal after change view --- dpos/manager/dposnormalhandler.go | 6 ++++++ dpos/manager/view_test.go | 14 ++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dpos/manager/dposnormalhandler.go b/dpos/manager/dposnormalhandler.go index 09ec5baaf..b9f7da47a 100644 --- a/dpos/manager/dposnormalhandler.go +++ b/dpos/manager/dposnormalhandler.go @@ -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 { diff --git a/dpos/manager/view_test.go b/dpos/manager/view_test.go index ae5d658be..ea8d95e9f 100644 --- a/dpos/manager/view_test.go +++ b/dpos/manager/view_test.go @@ -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++ { @@ -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++ { @@ -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 @@ -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 @@ -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 @@ -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