Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

WIP: Fix host counter #2884

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

nielscastien
Copy link
Contributor

@nielscastien nielscastien commented Mar 16, 2018

@DavidVorick This is a first attempt to fix the host financial metrics that are off most of the time for all the hosts.

I noticed that whenever my host financial metrics increased a lot in a small period of time, there were at the same time consensus errors in the host.log. These errors always repeated themselves 6 times with 15s interval. See host.log.

Therefore, I looked at negotiate.go and found out that there is a loop that calls
err = h.managedAddStorageObligation(so) .
Worst case this function is called 6 times if there are issues with the acceptance of the transaction set (leading to the logged errors). Every time this function is called on the same storage obligation, the host financial metrics are updated.

This PR tries to fix the double counting issue. This PR will not prevent additional insertions into the host database. These additional insertions could lead to several other bugs where a host can't provide a storage proof when a storage obligation ends.

I know the focus is on upgrading the renter. But this could potentially fix a lot of errors for the hosts. Any feedback is welcome...

cc @lukechampine

…en this function is called multiple times from negotiate.go line 252, this prevents adding values multiple times.
// Increase contract count by one only if this is a new filecontract.
if len(so.SectorRoots) == 0 {
h.financialMetrics.ContractCount++
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this part. I guess it depends on the precise meaning of ContractCount. Even if you renew a contract, the host still needs to track the old contract until it ends, so it might make sense to increment ContractCount even for renewed contracts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right! I reverted the commits. Was confused about the 'renewal' word, where it actually is a new storage obligation we need to track.

@lukechampine
Copy link
Member

This seems basically correct to me. Although, it makes me suspect that the host state isn't being properly rolled back in the event of an error. For example, there's a db.Update call earlier in the function; if managedAddStorageObligation ultimately fails, then we'd want to revert those changes, right? Perhaps that can be tackled in a subsequent PR.

… new contract and not a renewal"

This reverts commit 9d08da8.

Contract counter should be increased as it is forming a new obligation
for new contracts as well for renewals.
…tion. When this function is called multiple times from negotiate.go line 252, this prevents adding values multiple times."

This reverts commit e15c6d8.

When there is an error with the queuing of the action items, the storage obligation will be removed with status 'obligationRejected' and the function will return. Placing the financial metrics update at the end of the function will
in this case never be reached.
…ror.

Financial metrics are only updated when there are no errors.
AcceptTransactionSet call returns with an error.

This should reset the host to the original state. However, the rejected storage
obligation will stay in the database as rejected without SectorRoots.
@nielscastien
Copy link
Contributor Author

nielscastien commented Mar 17, 2018

@lukechampine I reverted the old and added some new commits. Please take a look if I am not missing something. Whenever managedAddStorageObligation returns with an error, everything should be rolled back correctly now.

The only thing that still bothers me is the way a storage obligation with obligatonRejected status is removed within removeStorageObligation. In this PR I make use of it twice (to prevent duplication of code):

  1. after AcceptTransactionSet returns an error (this PR),
  2. or if there is an error with a queueActionItem (original code)

Before the financial metrics are updated it checks:
h.financialMetrics.TransactionFeeExpenses.Cmp(so.TransactionFeesAdded) >= 0
but I don't know when this is true (or not). To be honest, I think this will only be true when the TransactionFeesAdded are 0. As far as I know, the TransactionFeeExpenses value of the host has a bug; it is always zero. Maybe some other hosts can confirm this.

If not, is it possible to define a new storage obligation status, obligationRollBack or something, so that we can make a dedicated branch in removeStorageObligation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants