-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: route state-backed requests to archive nodes #65
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
db0b0e7
feat: add NodeType config option
IvanVergiliev e11f94d
feat: add IsStatePresent filter for stateful requests
IvanVergiliev 59fd145
chore: move RequestMetadata to metadata package
IvanVergiliev c73eb6c
feat: add RequestMetadataParser
IvanVergiliev 12f914f
feat: add metadataParser field in Router and call it
IvanVergiliev c15fc35
feat: add RequestMetadata param to RouteNextRequest
IvanVergiliev de4d30b
refactor: pass RequestMetadata into NodeFilters
IvanVergiliev e9990bd
feat: enable SimpleIsStatePresent filter
IvanVergiliev ba08f05
test: add tests for SimpleIsStatePresentFilter
IvanVergiliev fa61061
test: add tests for RequestMetadataParser
IvanVergiliev a59a380
style: make linter happy
IvanVergiliev 0dde85d
feat: make NodeType required and update tests
IvanVergiliev c989bcf
chore: add nodeType to sample config
IvanVergiliev 46245fd
chore: add link to JSON RPC State methods
IvanVergiliev 352da16
refactor: simplify test
IvanVergiliev 0eb30cf
style: drop Filter suffix from state filter
IvanVergiliev 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package metadata | ||
|
||
type RequestMetadata struct { | ||
IsStateRequired bool | ||
} |
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,21 @@ | ||
package metadata | ||
|
||
import ( | ||
"github.com/satsuma-data/node-gateway/internal/jsonrpc" | ||
) | ||
|
||
type RequestMetadataParser struct{} | ||
|
||
func (p *RequestMetadataParser) Parse(requestBody jsonrpc.RequestBody) RequestMetadata { | ||
result := RequestMetadata{} | ||
|
||
switch requestBody.Method { | ||
case "eth_getBalance", "eth_getStorageAt", "eth_getTransactionCount", "eth_getCode", "eth_call", "eth_estimateGas": | ||
// List of state methods: https://ethereum.org/en/developers/docs/apis/json-rpc/#state_methods | ||
result.IsStateRequired = true | ||
default: | ||
result.IsStateRequired = false | ||
} | ||
|
||
return result | ||
} |
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,42 @@ | ||
package metadata | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/satsuma-data/node-gateway/internal/jsonrpc" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRequestMetadataParser_Parse(t *testing.T) { | ||
type args struct { | ||
requestBody jsonrpc.RequestBody | ||
} | ||
|
||
type testArgs struct { | ||
name string | ||
args args | ||
want RequestMetadata | ||
} | ||
|
||
testForMethod := func(methodName string, isStateRequired bool) testArgs { | ||
return testArgs{ | ||
methodName, | ||
args{jsonrpc.RequestBody{Method: methodName}}, | ||
RequestMetadata{IsStateRequired: isStateRequired}, | ||
} | ||
} | ||
|
||
tests := []testArgs{ | ||
testForMethod("eth_call", true), | ||
testForMethod("eth_getBalance", true), | ||
testForMethod("eth_getBlockByNumber", false), | ||
testForMethod("eth_getTransactionReceipt", false), | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
p := &RequestMetadataParser{} | ||
assert.Equalf(t, tt.want, p.Parse(tt.args.requestBody), "Parse(%v)", tt.args.requestBody) | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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.
nit: can we include add a link to the Eth docs that say which methods are state methods?
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.
Yep, good point! Added.