æternity Dev Tools Update: Middleware

For the æternity æpps and developer tools teams, our top priorities are the user and developer experiences. And in the case of developer tools, our users are also developers.

After the release of the Roma network, our focus is not only on optimizing, monitoring, and improving the æternity network, but also on growing the ecosystem in a number of ways. One of these ways is building tools which help everyone interact with the network.

The primary purpose of an æternity node is to maintain the chain and establish consensus with other nodes. But we also need to query the chain in ways which may not be so simple to answer. If the node were to offer all of the queries that we need, it would interfere with this primary purpose.

For instance, the Blockchain Explorer needs to query key blocks, micro blocks and transactions. In the case of a key block with 50 micro blocks and 1,000 transactions, this means that to show the details of one key block we may have to make over one thousand queries. We can avoid stressing the nodes, and give our users faster interactive performance by caching the blockchain in a SQL database, and serving the simpler queries from there.

Built out of necessity

The middleware is just such a caching layer which allows us to interact with the æternity blockchain more efficiently. There were 3 main reasons for building it:

We wanted to access the node information more quickly in order for the æternity explorer to work more smoothly.

The middleware makes it easy to query a node and adds additional queries, which return very useful information.

We can store the blockchain history in a PostgreSQL database for easy dump/import into other systems.

How it works

The middleware sits between clients and the node. When it is initially run, it populates its database by pulling all key- and micro- blocks and all transactions from the node, and stores them in its database. When it’s up-to-date, it regularly polls the node to find new blocks, and walks back through the chain checking that its database is correct. In this way, it can recover from forks.

The middleware is written in Rust, for its fast speed and safety.

Queries

Below you can see the queries which are available when querying a node directly but are served faster via the middleware.

/key-blocks/height/<height>

/transactions/<hash>

/generations/current

/micro-blocks/hash/<hash>/transactions

/micro-blocks/hash/<hash>/header

/key-blocks/current/height

/micro-blocks/hash/<hash>/transactions/count

In addition to the queries above, the middleware offers the following queries which aggregate information from the node and are not available anywhere else.

/transactions/account/<account>

/transactions/interval/<from>/<to>

/key-blocks/height/<height>/gas-price

This collection will grow over time as we add new functionality.

How to use it

To use the middleware you can clone the repository and run it locally. You can also connect to it at http://mdw.aepps.com:8080

There is already preliminary documentation in the GitHub repository, although we are very aware that it needs improvement. Additionally, if you’re a developer and you have requirements which the middleware could meet, we encourage you to raise an issue in GitHub.

Questions?

If you have any questions regarding the middleware feel free to post them in the Forum under the Development category.

Into the Future

We have many more exciting updates from the æpps and dev tools teams. As always, free free to connect with us using the links below!