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

Fix addGenesisAccount #4281

Merged
merged 6 commits into from
May 7, 2019
Merged

Fix addGenesisAccount #4281

merged 6 commits into from
May 7, 2019

Conversation

alexanderbez
Copy link
Contributor

@alexanderbez alexanderbez commented May 6, 2019

closes: #4271


  • Targeted PR against correct branch (see CONTRIBUTING.md)

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.

  • Wrote tests

  • Updated relevant documentation (docs/)

  • Added a relevant changelog entry: clog add [section] [stanza] [message]

  • rereviewed Files changed in the github PR explorer


For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@alexanderbez alexanderbez added WIP C:genesis relating to chain genesis labels May 6, 2019
@alexanderbez alexanderbez marked this pull request as ready for review May 6, 2019 15:59
@codecov
Copy link

codecov bot commented May 6, 2019

Codecov Report

Merging #4281 into master will increase coverage by 0.02%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #4281      +/-   ##
==========================================
+ Coverage    59.1%   59.13%   +0.02%     
==========================================
  Files         217      217              
  Lines       14595    14603       +8     
==========================================
+ Hits         8627     8635       +8     
  Misses       5330     5330              
  Partials      638      638

types/coin.go Show resolved Hide resolved
@alexanderbez alexanderbez requested a review from alessio May 6, 2019 17:10
Copy link
Contributor

@alessio alessio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACKed. Thanks!

@alexanderbez alexanderbez force-pushed the bez/4271-fix-addGenesisAccount branch from 4adf7eb to 2022fe6 Compare May 6, 2019 19:10
@alexanderbez
Copy link
Contributor Author

Actually, @alessio @faboweb I reverted the suggested changes. It doesn't make sense to use AllLTE because you don't have to vest the full amount(s).

func (coins Coins) IsAnyGT(coinsB Coins) bool {
if len(coinsB) == 0 {
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be

        // if len(coins) = 0 we know for sure no amount in coins can be GT coinsB
	if len(coins) == 0 {
		return false
	}

        // we learned from the above that coins contains some coins,
        // thus if len(coinsB) == 0 we know for sure there's something GT
	if len(coinsB) == 0 {
		return true
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, it is important to be consistent across the methods. This behaves the same as IsAnyGTE. If coinsB then no denom is present and thus no coin is GT.

Copy link
Contributor

@alessio alessio May 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This:

	if len(coins) == 0 {
		return false
	}

adds a bit of extra readability (thanks to early return) and does not conflict with If coinsB then no denom is present and thus no coin is GT., in fact the for _, coin := range coins would just not be executed anyway when len(coins) == 0. Also it does not break consistency with IsAnyGTE.

Though I see your point, this should be dropped:

	if len(coinsB) == 0 {
		return true
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually,

if len(coins) == 0 {
		return false
	}

is redundant though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I said so above :)

in fact the for _, coin := range coins would just not be executed anyway when len(coins) == 0

It's just early return, readability is added by sparing the reader from continuing reading the rest of the function when len(coins) == 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh I don't think this is necessary at all. The method is pretty concise as-is.

types/coin.go Show resolved Hide resolved
types/coin.go Show resolved Hide resolved
Co-Authored-By: alexanderbez <alexanderbez@users.noreply.github.com>
Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexanderbez alexanderbez merged commit 1bd70a2 into master May 7, 2019
@alexanderbez alexanderbez deleted the bez/4271-fix-addGenesisAccount branch May 7, 2019 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:genesis relating to chain genesis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All vesting coins' OriginalVesting amount should LessEqual to acc.Coins
4 participants