I checked go-ethereum code and I see this piece of code

// Service is an individual protocol that can be registered into a node.
// Notes:
// • Service life-cycle management is delegated to the node. The service is allowed to
// initialize itself upon creation, but no goroutines should be spun up outside of the
// Start method.
// • Restart logic is not required as the node will create a fresh instance
// every time a service is started.
type Service interface {
    // Protocols retrieves the P2P protocols the service wishes to start.
    Protocols() []p2p.Protocol

    // APIs retrieves the list of RPC descriptors the service provides
    APIs() []rpc.API

    // Start is called after all services have been constructed and the networking
    // layer was also initialized to spawn any goroutines required by the service.
    Start(server *p2p.Server) error

    // Stop terminates all goroutines belonging to the service, blocking until they
    // are all terminated.
    Stop() error

I guess the way go-ethereum works is that it will register services into a Node whenever needed, but I can't figure it out yet.

Can you please give me some hints about how to register my custom service (e.x Orderbook) into Ethereum?

I prefer the way that won't touch core go-ethereum code (modifying node.go or similar files directly). But if it's not possible, please show me how to modify these codes safety.

Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.