Skip to content

Commit

Permalink
hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
onemorebsmith committed Oct 7, 2022
1 parent 8890b2f commit 397ee8d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion make_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CMD_PATH="../cmd/kaspabridge"
rm -rf release
mkdir -p release
cd release
VERSION=1.1.4
VERSION=1.1.5
ARCHIVE="ks_bridge-${VERSION}"
OUTFILE="ks_bridge"
OUTDIR="ks_bridge"
Expand Down
2 changes: 1 addition & 1 deletion src/kaspastratum/client_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (c *clientListener) NewBlockAvailable(kapi *KaspaApi) {
return
}
RecordWorkerError(client.WalletAddr, ErrFailedSendWork)
client.Logger.Error(errors.Wrapf(err, "failed sending work packet %s", jobId).Error())
client.Logger.Error(errors.Wrapf(err, "failed sending work packet %d", jobId).Error())
}

RecordNewJob(client)
Expand Down
5 changes: 3 additions & 2 deletions src/kaspastratum/prom.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var blockCounter = promauto.NewCounterVec(prometheus.CounterOpts{
var blockGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "ks_mined_blocks_gauge",
Help: "Gauge containing 1 unique instance per block mined",
}, append(workerLabels, "nonce", "bluescore"))
}, append(workerLabels, "nonce", "bluescore", "hash"))

var disconnectCounter = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "ks_worker_disconnect_counter",
Expand Down Expand Up @@ -109,11 +109,12 @@ func RecordWeakShare(worker *gostratum.StratumContext) {
invalidCounter.With(labels).Inc()
}

func RecordBlockFound(worker *gostratum.StratumContext, nonce, bluescore uint64) {
func RecordBlockFound(worker *gostratum.StratumContext, nonce, bluescore uint64, hash string) {
blockCounter.With(commonLabels(worker)).Inc()
labels := commonLabels(worker)
labels["nonce"] = fmt.Sprintf("%d", nonce)
labels["bluescore"] = fmt.Sprintf("%d", bluescore)
labels["hash"] = fmt.Sprintf("%d", bluescore)
blockGauge.With(labels).Set(1)
}

Expand Down
2 changes: 1 addition & 1 deletion src/kaspastratum/prom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestPromValid(t *testing.T) {
RecordDupeShare(&ctx)
RecordInvalidShare(&ctx)
RecordWeakShare(&ctx)
RecordBlockFound(&ctx, 10000, 12345)
RecordBlockFound(&ctx, 10000, 12345, "abcdefg")
RecordDisconnect(&ctx)
RecordNewJob(&ctx)
RecordNetworkStats(1234, 5678, 910)
Expand Down
14 changes: 8 additions & 6 deletions src/kaspastratum/share_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/kaspanet/kaspad/app/appmessage"
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
"github.com/kaspanet/kaspad/domain/consensus/utils/pow"
"github.com/kaspanet/kaspad/infrastructure/network/rpcclient"
"github.com/onemorebsmith/kaspastratum/src/gostratum"
Expand Down Expand Up @@ -207,13 +208,14 @@ func (sh *shareHandler) submit(ctx *gostratum.StratumContext,
block *externalapi.DomainBlock, nonce uint64, eventId any) error {
mutable := block.Header.ToMutable()
mutable.SetNonce(nonce)
_, err := sh.kaspa.SubmitBlock(&externalapi.DomainBlock{
block = &externalapi.DomainBlock{
Header: mutable.ToImmutable(),
Transactions: block.Transactions,
})
}
_, err := sh.kaspa.SubmitBlock(block)
blockhash := consensushashing.BlockHash(block)
// print after the submit to get it submitted faster
ctx.Logger.Info("submitted block to kaspad", ctx.String())
ctx.Logger.Info(fmt.Sprintf("Submitted nonce: %d", nonce))
ctx.Logger.Info(fmt.Sprintf("Submitted block %s", blockhash))

if err != nil {
// :'(
Expand All @@ -234,12 +236,12 @@ func (sh *shareHandler) submit(ctx *gostratum.StratumContext,
}

// :)
ctx.Logger.Info("block accepted")
ctx.Logger.Info(fmt.Sprintf("block accepted %s", blockhash))
stats := sh.getCreateStats(ctx)
stats.LastShare = time.Now()
atomic.AddInt64(&stats.SharesFound, 1)
atomic.AddInt64(&sh.overall.SharesFound, 1)
RecordBlockFound(ctx, block.Header.Nonce(), block.Header.BlueScore())
RecordBlockFound(ctx, block.Header.Nonce(), block.Header.BlueScore(), blockhash.String())
return ctx.Reply(gostratum.JsonRpcResponse{
Result: true,
})
Expand Down
6 changes: 2 additions & 4 deletions src/kaspastratum/stratum_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.uber.org/zap/zapcore"
)

const version = "v1.1.4"
const version = "v1.1.5"

type BridgeConfig struct {
StratumPort string `yaml:"stratum_port"`
Expand Down Expand Up @@ -97,7 +97,5 @@ func ListenAndServe(cfg BridgeConfig) error {
go shareHandler.startStatsThread()
}

server := gostratum.NewListener(stratumConfig)
server.Listen(context.Background())
return nil
return gostratum.NewListener(stratumConfig).Listen(context.Background())
}

0 comments on commit 397ee8d

Please sign in to comment.