avalanchejs icon indicating copy to clipboard operation
avalanchejs copied to clipboard

Deserialize P Chain block

Open Sanghren opened this issue 4 years ago • 6 comments

Detailed Description

Add the possibility to deserialize PVM block's bytes coming out of the IPC socket .

Context

I was working on my rust pet project and while working on the PChain deserialization (with bytes coming out of the IPC socket) I noticed that I could not use avalancheJs PVM Tx.fromBuffer() . It would always fail .

It is because avalanchejs only deserialize bytes of a transaction , but on the pchain the bytes coming out of the socket are composed like this :

  • Bytes of a Block
  • Bytes of a Tx

So someone trying to use avalanchejs with the bytes coming out of the socket would only see errors .

It was rather confusing for me at first because even in the documentation there are no mentions of the structure of a PVM Block ( Added few issues in the repo as well) , and I had to dig in avalanchego code in order to understand how to deserialize it .

Possible Implementation

Follow same approach as for the PVM Tx .

Your Environment

  • Version used: 3.1.0

Sanghren avatar Jan 20 '21 21:01 Sanghren

Am up to implement it if it's something you want to add in avalanchejs ;)

Sanghren avatar Jan 20 '21 21:01 Sanghren

So someone trying to use avalanchejs with the bytes coming out of the socket would only see errors .

That's news to me. Happened after I left, I guess? I guess a simple block parser in the PlatformVM makes sense @cgcardona .

collincusce avatar Mar 09 '21 19:03 collincusce

Let me look into this and get back to you.

cgcardona avatar Mar 09 '21 19:03 cgcardona

If you want to have a look, I did an implementation in Rust here : https://github.com/tbrunain/avalanche-rs/blob/master/src/pvm/parser/block_parser.rs .

Sanghren avatar Mar 09 '21 20:03 Sanghren

I'm waiting on the platform team to get back to me w/ the serialization spec of blocks/vertices. Will get back ASAP w/ a code snippet once I have that serialization spec.

cgcardona avatar Sep 04 '21 03:09 cgcardona

Do I need to do the same for C-chain blocks ? Or is there a mean provided by this SDK ?

tdelabro avatar Mar 09 '22 22:03 tdelabro