Coder Social home page Coder Social logo

Comments (6)

mojoX911 avatar mojoX911 commented on September 28, 2024

On the other hand, this whole issue might be a case of premature optimization(?)

I think its probably better to handle it now rather than to leave for future. Its clear that some tidying up is needed and we might need to try different things before coming up with a good approach.

Possible way that came to my mind.

  • Define our own serialization/deserialzsation logic and use serde to link them as you mentioned.

  • Its better to make stuffs binary and compact(?), I have seen other projects using bitcoin consensus type encoding with little modification (mostly endian-ness). Should we have something like that? Can serde already handle that? then we might not need to write our own.

  • Writing our own might have added benefit of having future flexibility so better optimization can be done. We have to cover basic data types and then can export it to higher level structures as traits. Will be some work. But might make sense to get it done.

Also it seems rust-bitcoin already have core compatible encoding here https://github.com/rust-bitcoin/rust-bitcoin/blob/master/src/consensus/encode.rs, maybe something that we can directly use? We just need to implement the traits for our structs.

from teleport-transactions.

mojoX911 avatar mojoX911 commented on September 28, 2024

To further the discussion in this regard, I have made a trial encoding with rust-bitcoin here https://github.com/mojoX911/teleport-transactions/blob/cffba4d20c37f4a78af13eb5fc49bb44286e42b9/src/messages.rs#L96-L143.

It works, and there is a test here https://github.com/mojoX911/teleport-transactions/blob/cffba4d20c37f4a78af13eb5fc49bb44286e42b9/src/messages.rs#L286-L321

This can be done for other network messages also. Which will effectively compact the message size, and also will let us handle
allowed method logic more elegantly than string comparison as discussed #23 (comment).

Before proceeding further in this approach I would like to have agreement on using consensus encoding trait of rust-bitcoin for this purpose.

To me it seems easier than hand crafting our own encoding method, as all the primitive types are already covered in rust-bitcoin.

from teleport-transactions.

chris-belcher avatar chris-belcher commented on September 28, 2024

Using rust-bitcoin's already-existing function is a good idea. Your code looks good I think.

However see my comment in #23 (comment). Using bytes instead of strings doesnt make the allowed method logic more elegant, and also doesnt make use rust's compiler for error checking, only using enums does that. So the two goals are orthogonal.

from teleport-transactions.

mojoX911 avatar mojoX911 commented on September 28, 2024

@chris-belcher agreed. I misunderstood the goal in #23 . Updated the PR as per your comment.

And that I think allows us to remove method flag from messages all together.

I will start working on the encoding of remaining structures.

from teleport-transactions.

GeneFerneau avatar GeneFerneau commented on September 28, 2024

One thing we could consider is moving away from json serialization entirely and making everything be binary?

There is a serde_cbor crate for serializing data in resource constrained environments. That way we could move to a more efficient serialization format without abandoning the benefits of serde.

from teleport-transactions.

chris-belcher avatar chris-belcher commented on September 28, 2024

serde_cbor seems like almost exactly what we want I think(?)

from teleport-transactions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.