Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

feat: reorgs outside of confirmations range handling #273

Merged
merged 27 commits into from
Sep 8, 2020
Merged

Conversation

nduchak
Copy link
Contributor

@nduchak nduchak commented Aug 21, 2020

No description provided.

@lgtm-com
Copy link

lgtm-com bot commented Aug 21, 2020

This pull request introduces 2 alerts when merging 55be7e6 into a5b3a18 - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 21, 2020

This pull request introduces 1 alert when merging e1fcb73 into a5b3a18 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 21, 2020

This pull request introduces 1 alert when merging 626cec7 into a5b3a18 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 24, 2020

This pull request introduces 1 alert when merging 0699b59 into a5b3a18 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 24, 2020

This pull request introduces 1 alert when merging 1dd69b7 into a5b3a18 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 24, 2020

This pull request introduces 3 alerts when merging ca21a7c into a5b3a18 - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 24, 2020

This pull request introduces 2 alerts when merging 0a88d6a into a5b3a18 - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 24, 2020

This pull request introduces 2 alerts when merging 466b556 into a5b3a18 - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 25, 2020

This pull request introduces 2 alerts when merging df64345 into a5b3a18 - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 25, 2020

This pull request introduces 2 alerts when merging 127dc78 into a5b3a18 - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

add reorg service to blockchain init and channels
subscribe for reorgs for each of services and emit using reorg service
@lgtm-com
Copy link

lgtm-com bot commented Aug 26, 2020

This pull request introduces 2 alerts when merging 754b2bc into a5b3a18 - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 26, 2020

This pull request introduces 2 alerts when merging b6badf2 into a5b3a18 - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 26, 2020

This pull request introduces 2 alerts when merging 2cfd958 into a5b3a18 - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 27, 2020

This pull request introduces 2 alerts when merging efca52b into a5b3a18 - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 28, 2020

This pull request introduces 2 alerts when merging 7b76fd4 into 25db5ac - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Aug 28, 2020

This pull request introduces 2 alerts when merging e17acb1 into 25db5ac - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

@nduchak nduchak requested a review from AuHau August 31, 2020 11:37
@nduchak nduchak self-assigned this Aug 31, 2020
@nduchak nduchak added this to the v0.1.0 - First release milestone Aug 31, 2020
@nduchak nduchak marked this pull request as ready for review September 1, 2020 14:42
Copy link
Contributor

@AuHau AuHau left a comment

Choose a reason for hiding this comment

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

Hmm there are few questions and some things to improve. But it is on good path!

src/cli/start.ts Show resolved Hide resolved

const app = await appFactory()
const port = config.get('port')
const server = app.listen(port)
Copy link
Contributor

Choose a reason for hiding this comment

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

To be honest, I don't really like moving the server start&listening logic to the appFactory(). I don't actually think that it has to be there right? What was your motivation here?

Copy link
Contributor

Choose a reason for hiding this comment

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

In this shape it is not a "factory" anymore...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just want to make the same as we had it in pinner, as we use the same algorithm for reorgs

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmmmmm. I see you renamed it to startApp. I am still against this refactor. While I understand your motivation, the Pinner and Cache are different things, using different setups (Cache uses Feathers and it is a Web Server, Pinner is a specific custom-built daemon service). Yes, we use the same mechanism for handling reorgs, but the context is a bit different. You can still use this "algorithm" even with the original approach of appFactory()...

I think that bootstrapping the Feather's app and actually starting the listening on a port should be kept separate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted back

src/services/storage/index.ts Show resolved Hide resolved
src/utils.ts Outdated Show resolved Hide resolved
src/blockchain/reorg-emitter.ts Show resolved Hide resolved
src/utils.ts Outdated Show resolved Hide resolved
@@ -29,7 +28,7 @@ export function isServiceInitialized (serviceName: string): boolean {
return blockTracker.getLastFetchedBlock()[0] !== undefined
}

export function getEventsEmitterForService (serviceName: string, eth: Eth, contractAbi: AbiItem[]): EventEmitter {
export function getEventsEmitterForService (serviceName: string, eth: Eth, contractAbi: AbiItem[]): BaseEventsEmitter {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need the BaseEvemtsEmitter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need the stop method from BaseEvemtsEmitter

@@ -28,7 +29,8 @@ export enum ServiceAddresses {
STORAGE_AGREEMENTS = '/storage/v0/agreements',
XR = '/rates/v0/',
CONFIRMATIONS = '/confirmations',
NEW_BLOCK_EMITTER = '/new-block'
NEW_BLOCK_EMITTER = '/new-block',
REORG_EMITTER = '/reorg'
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I think we should incorporate in the naming of variables, paths etc the fact the this is not normal reorg but reorg outside of confirmation range. Because these two are different and it can lead to confusion later on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's fine as we can have different events based on this path. Separation happens there

src/utils.ts Outdated
type BackUpEntry = { name: string, block: { hash: string, number: BigNumber } }

function parseBackUps (backUpName: string): BackUpEntry {
const [block] = backUpName.split('.')[0].split('-')
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm what length of the names you usually get? Just to make sure we won't run in problems with FS...
My original idea was actually store these data as part of the Store, but I guess this will work as well 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not too big, like: add-name-to-user

src/cli/start.ts Outdated
backUpJob.stop()

// Restore DB from backup
await backUpJob.restoreDb(() => undefined)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you "ignore" the errorCallback here? And actually why there is even such a thing? Isn't rejected Promise enough?

@nduchak nduchak force-pushed the feat/reorgs branch 2 times, most recently from c6fb36d to 9836164 Compare September 4, 2020 09:24
Copy link
Contributor

@AuHau AuHau left a comment

Choose a reason for hiding this comment

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

Hmm still some things to tackle.

Btw. did you test how the UI handles when Cache disconnects? We should know its behavior as maybe there should be some added logic to the UI for handling when Cache is not online and also to listen on the Reorg channel...

Also, please don' do force-push once the review process starts. It makes it hard for me to track the increment changes you are making especially in big PRs like this...


const app = await appFactory()
const port = config.get('port')
const server = app.listen(port)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmmmmm. I see you renamed it to startApp. I am still against this refactor. While I understand your motivation, the Pinner and Cache are different things, using different setups (Cache uses Feathers and it is a Web Server, Pinner is a specific custom-built daemon service). Yes, we use the same mechanism for handling reorgs, but the context is a bit different. You can still use this "algorithm" even with the original approach of appFactory()...

I think that bootstrapping the Feather's app and actually starting the listening on a port should be kept separate.

src/db-backup.ts Outdated Show resolved Hide resolved
src/db-backup.ts Outdated Show resolved Hide resolved
config/default.json5 Outdated Show resolved Hide resolved
test/cli.spec.ts Outdated Show resolved Hide resolved
test/db-backup-restore.spec.ts Show resolved Hide resolved
src/cli/start.ts Outdated
backUpJob.stop()

// Restore DB from backup
await backUpJob.restoreDb()
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm so if the restore procedure fails for some reason then Cache craches, right? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's true. For that case, we should notify DevOps that the restore process fails

src/cli/start.ts Outdated Show resolved Hide resolved
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 7, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 6 Code Smells

No Coverage information No Coverage information
10.9% 10.9% Duplication

src/db-backup.ts Show resolved Hide resolved
Copy link
Contributor

@AuHau AuHau left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

@AuHau AuHau changed the title feat: reorgs feat: reorgs outside of confirmations range handling Sep 8, 2020
@AuHau AuHau merged commit 4d48f80 into master Sep 8, 2020
@AuHau AuHau deleted the feat/reorgs branch September 8, 2020 07:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants