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

Minor improvement Chelonia #1618

Merged

Conversation

@Silver-IT Silver-IT self-assigned this May 28, 2023
@Silver-IT Silver-IT linked an issue May 28, 2023 that may be closed by this pull request
@Silver-IT Silver-IT marked this pull request as draft May 28, 2023 23:04
@Silver-IT Silver-IT requested a review from taoeffect May 28, 2023 23:17
Copy link
Member Author

@Silver-IT Silver-IT left a comment

Choose a reason for hiding this comment

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

@taoeffect, need your review.

Comment on lines 256 to 271
const events = await sbp('chelonia/out/eventsAfter', contractID, recent || contractID)
// checks if the list of events consist of latest event
// TODO: if we use findLastIndex, it will be more clean
// but it needs upgrade Cypress version to 9.7.0 which is of bad performance
// https://docs.cypress.io/guides/references/changelog#9-7-0
// https://github.com/cypress-io/cypress/issues/22868
let isLatestExistance = false
for (let i = events.length - 1; i >= 0; i--) {
if (GIMessage.deserialize(events[i]).hash() === latest) {
isLatestExistance = true
break
}
}
if (!isLatestExistance) {
throw new ChelErrorUnexpected()
}
Copy link
Member Author

@Silver-IT Silver-IT May 29, 2023

Choose a reason for hiding this comment

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

@taoeffect, not sure if we should use findLastIndex here, and make it much smart.
Regarding the browser compatibility of findLastIndex, we should upgrade Cypress version to 9.7.0 or use the Chrome (not Electron) as the cypress default browser in the current version 7.7.0.

I would like to hear your opinion on this.

Copy link
Member Author

Choose a reason for hiding this comment

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

References

@Silver-IT Silver-IT marked this pull request as ready for review May 29, 2023 09:13
Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Great work @Silver-IT! Nicely done! 👍 Minor changes requested.

}
}
if (!isLatestExist) {
throw new ChelErrorUnexpected()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
throw new ChelErrorUnexpected()
throw new ChelErrorUnrecoverable(`expected hash ${latest} in list of events for contract ${contractID}`)

// but it needs upgrade Cypress version to 9.7.0 which is of bad performance
// https://docs.cypress.io/guides/references/changelog#9-7-0
// https://github.com/cypress-io/cypress/issues/22868
let isLatestExist = false
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let isLatestExist = false
let latestHashFound = false

Comment on lines 258 to 261
// TODO: if we use findLastIndex, it will be more clean
// but it needs upgrade Cypress version to 9.7.0 which is of bad performance
// https://docs.cypress.io/guides/references/changelog#9-7-0
// https://github.com/cypress-io/cypress/issues/22868
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// TODO: if we use findLastIndex, it will be more clean
// but it needs upgrade Cypress version to 9.7.0 which is of bad performance
// https://docs.cypress.io/guides/references/changelog#9-7-0
// https://github.com/cypress-io/cypress/issues/22868
// TODO: using findLastIndex, it will be more clean but it needs Cypress 9.7+ which has bad performance
// https://docs.cypress.io/guides/references/changelog#9-7-0
// https://github.com/cypress-io/cypress/issues/22868

@@ -253,7 +253,22 @@ export default (sbp('sbp/selectors/register', {
if (latest !== recent) {
console.debug(`[chelonia] Synchronizing Contract ${contractID}: our recent was ${recent || 'undefined'} but the latest is ${latest}`)
// TODO: fetch events from localStorage instead of server if we have them
const events = await sbp('chelonia/out/eventsSince', contractID, recent || contractID)
const events = await sbp('chelonia/out/eventsAfter', contractID, recent || contractID)
// checks if the list of events consist of latest event
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// checks if the list of events consist of latest event
// Sanity check: verify event with latest hash exists in list of events

hooks && hooks.postpublish && hooks.postpublish(message)
hooks?.prepublish?.(message)
message = await sbp('chelonia/private/out/publishEvent', message, publishOptions)
hooks?.postpublish?.(message)
Copy link
Member

Choose a reason for hiding this comment

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

Nice, I love this simplification of using ?. and how you added it to many places in the code that needs it!

Comment on lines +225 to +226
config.postOp?.(message, state)
config[`postOp_${opT}`]?.(message, state)
Copy link
Member

Choose a reason for hiding this comment

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

Beautiful 👍

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Great job @Silver-IT!! 😄 🎉

@taoeffect taoeffect merged commit 838dbeb into master Jun 3, 2023
1 check passed
@taoeffect taoeffect deleted the 1599-postpublish-should-be-given-message-actually-published branch June 3, 2023 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants