-
Notifications
You must be signed in to change notification settings - Fork 198
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
Conversation
…s and their ammounts and the delegators addresses and their amounts on each delegation system sc
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
api/mock/facade.go
Outdated
@@ -188,7 +190,7 @@ func (f *Facade) SendBulkTransactions(txs []*transaction.Transaction) (uint64, e | |||
return f.SendBulkTransactionsHandler(txs) | |||
} | |||
|
|||
//ValidateTransaction -- | |||
//ValidateTransaction - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// ValidateTransaction -
There was a problem hiding this comment.
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
Outdated
{ Name = "/config", Open = true } | ||
{ Name = "/config", Open = true }, | ||
|
||
# /network/direct-staked-info will return the metrics related to current direct staked list of addresses |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rephrased
cmd/node/config/api.toml
Outdated
# and their staked values | ||
{Name = "/direct-staked-info", Open = true}, | ||
|
||
# /network/delegated-info will return the metrics related to current delegated list of addresses |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
data/api/apiBlock.go
Outdated
|
||
// DirectStakedValue holds the total staked value for an address | ||
type DirectStakedValue struct { | ||
Address []byte `json:"address"` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
node/external/nodeApiResolver.go
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"will return". also below
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
node/trieIterators/errors.go
Outdated
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has*
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is a struct
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface*
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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"
?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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"
?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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"
?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NilHeader
?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
data/api/apiBlock.go
Outdated
|
||
// DirectStakedValue holds the total staked value for an address | ||
type DirectStakedValue struct { | ||
Address []byte `json:"address"` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
data/api/apiBlock.go
Outdated
// Delegator holds the delegator address and the slice of delegated values | ||
type Delegator struct { | ||
DelegatorAddress []byte `json:"delegatorAddress"` | ||
DelegatedTo []DelegatedValue `json:"delegatedTo"` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
data/api/apiBlock.go
Outdated
Address []byte `json:"address"` | ||
Staked *big.Int `json:"staked"` | ||
TopUp *big.Int `json:"topUp"` | ||
Total *big.Int `json:"total"` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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() ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System test passed.
Testing scenarios: start a testnet and then call these routes on the metachain observer:
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.