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

ValidateCoinsForZone can be more efficient #787

Closed
joe-bowman opened this issue Nov 10, 2023 · 2 comments
Closed

ValidateCoinsForZone can be more efficient #787

joe-bowman opened this issue Nov 10, 2023 · 2 comments
Labels

Comments

@joe-bowman
Copy link
Contributor

func (z *Zone) ValidateCoinsForZone(coins sdk.Coins) error {
	zoneVals := z.GetValidatorsAddressesAsSlice()

COINS:
	for _, coin := range coins.Sort() {
		if coin.Denom == z.BaseDenom {
			continue
		}

		for _, v := range zoneVals {
			if strings.HasPrefix(coin.Denom, v) {
				// continue 2 levels
				continue COINS
			}
		}
		return fmt.Errorf("invalid denom for zone: %s", coin.Denom)

	}
	return nil
}

for coins containing multiple coins, we could end up iterating over the entire validatorset (which may be hundreds of validators in length) multiple times. Converting zoneVals into map[string]bool will allow us to lookup the validators with a single iteration of the valset (because the change in lsm denom type means we can now split on '/', and thus conduct a simple lookup against the map).

@Dhoni77
Copy link

Dhoni77 commented Nov 10, 2023

Hi @joe-bowman I would like to work on this

@joe-bowman
Copy link
Contributor Author

Please feel free to!

@faddat faddat closed this as completed in 1adda79 Dec 11, 2023
joe-bowman pushed a commit that referenced this issue Dec 27, 2023
* add improved supply queries

* make supply endpoint config

* fix: improve performance of lsm share token validation; fixes #787

* fix: defensive checks in UpdateWithdrawalRecordsForSlash; add tests; fixes #607

* lint

* lint

* bump depdendencies; remove hanging reference to lsm types

* fixes

* tools: use xbuild for release builds

* tools: bump go/alpine

* tools: makefile build tags

* tools: bump hermes to v1.7.4

* fix: further lint fixes

* fix error response on no validator found

* upgrade: add v1.4.5-rc2 upgrade handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants