Skip to content
This repository has been archived by the owner on Jun 10, 2019. It is now read-only.

Queue new block root hash submissions #40

Open
karlfloersch opened this issue Feb 9, 2019 · 0 comments
Open

Queue new block root hash submissions #40

karlfloersch opened this issue Feb 9, 2019 · 0 comments
Labels
bug Something isn't working enhancement New feature or request SECURITY

Comments

@karlfloersch
Copy link
Contributor

Is your feature request related to a problem? Please describe.
It seems we may be running into problems with submitRootHash() being called, not completing, and then being called again. Because we are not providing any nonce management, this is sure to cause issues.

Describe the solution you'd like
A very simple temporary fix is adding a submitRootHashQueue similar to the one found in https://github.com/plasma-group/plasma-chain-operator/blob/master/src/block-manager/block-store.js#L51-L59 . The code would be something like:

  this.rootHashQueue = []

  async submitRootHash (rootHash) {
    log('Submitting root hash:', rootHash)
    const deferred = defer()
    this.rootHashQueue.push({ rootHash, resolve: deferred.resolve })
    if (this.rootHashQueue.length === 1) {
      this._processRootHashQueue()
    }
    return deferred.promise
  }

  async _processRootHashQueue () {
    let numRootHashProcesses
    for (numRootHashesProcessed = 0; numRootHashesProcessed < this.rootHashQueue.length; numRootHashesProcessed++) {
      this.rootHashQueue[numRootHashesProcessed].receipt = await es.plasmaChain.methods.submitBlock('0x' + this.rootHashQueue[numRootHashesProcessed].rootHash).send({gas: 400000, gasPrice: '5000000000'})
    }
    const processedRootHashes = this.rootHashQueue.splice(0, numRootHashesProcessed)
    for (const processedRootHash of processedRootHashes) {
      processedRootHash.resolve(processedRootHash.receipt)
    }
  }

Note that I just copied and pasted the code from block-manager and changed variable names. Probably should extract this logic into some kind of library & share code between them.

Describe alternatives you've considered
Eventually we probably want to store every transaction that is sent out of the operator & the latest nonce. This way we can have a full history of transactions which are sent and can ensure that we never send two txs with the same nonce. And if one tx we signed isn't getting through, we can add logic for rebroadcasting.

@karlfloersch karlfloersch added bug Something isn't working enhancement New feature or request SECURITY labels Feb 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working enhancement New feature or request SECURITY
Projects
None yet
Development

No branches or pull requests

1 participant