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 type tag to VSCMatured / SlashPackets #567

Closed
2 tasks done
jtremback opened this issue Dec 7, 2022 · 3 comments · Fixed by #626
Closed
2 tasks done

Add type tag to VSCMatured / SlashPackets #567

jtremback opened this issue Dec 7, 2022 · 3 comments · Fixed by #626
Assignees
Labels
invalid This doesn't seem right type: refactoring Code refactoring type: tech-debt Slows down development in the long run

Comments

@jtremback
Copy link
Contributor

jtremback commented Dec 7, 2022

Problem

We do not check the type before unmarshaling packets on the provider. We just try to unmarshal as one type, and if it fails, try as another type. This works for now, but is brittle and error prone.

Closing criteria

A type tag is implemented to distinguish packet types.

Problem details

On lines https://github.com/cosmos/interchain-security/blob/main/x/ccv/provider/ibc_module.go#L175-L189

We unmarshal without really knowing the type of packets on our CCV channel. This works, but is very sketchy.

Our two packet types are

type VSCMaturedPacketData struct {
	// the id of the VSC packet that reached maturity
	ValsetUpdateId uint64 `protobuf:"varint,1,opt,name=valset_update_id,json=valsetUpdateId,proto3" json:"valset_update_id,omitempty"`
}

and

type SlashPacketData struct {
	Validator types.Validator `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator" yaml:"validator"`
	// map to the infraction block height on the provider
	ValsetUpdateId uint64 `protobuf:"varint,2,opt,name=valset_update_id,json=valsetUpdateId,proto3" json:"valset_update_id,omitempty"`
	// tell if the slashing is for a downtime or a double-signing infraction
	Infraction types1.InfractionType `protobuf:"varint,3,opt,name=infraction,proto3,enum=cosmos.staking.v1beta1.InfractionType" json:"infraction,omitempty"`
}

The only actual difference between these two types is that SlashPacketData has a Validator field. InfractionType has omitempty so could be omitted, and ValsetUpdateId exists on both. It could be very easy for the one of these to parse as the other with some minor code changes.

We should come up with a tagging scheme and use it.

TODOs

  • Labels have been added for issue
  • Issue has been added to the ICS project
@jtremback jtremback added invalid This doesn't seem right ccv-core type: tech-debt Slows down development in the long run type: refactoring Code refactoring labels Dec 7, 2022
@jtremback jtremback moved this to Todo in Replicated Security Dec 7, 2022
@MSalopek
Copy link
Contributor

MSalopek commented Dec 8, 2022

We already use a wrapper structure on the consumer side: https://github.com/cosmos/interchain-security/blob/main/proto/interchain_security/ccv/consumer/v1/consumer.proto#L84.

Might be useful to use the same principle - we unmarshal the wrapper, check the type/tag and only then umarshal the embedded data.

@shaspitz
Copy link
Contributor

shaspitz commented Dec 16, 2022

Note that this issue could also make the way that we queue throttled packets a lot cleaner, see #609

@shaspitz
Copy link
Contributor

Wrapper idea sounds best 👍

@mpoke mpoke moved this from Todo to In Progress in Replicated Security Dec 22, 2022
@mpoke mpoke moved this from In Progress to Waiting for review in Replicated Security Dec 22, 2022
Repository owner moved this from Waiting for review to Done in Replicated Security Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right type: refactoring Code refactoring type: tech-debt Slows down development in the long run
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants