Skip to content

Commit

Permalink
Fixed decoding issue with block state headers
Browse files Browse the repository at this point in the history
The `header_extensions` field is not the struct as it was defined, changed to an `any[]` value since we can't define it better.

Also marked the `activated_protocol_features` field as optional since it's now returning a null value (instead of an object) on Savanna endpoints.
  • Loading branch information
aaroncox committed Oct 23, 2024
1 parent 350e565 commit cf515d1
Show file tree
Hide file tree
Showing 6 changed files with 1,593 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/api/v1/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class GetBlockResponse extends Struct {
@Struct.field('checksum256') declare action_mroot: Checksum256
@Struct.field('uint32') declare schedule_version: UInt32
@Struct.field(NewProducers, {optional: true}) new_producers?: NewProducers
@Struct.field('header_extension', {optional: true}) header_extensions?: HeaderExtension[]
@Struct.field('any', {optional: true}) header_extensions?: any[]
@Struct.field('any', {optional: true}) new_protocol_features?: any
@Struct.field('signature') declare producer_signature: Signature
@Struct.field(GetBlockResponseTransactionReceipt, {array: true})
Expand Down Expand Up @@ -341,8 +341,7 @@ export class BlockStateHeader extends Struct {
@Struct.field('checksum256') declare transaction_mroot: Checksum256
@Struct.field('checksum256') declare action_mroot: Checksum256
@Struct.field('uint32') declare schedule_version: UInt32
@Struct.field(HeaderExtension, {array: true, optional: true})
header_extensions?: HeaderExtension[]
@Struct.field('any', {array: true, optional: true}) declare header_extensions?: any[]
@Struct.field('signature') declare producer_signature: Signature
}

Expand All @@ -361,7 +360,7 @@ export class GetBlockHeaderStateResponse extends Struct {
@Struct.field('any') declare valid_block_signing_authority: any
@Struct.field('any') declare confirm_count: any
@Struct.field('any') declare pending_schedule: any
@Struct.field('any') declare activated_protocol_features: any
@Struct.field('any', {optional: true}) declare activated_protocol_features?: any
@Struct.field('any') declare additional_signatures: any
}

Expand Down
2 changes: 1 addition & 1 deletion src/p2p/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class BlockHeader extends Struct {
@Struct.field(BlockId) declare action_mroot: BlockId
@Struct.field('uint32') declare schedule_version: UInt32
@Struct.field(NewProducers, {optional: true}) new_producers?: NewProducers
@Struct.field(HeaderExtension, {array: true}) declare header_extensions: HeaderExtension[]
@Struct.field('any', {array: true}) declare header_extensions: any[]

get blockNum(): UInt32 {
return this.previous.blockNum.adding(1)
Expand Down
15 changes: 15 additions & 0 deletions test/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const wax = new APIClient({
provider: new MockProvider('https://wax.greymass.com'),
})

const telos = new APIClient({
provider: new MockProvider('https://telos.greymass.com'),
})

@Struct.type('transfer')
class Transfer extends Struct {
@Struct.field('name') from!: Name
Expand Down Expand Up @@ -330,6 +334,17 @@ suite('api v1', function () {
assert.equal(Number(header.block_num), 323978187)
})

test('chain get_block_header_state (header extensions)', async function () {
const header = await eos.v1.chain.get_block_header_state(400838396)
assert.equal(Number(header.block_num), 400838396)

const header2 = await wax.v1.chain.get_block_header_state(336356138)
assert.equal(Number(header2.block_num), 336356138)

const header3 = await telos.v1.chain.get_block_header_state(369358506)
assert.equal(Number(header3.block_num), 369358506)
})

test('chain get_block', async function () {
const block = await eos.v1.chain.get_block(8482113)
assert.equal(Number(block.block_num), 8482113)
Expand Down
67 changes: 67 additions & 0 deletions test/data/17e6fe827d856c9b69f0e9b659d895aaf831cfce.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"api": "https://eos.greymass.com",
"headers": {
"access-control-allow-headers": "X-Requested-With,Accept,Content-Type,Origin",
"access-control-allow-methods": "GET, POST, OPTIONS",
"access-control-allow-origin": "*",
"connection": "close",
"content-length": "1176",
"content-type": "application/json",
"date": "Wed, 23 Oct 2024 03:20:50 GMT",
"host": "eos.greymass.com",
"server": "nginx",
"x-cached": "MISS"
},
"status": 200,
"json": {
"block_num": 400838396,
"dpos_proposed_irreversible_blocknum": 0,
"dpos_irreversible_blocknum": 0,
"active_schedule": {
"version": 0,
"producers": []
},
"blockroot_merkle": {
"_active_nodes": [],
"_node_count": 0
},
"producer_to_last_produced": [],
"producer_to_last_implied_irb": [],
"valid_block_signing_authority": [
0,
{
"threshold": 0,
"keys": []
}
],
"confirm_count": [],
"id": "17e44efcfcd9cb439ab93de5f1e4328c4d02382281da17f0478f6f2810ee4789",
"header": {
"timestamp": "2024-10-23T03:17:45.000",
"producer": "atticlabeosb",
"confirmed": 0,
"previous": "17e44efb304a3d81378887b7f1e9cff1b4c2f7a065f5368b337a69bed5f57add",
"transaction_mroot": "f196c51b021c50ea09b482e09e00ab1ecf7207535c13089d20b003455faaca98",
"action_mroot": "8bf47442736dc9d7ac73580d5f936a8fc0f6d09580687d305cd1cd4c564a1159",
"schedule_version": 2147483648,
"header_extensions": [
[
2,
"fb4ee417010000"
]
],
"producer_signature": "SIG_K1_K3JYzkSiRLkWmWcbsELQJkaFnZHNVqegvrqgZjwpF45StmRUquUz4wjpSuxZC9Pv6uHrSzr1mpdXuA4MhXAM368FDC1kZp"
},
"pending_schedule": {
"schedule_lib_num": 0,
"schedule_hash": "0000000000000000000000000000000000000000000000000000000000000000",
"schedule": {
"version": 0,
"producers": []
}
},
"activated_protocol_features": null,
"additional_signatures": []
},
"text": "{\"block_num\":400838396,\"dpos_proposed_irreversible_blocknum\":0,\"dpos_irreversible_blocknum\":0,\"active_schedule\":{\"version\":0,\"producers\":[]},\"blockroot_merkle\":{\"_active_nodes\":[],\"_node_count\":0},\"producer_to_last_produced\":[],\"producer_to_last_implied_irb\":[],\"valid_block_signing_authority\":[0,{\"threshold\":0,\"keys\":[]}],\"confirm_count\":[],\"id\":\"17e44efcfcd9cb439ab93de5f1e4328c4d02382281da17f0478f6f2810ee4789\",\"header\":{\"timestamp\":\"2024-10-23T03:17:45.000\",\"producer\":\"atticlabeosb\",\"confirmed\":0,\"previous\":\"17e44efb304a3d81378887b7f1e9cff1b4c2f7a065f5368b337a69bed5f57add\",\"transaction_mroot\":\"f196c51b021c50ea09b482e09e00ab1ecf7207535c13089d20b003455faaca98\",\"action_mroot\":\"8bf47442736dc9d7ac73580d5f936a8fc0f6d09580687d305cd1cd4c564a1159\",\"schedule_version\":2147483648,\"header_extensions\":[[2,\"fb4ee417010000\"]],\"producer_signature\":\"SIG_K1_K3JYzkSiRLkWmWcbsELQJkaFnZHNVqegvrqgZjwpF45StmRUquUz4wjpSuxZC9Pv6uHrSzr1mpdXuA4MhXAM368FDC1kZp\"},\"pending_schedule\":{\"schedule_lib_num\":0,\"schedule_hash\":\"0000000000000000000000000000000000000000000000000000000000000000\",\"schedule\":{\"version\":0,\"producers\":[]}},\"activated_protocol_features\":null,\"additional_signatures\":[]}"
}
Loading

0 comments on commit cf515d1

Please sign in to comment.