Skip to content

Commit

Permalink
Add lastBlockHash to the bunch structure
Browse files Browse the repository at this point in the history
  • Loading branch information
zemse committed Jun 22, 2020
1 parent 0e946b5 commit 665edb3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/informer/to-eth/methods/compute-bunch-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function computeBunchProposal(
receiptsMegaRoot: computeMerkleRoot(
blocks.map((block) => block.receiptsRoot)
),
lastBlockHash: blocks[blocks.length - 1].blockHash,
signatures: [],
};
}
1 change: 1 addition & 0 deletions src/informer/to-eth/methods/initiate-bunch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export async function initiateBunch(
new Bytes(bunchDepth).hex(),
bunchProposal.transactionsMegaRoot.hex(),
bunchProposal.receiptsMegaRoot.hex(),
bunchProposal.lastBlockHash.hex(),
],
...signatures,
];
Expand Down
1 change: 1 addition & 0 deletions src/informer/to-eth/methods/sign-bunch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export async function signBunch(
new Bytes(_bunchProposal.bunchDepth).hex(),
_bunchProposal.transactionsMegaRoot.hex(),
_bunchProposal.receiptsMegaRoot.hex(),
_bunchProposal.lastBlockHash.hex(),
]);

return {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/bunch-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface BunchProposal {
bunchDepth: number;
transactionsMegaRoot: Bytes32;
receiptsMegaRoot: Bytes32;
lastBlockHash: Bytes32;
signatures: Signature[];
}

Expand All @@ -21,12 +22,14 @@ export function validateBunchProposal(
bunchDepth,
transactionsMegaRoot,
receiptsMegaRoot,
lastBlockHash,
signatures,
} = bunchProposal;
validateParam({ startBlockNumber }, t.number);
validateParam({ bunchDepth }, t.number);
validateParam({ transactionsMegaRoot }, t.hex32);
validateParam({ receiptsMegaRoot }, t.hex32);
validateParam({ lastBlockHash }, t.hex32);
validateParam({ signatures }, t.array);
if (signaturesPresent) {
bunchProposal.signatures.forEach((signature) => {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ export interface BlockCompact {
blockNumber: number;
transactionsRoot: Bytes32;
receiptsRoot: Bytes32;
blockHash: Bytes32;
}

interface ParityBlock {
interface ParityBlock extends ethers.providers.Block {
transactionsRoot: 'string';
receiptsRoot: 'string';
}
Expand Down Expand Up @@ -42,6 +43,7 @@ export async function fetchBlocks(
ethers.utils.arrayify(block.transactionsRoot)
),
receiptsRoot: new Bytes32(ethers.utils.arrayify(block.receiptsRoot)),
blockHash: new Bytes32(block.hash),
};

resolve();
Expand Down
1 change: 1 addition & 0 deletions test/json-rpc/block-proposal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const BlockProposal = () =>
blockNumber: response.result.blockNumber,
transactionsRoot: response.result.transactionsRoot,
receiptsRoot: response.result.receiptsRoot,
blockHash: response.result.blockHash,
};
});

Expand Down

0 comments on commit 665edb3

Please sign in to comment.