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

Growth supporting API routes #2961

Merged
merged 8 commits into from
Apr 9, 2021
Merged

Conversation

iulianpascalau
Copy link
Contributor

@iulianpascalau iulianpascalau commented Apr 6, 2021

  • added growth related API routes that can expose the staked addresses and their amounts and the delegators addresses and their amounts on each delegation system SC

Testing scenarios: start a testnet and then call these routes on the metachain observer:

http://x.x.x.x:8080/network/direct-staked-info
http://x.x.x.x:8080/network/delegated-info

the responses should contain all delegators and their delegated amount + the direct staked info. If no stake/unstake operation will be done, the values should match the genesis.json contents.

…s and their ammounts and the delegators addresses and their amounts on each delegation system sc
@codecov
Copy link

codecov bot commented Apr 6, 2021

Codecov Report

Merging #2961 (faea4fa) into master (95e198a) will increase coverage by 0.03%.
The diff coverage is 88.81%.

❗ Current head faea4fa differs from pull request most recent head 5864fef. Consider uploading reports for the commit 5864fef to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2961      +/-   ##
==========================================
+ Coverage   74.97%   75.01%   +0.03%     
==========================================
  Files         615      620       +5     
  Lines       58857    59055     +198     
==========================================
+ Hits        44130    44298     +168     
- Misses      10789    10803      +14     
- Partials     3938     3954      +16     
Impacted Files Coverage Δ
node/trieIterators/directStakedListProcessor.go 70.00% <70.00%> (ø)
node/trieIterators/delegatedListProcessor.go 78.49% <78.49%> (ø)
api/network/routes.go 100.00% <100.00%> (ø)
facade/nodeFacade.go 43.16% <100.00%> (+1.18%) ⬆️
node/external/nodeApiResolver.go 96.29% <100.00%> (+6.29%) ⬆️
node/trieIterators/commonStakingProcessor.go 100.00% <100.00%> (ø)
...ieIterators/factory/delegatedListHandlerFactory.go 100.00% <100.00%> (ø)
...terators/factory/directStakedListHandlerFactory.go 100.00% <100.00%> (ø)
...trieIterators/factory/stakeValuesHandlerFactory.go 100.00% <100.00%> (ø)
node/trieIterators/stakeValuesProcessor.go 100.00% <100.00%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 95e198a...5864fef. Read the comment docs.

@bogdan-rosianu bogdan-rosianu self-requested a review April 6, 2021 14:07
@miiu96 miiu96 self-requested a review April 6, 2021 14:17
@@ -188,7 +190,7 @@ func (f *Facade) SendBulkTransactions(txs []*transaction.Transaction) (uint64, e
return f.SendBulkTransactionsHandler(txs)
}

//ValidateTransaction --
//ValidateTransaction -
Copy link
Contributor

Choose a reason for hiding this comment

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

// ValidateTransaction -

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

{ Name = "/config", Open = true }
{ Name = "/config", Open = true },

# /network/direct-staked-info will return the metrics related to current direct staked list of addresses
Copy link
Contributor

Choose a reason for hiding this comment

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

# /network/direct-staked-info will return a list containing a list of current direct staked list of addresses
# and their staked values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rephrased

# and their staked values
{Name = "/direct-staked-info", Open = true},

# /network/delegated-info will return the metrics related to current delegated list of addresses
Copy link
Contributor

Choose a reason for hiding this comment

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

same here. they are not "metrics" as we "know" them

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


// DirectStakedValue holds the total staked value for an address
type DirectStakedValue struct {
Address []byte `json:"address"`
Copy link
Contributor

Choose a reason for hiding this comment

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

addresses: string and encode with bech32
values: string instead of big int

applicable in the entire file

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

@@ -64,6 +79,16 @@ func (nar *NodeApiResolver) GetTotalStakedValue() (*api.StakeValues, error) {
return nar.totalStakedValueHandler.GetTotalStakedValue()
}

// GetDirectStakedList will output the list for the direct staked addresses
Copy link
Contributor

Choose a reason for hiding this comment

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

"will return". also below

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

}

if len(vmOutput.ReturnData) != 1 {
return nil, fmt.Errorf("%w, getActiveFund function should have at least one value", epochStart.ErrExecutingSystemScCode)
Copy link
Contributor

Choose a reason for hiding this comment

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

remove at least ? from the condition it seems that there should be a single value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rephrased

keys = append(keys, key)
}

sort.Slice(keys, func(i, j int) bool {
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 you need to sort the elements in the slice? you use them as keys in a map.
Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just wanted to be consistent between calls (same call will produce exactly the same output for the same data). Might be dropped.

// ErrNodeNotInitialized signals that the node is not initialized and can not compute the required task yet
var ErrNodeNotInitialized = errors.New("the node is not fully initialized")

// ErrNilMutex signals that a nil mutex hax been provided
Copy link
Contributor

Choose a reason for hiding this comment

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

has*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

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

// ArgStakeProcessors is struct that contains components that are needed to create a TotalStakedValueHandler
Copy link
Contributor

Choose a reason for hiding this comment

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

is a struct

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

"github.com/ElrondNetwork/elrond-go/vm"
)

// AccountsWrapper extends the AccountsAdapter interfec
Copy link
Contributor

Choose a reason for hiding this comment

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

interface*

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

cmd/node/config/api.toml Show resolved Hide resolved
return nil, err
}
if vmOutput.ReturnCode != vmcommon.Ok {
return nil, fmt.Errorf("%w, error: %v message: %s", epochStart.ErrExecutingSystemScCode, vmOutput.ReturnCode, vmOutput.ReturnMessage)
Copy link
Contributor

Choose a reason for hiding this comment

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

"%w, return code: %v message: %s" ?

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

return nil, err
}
if vmOutput.ReturnCode != vmcommon.Ok {
return nil, fmt.Errorf("%w, error: %v message: %s", epochStart.ErrExecutingSystemScCode, vmOutput.ReturnCode, vmOutput.ReturnMessage)
Copy link
Contributor

Choose a reason for hiding this comment

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

"%w, return code: %v message: %s" ?

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

return nil, nil, err
}
if vmOutput.ReturnCode != vmcommon.Ok {
return nil, nil, fmt.Errorf("%w, error: %v message: %s", epochStart.ErrExecutingSystemScCode, vmOutput.ReturnCode, vmOutput.ReturnMessage)
Copy link
Contributor

Choose a reason for hiding this comment

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

"%w, return code: %v message: %s" ?

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

}

ctx := context.Background()
chLeaves, err := validatorAccount.DataTrie().GetAllLeavesOnChannel(rootHash, ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a TODO for analyzing if we can add a GetAllLeavesKeysOnChannel? Here and also in other parts of the code, we only use the keys, so no need to move high amount of data when we only need the keys

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


type delegatedListProc struct {
*commonStakingProcessor
publicKeyConverter core.PubkeyConverter
Copy link
Contributor

Choose a reason for hiding this comment

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

oh.. a pub key converter. you might need it 😈

publicKeyConverter core.PubkeyConverter
}

var metachainIdentifier, _ = hex.DecodeString("ff")
Copy link
Contributor

Choose a reason for hiding this comment

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

why not declaring a const and set it with the bytes value?

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

require.Equal(t, expectedErr, err)
}

func TestTotalStakedValueProcessor_GetTotalStakedValueilHeaderShouldError(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NilHeader ?

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

@@ -0,0 +1,379 @@
package trieIterators
Copy link
Contributor

Choose a reason for hiding this comment

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

following go principles, package names should not use camel case

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 guess we should start refactoring half of the project then. I know it should have been one word there but I guess those 2 words better explain what the package should do.

Copy link
Contributor

Choose a reason for hiding this comment

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

it could have been trieiterators but it's fine


// DirectStakedValue holds the total staked value for an address
type DirectStakedValue struct {
Address []byte `json:"address"`
Copy link
Contributor

Choose a reason for hiding this comment

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

address as type string and bech32 encoded?

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

// Delegator holds the delegator address and the slice of delegated values
type Delegator struct {
DelegatorAddress []byte `json:"delegatorAddress"`
DelegatedTo []DelegatedValue `json:"delegatedTo"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use a pointer here?

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

Address []byte `json:"address"`
Staked *big.Int `json:"staked"`
TopUp *big.Int `json:"topUp"`
Total *big.Int `json:"total"`
Copy link
Contributor

Choose a reason for hiding this comment

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

also, return string on the API response instead of big.Int

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

delegatorInfo.Total = delegatorInfo.TotalAsBigInt.String()
delegatorInfo.DelegatedTo = append(delegatorInfo.DelegatedTo, &api.DelegatedValue{
DelegationScAddress: dlp.publicKeyConverter.Encode(delegationSC),
Value: big.NewInt(0).Set(value).String(),
Copy link
Contributor

Choose a reason for hiding this comment

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

why you use big.NewInt(0).Set(value).String() instead value.String() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remained from first implementation. Fixing

Copy link
Collaborator

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

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

System test passed.

@iulianpascalau iulianpascalau merged commit daf18b8 into master Apr 9, 2021
@iulianpascalau iulianpascalau deleted the growth-releated-api-routes branch April 9, 2021 14:54
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