StakingToken
StakingToken copied to clipboard
Question about the array handling.
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.
I agree. Using an array will lead to DOS attack.
@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
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..
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.