hermeznetwork / hermez-node

Hermez node Go implementation
GNU Affero General Public License v3.0
61 stars 33 forks source link

Flow paradigm applied to transaction processor and selection #1101

Open Mikelle opened 3 years ago

Mikelle commented 3 years ago

Rationale

Currently, transactions in tx processor got processed one by one. The idea is to make tx processor process transactions concurrently, using flow programming, for example, make transaction verification from step by step to verify each condition in separate goroutine

Implementation

Tx processor and tx selector refactor

Currently transactions are verified and processed sequentially one by one. So the idea is to make this process run concurrently using pipeline pattern.

New algorithm

  1. We could verify transactions concurrently and add them to the following group.
  2. When group building will be finished, we can proceed to the next step and process txs.
  3. To process txs we have to divide ZKI calculation from the processing. Currently, it's strongly coupled in the code, but the calculation is not reliant on the tx processing
  4. When processing and ZKI calculation will be finished, we can build a batch.

Steps to implement

  1. Make process of verification and group setting run concurrently. For every group of txs we can define channel and add txs to them.
    • Note: atomic group txs are strongly coupled to a sequential process. Have to rethink this
  2. As the next step, we could make all verifications run concurrently too.
  3. Split tx processing and ZKI calculation
  4. Make the process of processing txs and zki calculation run concurrently.
    • Note: as the next step we could try not to wait until all transactions are selected, but start to process selected tx right away