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 MinObservation to make observations per observer unique [CCIP-5050] #495

Merged
merged 11 commits into from
Feb 4, 2025

Conversation

asoliman92
Copy link
Contributor

@asoliman92 asoliman92 commented Jan 23, 2025

Make sure that minObservations are unique per observer.

@asoliman92 asoliman92 changed the title Fix MinObservation to make observations per observer unique Fix MinObservation to make observations per observer unique [CCIP-4830] Jan 23, 2025
@asoliman92 asoliman92 changed the title Fix MinObservation to make observations per observer unique [CCIP-4830] Fix MinObservation to make observations per observer unique [CCIP-5050] Jan 28, 2025
execute/plugin.go Outdated Show resolved Hide resolved
@asoliman92 asoliman92 marked this pull request as ready for review February 4, 2025 12:24
@asoliman92 asoliman92 requested a review from a team as a code owner February 4, 2025 12:24
@asoliman92 asoliman92 enabled auto-merge (squash) February 4, 2025 12:48
Comment on lines +37 to +41
if idFunc == nil {
idFunc = func(data T) [32]byte {
return sha3.Sum256([]byte(fmt.Sprintf("%v", data)))
}
}
Copy link
Contributor

@winder winder Feb 4, 2025

Choose a reason for hiding this comment

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

Thinking out loud, but could this version be implemented by overloading the ID func?

	if idFunc == nil {
		idFunc = func(oracle int, data T) [32]byte {
			return sha3.Sum256([]byte(fmt.Sprintf("%d_%v", oracle, data)))
		}
	} else {
		idFunc = func(oracle int, data T) [32]byte {
			return sha3.Sum256([]byte(fmt.Sprintf("%d_%v", oracle, idFunc(data))))
		}
	}

Copy link
Contributor Author

@asoliman92 asoliman92 Feb 4, 2025

Choose a reason for hiding this comment

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

thought about this and tried it, was't straightforward to use from the callers' though. don't remember the specific reason for it now.

Comment on lines 17 to 20
// OracleMinObservation provides a way to ensure a minimum number of observations for
// some piece of data have occurred. It maintains an internal cache and provides a list
// of valid or invalid data points.
type OracleMinObservation[T any] interface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This API doc comment should outline why this would be used instead of MinObservation. I think you can say that OracleMinObservation ensures that duplicate observations from the same observer are only counted once? TBH this should be the default behavior, I'm not even sure we should have a separate MinObservation and OracleMinObservation.

cc @winder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned in DM I agree we should have one. It's a big change that will take some time and other plugins already use maps for most observations which by design prevents duplicates.

internal/plugincommon/consensus/oracle_min_observation.go Outdated Show resolved Hide resolved
internal/plugincommon/consensus/oracle_min_observation.go Outdated Show resolved Hide resolved
internal/plugincommon/consensus/oracle_min_observation.go Outdated Show resolved Hide resolved
winder
winder previously approved these changes Feb 4, 2025
Co-authored-by: Will Winder <wwinder.unh@gmail.com>
Copy link

github-actions bot commented Feb 4, 2025

Metric CCIP-4830-harden-consensus main
Coverage 75.8% 75.8%

@asoliman92 asoliman92 merged commit 74259ab into main Feb 4, 2025
17 checks passed
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

Successfully merging this pull request may close these issues.

3 participants