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

Construction API Testing 2.0 #112

Closed
28 of 30 tasks
patrick-ogrady opened this issue Aug 18, 2020 · 0 comments · Fixed by #135
Closed
28 of 30 tasks

Construction API Testing 2.0 #112

patrick-ogrady opened this issue Aug 18, 2020 · 0 comments · Fixed by #135
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@patrick-ogrady
Copy link
Contributor

patrick-ogrady commented Aug 18, 2020

Replaces #86
Closes #119

Motivation

The recently added Construction API testing (#81) does not support multi-currency sends, on-chain address generation, testing non-transfer transactions, or testing account/utxo transfers on the same network. This makes it impossible to test the Construction API of many projects implementing the Rosetta API.

Solution

We need to redesign the constructor to allow for the generic execution of a core set of primitives (generate_key, save_address, derive, set_variable, find_account, find_coin, print_message, wait_for_funds, math, random_string) that can be stitched together into scripts (with some shared state). These "scripts" should be called scenarios and it should be possible to combine multiple scenarios together into a workflow where all execution state is shared. At the end of each scenario execution it should be possible to execute a transaction which will allow multiple transactions to be broadcasted as part of a workflow. The constructor will manage the execution of these workflows (instantiated as jobs) using a new storage backend called JobStorage.

Preview

Workflow
  []Scenario
    []Action

Job (instance of a plan)
  Identifier
  State
  Index
  []Scenario
  Status [ready, broadcasting, failed, complete]

  Create(Plan) Job
  Intent() [run after execute] -> sets status to broadcasting

Worker (executes job)
  Helper (fetcher, balanceStorage, coinStorage, broadcastStorage, keyStorage)
    Derive
    LockedAddresses
    AccountBalance
    CoinBalance
    StoreAddress

  processScenario(State, []Actions) -> NewState, Error
  Process(job) -> updatedJob, intent, error


Constructor (creates jobs, coordinates worker, manages Construction API Flow)
  Helper (broadcastStorage, keyStorage, flowStorage)
    ConstructionAPIFlow (-Submit)
    Broadcast()
    Sign()
    JobsProcessing() -> Count
    JobsReady() []jobs
  Handler
    AddressCreated
    TransactionCreated

  Loop:
    var job
    var intent
    for [
      ready jobs...,
      (new jobs excluding create_account and request_funds as long as concurrency lower than required)plans...,
      request funds (if no broadcasting jobs and broadcast completed hasn't been updated since start)
    ]:
      Worker.Process(Job) -> updatedJob, Intent, error
      if errInsufficientAccounts:
        run "create_account" then try jobs again (as long as not existing create account)
      if errInsufficientFunds, errUnsatisfiable:
        continue
      if err != nil:
        THROW ERROR

      job = updatedJob
      intent = intent
      break

    jobID = JobStorage.Update(job) -> only assign identifier and store once successful at least once/only update if successful processing
    if intent:
      networktransaction, transactionidentifier = CreateTransaction(intent) [existing]
      Broadcast(network transaction, intent, transactionIdentifier, jobID)

  Errors:
    ErrUnsatisfiable -> if some action can't be completed because of lack of resources, but not error
    ErrInsufficientFunds -> if all ready fail + no in progress + creating all new jobs fails (don't try create account and request funds), request funds
    ErrInsufficientAccounts -> means we should create a new account, returned when we don't max out (only some addresses are creatable)
  Methods:
    CreateTransaction(Intent) Broadcast, error

Todos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

1 participant