Skip to content

Commit

Permalink
Merge pull request #4812 from ElrondNetwork/merge-rc-v150-into-feat-p…
Browse files Browse the repository at this point in the history
…ubkey-19.12.2022

Merge rc v150 into feat pubkeyconverter refactor 19.12.2022
  • Loading branch information
schimih authored Dec 19, 2022
2 parents f7a1f25 + 8626410 commit f0d6042
Show file tree
Hide file tree
Showing 272 changed files with 8,828 additions and 5,378 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build

on:
pull_request:
branches: [development]
branches: [ master, rc/* ]
types: [opened, ready_for_review]
push:
workflow_dispatch:
Expand Down Expand Up @@ -33,9 +33,7 @@ jobs:
fi
- name: Build
run: |
export ARWEN_PATH=${GITHUB_WORKSPACE}/arwen
cd ${GITHUB_WORKSPACE}/cmd/node && go build .
cd ${GITHUB_WORKSPACE}/cmd/keygenerator && go build .
cd ${GITHUB_WORKSPACE}/cmd/logviewer && go build .
cd ${GITHUB_WORKSPACE}/cmd/termui && go build .
cd ${GITHUB_WORKSPACE} && make arwen
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- master
pull_request:
branches: [ master, development, feat/*, rc/* ]
branches: [ master, feat/*, rc/* ]

workflow_dispatch:

Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- master
- main
- rc/*
workflow_dispatch:

Expand All @@ -16,7 +15,7 @@ jobs:
build:
strategy:
matrix:
runs-on: [ubuntu-latest, macos-latest]
runs-on: [ubuntu-latest] # TODO add macos-latest when builds are possible on macs
runs-on: ${{ matrix.runs-on }}
name: Build
steps:
Expand Down Expand Up @@ -48,16 +47,13 @@ jobs:
GOPATH=$(go env GOPATH)
ARCHIVE="elrond_""$APP_VER_SHORT""_""$GOOS""_""$GOARCH"".tgz"
BUILD_DIR=${GITHUB_WORKSPACE}/build
ARWEN_VERSION=$(cat go.mod | grep arwen | sed 's/^.*arwen-wasm-vm *//' | tail -n 1)
ARWEN_PATH=${GITHUB_WORKSPACE}/build/arwen
WASMER_DIR=${GOPATH}/pkg/mod/github.com/\!elrond\!network/arwen-wasm-vm@${ARWEN_VERSION}/wasmer
WASM_VERSION=$(cat go.mod | grep wasm | sed 's/^.*wasm-vm-v1_4 *//' | tail -n 1)
WASMER_DIR=${GOPATH}/pkg/mod/github.com/\!elrond\!network/wasm-vm-v1_4@${WASM_VERSION}/wasmer
echo "GOOS=${GOOS}" >> $GITHUB_ENV
echo "GOARCH=${GOARCH}" >> $GITHUB_ENV
echo "ARCHIVE=${ARCHIVE}" >> $GITHUB_ENV
echo "BUILD_DIR=${BUILD_DIR}" >> $GITHUB_ENV
echo "ARWEN_VERSION=${ARWEN_VERSION}" >> $GITHUB_ENV
echo "ARWEN_PATH=${ARWEN_PATH}" >> $GITHUB_ENV
echo "WASMER_DIR=${WASMER_DIR}" >> $GITHUB_ENV
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- master
pull_request:
branches: [ master, development, feat/*, rc/* ]
branches: [ master, feat/*, rc/* ]

permissions:
contents: read
Expand Down
3 changes: 3 additions & 0 deletions api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ var ErrGetTransaction = errors.New("getting transaction failed")
// ErrGetBlock signals an error happening when trying to fetch a block
var ErrGetBlock = errors.New("getting block failed")

// ErrGetValidatorsInfo signals an error happening when trying to fetch validators info
var ErrGetValidatorsInfo = errors.New("validators info failed")

// ErrGetAlteredAccountsForBlock signals an error happening when trying to fetch the altered accounts for a block
var ErrGetAlteredAccountsForBlock = errors.New("getting altered accounts for block failed")

Expand Down
58 changes: 42 additions & 16 deletions api/groups/internalGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,28 @@ import (
"github.com/ElrondNetwork/elrond-go/api/shared"
"github.com/ElrondNetwork/elrond-go/api/shared/logging"
"github.com/ElrondNetwork/elrond-go/common"
"github.com/ElrondNetwork/elrond-go/state"
"github.com/gin-gonic/gin"
)

const (
getRawMetaBlockByNoncePath = "/raw/metablock/by-nonce/:nonce"
getRawMetaBlockByHashPath = "/raw/metablock/by-hash/:hash"
getRawMetaBlockByRoundPath = "/raw/metablock/by-round/:round"
getRawStartOfEpochMetaBlockPath = "/raw/startofepoch/metablock/by-epoch/:epoch"
getRawShardBlockByNoncePath = "/raw/shardblock/by-nonce/:nonce"
getRawShardBlockByHashPath = "/raw/shardblock/by-hash/:hash"
getRawShardBlockByRoundPath = "/raw/shardblock/by-round/:round"
getJSONMetaBlockByNoncePath = "/json/metablock/by-nonce/:nonce"
getJSONMetaBlockByHashPath = "/json/metablock/by-hash/:hash"
getJSONMetaBlockByRoundPath = "/json/metablock/by-round/:round"
getJSONStartOfEpochMetaBlockPath = "/json/startofepoch/metablock/by-epoch/:epoch"
getJSONShardBlockByNoncePath = "/json/shardblock/by-nonce/:nonce"
getJSONShardBlockByHashPath = "/json/shardblock/by-hash/:hash"
getJSONShardBlockByRoundPath = "/json/shardblock/by-round/:round"
getRawMiniBlockByHashPath = "/raw/miniblock/by-hash/:hash/epoch/:epoch"
getJSONMiniBlockByHashPath = "/json/miniblock/by-hash/:hash/epoch/:epoch"
getRawMetaBlockByNoncePath = "/raw/metablock/by-nonce/:nonce"
getRawMetaBlockByHashPath = "/raw/metablock/by-hash/:hash"
getRawMetaBlockByRoundPath = "/raw/metablock/by-round/:round"
getRawStartOfEpochMetaBlockPath = "/raw/startofepoch/metablock/by-epoch/:epoch"
getRawShardBlockByNoncePath = "/raw/shardblock/by-nonce/:nonce"
getRawShardBlockByHashPath = "/raw/shardblock/by-hash/:hash"
getRawShardBlockByRoundPath = "/raw/shardblock/by-round/:round"
getJSONMetaBlockByNoncePath = "/json/metablock/by-nonce/:nonce"
getJSONMetaBlockByHashPath = "/json/metablock/by-hash/:hash"
getJSONMetaBlockByRoundPath = "/json/metablock/by-round/:round"
getJSONStartOfEpochMetaBlockPath = "/json/startofepoch/metablock/by-epoch/:epoch"
getJSONStartOfEpochValidatorsInfoPath = "/json/startofepoch/validators/by-epoch/:epoch"
getJSONShardBlockByNoncePath = "/json/shardblock/by-nonce/:nonce"
getJSONShardBlockByHashPath = "/json/shardblock/by-hash/:hash"
getJSONShardBlockByRoundPath = "/json/shardblock/by-round/:round"
getRawMiniBlockByHashPath = "/raw/miniblock/by-hash/:hash/epoch/:epoch"
getJSONMiniBlockByHashPath = "/json/miniblock/by-hash/:hash/epoch/:epoch"
)

// internalBlockFacadeHandler defines the methods to be implemented by a facade for handling block requests
Expand All @@ -44,6 +46,7 @@ type internalBlockFacadeHandler interface {
GetInternalMetaBlockByRound(format common.ApiOutputFormat, round uint64) (interface{}, error)
GetInternalMiniBlockByHash(format common.ApiOutputFormat, hash string, epoch uint32) (interface{}, error)
GetInternalStartOfEpochMetaBlock(format common.ApiOutputFormat, epoch uint32) (interface{}, error)
GetInternalStartOfEpochValidatorsInfo(epoch uint32) ([]*state.ShardValidatorInfo, error)
IsInterfaceNil() bool
}

Expand Down Expand Up @@ -145,6 +148,11 @@ func NewInternalBlockGroup(facade internalBlockFacadeHandler) (*internalBlockGro
Method: http.MethodGet,
Handler: ib.getJSONMiniBlockByHash,
},
{
Path: getJSONStartOfEpochValidatorsInfoPath,
Method: http.MethodGet,
Handler: ib.getJSONStartOfEpochValidatorsInfo,
},
}
ib.endpoints = endpoints

Expand Down Expand Up @@ -450,6 +458,24 @@ func (ib *internalBlockGroup) getJSONMiniBlockByHash(c *gin.Context) {
shared.RespondWith(c, http.StatusOK, gin.H{"miniblock": miniBlock}, "", shared.ReturnCodeSuccess)
}

func (ib *internalBlockGroup) getJSONStartOfEpochValidatorsInfo(c *gin.Context) {
epoch, err := getQueryParamEpoch(c)
if err != nil {
shared.RespondWithValidationError(c, errors.ErrGetValidatorsInfo, errors.ErrInvalidEpoch)
return
}

start := time.Now()
validatorsInfo, err := ib.getFacade().GetInternalStartOfEpochValidatorsInfo(epoch)
logging.LogAPIActionDurationIfNeeded(start, "API call: GetInternalStartOfEpochValidatorsInfo with JSON")
if err != nil {
shared.RespondWithInternalError(c, errors.ErrGetValidatorsInfo, err)
return
}

shared.RespondWith(c, http.StatusOK, gin.H{"validators": validatorsInfo}, "", shared.ReturnCodeSuccess)
}

func (ib *internalBlockGroup) getFacade() internalBlockFacadeHandler {
ib.mutFacade.RLock()
defer ib.mutFacade.RUnlock()
Expand Down
99 changes: 99 additions & 0 deletions api/groups/internalGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ElrondNetwork/elrond-go/api/mock"
"github.com/ElrondNetwork/elrond-go/common"
"github.com/ElrondNetwork/elrond-go/config"
"github.com/ElrondNetwork/elrond-go/state"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -68,6 +69,14 @@ type internalMiniBlockResponse struct {
Code string `json:"code"`
}

type internalValidatorsInfoResponse struct {
Data struct {
ValidatorsInfo []*state.ShardValidatorInfo `json:"validators"`
} `json:"data"`
Error string `json:"error"`
Code string `json:"code"`
}

func TestNewInternalBlockGroup(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1492,6 +1501,95 @@ func TestGetInternalMiniBlockByHash_ShouldWork(t *testing.T) {
assert.Equal(t, expectedOutput, response.Data.Block)
}

func TestGetInternalStartOfEpochValidatorsInfo(t *testing.T) {
t.Parallel()

t.Run("no epoch param should fail", func(t *testing.T) {
t.Parallel()

facade := mock.FacadeStub{
GetInternalStartOfEpochValidatorsInfoCalled: func(epoch uint32) ([]*state.ShardValidatorInfo, error) {
return make([]*state.ShardValidatorInfo, 0), nil
},
}

blockGroup, err := groups.NewInternalBlockGroup(&facade)
require.NoError(t, err)

ws := startWebServer(blockGroup, "internal", getInternalBlockRoutesConfig())

req, _ := http.NewRequest("GET", "/internal/json/startofepoch/validators/by-epoch/aaa", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

response := internalValidatorsInfoResponse{}
loadResponse(resp.Body, &response)
assert.Equal(t, http.StatusBadRequest, resp.Code)
assert.True(t, strings.Contains(response.Error, apiErrors.ErrGetValidatorsInfo.Error()))
})

t.Run("facade error should fail", func(t *testing.T) {
t.Parallel()

expectedErr := errors.New("facade error")
facade := mock.FacadeStub{
GetInternalStartOfEpochValidatorsInfoCalled: func(epoch uint32) ([]*state.ShardValidatorInfo, error) {
return nil, expectedErr
},
}

blockGroup, err := groups.NewInternalBlockGroup(&facade)
require.NoError(t, err)

ws := startWebServer(blockGroup, "internal", getInternalBlockRoutesConfig())

req, _ := http.NewRequest("GET", "/internal/json/startofepoch/validators/by-epoch/1", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

response := internalValidatorsInfoResponse{}
loadResponse(resp.Body, &response)

assert.Equal(t, http.StatusInternalServerError, resp.Code)
assert.True(t, strings.Contains(response.Error, expectedErr.Error()))
})

t.Run("should work", func(t *testing.T) {
t.Parallel()

expectedOutput := []*state.ShardValidatorInfo{
{
PublicKey: []byte("pubkey1"),
ShardId: 0,
Index: 1,
TempRating: 500,
},
}

facade := mock.FacadeStub{
GetInternalStartOfEpochValidatorsInfoCalled: func(epoch uint32) ([]*state.ShardValidatorInfo, error) {
return expectedOutput, nil
},
}

blockGroup, err := groups.NewInternalBlockGroup(&facade)
require.NoError(t, err)

ws := startWebServer(blockGroup, "internal", getInternalBlockRoutesConfig())

req, _ := http.NewRequest("GET", "/internal/json/startofepoch/validators/by-epoch/1", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

response := internalValidatorsInfoResponse{}
loadResponse(resp.Body, &response)
assert.Equal(t, http.StatusOK, resp.Code)

assert.Equal(t, expectedOutput, response.Data.ValidatorsInfo)
})

}

func getInternalBlockRoutesConfig() config.ApiRoutesConfig {
return config.ApiRoutesConfig{
APIPackages: map[string]config.APIPackageConfig{
Expand All @@ -1513,6 +1611,7 @@ func getInternalBlockRoutesConfig() config.ApiRoutesConfig {
{Name: "/json/shardblock/by-hash/:hash", Open: true},
{Name: "/json/shardblock/by-round/:round", Open: true},
{Name: "/json/miniblock/by-hash/:hash/epoch/:epoch", Open: true},
{Name: "/json/startofepoch/validators/by-epoch/:epoch", Open: true},
},
},
},
Expand Down
10 changes: 10 additions & 0 deletions api/mock/facadeStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type FacadeStub struct {
GetInternalMetaBlockByHashCalled func(format common.ApiOutputFormat, hash string) (interface{}, error)
GetInternalMetaBlockByRoundCalled func(format common.ApiOutputFormat, round uint64) (interface{}, error)
GetInternalStartOfEpochMetaBlockCalled func(format common.ApiOutputFormat, epoch uint32) (interface{}, error)
GetInternalStartOfEpochValidatorsInfoCalled func(epoch uint32) ([]*state.ShardValidatorInfo, error)
GetInternalMiniBlockByHashCalled func(format common.ApiOutputFormat, txHash string, epoch uint32) (interface{}, error)
GetTotalStakedValueHandler func() (*api.StakeValues, error)
GetAllIssuedESDTsCalled func(tokenType string) ([]string, error)
Expand Down Expand Up @@ -527,6 +528,15 @@ func (f *FacadeStub) GetGasConfigs() (map[string]map[string]uint64, error) {
return nil, nil
}

// GetInternalStartOfEpochValidatorsInfo -
func (f *FacadeStub) GetInternalStartOfEpochValidatorsInfo(epoch uint32) ([]*state.ShardValidatorInfo, error) {
if f.GetInternalStartOfEpochValidatorsInfoCalled != nil {
return f.GetInternalStartOfEpochValidatorsInfoCalled(epoch)
}

return nil, nil
}

// Trigger -
func (f *FacadeStub) Trigger(_ uint32, _ bool) error {
return nil
Expand Down
1 change: 1 addition & 0 deletions api/shared/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type FacadeHandler interface {
GetInternalMetaBlockByHash(format common.ApiOutputFormat, hash string) (interface{}, error)
GetInternalMetaBlockByRound(format common.ApiOutputFormat, round uint64) (interface{}, error)
GetInternalStartOfEpochMetaBlock(format common.ApiOutputFormat, epoch uint32) (interface{}, error)
GetInternalStartOfEpochValidatorsInfo(epoch uint32) ([]*state.ShardValidatorInfo, error)
GetInternalMiniBlockByHash(format common.ApiOutputFormat, hash string, epoch uint32) (interface{}, error)
Trigger(epoch uint32, withEarlyEndOfEpoch bool) error
IsSelfTrigger() bool
Expand Down
23 changes: 3 additions & 20 deletions cmd/keygenerator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"github.com/ElrondNetwork/elrond-go-crypto/signing"
"github.com/ElrondNetwork/elrond-go-crypto/signing/ed25519"
"github.com/ElrondNetwork/elrond-go-crypto/signing/mcl"
"github.com/ElrondNetwork/elrond-go-crypto/signing/secp256k1"
logger "github.com/ElrondNetwork/elrond-go-logger"
"github.com/ElrondNetwork/elrond-go/cmd/keygenerator/converter"
"github.com/ElrondNetwork/elrond-go/p2p/factory"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -189,6 +189,7 @@ func generateKeys(typeKey string, numKeys int, prefix string, shardID int) ([]ke

blockSigningGenerator := signing.NewKeyGenerator(mcl.NewSuiteBLS12())
txSigningGenerator := signing.NewKeyGenerator(ed25519.NewEd25519())
p2pKeyGenerator := signing.NewKeyGenerator(secp256k1.NewSecp256k1())

for i := 0; i < numKeys; i++ {
switch typeKey {
Expand All @@ -203,7 +204,7 @@ func generateKeys(typeKey string, numKeys int, prefix string, shardID int) ([]ke
return nil, nil, nil, err
}
case p2pType:
p2pKeys, err = generateP2pKey(p2pKeys)
p2pKeys, err = generateKey(p2pKeyGenerator, p2pKeys)
if err != nil {
return nil, nil, nil, err
}
Expand Down Expand Up @@ -232,24 +233,6 @@ func generateKeys(typeKey string, numKeys int, prefix string, shardID int) ([]ke
return validatorKeys, walletKeys, p2pKeys, nil
}

func generateP2pKey(list []key) ([]key, error) {
generator := factory.NewIdentityGenerator()
privateKeyBytes, pid, err := generator.CreateRandomP2PIdentity()
if err != nil {
return nil, err
}

list = append(
list,
key{
skBytes: privateKeyBytes,
pkBytes: []byte(pid.Pretty()),
},
)

return list, nil
}

func generateKey(keyGen crypto.KeyGenerator, list []key) ([]key, error) {
sk, pk := keyGen.GeneratePair()
skBytes, err := sk.ToByteArray()
Expand Down
6 changes: 5 additions & 1 deletion cmd/node/config/api.toml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@
{ Name = "/raw/miniblock/by-hash/:hash/epoch/:epoch", Open = true },

# /internal/json/miniblock/by-hash/:hash will return the miniblock in JSON format based on hash for a specified epoch
{ Name = "/json/miniblock/by-hash/:hash/epoch/:epoch", Open = true }
{ Name = "/json/miniblock/by-hash/:hash/epoch/:epoch", Open = true },

# /internal/raw/startofepoch/validators/by-epoch/:epoch will return the start of epoch validators info in json format based on epoch
{ Name = "/json/startofepoch/validators/by-epoch/:epoch", Open = true }

]

[APIPackages.proof]
Expand Down
Loading

0 comments on commit f0d6042

Please sign in to comment.