-
Notifications
You must be signed in to change notification settings - Fork 18
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
MX-14354: snapshotless observers support #388
Merged
bogdan-rosianu
merged 15 commits into
feat/snapshotless-observer-support
from
MX-14354-snapshotless-observers
Sep 26, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bed8f52
[WIP] snapshotless observers support
bogdan-rosianu ec2c8a6
fixes + tests
bogdan-rosianu 49367d4
test fix
bogdan-rosianu 42dbb75
Merge branch 'rc/v1.6.0' into MX-14354-snapshotless-observers
bogdan-rosianu 3c114c9
fixes after merge
bogdan-rosianu f5f5e53
Merge branch 'rc/v1.6.0' into MX-14354-snapshotless-observers
bogdan-rosianu e1b2a6f
fix test
bogdan-rosianu 29ad567
fixes after system tests
bogdan-rosianu a713a29
refactoring
bogdan-rosianu 394794c
fix after review
bogdan-rosianu d603fed
unit test fix
bogdan-rosianu f8fd10f
fixes after review
bogdan-rosianu adff3fc
fixes after second review
bogdan-rosianu 62c03fa
fix test
bogdan-rosianu fcd67a4
change clone function
bogdan-rosianu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package availabilityCommon | ||
|
||
import ( | ||
"github.com/multiversx/mx-chain-proxy-go/common" | ||
"github.com/multiversx/mx-chain-proxy-go/data" | ||
) | ||
|
||
// AvailabilityProvider is a stateless component that aims to group common operations regarding observers' data availability | ||
type AvailabilityProvider struct { | ||
} | ||
|
||
// AvailabilityForAccountQueryOptions returns the availability needed for the provided query options | ||
func (ap *AvailabilityProvider) AvailabilityForAccountQueryOptions(options common.AccountQueryOptions) data.ObserverDataAvailabilityType { | ||
availability := data.AvailabilityRecent | ||
if options.AreHistoricalCoordinatesSet() { | ||
availability = data.AvailabilityAll | ||
} | ||
return availability | ||
} | ||
|
||
// AvailabilityForVmQuery returns the availability needed for the provided query options | ||
func (ap *AvailabilityProvider) AvailabilityForVmQuery(query *data.SCQuery) data.ObserverDataAvailabilityType { | ||
availability := data.AvailabilityRecent | ||
if query.BlockNonce.HasValue || len(query.BlockHash) > 0 { | ||
availability = data.AvailabilityAll | ||
} | ||
return availability | ||
} | ||
|
||
// IsNodeValid returns true if the provided node is valid based on the availability | ||
func (ap *AvailabilityProvider) IsNodeValid(node *data.NodeData, availability data.ObserverDataAvailabilityType) bool { | ||
isInvalidSnapshotlessNode := availability == data.AvailabilityRecent && !node.IsSnapshotless | ||
isInvalidRegularNode := availability == data.AvailabilityAll && node.IsSnapshotless | ||
isInvalidNode := isInvalidSnapshotlessNode || isInvalidRegularNode | ||
return !isInvalidNode | ||
} | ||
|
||
// GetDescriptionForAvailability returns a short description string about the provided availability | ||
func (ap *AvailabilityProvider) GetDescriptionForAvailability(availability data.ObserverDataAvailabilityType) string { | ||
switch availability { | ||
case data.AvailabilityAll: | ||
return "regular nodes" | ||
case data.AvailabilityRecent: | ||
return "snapshotless nodes" | ||
default: | ||
return "N/A" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package availabilityCommon | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
"github.com/multiversx/mx-chain-proxy-go/common" | ||
"github.com/multiversx/mx-chain-proxy-go/data" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAvailabilityForAccountQueryOptions(t *testing.T) { | ||
ap := &AvailabilityProvider{} | ||
|
||
// Test with historical coordinates set | ||
options := common.AccountQueryOptions{BlockHash: []byte("hash")} | ||
require.Equal(t, data.AvailabilityAll, ap.AvailabilityForAccountQueryOptions(options)) | ||
|
||
// Test without historical coordinates set | ||
options = common.AccountQueryOptions{} | ||
require.Equal(t, data.AvailabilityRecent, ap.AvailabilityForAccountQueryOptions(options)) | ||
} | ||
|
||
func TestAvailabilityForVmQuery(t *testing.T) { | ||
ap := &AvailabilityProvider{} | ||
|
||
// Test with BlockNonce set | ||
query := &data.SCQuery{BlockNonce: core.OptionalUint64{HasValue: true, Value: 37}} | ||
require.Equal(t, data.AvailabilityAll, ap.AvailabilityForVmQuery(query)) | ||
|
||
// Test without BlockNonce set but with BlockHash | ||
query = &data.SCQuery{BlockHash: []byte("hash")} | ||
require.Equal(t, data.AvailabilityAll, ap.AvailabilityForVmQuery(query)) | ||
|
||
// Test without BlockNonce and BlockHash | ||
query = &data.SCQuery{} | ||
require.Equal(t, data.AvailabilityRecent, ap.AvailabilityForVmQuery(query)) | ||
} | ||
|
||
func TestIsNodeValid(t *testing.T) { | ||
ap := &AvailabilityProvider{} | ||
|
||
// Test with AvailabilityRecent and snapshotless node | ||
node := &data.NodeData{IsSnapshotless: true} | ||
require.True(t, ap.IsNodeValid(node, data.AvailabilityRecent)) | ||
|
||
// Test with AvailabilityRecent and regular node | ||
node = &data.NodeData{} | ||
require.False(t, ap.IsNodeValid(node, data.AvailabilityRecent)) | ||
|
||
// Test with AvailabilityAll and regular node | ||
node = &data.NodeData{} | ||
require.True(t, ap.IsNodeValid(node, data.AvailabilityAll)) | ||
|
||
// Test with AvailabilityAll and Snapshotless node | ||
node = &data.NodeData{IsSnapshotless: true} | ||
require.False(t, ap.IsNodeValid(node, data.AvailabilityAll)) | ||
} | ||
|
||
func TestGetDescriptionForAvailability(t *testing.T) { | ||
ap := &AvailabilityProvider{} | ||
|
||
require.Equal(t, "regular nodes", ap.GetDescriptionForAvailability(data.AvailabilityAll)) | ||
require.Equal(t, "snapshotless nodes", ap.GetDescriptionForAvailability(data.AvailabilityRecent)) | ||
require.Equal(t, "N/A", ap.GetDescriptionForAvailability("invalid")) // Invalid value | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added