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

EN-7804: api and components versioning #96

Merged
merged 20 commits into from
Dec 16, 2020
Merged

Conversation

bogdan-rosianu
Copy link
Contributor

@bogdan-rosianu bogdan-rosianu commented Oct 12, 2020

Testing procedure:

  1. start proxy as usual
  2. for all proxy clients, append a /v1.0 in the URL. Example: http://127.0.0.1:8080 => http://127.0.0.1:8080/v1.0
  3. everything should work the same

# Conflicts:
#	api/api.go
#	cmd/proxy/main.go
#	process/baseProcessor.go
#	process/mock/processorStub.go
api/groups/baseAccountsGroup.go Outdated Show resolved Hide resolved
api/groups/baseTransactionGroup.go Outdated Show resolved Hide resolved
api/groups/baseVmValuesGroup.go Outdated Show resolved Hide resolved
import "github.com/ElrondNetwork/elrond-proxy-go/data"

// AccountsFacadeHandlerV1_2 interface defines methods that can be used from facade context variable
type AccountsFacadeHandlerV1_2 interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to have a single facade implementation that will satisfy all the interfaces?
The question arose from seeing the function GetShardIDForAddressV1_2.
We can have multiple facade implementations that will be consumed by various endpoint versions. Having all functions in a single monstrous facade implementation will impact struct size (which should be kept as small as possible)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean that we should drop the facade entity that holds all the processors and calls the appropriate methods of them?

facade/versions/elrondProxyFacadeV1_0.go Show resolved Hide resolved
versions/factory/versionedFacadeCreator.go Outdated Show resolved Hide resolved
versions/factory/versionedFacadeCreator.go Outdated Show resolved Hide resolved
@@ -0,0 +1,8 @@
package versions

//// VersionManagerHandler defines the actions that a version manager implementation has to do
Copy link
Contributor

Choose a reason for hiding this comment

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

remove or uncomment

versions/versionManager.go Outdated Show resolved Hide resolved
api/groups/v1_2/accountsGroupV1_2.go Outdated Show resolved Hide resolved
Copy link
Contributor

@iulianpascalau iulianpascalau left a comment

Choose a reason for hiding this comment

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

Minor stuff remained. Code looks way better. GJ! 👍

func NewCommonApiHandler() *commonApiHandler {
return &commonApiHandler{
groups: initBaseGroups(),
func NewApiHandler(facade data.FacadeHandler) (*commonApiHandler, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

missing comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -58,8 +63,8 @@ func getTransactions(c *gin.Context) ([]data.DatabaseTransaction, int, error) {

// GetAccount returns an accountResponse containing information
// about the account correlated with provided address
func GetAccount(c *gin.Context) {
account, status, err := getAccount(c)
func (ag *accountsGroup) GetAccount(c *gin.Context) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we still need these methods exported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

made them unexported

}

baseRoutesHandlers := map[string]*data.EndpointHandlerData{
"/hex": {Handler: vvg.getHex, Method: http.MethodPost},
Copy link
Contributor

Choose a reason for hiding this comment

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

unexported methods 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

func createVersionManager(
cfg *config.Config,
ecConf *erdConfig.EconomicsConfig,
exCfg *erdConfig.ExternalConfig,
pemFileLocation string,
isRosettaOn bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

isRosettaEnabled (On can mean something else :D )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to isRosettaModeEnabled

*facade.ElrondProxyFacade
}

func (epf *ElrondProxyFacadeV1_2) GetShardIDForAddressV1_2(address string, additionalField int) (uint32, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ok

"github.com/ElrondNetwork/elrond-proxy-go/process"
)

type TransactionProcessorV1_0 struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Some elements without comments remained in this file

}

vm.mutVersions.Lock()
vm.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@bogdan-rosianu bogdan-rosianu changed the title [WIP] EN-7804: api and components versioning EN-7804: api and components versioning Nov 11, 2020
@bogdan-rosianu bogdan-rosianu marked this pull request as ready for review November 11, 2020 14:57
api/api.go Outdated
@@ -35,7 +27,10 @@ func CreateServer(elrondProxyFacade ElrondProxyHandler, port int) (*http.Server,
return nil, err
}

registerRoutes(ws, elrondProxyFacade)
err = registerRoutes(ws, versionManager)
Copy link
Contributor

Choose a reason for hiding this comment

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

Optionally, reorder the definitions of registerRoutes, registerValidators, with respect to the order of their usage.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now I see (older code) - why do we need skValidator? CC: @iulianpascalau?

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK, skValidator is used in the authentication & authorization process when accessing a REST API endpoint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reordered. it's not used now, but can remain as a placeholder for further authorized requests

api/api.go Outdated
blockAtlasRoutes := ws.Group("/block-atlas")
blockAtlasRoutes.Use(WithElrondProxyFacade(elrondProxyFacade))
blockatlas.Routes(blockAtlasRoutes)
for version, versionData := range versionsMap {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

api/api.go Outdated
blockAtlasRoutes := ws.Group("/block-atlas")
blockAtlasRoutes.Use(WithElrondProxyFacade(elrondProxyFacade))
blockatlas.Routes(blockAtlasRoutes)
for version, versionData := range versionsMap {
Copy link
Contributor

Choose a reason for hiding this comment

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

Optionally, we can rename VersionData (the struct, the variables) to VersionBundle or VersionController. But In this sense, perhaps also rename VersionManager to ApiVersioningRegistry or VersionsRegistry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the current naming is better because VersionData only holds the specific components for each version and it doesn't have any functions.
However, renamed VersionManager to VersionsRegistry

api/api.go Outdated Show resolved Hide resolved
api/apiHandler.go Outdated Show resolved Hide resolved
api/groups/baseBlockAtlasGroup.go Outdated Show resolved Hide resolved
api/groups/baseGroup.go Outdated Show resolved Hide resolved
api/groups/interface.go Show resolved Hide resolved
process/v1_0/transactionProcessorV1_0.go Outdated Show resolved Hide resolved
process/v1_0/transactionProcessorV1_0.go Outdated Show resolved Hide resolved
iulianpascalau
iulianpascalau previously approved these changes Nov 16, 2020
api/api.go Outdated
@@ -86,11 +85,3 @@ func skValidator(
) bool {
return true
}

// WithElrondProxyFacade middleware will set up an ElrondFacade object in the gin context
func WithElrondProxyFacade(elrondProxyFacade ElrondProxyHandler, version string) gin.HandlerFunc {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

andreibancioiu
andreibancioiu previously approved these changes Nov 16, 2020
})
}

// GetShardForAccountV_next is an example of an updated endpoint in the version v_next
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -1,2 +1,2 @@
// Package v1.2 represents the processors needed for the version v1.2 of the API
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe update the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

# Conflicts:
#	api/address/interface.go
#	api/groups/baseAccountsGroup.go
#	api/groups/baseTransactionGroup.go
#	api/transaction/interface.go
iulianpascalau
iulianpascalau previously approved these changes Dec 7, 2020
andreibancioiu
andreibancioiu previously approved these changes Dec 7, 2020
- `/v1.0/hyperblock/by-hash/:hash` (GET) --> returns a hyperblock by hash, with transactions included

# V_next
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -5,12 +5,13 @@ COPY . .
# Proxy
WORKDIR /elrond/cmd/proxy
RUN go build
# $(ls /go/pkg/mod/github.com/!elrond!network/ | grep arwen-wasm-vm | sed 's/.* //' | head -1) this command is required to be able to extract the full name of the directory that starts with 'arwen-wasm-wm'
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why Github picked these as PR changes.

@@ -14,12 +14,21 @@ var ErrGetValueForKey = errors.New("get value for key error")
// ErrComputeShardForAddress signals an error in computing the shard ID for a given address
var ErrComputeShardForAddress = errors.New("compute shard ID for address error")

// ErrGetESDTTokenData signals an error in fetching an ESDT token data
var ErrGetESDTTokenData = errors.New("cannot get ESDT token data")
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why Github picked these as PR changes.

Status transaction.TxStatus `json:"status,omitempty"`
HyperblockNonce uint64 `json:"hyperblockNonce,omitempty"`
HyperblockHash string `json:"hyperblockHash,omitempty"`
Type string `json:"type"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why Github picked these as PR changes.

go.mod Outdated
@@ -3,10 +3,9 @@ module github.com/ElrondNetwork/elrond-proxy-go
go 1.12

require (
github.com/ElrondNetwork/elrond-go v1.1.2-0.20201016080150-915a6ef433de
github.com/ElrondNetwork/elrond-go v1.1.6-0.20201126175543-3e5a9696c46f
Copy link
Contributor

Choose a reason for hiding this comment

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

v1.1.10+?

@@ -100,6 +100,67 @@ func (ap *AccountProcessor) GetValueForKey(address string, key string) (string,
return "", ErrSendingRequest
}

// GetESDTTokenData returns the token data for a token with the given name
func (ap *AccountProcessor) GetESDTTokenData(address string, key string) (*data.GenericAPIResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why Github picked these as PR changes.

@@ -455,19 +465,42 @@ func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType reques
return nil, errors.ErrTransactionNotFound
}

func (tp *TransactionProcessor) getTxWithSenderAddr(txHash, sender string) (*data.FullTransaction, error) {
func (tp *TransactionProcessor) alterTxWithScResultsFromSourceIfNeeded(txHash string, tx *data.FullTransaction, withResults bool) *data.FullTransaction {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why Github picked these as PR changes.

andreibancioiu
andreibancioiu previously approved these changes Dec 11, 2020
@LucianMincu LucianMincu merged commit 5eda4f5 into development Dec 16, 2020
@andreibancioiu andreibancioiu deleted the EN-7804-versioning branch December 16, 2020 15:34
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.

None yet

4 participants