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

Concurrency or catch errors at Handle? #206

Open
HarleyAppleChoi opened this issue Sep 24, 2021 · 0 comments
Open

Concurrency or catch errors at Handle? #206

HarleyAppleChoi opened this issue Sep 24, 2021 · 0 comments

Comments

@HarleyAppleChoi
Copy link
Contributor

Description

For most of the handle functions, we follow the following pattern :
modules/staking/handle_genesis.go

err = saveParams(doc.InitialHeight, genState.Params, db)
if err != nil {
		return fmt.Errorf("error while storing staking genesis params: %s", err)
}

// Parse genesis transactions
err = parseGenesisTransactions(doc, appState, cdc, db)
if err != nil {
	return fmt.Errorf("error while storing genesis transactions: %s", err)
}
...

However, In modules/staking/handle_block.go, the pattern is different from other that use "go" concurrency instead of catching error one by one:

	go updateParams(block.Block.Height, stakingClient, db)

	// Update the voting powers
	go updateValidatorVotingPower(block.Block.Height, vals, db)

	// Update the validators statuses
	go updateValidatorsStatus(block.Block.Height, validators, cdc, db)

The functions calling log later on if there are errors :

err = db.SaveStakingParams(types.NewStakingParams(res.Params, height))
	if err != nil {
		log.Error().Str("module", "staking").Err(err).
			Int64("height", height).
			Msg("error while saving params")
		return
	}

Pros

All calls keep running even if one of the call return errors, which the old one returns when one of the calls gives out an error.

Cons

Error handling might be weird. Need to call log every time for error handling. That might reduce efficiency and harder to read code.

Implementation proposal

Concurrency

Implement a concurrency wrapper function for Handle that can do concurrency and also catching errors.

Stay on the current approach

Do not need to do anything and stay on the current approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant