Skip to content

Commit

Permalink
magellan wip
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht committed Sep 5, 2023
1 parent 581065d commit 6eaeb92
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions vms/platformvm/dac/camino_change_base_fee_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,31 @@ func (p *BaseFeeProposalState) AddVote(voterAddress ids.ShortID, voteIntf Vote)
return updatedProposal, nil
}

// Will return modified proposal with added vote ignoring allowed voters, original proposal will not be modified!
func (p *BaseFeeProposalState) ForceAddVote(voterAddress ids.ShortID, voteIntf Vote) (ProposalState, error) {
vote, ok := voteIntf.(*SimpleVote)
if !ok {
return nil, ErrWrongVote
}
if int(vote.OptionIndex) >= len(p.Options) {
return nil, ErrWrongVote
}

updatedProposal := &BaseFeeProposalState{
Start: p.Start,
End: p.End,
AllowedVoters: p.AllowedVoters,
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: make([]SimpleVoteOption[uint64], len(p.Options)),
},
TotalAllowedVoters: p.TotalAllowedVoters,
}
// we can't use the same slice, cause we need to change its element
copy(updatedProposal.Options, p.Options)
updatedProposal.Options[vote.OptionIndex].Weight++
return updatedProposal, nil
}

func (p *BaseFeeProposalState) Visit(visitor ExecutorVisitor) error {
return visitor.BaseFeeProposal(p)
}
4 changes: 4 additions & 0 deletions vms/platformvm/dac/camino_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ type ProposalState interface {
Visit(ExecutorVisitor) error
// Will return modified ProposalState with added vote, original ProposalState will not be modified!
AddVote(voterAddress ids.ShortID, vote Vote) (ProposalState, error)

// Will return modified proposal with added vote ignoring allowed voters, original proposal will not be modified!
// (used in magellan)
ForceAddVote(voterAddress ids.ShortID, voteIntf Vote) (ProposalState, error)
}

0 comments on commit 6eaeb92

Please sign in to comment.