Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/gov/types: NewProposal unnecessarily creates a Proposal object that’s discarded on any error #8571

Closed
2 of 4 tasks
odeke-em opened this issue Feb 12, 2021 · 0 comments · Fixed by #8586
Closed
2 of 4 tasks
Labels
good first issue Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity.

Comments

@odeke-em
Copy link
Collaborator

Summary of Bug

This code could be improved to create the proposal only when the coast is clear

func NewProposal(content Content, id uint64, submitTime, depositEndTime time.Time) (Proposal, error) {
p := Proposal{
ProposalId: id,
Status: StatusDepositPeriod,
FinalTallyResult: EmptyTallyResult(),
TotalDeposit: sdk.NewCoins(),
SubmitTime: submitTime,
DepositEndTime: depositEndTime,
}
msg, ok := content.(proto.Message)
if !ok {
return Proposal{}, fmt.Errorf("%T does not implement proto.Message", content)
}
any, err := types.NewAnyWithValue(msg)
if err != nil {
return Proposal{}, err
}
p.Content = any
return p, nil
}

otherwise presently it expends RAM. Unfortunately because there are property assignments, memory is consumed. If it were just a variable declaration, it wouldn’t be a problem. To expend RAM, one could create many error-ing proposals.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@odeke-em odeke-em added good first issue Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity. labels Feb 12, 2021
@mergify mergify bot closed this as completed in #8586 Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant