Workshop: Extending on Reth - ETHGlobal Sydney 2024
ETHGlobal·Wed, Oct 9, 2024, 12:00 AM
Join lib evm of Mantle for a workshop titled, "Extending on Reth." Reth is an Ethereum execution layer, built by paradigm. In this workshop we will be going through why build on top of an EL in the first place, and if so, how/what would you begin. This workshop took place at ETHGlobal Sydney 2024, the first major Ethereum hackathon in Oceania, hosted by ETHGlobal, May 3-5 at The Venue Alexandria. ----------------- Follow us: https://x.com/ethglobal Check us out: https://ethglobal.com Email us at: hello@ethglobal.com
Transcript
[Music] all right thanks everyone for tuning in welcome to extending on ra I'm uh lip evm or Library uh it dur virtual machine and I'm currently with mantle so yeah background I'm at lip evm on Twitter currently at Dev on mantle. XYZ I also run a me dashboard called lip m.com and we also run a this is separate to manle by the way it's my own thing we also run an ethereum block Builder called penguin build and we're currently about 2% of all block space so anyway extending on ref why why do you care about extending on an execution client well one you're you're R curious your data curious or you're curious about the lowlevel details of etherum like how does um how do you sync up with peers or how do you validate a transaction how do you calculate the merel tribe blah blah blah blah blah or you're just a Geo's Fanboy so any one of the above can be valid um and yes what is ref ref is a ethereum execution client written in Rust hence ref rust ethereum uh the whole point of ref is that it's designed to be extendable so the components are modular it's intended to be used as a library uh or as a stand Standalone note where you can extend upon it um this is very different from the design choices of GE where it was designed to very monolithic um and building on top of GE is very painful because that means that every time you want to merge any Upstream changes you have to do like a rebase but with ref you can use S because you can use it as a library there's no need to pull in the Upstream changes you you just bump the version up or the GI has depending on how you uh handle your application uh and I know what we're all thinking just show me the code I don't really care blah blah blah blah blah so I will so uh one example is the custom RPC method so say you're a developer and you really really really want to extend and let's say there's no there's a there isn't an RPC call that allows you to do what you want to do you can easily extend on ref and build your own custom RPC method for example if you like e call but you want e call _ call to do something more you can and with a few lines of code you can do that so in this example you have a uh you define the trait of your uh custom API in this case my my trait name is called custom e Nam space extension API very verbose I understand but uh you you can always shorten it to whatever suits your purpose and in this case I want to add a new function called block gas which gives me the gas used in a block so I don't want to query the block get a bunch of useless data and then find out the the gas used from that I just want to be able to get the gas used From the Block in one transaction so I create a custom struct called custom e namespace extension which takes in a provider and then I write the implementation so uh custom e namespace extension API server and all I do here is I get the block and I return the block. gasu and from there I able to extend on the Node and create my own custom name space in this case it's called My Name space where I can get the block gas and to add it in and to insert it into the main function you just need a few lines of code all of which um are in the examples um so you just Define your server in this case um sorry uh you you you create your RPC server so this is all in the ref examples and then you create your custom RPC custom e namespace and all you do is call Custom RPC do into RPC and boom you have a whole new namespace and uh RPC method and to query it this is all you do it's a standard um RPC method so you can do a post request and you can just specify the uh the method name in this case it's my name spacecore block gas and you can supply the params it's that easy and I know you might ask why do I I care about extending my own custom name space this this block gas method seems very very useless and very pointless but in the event that you're trying to do something non-standard for example extended note where it emits Shadow logs you can do that quite easily now Aragon has this feature called overlay unor get logs but it's very non-standard and it's not implemented in a lot of clients but you as a as a budding uh rust Fanboy or ethereum lover if you will you can easily extend ref and add add in this um custom method overlay get logs without diving deep into the ref codebase but rather using it as a library in addition to that if you would like to add in your own uh RPC method while maintaining compatibility with the Upstream you do not need to wait so you do not need to wait for years is for your PR to be merged in main for example this is um a request for RPC method called _ batch call this was proposed and in 2022 September um where there was I think Cena wanted to merge this into ethereum main for various reasons and till date it Still Remains unmerged very epic um but yes anyway so that's that's one of the few reasons on why you might be interested in ref so again something emphasize is that ref is used as a library not you're not forking it and extending on it it is used as a library you extend and go and all you have to do is to merge Upstream changes is to change your version up you bump the version up up and then you fix all the bugs that ref previously had and you're good to go no fuss all right showcase too uh mempo analysis so uh hypothetically if you're running some sort of uh mol analysis tool like flash Bots is doing and you would like are private or public in this case on ether scan you can actually see them quite clearly if it says transaction see uh mined within x amount of seconds that's usually a public transaction but if it doesn't show the time stamp it's usually a private transaction but if you would like to do some kind of analysis to kind of log the data like these transactions are private or public into a database you can actually do it in a few lines of code and keep in mind this is the main function so we're not and we're using ref as a library here so we're not going into the code base and then injecting stuff uh in random places we just calling it like a library so all we do is call ref CLI pass so this passes your CLI parameters which spawns a Builder which is the Noe Builder and some arguments you can then get the pending transaction stream from the node and then you can execute a new task asynchronous task to kind and you can do whatever you want um in that task in this case I'm listening for pending transactions and you can do any kinds of uh whatever kind of an analytics you would like so you could dump it to a database uh you could you could analyze uh where the transactions originate from is it from these peers and what IPS are these peers are they from uh APAC region are they from the US region like um and you could probably May uh do some further analysis on it if you're curious and this is all done within I think 30 lines of code and to ex to extend on upon it to get the pending molst stream and perform some analysis um yeah so within a few lines of code the you've essentially made a public good and a transaction labeler very very nice um one use case is The Flash Bots mle dumpster where it it dumps out like a pocket database of whether or not the transactions are public or private uh this is used in a lot of Dune analytics dashboards to kind of determine uh Mev data flow uh in terms of like private/public transactions the the share uh the OWN the percentage of private/public transactions and how much do they contribute to block Builders winning the block if that's uh that's partially why I'm curious about this and showcase three would be a standalone P2P node and so when you have the ethereum node you have um the peer-to-peer um protocol I don't actually remember what it's called Uh but you communicate with other e clients um through this protocol and you can also do further analysis on this you can um like you can uh identify like which which transactions sorry which peers are sending you more transactions and what kind of clients each peers are running so for example um in this case I'm skipping ahead but you can do like a P2P network analysis like e the not.org you can see okay what the majority of the nodes are running is it geff is it neamine is it Basu is it Aragon and you don't need to rely on these uh these third parties to verify the data you can very easily run your own node with a few lines of code to verify the data yourself remember it's uh trust uh verify not trust not the other way around but yeah with a very very very minor amount of work you're able to kind of spawn a new node or a standalone note component to kind of communicate with the P2P Network which is very painful um and do analysis on it um there's also a lot more examples like we can actually check it out on the official ref examples you have if everyone can see uh you can run your own uh you can you can run your own custom evm if you want to add in your own pre-compile for example you can run your own payload Builder if you think the pre-existing uh block building algorithm is two week you can directly access the database of which uh to do further analysis on the transaction data mind transaction data in this case obviously um so ref is a archival note by default as well so you get most you can trace back to the beginning of the Genesis and with database access you're not querying data through some kind of websocket um or or HTTP Port so the data you get there is very uh it's very quick to do analysis on there um you can add custom Hooks and I think the latest thing in the in the reflan is XX or execution extensions if anyone's uh following along I do not know what it means they coined the term last week and I just saw this tweet and decided to put it in but XX is a thing now so uh you heard it from here first folks um yes hopefully I have pilled most of you enough to start looking into ref it is a very very nice uh learning tool as well as a practical tool if you're curious on a dur execution client development it's very easy to get started and uh very hard to break things um and also it also helps you learn a bit of Russ if you're curious and uh I think that's kind of my time so thank thank you guys for listening if you guys have any questions uh happy to answer them [Music]
Automatic transcript — names and jargon may be misspelled.