-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Utility] trustless relays servicer token validation (#803)
## Description Add validation of application's session tokens to the servicer. ## Issue Part of work on #754 ## Type of change Please mark the relevant option(s): - [x] New feature, functionality or library - [ ] Bug fix - [ ] Code health or cleanup - [ ] Major breaking change - [ ] Documentation - [ ] Other <!-- add details here if it a different type of change --> ## List of changes - Servicer now validates the availability of tokens in the current session before executing relays. ## Testing - [x] `make develop_test`; if any code changes were made - [ ] `make test_e2e` on [k8s LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md); if any code changes were made - [ ] `e2e-devnet-test` passes tests on [DevNet](https://pocketnetwork.notion.site/How-to-DevNet-ff1598f27efe44c09f34e2aa0051f0dd); if any code was changed - [ ] [Docker Compose LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md); if any major functionality was changed or introduced - [ ] [k8s LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md); if any infrastructure or configuration changes were made ## Required Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [] I have added, or updated, [`godoc` format comments](https://go.dev/blog/godoc) on touched members (see: [tip.golang.org/doc/comment](https://tip.golang.org/doc/comment)) - [x] I have tested my changes using the available tooling - [x] I have updated the corresponding CHANGELOG ### If Applicable Checklist - [ ] I have updated the corresponding README(s); local and/or global - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added, or updated, [mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding README(s) - [ ] I have added, or updated, documentation and [mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*` if I updated `shared/*`README(s)
- Loading branch information
Showing
20 changed files
with
736 additions
and
76 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package local | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/pokt-network/pocket/logger" | ||
coreTypes "github.com/pokt-network/pocket/shared/core/types" | ||
"github.com/pokt-network/pocket/shared/modules" | ||
"github.com/pokt-network/pocket/shared/modules/base_modules" | ||
) | ||
|
||
const ( | ||
LocalModuleName = "local" | ||
) | ||
|
||
var _ modules.PersistenceLocalContext = &persistenceLocalContext{} | ||
|
||
type persistenceLocalContext struct { | ||
base_modules.IntegratableModule | ||
|
||
logger *modules.Logger | ||
databasePath string | ||
} | ||
|
||
func WithLocalDatabasePath(databasePath string) modules.ModuleOption { | ||
return func(m modules.InitializableModule) { | ||
if plc, ok := m.(*persistenceLocalContext); ok { | ||
plc.databasePath = databasePath | ||
} | ||
} | ||
} | ||
|
||
func CreateLocalContext(bus modules.Bus, options ...modules.ModuleOption) (modules.PersistenceLocalContext, error) { | ||
m, err := new(persistenceLocalContext).Create(bus, options...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return m.(modules.PersistenceLocalContext), nil | ||
} | ||
|
||
func (*persistenceLocalContext) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { | ||
m := &persistenceLocalContext{} | ||
|
||
for _, option := range options { | ||
option(m) | ||
} | ||
|
||
bus.RegisterModule(m) | ||
|
||
m.logger = logger.Global.CreateLoggerForModule(m.GetModuleName()) | ||
|
||
return m, nil | ||
} | ||
|
||
func (m *persistenceLocalContext) GetModuleName() string { | ||
return LocalModuleName | ||
} | ||
|
||
// INCOMPLETE(#826): implement this | ||
func (m *persistenceLocalContext) Start() error { | ||
return nil | ||
} | ||
|
||
// INCOMPLETE(#826): implement this | ||
func (m *persistenceLocalContext) Stop() error { | ||
return nil | ||
} | ||
|
||
// INCOMPLETE(#826): implement this | ||
// OPTIMIZE: both the relay and the response can be large structures: we may need to truncate the stored values | ||
// StoreServicedRelay implements the PersistenceLocalContext interface | ||
func (local *persistenceLocalContext) StoreServicedRelay(session *coreTypes.Session, relayDigest, relayReqResBytes []byte) error { | ||
return nil | ||
} | ||
|
||
// INCOMPLETE(#826): implement this | ||
// GetSessionTokensUsed implements the PersistenceLocalContext interface | ||
func (local *persistenceLocalContext) GetSessionTokensUsed(*coreTypes.Session) (*big.Int, error) { | ||
return nil, nil | ||
} |
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
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
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.