We made them objects so we could add fields like that.
I agree. Actually I agree that we should make them objects so that we can add necessary fields later.
Actually IMO, {accept: {addr: xxx}, {pubkey: xxx}}
should be almost identical as {accept: {addr: xxx, pubkey: false}, {addr: xxx, pubkey: true}}
in terms of code complexity:
// permission is {addr: xxx} or {pubkey: xxx}
func checkAccept(addr, perm) {
if (perm.pubkey) {
// handle wildcard
return addrToPubkey(addr) === perm.pubkey;
} else if (perm.addr) {
// handle wildcard
return addr === perm.addr;
}
return false;
}
// permission is{addr: xxx, pubkey: false} or {addr: xxx, pubkey: true}
func checkAccept(addr, perm) {
if (perm.pubkey) {
// handle wildcard
return addrToPubkey(addr) === perm.addr;
} else if (perm.addr) {
// handle wildcard
return addr === perm.addr;
}
return false;
}
you just overwrote your own subscription tx
This should not happen usually because SDK will try to get nonce from txpool first. So you if you send 2 txns without waiting, they will not override, unless they are subscribing to the same topic with the same identifier. So separating permission identifier and admin’s own identifier has one advantage: he can subscribe and change permission at the same time without affecting each other.
Maybe we add the permissions into the original identifier, instead of the __n__.__permissions__
identifier.
Most importantly, __n__.__permissions__
is needed because of the meta size limit. Since each metadata needs to be <= 1024 bytes, each meta can only store up to 14 subscribers if we use hex representation. We can use more efficient representation (e.g. wallet address, short hash, or even bloom filter), but ~50 subscribers are probably the limit.
I think we can use a special identifier to store some group metadata, like what’s the range of n
in __n__.__permissions__
. IMO using a fixed special identifier is better than using owner’s identifier because:
- owner’s identifier is not unique, so there might be a conflict. And if there is a priority, user needs to get all subscribers in order to find the effective one.
- other people don’t know owner’s identifier in advance, so it’s possible to attack such group by sending massive subscribe txns and make it very inefficient to find the real owner. If this group is very important, then attacker definitely has a motivation to spend some txn fee and attack the group.
So my suggestion is that:
- We still separate permission identifier and owner’s identifier, and owner needs to send 2 txn. Because they use different identifier, there won’t be a conflict or override.
- We choose a fixed identifier to store some group metadata like range of
n
- For the fixed identifier, we can probably use
__0__.__metadata__
or something else. The __0__
is added in case we want to make it multiple (e.g. due to meta size limit) in the future.