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

changes to the chain to match mauve's logic (mvp) #22

Closed
ninabreznik opened this issue May 19, 2020 · 2 comments
Closed

changes to the chain to match mauve's logic (mvp) #22

ninabreznik opened this issue May 19, 2020 · 2 comments
Milestone

Comments

@ninabreznik
Copy link
Member

ninabreznik commented May 19, 2020

  • register a role (=offer the service) (Encoder, Attestor, Hoster) => list for each role
  • publishData

Problem:

  • registerHoster has the logic to assign the hypercore to the newly registered Hoster -> but how do we now also asign the hypercore to the encoder??
  • we should instead emit event (selected encoders & selected hosters)

Solution?

  • additional logic in RegisterHoster/Register Encoder/Publish data
  • each hypercore would have a count of how many hosters/encoder are available
  • when new registerHoster or registerEncoder we check if count_Encoder >= min && count_Hoster >= min (min = 3) => then emit event (newHostingRequest)
  • newHostingRequest emits 3 selected hosters and 3 selected encoders

  • hoster triggers hosterReady(feedID, hoster pubKey) function
  • chain emits event hosterReady
  • publisher triggers Start a Challenge
@serapath serapath mentioned this issue May 19, 2020
28 tasks
@serapath
Copy link
Member

serapath commented May 19, 2020

const chainAPI = { registerHoster, registerEncoder, publishData }

function registerHoster (payload) {
  const hosterID = saveHoster(payload)
  const hostingEvents = calculateAsHoster(hosterID, payload)
  emitHostingEvents(hostingEvents)
}

function publishData (payload) {
  const feedID = saveHoster(payload)
  const hostingEvents = calculateAsPublisher(feedID, payload)
  emitHostingEvents(hostingEvents)
}

function registerEncoder (payload) {
  const encoderID = saveEncoder(payload)
  const hostingEvents = calculateAsEncoder(encoderID, payload)
  emitHostingEvents(hostingEvents)
}

/************************************************************************/
// INTERNAL
const underemployed_hosters = []
const unemployed_encoders = []
const waiting_feeds = []

function emitHostingEvents (hostingEvents) {
  if (!hostingEvents.length) return
  for (const [feedID, encoderID, hosterID] in hostingEvents) {
    emit(['NewPin', feedID, encoderID, hosterID]) 
  }
}

function calculateAsEncoder(encoderID, payload) {
  const events = []
  const len = Math.min(waiting_feeds.length, underemployed_hosters.length)
  for (var i = 0; i < len; i++) {
    events.push([waiting_feeds[i], encoderID, underemployed_hosters[i]])
  }
  return events  
}
function calculateAsHoster(hosterID, payload) {
  const events = []
  const len = Math.min(waiting_feeds.length, unemployed_encoders.length)
  for (var i = 0; i < len; i++) {
    events.push([waiting_feeds[i], , unemployed_encoders[i], hosterID])
  }
  return events  
}
function calculateAsPublisher(feedID, payload) {
  const events = []
  const len = Math.min(unemployed_encoders.length, underemployed_hosters.length)
  for (var i = 0; i < len; i++) {
    events.push([feedID, unemployed_encoders[i], underemployed_hosters[i]])
  }
  return events  
}

@jam10o-new
Copy link

jam10o-new commented May 19, 2020

my goal is to simplify the storage of challenges held by hosters from multiple storage values, to:

(hoster, archive) => HostedArchive

(or, use DoubleMap, so we can iterate over exclusively hosters to find all archives they host)

hoster, archive => HostedArchive

where

struct HostedArchive {
    encoded: SortedVec<(ChunkIndex, EncoderId)>,
    state: State,
}
enum State {
    Encoding,
    Ready(Vec<Challenge>),
}

enum Challenge {
   Active(blockNumber, chunk),
   Attesting(ChallengeAttestations),
}

the goal of which would be that we can drastically reduce the storage lookups when challenging a hoster

@jam10o-new jam10o-new added this to the Month 1 milestone May 19, 2020
jam10o-new pushed a commit that referenced this issue Jun 13, 2021
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