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

Question about the array handling. #11

Open
swtrse opened this issue Sep 16, 2021 · 4 comments
Open

Question about the array handling. #11

swtrse opened this issue Sep 16, 2021 · 4 comments

Comments

@swtrse
Copy link

swtrse commented Sep 16, 2021

I see that the array will be searched every time-
Is the position of the items inside the array different every time the contract get loaded into an client?
If the position is fixed then maybe a more processor time friendly logic could be implemented.

@SKFrozenCloud
Copy link

I agree. Using an array will lead to DOS attack.

@jaglinux
Copy link

@swtrse position of item inside array is not fixed. When item is deleted, the last element is swapped with item to be deleted index and the last element is removed/pop.
https://github.com/HQ20/StakingToken/blob/master/contracts/StakingToken.sol#L136

@swtrse
Copy link
Author

swtrse commented Oct 24, 2021

Thanks, that clears it up for this specific implementation. That helps too but what I wanted to know is if there is something possible like a queue where you push new elements on the end and pop old elements of the front. I do not have an concrete implementation in mind but I want to get a feeling for the underlying concepts.
So for example if I generate an array in C and fill the array with values. I can take it for granted that the order of the items is always the same for the lifetime of the array. However in an distributed environment this has not to be the case and I was wondering if the order of elements will be the same for each distributed client or if each client can hold a different order of array elements because an array is not ordered per se and order should not matter at least most of the times..

@jaglinux
Copy link

Main issue is when someone wants to removeStake(). Instead of swapping, we can just make the value as 0.
Then we can maintain the index position, new users will be pushed at the end as usual.
Downside is that the array will keep growing.

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

No branches or pull requests

3 participants