Skip to content

Commit

Permalink
Merge pull request #3438 from ElrondNetwork/merge-from-dev-to-ls
Browse files Browse the repository at this point in the history
Merge from dev to ls
  • Loading branch information
sasurobert committed Sep 15, 2021
2 parents 6ab9cd5 + 2583bb9 commit 3480081
Show file tree
Hide file tree
Showing 160 changed files with 4,995 additions and 886 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ $ ./keygenerator

### Start the node
#### Step 4a: Join Elrond testnet:
Follow the steps outlined [here](https://docs.elrond.com/validators/install). This is because in order to join the testnet you need a specific node configuration.
Follow the steps outlined [here](https://docs.elrond.com/validators/testnet/config-scripts/). This is because in order to join the testnet you need a specific node configuration.
______
OR
______
Expand Down
3 changes: 3 additions & 0 deletions api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ var ErrInvalidQueryParameter = errors.New("invalid query parameter")
// ErrValidationEmptyBlockHash signals an empty block hash was provided
var ErrValidationEmptyBlockHash = errors.New("block hash is empty")

// ErrValidationEmptyToken signals that an empty token was provided
var ErrValidationEmptyToken = errors.New("token is empty")

// ErrGetTransaction signals an error happening when trying to fetch a transaction
var ErrGetTransaction = errors.New("getting transaction failed")

Expand Down
10 changes: 10 additions & 0 deletions api/mock/facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ type Facade struct {
GetProofCalled func(string, string) ([][]byte, error)
GetProofCurrentRootHashCalled func(string) ([][]byte, []byte, error)
VerifyProofCalled func(string, string, [][]byte) (bool, error)
GetTokenSupplyCalled func(token string) (string, error)
}

// GetTokenSupply -
func (f *Facade) GetTokenSupply(token string) (string, error) {
if f.GetTokenSupplyCalled != nil {
return f.GetTokenSupplyCalled(token)
}

return "", nil
}

// GetProof -
Expand Down
41 changes: 41 additions & 0 deletions api/network/routes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package network

import (
"fmt"
"net/http"

"github.com/ElrondNetwork/elrond-go-core/core"
Expand All @@ -22,6 +23,7 @@ const (
getFFTsPath = "/esdt/fungible-tokens"
getSFTsPath = "/esdt/semi-fungible-tokens"
getNFTsPath = "/esdt/non-fungible-tokens"
getESDTSupply = "/esdt/supply/:token"
directStakedInfoPath = "/direct-staked-info"
delegatedInfoPath = "/delegated-info"
)
Expand All @@ -33,6 +35,7 @@ type FacadeHandler interface {
GetDelegatorsList() ([]*api.Delegator, error)
StatusMetrics() external.StatusMetricsHandler
GetAllIssuedESDTs(tokenType string) ([]string, error)
GetTokenSupply(token string) (string, error)
IsInterfaceNil() bool
}

Expand All @@ -48,6 +51,7 @@ func Routes(router *wrapper.RouterWrapper) {
router.RegisterHandler(http.MethodGet, getNFTsPath, getHandlerFuncForEsdt(core.NonFungibleESDT))
router.RegisterHandler(http.MethodGet, directStakedInfoPath, DirectStakedInfo)
router.RegisterHandler(http.MethodGet, delegatedInfoPath, DelegatedInfo)
router.RegisterHandler(http.MethodGet, getESDTSupply, getESDTTokenSupply)
}

func getFacade(c *gin.Context) (FacadeHandler, bool) {
Expand Down Expand Up @@ -258,3 +262,40 @@ func DelegatedInfo(c *gin.Context) {
},
)
}

func getESDTTokenSupply(c *gin.Context) {
facade, ok := getFacade(c)
if !ok {
return
}

token := c.Param("token")
if token == "" {
shared.RespondWithValidationError(
c, fmt.Sprintf("%s: %s", errors.ErrValidation.Error(), errors.ErrValidationEmptyToken.Error()),
)
return
}

supply, err := facade.GetTokenSupply(token)
if err != nil {
c.JSON(
http.StatusInternalServerError,
shared.GenericAPIResponse{
Data: nil,
Error: err.Error(),
Code: shared.ReturnCodeInternalError,
},
)
return
}

c.JSON(
http.StatusOK,
shared.GenericAPIResponse{
Data: gin.H{"supply": supply},
Error: "",
Code: shared.ReturnCodeSuccess,
},
)
}
24 changes: 23 additions & 1 deletion api/network/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type esdtTokensResponseData struct {
Expand Down Expand Up @@ -391,7 +392,7 @@ func TestDelegatedInfo_ShouldWork(t *testing.T) {

func delegatorFoundInResponse(response string, delegator api.Delegator) bool {
if strings.Contains(response, delegator.TotalAsBigInt.String()) {
//we should have not encoded the total as big int
// we should have not encoded the total as big int
return false
}

Expand All @@ -403,6 +404,26 @@ func delegatorFoundInResponse(response string, delegator api.Delegator) bool {
return found
}

func TestGetESDTTotalSupply(t *testing.T) {
facade := mock.Facade{
GetTokenSupplyCalled: func(token string) (string, error) {
return "1000", nil
},
}

ws := startNodeServer(&facade)
req, _ := http.NewRequest("GET", "/network/esdt/supply/mytoken-aabb", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

respBytes, _ := ioutil.ReadAll(resp.Body)
respStr := string(respBytes)
assert.Equal(t, resp.Code, http.StatusOK)

keyAndValueInResponse := strings.Contains(respStr, "supply") && strings.Contains(respStr, "1000")
require.True(t, keyAndValueInResponse)
}

func TestDelegatedInfo_CannotGetDelegatedList(t *testing.T) {
expectedError := fmt.Errorf("%s", "expected error")
facade := mock.Facade{
Expand Down Expand Up @@ -532,6 +553,7 @@ func getRoutesConfig() config.ApiRoutesConfig {
{Name: "/enable-epochs", Open: true},
{Name: "/direct-staked-info", Open: true},
{Name: "/delegated-info", Open: true},
{Name: "/esdt/supply/:token", Open: true},
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions cmd/node/config/api.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
# /network/non-fungible-tokens will return all the issued non fungible tokens on the protocol
{ Name = "/esdt/non-fungible-tokens", Open = true },

# /network/esdt/supply/:token will return the supply for a given token
{ Name = "/esdt/supply/:token", Open = true },

# /network/direct-staked-info will return a list containing direct staked list of addresses
# and their staked values
{ Name = "/direct-staked-info", Open = true},
Expand Down
10 changes: 10 additions & 0 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,16 @@
BatchDelaySeconds = 2
MaxBatchSize = 20000
MaxOpenFiles = 10
[DbLookupExtensions.ESDTSuppliesStorageConfig.Cache]
Name = "DbLookupExtensions.ESDTSuppliesStorage"
Capacity = 20000
Type = "LRU"
[DbLookupExtensions.ESDTSuppliesStorageConfig.DB]
FilePath = "DbLookupExtensions_ESDTSupplies"
Type = "LvlDBSerial"
BatchDelaySeconds = 2
MaxBatchSize = 20000
MaxOpenFiles = 10

[Logs]
LogFileLifeSpanInSec = 86400
Expand Down
2 changes: 2 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
GetReturnData = 100
GetNumReturnData = 100
GetReturnDataSize = 100
GetOriginalTxHash = 10000

[EthAPICost]
UseGas = 100
Expand Down Expand Up @@ -185,6 +186,7 @@
UnmarshalECC = 20000
UnmarshalCompressedECC = 270000
GenerateKeyECC = 7000000
EncodeDERSig = 10000000

[ManagedBufferAPICost]
MBufferNew = 2000
Expand Down
2 changes: 2 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
GetReturnData = 100
GetNumReturnData = 100
GetReturnDataSize = 100
GetOriginalTxHash = 10000

[EthAPICost]
UseGas = 100
Expand Down Expand Up @@ -183,6 +184,7 @@
UnmarshalECC = 20000
UnmarshalCompressedECC = 270000
GenerateKeyECC = 7000000
EncodeDERSig = 10000000

[ManagedBufferAPICost]
MBufferNew = 2000
Expand Down
2 changes: 2 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
GetReturnData = 100
GetNumReturnData = 100
GetReturnDataSize = 100
GetOriginalTxHash = 10000

[EthAPICost]
UseGas = 100
Expand Down Expand Up @@ -185,6 +186,7 @@
UnmarshalECC = 20000
UnmarshalCompressedECC = 270000
GenerateKeyECC = 7000000
EncodeDERSig = 10000000

[ManagedBufferAPICost]
MBufferNew = 2000
Expand Down
6 changes: 3 additions & 3 deletions cmd/node/config/p2p.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@
[Sharding]
# The targeted number of peer connections
TargetPeerCount = 36
MaxIntraShardValidators = 12
MaxIntraShardValidators = 10
MaxCrossShardValidators = 8
MaxIntraShardObservers = 2
MaxCrossShardObservers = 1
MaxIntraShardObservers = 4
MaxCrossShardObservers = 4
MaxSeeders = 2

#available options:
Expand Down
17 changes: 0 additions & 17 deletions cmd/node/factory/structsStatusHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,3 @@ func (shi *statusHandlersInfo) SignalLogRewrite() {
func (shi *statusHandlersInfo) IsInterfaceNil() bool {
return shi == nil
}

func (shi *statusHandlersInfo) updateTpsMetrics(metricsMap map[string]interface{}) {
for key, value := range metricsMap {
stringValue, isString := value.(string)
if isString {
log.Trace("setting metric value", "key", key, "value string", stringValue)
shi.AppStatusHandler.SetStringValue(key, stringValue)
continue
}

uint64Value, isUint64 := value.(uint64)
if isUint64 {
log.Trace("setting metric value", "key", key, "value uint64", uint64Value)
shi.AppStatusHandler.SetUInt64Value(key, uint64Value)
}
}
}
3 changes: 1 addition & 2 deletions cmd/termui/presenter/chainInfoGetters.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,12 @@ func (psh *PresenterStatusHandler) GetEpochInfo() (uint64, uint64, int, string)
if epochFinishRound < currentRound {
roundsRemained = 0
}
if roundsRemained == 0 || roundsPerEpoch == 0 || roundDuration == 0 {
if roundsPerEpoch == 0 || roundDuration == 0 {
return 0, 0, 0, ""
}
secondsRemainedInEpoch := roundsRemained * roundDuration / 1000

remainingTime := core.SecondsToHourMinSec(int(secondsRemainedInEpoch))

epochLoadPercent := 100 - int(float64(roundsRemained)/float64(roundsPerEpoch)*100.0)

return currentRound, epochFinishRound, epochLoadPercent, remainingTime
Expand Down
44 changes: 44 additions & 0 deletions cmd/termui/presenter/chainInfoGetters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,47 @@ func TestPresenterStatusHandler_GetEpochInfo(t *testing.T) {
assert.Equal(t, expectedRemainingTime, remainingTime)
assert.Equal(t, 50, epochLoadPercent)
}

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

numRoundsPerEpoch := uint64(20)
roundDuration := uint64(5000)
roundAtEpochStart := uint64(60)
currentRound := uint64(80)

presenterStatusHandler := NewPresenterStatusHandler()
presenterStatusHandler.SetUInt64Value(common.MetricRoundDuration, roundDuration)
presenterStatusHandler.SetUInt64Value(common.MetricRoundsPerEpoch, numRoundsPerEpoch)
presenterStatusHandler.SetUInt64Value(common.MetricRoundAtEpochStart, roundAtEpochStart)
presenterStatusHandler.SetUInt64Value(common.MetricCurrentRound, currentRound)

expectedRemainingTime := ""
currentEpochRound, currentEpochFinishRound, epochLoadPercent, remainingTime := presenterStatusHandler.GetEpochInfo()
assert.Equal(t, currentRound, currentEpochRound)
assert.Equal(t, numRoundsPerEpoch+roundAtEpochStart, currentEpochFinishRound)
assert.Equal(t, expectedRemainingTime, remainingTime)
assert.Equal(t, 100, epochLoadPercent)
}

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

numRoundsPerEpoch := uint64(20)
roundDuration := uint64(5000)
roundAtEpochStart := uint64(60)
currentRound := uint64(81)

presenterStatusHandler := NewPresenterStatusHandler()
presenterStatusHandler.SetUInt64Value(common.MetricRoundDuration, roundDuration)
presenterStatusHandler.SetUInt64Value(common.MetricRoundsPerEpoch, numRoundsPerEpoch)
presenterStatusHandler.SetUInt64Value(common.MetricRoundAtEpochStart, roundAtEpochStart)
presenterStatusHandler.SetUInt64Value(common.MetricCurrentRound, currentRound)

expectedRemainingTime := ""
currentEpochRound, currentEpochFinishRound, epochLoadPercent, remainingTime := presenterStatusHandler.GetEpochInfo()
assert.Equal(t, currentRound, currentEpochRound)
assert.Equal(t, numRoundsPerEpoch+roundAtEpochStart, currentEpochFinishRound)
assert.Equal(t, expectedRemainingTime, remainingTime)
assert.Equal(t, 100, epochLoadPercent)
}
6 changes: 5 additions & 1 deletion cmd/termui/view/termuic/termuiRenders/widgetsRender.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,11 @@ func (wr *WidgetsRender) prepareLoads() {
currentEpochRound, currentEpochFinishRound, epochLoadPercent, remainingTime := wr.presenter.GetEpochInfo()
wr.epochLoad.Title = "Epoch - info:"
wr.epochLoad.Percent = epochLoadPercent
str = fmt.Sprintf("%d / %d rounds (~%sremaining)", currentEpochRound, currentEpochFinishRound, remainingTime)
if len(remainingTime) > 0 {
remainingTime = fmt.Sprintf(" (~%sremaining)", remainingTime)
}

str = fmt.Sprintf("%d / %d rounds%s", currentEpochRound, currentEpochFinishRound, remainingTime)
wr.epochLoad.Label = fitStringToWidth(str, wr.epochLoad.Size().X)

totalBytesSentInEpoch := wr.presenter.GetNetworkSentBytesInEpoch()
Expand Down

0 comments on commit 3480081

Please sign in to comment.