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

Add watchdog for watchers #106

Merged
merged 10 commits into from
Oct 25, 2018
Merged

Add watchdog for watchers #106

merged 10 commits into from
Oct 25, 2018

Conversation

fvictorio
Copy link

Closes #105.

The environment variable used for the max time is MAX_PROCESSING_TIME. If it's not set, the watchdog is not used.

I also moved the exit codes to the constants files, so that we know what each of them means.

@ghost ghost assigned fvictorio Oct 18, 2018
@ghost ghost added the review label Oct 18, 2018
@akolotov
Copy link
Collaborator

akolotov commented Oct 19, 2018

Please change the target branch to develop.
Or even better to support-erc20-native-#81

.env.example Outdated
@@ -28,6 +28,8 @@ REDIS_LOCK_TTL=1000
HOME_START_BLOCK=
FOREIGN_START_BLOCK=

MAX_PROCESSING_TIME=600000
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is my understanding correct and 10 min is too much for the watchdog timer? Could you estimate max time expected to handle one iteration of watcher?

Copy link
Author

Choose a reason for hiding this comment

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

I guess it depends on the number of events processed at the same time. I will try sending several transactions to the kovan-sokol bridge and see how much time is spent processing them.

Copy link
Author

Choose a reason for hiding this comment

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

Sent 10 transactions to Sokol. 2 of them were processed in one block, 8 in another. The time difference between the first log, and the log of the sender receiving the last transactions to send was 3 seconds (that is Sokol's block time, isn't it?).

The time is going to depend on the chain, but I guess one minute should be enough in the vast majority of cases (and it can be configured, anyway).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm. I think the timout should be comparable with the polling time. I think 3 or 4 times more than the polling time of the corresponding network. What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that sounds reasonable. You mean using that as the example, or that the timeout should be computed from the polling time?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, let's set the timeout in the example to be 4 times more that the longest polling time and provide these recommendations in README.

Copy link
Author

Choose a reason for hiding this comment

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

Please check 3171c1e.

.env.example Show resolved Hide resolved
@akolotov
Copy link
Collaborator

I believe we need to expanse these changes on the senders as well. What do you think?

@fvictorio
Copy link
Author

I believe we need to expanse these changes on the senders as well. What do you think?

Sure. They didn't cause issues yet, but it wouldn't hurt to have it there too.

@fvictorio fvictorio changed the base branch from master to support-erc20-native-#81 October 19, 2018 19:26
src/sender.js Show resolved Hide resolved
src/watcher.js Show resolved Hide resolved
src/watcher.js Show resolved Hide resolved
src/sender.js Show resolved Hide resolved
src/sender.js Outdated
@@ -32,6 +33,8 @@ const nonceLock = `lock:${config.id}:nonce`
const nonceKey = `${config.id}:nonce`
let chainId = 0

const maxProcessingTime = process.env.MAX_PROCESSING_TIME
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to define a default value which will be used if MAX_PROCESSING_TIME was missed by some reason in the configuration file.

Copy link
Author

Choose a reason for hiding this comment

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

This was intentional, to allow not setting the watchdog. If you think it should always be enabled, we can add a default value here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What risks can you see if we enable the watchdog by default? In this case the user could disable the watchdog by zeroing the configuration parameter explicitly.

Copy link
Author

Choose a reason for hiding this comment

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

That is a bit complicated. Javascript treats 0 as a falsy value, so doing 0 || 10 evaluates to 10.

On the other hand, the environment variables are strings, so '0' || 10 does evaluate to '0', but it's not good to rely on that; we could easily "break" it if we add environment variables validation and casting, like we did in poa-bridge-contracts/deploy.

A possible solution is to use a negative value to disable it. That will work both with strings and with numbers: '-1' < 0 is equivalent to -1 < 0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not understand this.
Could you use something like:

if (process.env.MAX_PROCESSING_TIME === '0') {
...
} else {
...
}

And later, when you add environment variables validation and casting you will change this.

Copy link
Author

Choose a reason for hiding this comment

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

That can work. This is what I did (see f38688c):

  1. If value is explicitly set to 0, the watchdog is not used.
  2. If the value is not set, it is computed using 4 * maxPollingTime
  3. Otherwise, the set value is used

I didn't want to add this logic twice (in the watcher and the sender), so I moved it to the config. And since the senders weren't including the base config, I also added it to them.

What do you think?

src/watcher.js Outdated
@@ -30,6 +31,8 @@ const eventContract = new web3Instance.eth.Contract(config.eventAbi, config.even
const lastBlockRedisKey = `${config.id}:lastProcessedBlock`
let lastProcessedBlock = BN.max(config.startBlock.sub(ONE), ZERO)

const maxProcessingTime = process.env.MAX_PROCESSING_TIME
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to define a default value which will be used if MAX_PROCESSING_TIME was missed by some reason in the configuration file.

Copy link
Collaborator

@akolotov akolotov left a comment

Choose a reason for hiding this comment

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

Approved.

@akolotov
Copy link
Collaborator

Merge the branch support-erc20-native-#81 in order to fix the issue with TravisCI and as soon as Travis does not report about any issue, merge this PR.

@ghost ghost assigned patitonar Oct 25, 2018
@patitonar patitonar merged commit e13bf28 into support-erc20-native-#81 Oct 25, 2018
@ghost ghost removed the review label Oct 25, 2018
@patitonar patitonar deleted the add-watchdog branch October 25, 2018 17:54
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.

None yet

3 participants