Using plugins to extend Neo features

Ricardo Prado
Nov 26 · Unlisted

The need for a plugin system

If you are running your product on the blockchain, it is almost mandatory that you monitor the network, to track changes in managed contracts, and react to notifications, such behavior can be achieved using or implementing a plugin. Another common use case is to load blockchain data into a relational database like MySQL and use this database as a central point for your off-chain code.

Implementing such a feature on Neo is quite easy if you choose to use the plugin system. All you have to do is implement the IPersistence plugin interface and wait for your code to be called.

The plugin structure

Plugins are loaded during the application start. The application loads plugins using their DLLs, meaning you can use your custom plugins with the latest release of neo-cli.

Plugins are called depending on the interface they implement. You can have more than one plugin for each interface.

If you are building a plugin to store information on a MySQL node, you can use a configuration file to make your code more portable, allowing it to be reused in different DB instances by only changing the configuration file.

A plugin must respond to the Configure method. The most common way to implement the Configure method is by using it to load the configuration from a JSON file. You can find examples here.

Neo library has several extension endpoints that can be used to enrich neo functionalities. These extension endpoints are represented by the interfaces above.

New plugins on Neo 3

New plugins are expected on Neo 3. These important plugins will be used at the storage and P2P layer, adding new data structures and storage providers.

IStorage Plugin

The idea is to detach our storage layer currently implemented by the Blockchain class to a new abstraction layer supported by the IRepository interface.
We expect to launch this new interface along with memory, LevelDB, and RocksDB implementations.

The future of RPC

Neo already has RPC endpoints implemented as plugins, however, we are looking to move all the RPC server code into a plugin. This change will allow neo library to contain only the basic code it needs to participate in the network, making it more portable and easier to maintain.

New data structures

New data structures can be used to save space, allow sharding and improve IO. This is already the subject of research from our team, especially to our core developer Rodolfo and neo-research team.

Merkle Patricia Tries
We can expect some kind of adoption of the Merkle Patricia Tries, either for the storage or for the P2P layer. An implementation already exists but the team is still deciding about where and when to use it.

Sparse Merkle Tree
This implementation is also being evaluated by the core developer team. This kind of tree is already being discussed in the Ethereum community and you can find a good article about it here.

Conclusion

Plugins play an important role in the neo ecosystem by allowing non-essential features to be added to it without having to recompile the whole project.
On Neo 3, plugins will have a bigger role with the additions of RPC, new data structures and different options of storage.

Unlisted

Ricardo Prado

Written by

Neo Core Developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade