Skip to content

Commit

Permalink
Merge pull request #4 from Tritonn204/main
Browse files Browse the repository at this point in the history
Invalid share/block tracking enabled
  • Loading branch information
0xA001113 authored Oct 10, 2024
2 parents a8ebe7d + dd3ec35 commit c1da2c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 42 deletions.
63 changes: 24 additions & 39 deletions src/spectrestratum/share_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"sync"
"time"

// "encoding/binary"

"github.com/pkg/errors"
"github.com/spectre-project/spectre-stratum-bridge/src/gostratum"
"github.com/spectre-project/spectred/app/appmessage"
Expand Down Expand Up @@ -189,22 +187,24 @@ func (sh *shareHandler) HandleSubmit(ctx *gostratum.StratumContext, event gostra
}
}
stats := sh.getCreateStats(ctx)
// if err := sh.checkStales(ctx, submitInfo); err != nil {
// if err == ErrDupeShare {
// ctx.Logger.Info("dupe share "+submitInfo.noncestr, ctx.WorkerName, ctx.WalletAddr)
// atomic.AddInt64(&stats.StaleShares, 1)
// RecordDupeShare(ctx)
// return ctx.ReplyDupeShare(event.Id)
// } else if errors.Is(err, ErrStaleShare) {
// ctx.Logger.Info(err.Error(), ctx.WorkerName, ctx.WalletAddr)
// atomic.AddInt64(&stats.StaleShares, 1)
// RecordStaleShare(ctx)
// return ctx.ReplyStaleShare(event.Id)
// }
// // unknown error somehow
// ctx.Logger.Error("unknown error during check stales: ", err.Error())
// return ctx.ReplyBadShare(event.Id)
// }
if err := sh.checkStales(ctx, submitInfo); err != nil {
if err == ErrDupeShare {
ctx.Logger.Warn("duplicate share: "+submitInfo.noncestr)
RecordDupeShare(ctx)
stats.InvalidShares.Add(1)
sh.overall.InvalidShares.Add(1)
return ctx.ReplyDupeShare(event.Id)
} else if errors.Is(err, ErrStaleShare) {
ctx.Logger.Warn("stale share")
stats.StaleShares.Add(1)
sh.overall.StaleShares.Add(1)
RecordStaleShare(ctx)
return ctx.ReplyStaleShare(event.Id)
}
// unknown error somehow
ctx.Logger.Error("unknown error during check stales")
return ctx.ReplyBadShare(event.Id)
}

converted, err := appmessage.RPCBlockToDomainBlock(submitInfo.block)
if err != nil {
Expand All @@ -216,23 +216,6 @@ func (sh *shareHandler) HandleSubmit(ctx *gostratum.StratumContext, event gostra
powState := pow.NewState(mutableHeader)
powValue := powState.CalculateProofOfWorkValue()

// zeroes := make([]byte, 32)

// ctx.Logger.Warn(fmt.Sprintf("Reconstructed timestamp = %x", powState.Timestamp))

// b := make([]byte, 8)
// binary.LittleEndian.PutUint64(b, uint64(powState.Timestamp))

// b2 := make([]byte, 8)
// binary.LittleEndian.PutUint64(b2, uint64(powState.Nonce))

// templateString := fmt.Sprintf("%x%x%x%x",
// powState.PrePowHash.ByteSlice(),
// b,
// zeroes[:],
// b2,
// )

// The block hash must be less or equal than the claimed target.
if powValue.Cmp(&powState.Target) <= 0 {
if err := sh.submit(ctx, converted, submitInfo.nonceVal, event.Id); err != nil {
Expand All @@ -244,9 +227,11 @@ func (sh *shareHandler) HandleSubmit(ctx *gostratum.StratumContext, event gostra
} else {
ctx.Logger.Warn("weak share")
}
ctx.Logger.Warn(fmt.Sprintf("Net Target: %s", powState.Target.String()))
ctx.Logger.Warn(fmt.Sprintf("Stratum Target: %s", state.stratumDiff.targetValue.String()))
ctx.Logger.Warn(fmt.Sprintf("PowValue: %s", powValue.String()))
ctx.Logger.Warn(fmt.Sprintf("Net Target: %s\n", powState.Target.String()))
ctx.Logger.Warn(fmt.Sprintf("Stratum Target: %s\n", state.stratumDiff.targetValue.String()))
ctx.Logger.Warn(fmt.Sprintf("PowValue: %064x\n", powValue.Bytes()))
stats.InvalidShares.Add(1)
sh.overall.InvalidShares.Add(1)
RecordWeakShare(ctx)
return ctx.ReplyLowDiffShare(event.Id)
}
Expand Down Expand Up @@ -340,7 +325,7 @@ func (sh *shareHandler) startStatsThread() error {
str += fmt.Sprintf(" Total | %14.14s | %14.14s | %12d | %11s",
rateStr, ratioStr, sh.overall.BlocksFound.Load(), time.Since(start).Round(time.Second))
str += "\n-------------------------------------------------------------------------------\n"
str += " Network Hashrate: " + stringifyHashrate(DiffToHash(sh.soloDiff))
str += " Est. Network Hashrate: " + stringifyHashrate(DiffToHash(sh.soloDiff))
str += "\n======================================================== spr_bridge_" + version + " ===\n"
// sh.statsLock.Unlock()
log.Println(str)
Expand Down
6 changes: 3 additions & 3 deletions src/spectrestratum/stratum_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"go.uber.org/zap/zapcore"
)

const version = "v0.3.16"
const minBlockWaitTime = 3 * time.Second
const version = "v0.3.17"
const minBlockWaitTime = 250 * time.Millisecond

type BridgeConfig struct {
StratumPort string `yaml:"stratum_port"`
Expand Down Expand Up @@ -64,7 +64,7 @@ func ListenAndServe(cfg BridgeConfig) error {
}

blockWaitTime := cfg.BlockWaitTime
if blockWaitTime == 0 {
if blockWaitTime < minBlockWaitTime {
blockWaitTime = minBlockWaitTime
}
sprApi, err := NewSpectreAPI(cfg.RPCServer, blockWaitTime, logger)
Expand Down

0 comments on commit c1da2c3

Please sign in to comment.