plebbit / plebbit-js

A Javascript API to build applications using plebbit
GNU General Public License v2.0
41 stars 7 forks source link

implement default subs votes over pubsub #25

Open estebanabaroa opened 11 months ago

estebanabaroa commented 11 months ago
Settings {
  chainTicker: 'eth'
  tokenAddress: '0x...'

  // don't store votes for a sub unless it has at least 1 vote with 1bil tokens or more, prevents people spamming votes for subs that dont exist
  minBalanceToProposeVote: 1bil

  // only store the last 100 votes per address, prevents people spamming votes for subs that dont exist 
  maxVotesPerAddress: 100

  // we can't fetch some address' balance at block 100 and another at block 101, we must use the same block for everyone
  // 25min at 15 secs per block on eth
  blocksPerBucket: 100
}

(put all the settings in the pubsub topic so the network can validate without any intermediaries) pubsubTopic = /default-subplebbits/<settings.chainTicker>/<settings.tokenAddress>/<settings.minBalanceToProposeVote>/<settings.maxVotesPerAddress>/<settings.blocksPerBucket>

steps to get votes:

join pubsub <pubsubTopic>

the value received is Votes[] (1 Votes[] per author)

Votes {
  author: Author
  signature: Signature
  votes: Vote[] // length must be smaller than maxVotesPerAddress
  blockNumber: number
}
Vote {
  subplebbitAddress: string
  vote: 1 | -1
}

how to verify:

potential problems:

steps to publish votes

notes:

when receiving a fetch protocol /last-votes/... dont send all the known Votes, only send the highest balance and/or the votes similar to your own, not sure what the max should be, maybe 100kb or something. possibly we could send only the closest k peers of the eth address (like DHT does), or just send random ones.

in the UI, if the user is voting for more subs than settings.maxVotesPerAddress warn him that he must stop voting for some subs to vote for new ones