New ABI Package #88
ryandotsmith
announced in
Announcements
Replies: 1 comment
-
I'd also like to explicitly say that I have nothing but respect for the heroic effort put forth by the Geth team. I am a huge fan of their work! Without it the world would not be as interesting. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A Go package for encoding/decoding ABI data.
Click here for a primer on ABI encoding.
The most common way for a Go project to deal with ABI encoded data is to use Geth's ABI packages. But today I’m excited to announce another option: Index Supply’s ABI package. Here are a few key differences between Geth and Index Supply:
Our goal is to decode logs from common contracts in ~1000 ns which enables us to process millions of logs per second. This is important for Index Supply because we are building a system that can quickly backfill new indexes.
Reduced Memory Usage
We avoided using Go's reflection package and paid close attention to allocations. Our benchmarks indicate 0 allocations occur during a decode operation once the package has been initialized. Here are some benchmarks comparing Geth and Index Supply:
ERC721 Transfer
Index Supply’s ABI package allocates 0 memory because for an ERC721 Transfer, all of the data is indexed, meaning there is no ABI encoded data to decode!
Seaport OrderFulfilled
The 2 allocations in the Index Supply benchmark occur in the generated code. We have to allocate some slices to hold the nested tuple arrays inside the Seaport event structure. It's possible that these allocations can be factored out as well. You can still achieve 0 allocations if you use the abi Decode package directly.
More Functionality With a Simpler Interface
The primary way to interact with the abi package is by using abi.Encode, abi.Decode, and schema.Parse. For example:
Of course this code can be generated based on an ABI JSON file using our genabi command:
Smaller Implementation
Having a concise implementation makes debugging, feature addition, and performance work a pleasant experience. The core encoding and decoding functions are ~200 LOC and are found in a single file: Encode & Decode.
Our ABI package has a not-so-bad test corpus as well.
Owning our stack
In addition to the form factor and performance improvements we made, another big motivation for the rewrite is that we need to own our stack. Index Supply is in the business of indexing ethereum data –most of which is ABI encoded. As we have gone live with our first customer, we have already seen ROI from our ability to quickly add features and diagnose performance issues. We won't reinvent everything, but investing in the core parts of our stack will be worth our while –and it's a lot of fun!
Roadmap
We are on a mission to create an Ethereum node that is purpose built for indexing operations. This is a large undertaking and will require years of development. That being said, we aren’t developing in the dark. We are finding sub-projects that help teams in the short term that also fit into our long term vision. ABI decoding is something that a lot of teams currently deal with and also something that is necessary for our node.
If you have an idea for a project please reach out!
Examples
Parsing a Seaport OrderFulfilled Log
Generating from an ABI
First install
genabi
Using Decode Directly
Using Decode and Parsing a Schema
Bugs
Give the abi package a try! If you hit any snags, please open an issue ASAP! I'm eager to get more mileage on this code.
Beta Was this translation helpful? Give feedback.
All reactions