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

Add a generic function to construct error acks with abci codes & string const #819

Closed
4 tasks
damiannolan opened this issue Feb 1, 2022 · 6 comments · Fixed by #1565
Closed
4 tasks
Assignees
Labels
core type: refactor Architecture, code or CI improvements that may or may not tackle technical debt.

Comments

@damiannolan
Copy link
Member

damiannolan commented Feb 1, 2022

Summary

Code is duplicated in ics27 and ics20 in package types to provide deterministic error acknowledgements that include the ABCI error code and a string constant defined at the local package level.
Application developers may want to define their own string constants to be included, however a generic approach would also be useful.

See: #777 & #794

Proposal

  • Add a generic function to 04-channel/types which extracts the ABCI code from a given error and returns a deterministic error acknowledgement

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged/assigned
@damiannolan damiannolan added core type: refactor Architecture, code or CI improvements that may or may not tackle technical debt. labels Feb 1, 2022
@colin-axner
Copy link
Contributor

After giving this more thought. I'm very much in favor of adjusting the current channeltypes.NewErrorAcknowledgement to perform this behaviour. I'd rather require developers to explicitly work around this function (if they really want to avoid the error message extraction)

@damiannolan
Copy link
Member Author

Is this something we should try to get included for v3? If so, I can pick this up later this week.

@colin-axner
Copy link
Contributor

colin-axner commented Mar 14, 2022

I think not (that boat has sailed), but lets get it in for a minor release (it doesn't need to be API breaking)

@crodriguezvega crodriguezvega added this to the Q2-2022-backlog milestone Mar 31, 2022
@crodriguezvega
Copy link
Contributor

So is it the idea to refactor the existing channeltypes.NewErrorAcknowledgement, so that it looks like this?

func NewErrorAcknowledgement(err error, errString string) Acknowledgement {
	// the ABCI code is included in the abcitypes.ResponseDeliverTx hash
	// constructed in Tendermint and is therefore deterministic
	_, code, _ := sdkerrors.ABCIInfo(err, false) // discard non-determinstic codespace and log values

	errorString := fmt.Sprintf("ABCI code: %d: %s", code, errString)

	return Acknowledgement{
		Response: &Acknowledgement_Error{
			Error: errorString,
		},
	}
}

The errString passed as input parameter can be "error handling packet on host chain: see events for details" for interchain accounts, "error handling packet on destination chain: see events for details" for transfers, or any other message that is currently used in the other locations where we use channeltypes.NewErrorAcknowledgement?

@colin-axner
Copy link
Contributor

I actually don't think we should take in an error string as an argument. The intention behind this function is that we remove the possibility of accidental state changes via modification of the error string. I think it is very likely this function would be misused if we allowed the developers to pass in their own error string. I'd prefer to use our own constant "error handling packet: see events for details". If developers want a custom error string, they can construct their own error acknowledgement (as currently requried)

@crodriguezvega
Copy link
Contributor

crodriguezvega commented May 11, 2022

Ok, cool. Then we have to remove the NewErrorAcknowledgement for transfers and the NewErrorAcknowledgement for ICA and we refactor channeltypes.NewErrorAcknowledgement so that it becomes

const (
	// ackErrorString defines a string constant included in error acknowledgements
	// NOTE: Changing this const is state machine breaking as acknowledgements are written into state
	ackErrorString = "error handling packet: see events for details"
)

// NewErrorAcknowledgement returns a deterministic error string which may be used in
// the packet acknowledgement.
func NewErrorAcknowledgement(err error) channeltypes.Acknowledgement {
	// the ABCI code is included in the abcitypes.ResponseDeliverTx hash
	// constructed in Tendermint and is therefore deterministic
	_, code, _ := sdkerrors.ABCIInfo(err, false) // discard non-determinstic codespace and log values

	errorString := fmt.Sprintf("ABCI code: %d: %s", code, ackErrorString)

	return Acknowledgement{
		Response: &Acknowledgement_Error{
			Error: errorString,
		},
	}
}

And we use this one everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core type: refactor Architecture, code or CI improvements that may or may not tackle technical debt.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants