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

feat: Connor the bot #1227

Merged
merged 1 commit into from
Aug 3, 2018
Merged

feat: Connor the bot #1227

merged 1 commit into from
Aug 3, 2018

Conversation

nikonov1101
Copy link
Member

@nikonov1101 nikonov1101 commented Jul 24, 2018

This commit introduces Connor, the bot which buying resources
for mining. The current implementation can:

  • Places BID orders according to config.
  • Restores orders, deals, and tasks between restarts.
  • Loads actual price of the target token, create orders according to price and marginality coefficient.
  • Tracks token price changes using CoinMarketCap, re-create orders if the price changed sufficiently.
  • Looks for actual hashrate by logs and mining pool statistics.
  • Closes deals which give us less hash-rate than offered.

Note that current implementation is strongly coupled with the Ethereum mining on the DwarfPool.
Next, we'll make it more modular and configurable for other popular tokens and pools.

@3Hren 3Hren added the T: WIP This PR/Issue still in progress label Jul 25, 2018
@nikonov1101 nikonov1101 force-pushed the feat/connor-v2 branch 3 times, most recently from 8600434 to f71d78f Compare July 30, 2018 10:43
Copy link
Member

@3Hren 3Hren left a comment

Choose a reason for hiding this comment

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

Please drop _v2 everywhere and we can begin...

Makefile Outdated
@@ -112,9 +113,13 @@ build/oracle:
@echo "+ $@"
${GO} build -tags "$(TAGS)" -ldflags "$(LDFLAGS)" -o ${ORACLE} ${GOCMD}/oracle

build/connor:
@echo "+ $@"
${GO} build -tags "$(TAGS)" -ldflags "$(LDFLAGS)" -o ${CONNOR} ${GOCMD}/connor_v2
Copy link
Member

Choose a reason for hiding this comment

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

Drop _v2.

@nikonov1101 nikonov1101 force-pushed the feat/connor-v2 branch 3 times, most recently from bea5e00 to d2d5888 Compare August 1, 2018 22:44
@nikonov1101 nikonov1101 changed the title [WIP] connor v2 feat: Connor the bot Aug 1, 2018
@nikonov1101 nikonov1101 added T: feature This PR/Issue adds a new feature P: HIGH This PR/Issue has the high priority S: Connor This PR/Issue changes Connor and removed T: WIP This PR/Issue still in progress labels Aug 1, 2018
Copy link
Member

@3Hren 3Hren left a comment

Choose a reason for hiding this comment

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

Superficially overviewed the code, not the functionality.

}

func lifeTime(deal *sonm.Deal) time.Duration {
return time.Now().Sub(deal.GetStartTime().Unix())
Copy link
Member

Choose a reason for hiding this comment

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

You can use time.Since.

}

type antiFraud struct {
mu sync.RWMutex
Copy link
Member

Choose a reason for hiding this comment

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

Either describe or put the mutex near variables it protects.

blacklistWatchers: map[common.Address]*blacklistWatcher{},
nodeConnection: nodeConnection,
deals: sonm.NewDealManagementClient(nodeConnection),
log: log,
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather use sugared logger instead of garbaging attributes space.

for {
select {
case <-ctx.Done():
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason not to return ctx.Err()?

log.Warn("task quality is less that required, closing deal",
zap.Float64("calculated", qualityByLogs), zap.Float64("required", m.cfg.TaskQuality))

if err := m.finishDeal(dealMeta.deal, sonm.BlacklistType_BLACKLIST_WORKER); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

It's potentially long-running method, but the mutex is held.

}

func (w *dwarfPoolWatcher) TaskQuality() (bool, float64) {
accurate := w.startTime.Add(10 * time.Minute).Before(time.Now())
Copy link
Member

Choose a reason for hiding this comment

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

Hardcode?

}

func (w *dwarfPoolWatcher) watch() error {
url := fmt.Sprintf("http://dwarfpool.com/eth/api?wallet=%s", strings.ToLower(w.wallet.Hex()))
Copy link
Member

Choose a reason for hiding this comment

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

Hardcode?


type engine struct {
log *zap.Logger
ctx context.Context
Copy link
Member

Choose a reason for hiding this comment

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

Bad thing.

connor/engine.go Outdated
if ord.GetOrderStatus() == sonm.OrderStatus_ORDER_INACTIVE {
log.Info("order becomes inactive, looking for related deal")

if ord.GetDealID() == nil || ord.GetDealID().IsZero() {
Copy link
Member

Choose a reason for hiding this comment

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

Checking for ord.GetDealID() == nil is redundant.

}

func (p *nullPriceProvider) GetPrice() *big.Int {
v, _ := big.NewFloat(0).Mul(big.NewFloat(5e5), big.NewFloat(p.cfg.Margin)).Int(nil)
Copy link
Member

Choose a reason for hiding this comment

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

🤔

@nikonov1101 nikonov1101 force-pushed the feat/connor-v2 branch 4 times, most recently from 63630b6 to 79b1778 Compare August 3, 2018 12:20
This commit introduces Connor, the bot which buying resources
for mining. The current implementation can:

- Places BID orders according to config.
- Restores orders, deals, and tasks between restarts.
- Loads actual price of the target token, create orders according to price and marginality coefficient.
- Tracks token price changes using CoinMarketCap, re-create orders if the price changed sufficiently.
- Looks for actual hashrate by logs and mining pool statistics.
- Closes deals which give us less hash-rate than offered.

Note that current implementation is strongly coupled with the Ethereum mining on the DwarfPool.
Next, we'll make it more modular and configurable for other popular tokens and pools.
@3Hren 3Hren merged commit 7cf22d7 into master Aug 3, 2018
@3Hren 3Hren deleted the feat/connor-v2 branch August 3, 2018 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P: HIGH This PR/Issue has the high priority S: Connor This PR/Issue changes Connor T: feature This PR/Issue adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants