Skip to content

Commit

Permalink
fix(dpos): get block with PID
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Jan 22, 2025
1 parent 01563e0 commit 7ddf3e3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions dpos/manager/dposnormalhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func (h *DPOSNormalHandler) ChangeView(firstBlockHash *common.Uint256) {
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)
if h.consensus.GetViewOffset() == v.Proposal.ViewOffset {
h.proposalDispatcher.ProcessProposal(v.ID, v.Proposal, false)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions dpos/manager/illegalbehaviormonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (i *IllegalBehaviorMonitor) Reset(changeView bool) {
i.cachedProposals[k] = v
}
for k, v := range i.dispatcher.precociousProposals {
i.cachedProposals[k] = v
i.cachedProposals[k] = v.Proposal
}
}
}
Expand Down Expand Up @@ -105,8 +105,8 @@ func (i *IllegalBehaviorMonitor) IsLegalProposal(p *payload.DPOSProposal) (*payl
}
}
for _, pre := range i.dispatcher.precociousProposals {
if i.isProposalsIllegal(p, pre) {
return pre, false
if i.isProposalsIllegal(p, pre.Proposal) {
return pre.Proposal, false
}
}

Expand Down
24 changes: 15 additions & 9 deletions dpos/manager/proposaldispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package manager
import (
"bytes"
"errors"

"github.com/elastos/Elastos.ELA/benchmark/common/utils"

"github.com/elastos/Elastos.ELA/blockchain"
Expand Down Expand Up @@ -42,6 +43,11 @@ type ProposalDispatcherConfig struct {
TimeSource dtime.MedianTimeSource
}

type ProposalWithID struct {
Proposal *payload.DPOSProposal
ID peer.PID
}

type ProposalDispatcher struct {
cfg ProposalDispatcherConfig

Expand All @@ -52,7 +58,7 @@ type ProposalDispatcher struct {
acceptVotes map[common.Uint256]*payload.DPOSProposalVote
rejectedVotes map[common.Uint256]*payload.DPOSProposalVote
pendingProposals map[common.Uint256]*payload.DPOSProposal
precociousProposals map[common.Uint256]*payload.DPOSProposal
precociousProposals map[common.Uint256]*ProposalWithID
pendingVotes map[common.Uint256]*payload.DPOSProposalVote

proposalProcessFinished bool
Expand Down Expand Up @@ -220,7 +226,7 @@ func (p *ProposalDispatcher) CleanProposals(changeView bool) {
p.currentInactiveArbitratorTx = nil
p.signedTxs = map[common.Uint256]interface{}{}
p.pendingProposals = make(map[common.Uint256]*payload.DPOSProposal)
p.precociousProposals = make(map[common.Uint256]*payload.DPOSProposal)
p.precociousProposals = make(map[common.Uint256]*ProposalWithID)

p.eventAnalyzer.Clear()
} else {
Expand All @@ -232,7 +238,7 @@ func (p *ProposalDispatcher) CleanProposals(changeView bool) {
}
}
for k, v := range p.precociousProposals {
if v.ViewOffset < currentOffset {
if v.Proposal.ViewOffset < currentOffset {
delete(p.precociousProposals, k)
}
}
Expand All @@ -253,7 +259,7 @@ func (p *ProposalDispatcher) ResetByCurrentView() {
p.currentInactiveArbitratorTx = nil
p.signedTxs = map[common.Uint256]interface{}{}
p.pendingProposals = make(map[common.Uint256]*payload.DPOSProposal)
p.precociousProposals = make(map[common.Uint256]*payload.DPOSProposal)
p.precociousProposals = make(map[common.Uint256]*ProposalWithID)

p.eventAnalyzer.Clear()

Expand Down Expand Up @@ -294,7 +300,7 @@ func (p *ProposalDispatcher) ProcessProposal(id peer.PID, d *payload.DPOSProposa
if d.ViewOffset != p.cfg.Consensus.GetViewOffset() {
log.Info("have different view offset")
if d.ViewOffset > p.cfg.Consensus.GetViewOffset() {
p.precociousProposals[d.Hash()] = d
p.precociousProposals[d.Hash()] = &ProposalWithID{d, id}
}
return true, !self
}
Expand Down Expand Up @@ -392,10 +398,10 @@ func (p *ProposalDispatcher) OnBlockAdded(b *types.Block) {
func (p *ProposalDispatcher) UpdatePrecociousProposals() {
for k, v := range p.precociousProposals {
if p.cfg.Consensus.IsRunning() &&
v.ViewOffset == p.cfg.Consensus.GetViewOffset() {
v.Proposal.ViewOffset == p.cfg.Consensus.GetViewOffset() {
if needRecord, _ := p.ProcessProposal(
peer.PID{}, v, true); needRecord {
p.illegalMonitor.AddProposal(v)
peer.PID{}, v.Proposal, true); needRecord {
p.illegalMonitor.AddProposal(v.Proposal)
}
delete(p.precociousProposals, k)
}
Expand Down Expand Up @@ -1070,7 +1076,7 @@ func NewDispatcherAndIllegalMonitor(cfg ProposalDispatcherConfig) (
acceptVotes: make(map[common.Uint256]*payload.DPOSProposalVote),
rejectedVotes: make(map[common.Uint256]*payload.DPOSProposalVote),
pendingProposals: make(map[common.Uint256]*payload.DPOSProposal),
precociousProposals: make(map[common.Uint256]*payload.DPOSProposal),
precociousProposals: make(map[common.Uint256]*ProposalWithID),
pendingVotes: make(map[common.Uint256]*payload.DPOSProposalVote),
signedTxs: make(map[common.Uint256]interface{}),
firstBadNetworkRecover: true,
Expand Down

0 comments on commit 7ddf3e3

Please sign in to comment.