question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formalize API for Computation object.

See original GitHub issue

What is wrong?

Currently, the Computation object houses lots of information and sub-APIs for things like maniputlating the stack, consuming gas, etc. This creates a lot of public API surface area since we are effectively support two public APIs for anything needed from a sub-property of the Computation object.

  • Computation.memory is the API for getting at the Memory
  • Computation.memory.read is the API for reading from memory.

How can it be fixed

I propose moving all sub-APIs to private properties and only exposing them through a single public API on the Computation object itself.

For example.

  • Computation.memory -> Computation._memory
  • Computation.memory.read() -> Computation.memory_read()

In the process we should organize the body of the Computation object by subject/sub-API meaning that we co-locate all of the memory APIs together, and so on for each category.

Maybe use abbreviated suffixes

Some of these accessors can be long:

  • Computation.gas_meter.consume_gas

For APIs that are unambiguous like this one we can just use:

  • Computation.consume_gas()

However, some APIs will need to be prefixed such as Computation.stack.pop(). In cases like this we should use a prefixed method name:

  • Computation.stack_pop()
  • Computation.memory_read()

Common base class

The BaseComputation class should be converted to have only STUB implementations of these methods with NotImplementedError exceptions being raised in the methods.

Then, a Computation class can be created at evm.computation.Computation which contains all of the current implementations of these methods.

Documentation

This should also include a page in the docs/ that lists all of these APIs and has a basic human readable description of what they do.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:23 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
carvercommented, Feb 8, 2018

👍 Occasionally it’s nice to be able to dir() at the repl, so dir(computation) would be much nicer this way.

Computation.gm_consume_gas()

Maybe this could even just be Computation.consume_gas(). It seems unambiguously named. The fact that it’s called gas meter seems like an unnecessary implementation detail.

The other main modules seem to work follow the memory example nicely:

  • stack
  • memory
  • code

Like: Computation.stack_pop()

A possible argument against this is that the sharding changes may introduce new APIs which are not used pre-sharding, and in some cases, potentially removing APIs which are no longer part of the sharding EVM.

Seems like BaseComputation should just shrink, then, to the intersection of the APIs. I imagine there would still be a useful subset of methods to document.

1reaction
owockicommented, Mar 21, 2018

@pipermerriam @murduk 👋

paid oot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guide to building an enterprise API strategy
APIs enable enterprises to better deliver diverse data and services to internal and external customers, and open up new revenue streams.
Read more >
RESTful API Design. Best Practices in a Nutshell.
Best Practices for Designing HTTP and RESTful APIs. Introduction to URL structure, HTTP methods, relationships, pagination and versioning.
Read more >
Creating API requests and handling responses
This document describes how to construct API requests and handle API responses from the Compute Engine API. It covers how to: Construct a...
Read more >
A Look at REST API Design Patterns
In this article, we talk a bit about useful and intuitive design patterns in RestFul Webservice API architecture.
Read more >
Representational state transfer
Representational state transfer (REST) is a software architectural style that describes a uniform interface between physically separate components, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found