Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block deserialization with dynafed support #25

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

sekulicd
Copy link

@sekulicd sekulicd commented Sep 22, 2021

This adds supports to deserialise dynafed block.

This closes #23

@tiero @asoltys please review.

@tiero
Copy link
Member

tiero commented Sep 22, 2021

add .idea to gitignore @sekulicd

@tiero
Copy link
Member

tiero commented Sep 22, 2021

Please run npm run prettier on your code to format correclty @sekulicd

@tiero tiero changed the title block deser dynafed support block deserialization with dynafed support Sep 22, 2021

const readVarInt = (): number => {
const vi = varuint.decode(buffer, offset);
offset += varuint.decode.bytes;
return vi;
};

const block = new Block();
block.version = readUInt32();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the BufferReader from bufferutils.ts to read the bytes instead of read* functions.

ts_src/block.ts Outdated Show resolved Hide resolved
@louisinger
Copy link
Collaborator

louisinger commented Sep 22, 2021

add .idea to gitignore @sekulicd

You also need to delete the folder and repush with "deleted .idea" in order to remove it from remote git repo


describe('block deserialization ', () => {
fixtures.test.forEach(f => {
block.Block.fromBuffer(Buffer.from(f.hex, 'hex'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to check result is non null? @louisinger

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this checks if fromBuffer throws an error so LGTM. Best way to test is to check if all the block's fields are deserialized but may be hard to make the fixtures

Copy link
Member

@tiero tiero Sep 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean we need an it ro specify the test

ie.

Suggested change
block.Block.fromBuffer(Buffer.from(f.hex, 'hex'));
it('should de-serialize dyna-fed blcoks', () => {
const bock = block.Block.fromBuffer(Buffer.from(f.hex, 'hex'));
//assert block is non empty
});

@asoltys
Copy link

asoltys commented Sep 24, 2021

I added another test fixture for a block with compact current and null proposed params taken from https://github.com/ElementsProject/rust-elements/blob/acc702c/src/block.rs#L653 and added assertions to check the expected block hash, version, and signBlockWitnessLimit, along with number of transactions.

The block hashes resulting from block.getHash() are not matching those expected by the tests in rust-elements. Any ideas why?

@tiero
Copy link
Member

tiero commented Sep 24, 2021

The block hashes resulting from block.getHash() are not matching those expected by the tests in rust-elements. Any ideas why?

cc/ @sekulicd

@sekulicd
Copy link
Author

@asoltys seems that toBuffer func used to calculate Block hash is outdated.

@tiero
Copy link
Member

tiero commented Sep 24, 2021

thanks @asoltys

@sekulicd can you cherry-pick his commit to add the test? asoltys@4a0bb0c

@altafan
Copy link
Collaborator

altafan commented Jan 27, 2023

@sekulicd @tiero @louisinger what's the status of this?

@tiero
Copy link
Member

tiero commented Jan 27, 2023

@sekulicd @tiero @louisinger what's the status of this?

Has been tested by @asoltys and confirmed was working, but we miss to clean it up, solve conflicts etc.. for proper merge in master branch

@sekulicd
Copy link
Author

sekulicd commented Mar 7, 2023

@tiero @altafan i merged with master and added code for block serialisation, please review commit a0edc38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynafed block parsing
5 participants