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

FABN-1530: Timestamp added to full and private block transaction events #490

Merged
merged 9 commits into from
Sep 2, 2021

Conversation

sapthasurendran
Copy link
Contributor

No description provided.

@sapthasurendran sapthasurendran requested a review from a team as a code owner August 27, 2021 15:18
@sapthasurendran sapthasurendran force-pushed the event branch 2 times, most recently from 96eee59 to fcd4ce2 Compare August 27, 2021 17:45
Copy link
Member

@bestbeforetoday bestbeforetoday left a comment

Choose a reason for hiding this comment

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

A few comments that I think would make it more user friendly and make the testing more robust. See what you think.

It might also be worth a unit test for the filtered blocks case, where we expect timestamp to be undefined since we don't get the timestamp in the raw event.

@@ -24,6 +24,7 @@ export interface TransactionEvent {
readonly transactionData: fabproto6.protos.ITransaction | fabproto6.protos.IFilteredTransaction;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
readonly privateData?: any;
readonly timestamp?:string;
Copy link
Member

Choose a reason for hiding this comment

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

It might be more helpful for us to expose a JavaScript Date object instead of a string

Comment on lines 129 to 130
const timestamp = new fabproto6.google.protobuf.Timestamp({seconds:1630075029083});
channelHeader.timestamp = new Date(timestamp.seconds as number).toISOString();
Copy link
Member

Choose a reason for hiding this comment

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

The block decoder looks to decode the protobuf timestamp to a date string like you've done here, so that's good. So we know the value to expect in the timestamp field, I think we'd be better to declare a constant in the describe block, something like const timestamp = new Date(), and then populate the timestamp with timestamp.toISOString()

await network.addBlockListener(listener, listenerOptions);
eventService.sendEvent(event);
const actual = await listener.completePromise;
expect(actual[0].getTransactionEvents()[0].timestamp).not.null;
Copy link
Member

Choose a reason for hiding this comment

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

Should check the value is correct, not just that it exists. So if we've defined a timestamp Date value for these tests, we could test that the timestamp we get from the event matches our expected timestamp value

await network.addBlockListener(listener, listenerOptions);
eventService.sendEvent(event);
const actual = await listener.completePromise;
expect(actual[0].getTransactionEvents()[0].timestamp).not.null;
Copy link
Member

Choose a reason for hiding this comment

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

Should check the value is correct

@@ -41,6 +41,7 @@ export function newFullTransactionEvent(blockEvent: BlockEvent, txEnvelopeIndex:

const envelope: any = block.data.data[txEnvelopeIndex];
const transactionId = envelope.payload.header.channel_header.tx_id;
const timestamp = envelope.payload.header.channel_header.timestamp;
Copy link
Member

Choose a reason for hiding this comment

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

We should be able to fluff up a Date object from the string with new Date(envelope.payload.header.channel_header.timestamp)

Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
Comment on lines 135 to 139
function newEnvelope(transaction: any, transactionId?: string, timestamp?:Date): any {
const channelHeader :any = {};
channelHeader.type = fabproto6.common.HeaderType.ENDORSER_TRANSACTION;
channelHeader.tx_id = transactionId;
channelHeader.timestamp = timestamp.toISOString();
Copy link
Member

Choose a reason for hiding this comment

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

Unsafe use of optional (Date | undefined) timestamp variable here, which would fail at runtime if not set

Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
@bestbeforetoday bestbeforetoday merged commit bfae06c into hyperledger:main Sep 2, 2021
bestbeforetoday added a commit to bestbeforetoday/fabric-sdk-node that referenced this pull request Mar 8, 2023
Release includes:

- Add support for getting CA server information (hyperledger#510)
- Close Client in Gateway disconnect (hyperledger#287)
- Include timestamp in transaction events (hyperledger#490)

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
@bestbeforetoday bestbeforetoday mentioned this pull request Mar 8, 2023
bestbeforetoday added a commit that referenced this pull request Mar 8, 2023
Release includes:

- Add support for getting CA server information (#510)
- Close Client in Gateway disconnect (#287)
- Include timestamp in transaction events (#490)

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
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.

2 participants