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

[1.0.2] add block header extension types to state history ABI #783

Merged
merged 4 commits into from
Sep 23, 2024

Conversation

spoonincode
Copy link
Member

@spoonincode spoonincode commented Sep 13, 2024

This adds the block header extensions to the state history ABI making it easy for state history clients to parse these.

An example (crude) state history client easily accessing these,

import WebSocket from 'ws';
import {ABI, Serializer} from '@wharfkit/antelope';

let abi = null;
const ws = new WebSocket('ws://127.0.0.1:8080/');

ws.on('message', msg => {
   if(!abi) {
      abi = new ABI(JSON.parse(msg));

      const req = {
         start_block_num: 2,
         end_block_num: 9999999,
         max_messages_in_flight: 9999999,
         have_positions: [],
         irreversible_only: false,
         fetch_block: true,
         fetch_traces: false,
         fetch_deltas: false,
         fetch_finality_data:false
      };
      ws.send(Serializer.encode({object: ['get_blocks_request_v1', req], abi, type:'request'}).array);
   }
   else {
      let signed_block = Serializer.objectify(Serializer.decode({data:
                           Serializer.objectify(Serializer.decode({data: msg, abi, type: 'result'}))[1].block,
                         abi, type: 'signed_block'}));
      if(signed_block.header_extensions.length) {
         console.log(`block at time ${signed_block.timestamp} has ${signed_block.header_extensions.length} header extensions:`);
         for(const header_extension of signed_block.header_extensions) {
            const extension_type_name = abi.getVariant('block_header_extension').types[header_extension.type];
            console.log(`${extension_type_name}:`,
               Serializer.objectify(Serializer.decode({data: header_extension.data, abi, type: extension_type_name})));
         }
      }
   }
});

Example outputs look like

block at time 2024-09-13T18:56:31.500 has 1 header extensions:
protocol_feature_activation_extension: {
  protocol_features: [
    '4fca8bd82bbd181e714e283f83e1b45d95ca5af40fb89ad3977b653c448f78c2',
    '5443fcf88330c586bc0e5f3dee10e7f63c76c00249c87fe4fbf7f38c082006b4',
    '63320dd4a58212e4d32d1f58926b73ca33a247326c2a5e9fd39268d2384e011a',
    '68dcaa34c0517d19666e6b33add67351d8c5f69e999ca1e37931bc410a297428',
…
block at time 2024-09-13T18:56:41.000 has 1 header extensions:
producer_schedule_change_extension: {
  version: 1,
  producers: [
    { producer_name: 'inita', authority: [Array] },
    { producer_name: 'initb', authority: [Array] },
    { producer_name: 'initc', authority: [Array] },
    { producer_name: 'initd', authority: [Array] },
    { producer_name: 'inite', authority: [Array] },
    { producer_name: 'initf', authority: [Array] }
  ]
}
block at time 2024-09-13T18:56:56.000 has 1 header extensions:
finality_extension: {
  qc_claim: { block_num: 112, is_strong_qc: false },
  new_finalizer_policy_diff: {
    generation: 1,
    threshold: 4,
    remove_indexes: [],
    insert_indexes: [ [Object], [Object], [Object], [Object], [Object], [Object] ]
  },
  new_proposer_policy_diff: null
}

@n8d
Copy link

n8d commented Sep 15, 2024

Thanks @spoonincode! I was able to test this by dynamically merging your ABI changes into the ABI I received from a 1.0.0 node, which lets me parse finality_extension and get the proposer diffs I'm after. Even without quorum_certificate_extension I think this is useful.

@greg7mdp
Copy link
Contributor

greg7mdp commented Sep 16, 2024

We should probably also deserialize the [Object] in insert_indexes, which are pair<uint32_t, finalizer_authority>.

@spoonincode
Copy link
Member Author

That is due to console.log() just not doing a deep inspection. If I add some additional code to do a deep object inspection the logs look like,

block at time 2024-09-13T18:56:41.000 has 1 header extensions:
producer_schedule_change_extension: {
  version: 1,
  producers: [
    {
      producer_name: 'inita',
      authority: [
        'block_signing_authority_v0',
        {
          threshold: 1,
          keys: [
            {
              key: 'PUB_K1_6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5BoDq63',
              weight: 1
            }
          ]
        }
      ]
    },
    {
      producer_name: 'initb',
      authority: [
        'block_signing_authority_v0',
…
block at time 2024-09-13T18:56:56.000 has 1 header extensions:
finality_extension: {
  qc_claim: { block_num: 112, is_strong_qc: false },
  new_finalizer_policy_diff: {
    generation: 1,
    threshold: 4,
    remove_indexes: [],
    insert_indexes: [
      {
        index: 0,
        value: {
          description: 'inita',
          weight: 1,
          public_key: '29f8eea32968f82b3957b484cbec0407a4190af73f146d82679c13615fe467688c95fb12129268da4bb2127aa1cb7a0630faa6b97090ff86e2f861151d2fdecd62b875b552d5a4b56b0f1d24bc47642f439e5657681c18962add59ea85d36402'
        }
      },
      {
        index: 1,
        value: {
          description: 'initb',
          weight: 1,
          public_key: '79a8e805b5aa2b5f8b4d9e48c79d26cd50003a0a064f589ad7e00b721ed0f7c2409627ec4604524ef9bcf16b53da990deeaa214e399471ea1a5f86100dde1be13e846e84321f3f9f49fe4c35bb36c9c4963674f275afc0812c31680e32673112'
        }
      },
…

@spoonincode
Copy link
Member Author

We will need AntelopeIO/abieos#34 as part of this; to keep abieos in sync.

Also @heifner @greg7mdp if you didn't check the naming of the new items before approval last time, maybe double check them again -- they aren't exactly 1:1 with the c++ structs

@spoonincode spoonincode changed the base branch from main to release/1.0 September 17, 2024 16:26
@spoonincode spoonincode changed the title [1.?/experiment/RFC] add extension types to state history ABI [1.0.2] add extension types to state history ABI Sep 17, 2024
@spoonincode spoonincode marked this pull request as ready for review September 17, 2024 16:26
@greg7mdp
Copy link
Contributor

maybe double check them again -- they aren't exactly 1:1 with the c++ structs

lgtm

@spoonincode spoonincode changed the title [1.0.2] add extension types to state history ABI [1.0.2] add block header extension types to state history ABI Sep 17, 2024
@ericpassmore
Copy link
Contributor

ericpassmore commented Sep 17, 2024

Note:start
category: Other
component: SHiP
summary: Add block header extensions types to state history ABI.
Note:end

@arhag arhag linked an issue Sep 23, 2024 that may be closed by this pull request
@BenjaminGormanPMP BenjaminGormanPMP requested review from linh2931 and removed request for linh2931 September 23, 2024 21:01
@spoonincode spoonincode merged commit 895b2b4 into release/1.0 Sep 23, 2024
36 checks passed
@spoonincode spoonincode deleted the ship_abi_extensions branch September 23, 2024 23:12
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.

Block extension data available via SHiP but not in ABI
5 participants