poanetwork / poa-popa

DApp for proof of physical address (PoPA) attestation for validators of POA Network
https://popa.poa.network
GNU General Public License v3.0
24 stars 18 forks source link

(Refactor) change address removal method #149

Closed phahulin closed 6 years ago

phahulin commented 6 years ago

https://github.com/poanetwork/poa-popa/blob/master/blockchain/contracts/ProofOfPhysicalAddress.sol#L341

In current implementation when address is removed by a user, elements of physicalAddresses array are shifted and then the last element is deleted:

[0, 1, 2, 3, 4] --> remove 2 --> [0, 1, 3, 4, 4] --> [0, 1, 3, 4]

Suggestion is to copy the last element of array to the place of the removed element, then delete the last element:

[0, 1, 2, 3, 4] --> remove 2 --> [0, 1, 4, 3, 4] --> [0, 1, 4, 3]

(this is for the case when removed element is not already the last one)

This method requires fewer operations and hence less gas, however the order of elements is not preserved. But it doesn't seem to be important, since they can be ordered by creation block anyway.

@fvictorio @matiasgaratortiz what do you think?

fvictorio commented 6 years ago

Sounds good! I don't think the order of elements is important. I'll implement it.