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

add balance maintainer job #47

Merged
merged 4 commits into from
Oct 11, 2016
Merged

add balance maintainer job #47

merged 4 commits into from
Oct 11, 2016

Conversation

avahowell
Copy link
Contributor

This PR adds a config option, "DesiredCurrency": int (SC), which is input to a balanceMaintainer job in sia-ant. This job will mine until the DesiredCurrency amount exists in the wallet, after which point it stops the miner. If the wallet balance drops below DesiredCurrency, balanceMaintainer will start the miner again. This should greatly reduce the performance impact of running several renters and hosts.

}

// Mine at least 50,000 SC
// acquire at least 50,000 SC
desiredbalance := types.NewCurrency64(50000).Mul(types.SiacoinPrecision)
Copy link
Member

Choose a reason for hiding this comment

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

more concise is types.SiacoinPrecision.Mul64(50000)

log.Printf("[%v balanceMaintainer ERROR]: %v\n", j.siaDirectory, err)
}
if walletInfo.ConfirmedSiacoinBalance.Cmp(desiredBalance) < 0 {
log.Printf("[%v balanceMaintainer INFO]: not enough currency, starting the miner\n", j.siaDirectory)
Copy link
Member

Choose a reason for hiding this comment

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

this will be printed every 20s until enough currency is mined. Maybe check the current miner state and do nothing if it is already mining?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, good call.

if !minerRunning {
log.Printf("[%v balanceMaintainer INFO]: not enough currency, starting the miner\n", j.siaDirectory)
minerRunning = true
}
Copy link
Member

Choose a reason for hiding this comment

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

this still calls /miner/start if the miner is running. Better would be:

haveDesiredBalance := walletInfo.ConfirmedSiacoinBalanace.Cmp(desiredBalance) > 0
if !minerRunning && !haveDesiredBalance {
    // log, start miner
} else if minerRunning && haveDesiredBalance {
    // log, stop miner
}

@lukechampine
Copy link
Member

it appears that this will stop the miner job from continuously mining. This is a problem for my tests because none of the ants will mine, meaning the blockheight will never change.

@avahowell
Copy link
Contributor Author

ok, I changed this so that if a miner job is run, the balanceMaintainer is not run.

@avahowell
Copy link
Contributor Author

This PR has been rebased off the sia-ant refactor. It's much simpler now as well: DesiredCurrency is an optional field that is passed to the miner. If it is not provided, the miner will run forever, otherwise the miner will run as long as the balance is below DesiredCurrency.

if err != nil {
log.Printf("[%v blockMining ERROR]: %v\n", j.siaDirectory, err)
// If desiredBalance is zero, just return, leaving the miner running.
runForever := desiredBalance.Cmp(types.ZeroCurrency) == 0
Copy link
Member

Choose a reason for hiding this comment

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

if I understand correctly, it's still possible to avoid mining entirely by not passing -miner, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct. by not including miner in the Jobs, the miner never gets run, regardless of DesiredCurrency.

@avahowell
Copy link
Contributor Author

Based on feedback from @DavidVorick, balance maintainer is its own job again and is mutually exclusive with miner. If the user specifies both a miner job and a desiredcurrency, an error is thrown.

@lukechampine lukechampine merged commit d6e418d into master Oct 11, 2016
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