-
Notifications
You must be signed in to change notification settings - Fork 75
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
feat: Connor the bot #1227
Conversation
e584ccd
to
b1a8a6f
Compare
8600434
to
f71d78f
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop _v2
.
bea5e00
to
d2d5888
Compare
There was a problem hiding this 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.
connor/antifraud/antifraud.go
Outdated
} | ||
|
||
func lifeTime(deal *sonm.Deal) time.Duration { | ||
return time.Now().Sub(deal.GetStartTime().Unix()) |
There was a problem hiding this comment.
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
.
connor/antifraud/antifraud.go
Outdated
} | ||
|
||
type antiFraud struct { | ||
mu sync.RWMutex |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
connor/antifraud/antifraud.go
Outdated
for { | ||
select { | ||
case <-ctx.Done(): | ||
return nil |
There was a problem hiding this comment.
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()
?
connor/antifraud/antifraud.go
Outdated
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 { |
There was a problem hiding this comment.
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.
connor/antifraud/pool_processor.go
Outdated
} | ||
|
||
func (w *dwarfPoolWatcher) TaskQuality() (bool, float64) { | ||
accurate := w.startTime.Add(10 * time.Minute).Before(time.Now()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcode?
connor/antifraud/pool_processor.go
Outdated
} | ||
|
||
func (w *dwarfPoolWatcher) watch() error { | ||
url := fmt.Sprintf("http://dwarfpool.com/eth/api?wallet=%s", strings.ToLower(w.wallet.Hex())) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
63630b6
to
79b1778
Compare
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.
79b1778
to
cd4c897
Compare
This commit introduces Connor, the bot which buying resources
for mining. The current implementation can:
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.