mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-02-27 05:33:18 +00:00
Compare commits
4 Commits
v1.9.13-te
...
v0.6.10-de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1743dc694a | ||
|
|
8fb30a5895 | ||
|
|
d59ed71465 | ||
|
|
ea0f5ca60e |
@@ -44,8 +44,12 @@ func (m *Manager) routerInitializer(router *router.Router, netConnection *netada
|
||||
err := m.handleIncomingMessages(router, incomingRoute)
|
||||
m.handleError(err, netConnection)
|
||||
})
|
||||
|
||||
notificationListener := m.context.NotificationManager.AddListener(router)
|
||||
spawn("routerInitializer-handleOutgoingNotifications", func() {
|
||||
err := m.handleOutgoingNotifications(router)
|
||||
defer m.context.NotificationManager.RemoveListener(router)
|
||||
|
||||
err := m.handleOutgoingNotifications(notificationListener)
|
||||
m.handleError(err, netConnection)
|
||||
})
|
||||
}
|
||||
@@ -72,9 +76,7 @@ func (m *Manager) handleIncomingMessages(router *router.Router, incomingRoute *r
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) handleOutgoingNotifications(router *router.Router) error {
|
||||
notificationListener := m.context.NotificationManager.AddListener(router)
|
||||
defer m.context.NotificationManager.RemoveListener(router)
|
||||
func (m *Manager) handleOutgoingNotifications(notificationListener *rpccontext.NotificationListener) error {
|
||||
for {
|
||||
err := notificationListener.ProcessNextNotification()
|
||||
if err != nil {
|
||||
|
||||
34
cmd/kaspactl/docker/Dockerfile
Normal file
34
cmd/kaspactl/docker/Dockerfile
Normal file
@@ -0,0 +1,34 @@
|
||||
# -- multistage docker build: stage #1: build stage
|
||||
FROM golang:1.14-alpine AS build
|
||||
|
||||
RUN mkdir -p /go/src/github.com/kaspanet/kaspad
|
||||
|
||||
WORKDIR /go/src/github.com/kaspanet/kaspad
|
||||
|
||||
RUN apk add --no-cache curl git openssh binutils gcc musl-dev
|
||||
RUN go get -u golang.org/x/lint/golint
|
||||
|
||||
COPY go.mod .
|
||||
COPY go.sum .
|
||||
|
||||
RUN go mod download
|
||||
|
||||
COPY . .
|
||||
|
||||
WORKDIR /go/src/github.com/kaspanet/kaspad/cmd/kaspactl
|
||||
|
||||
RUN GOFMT_RESULT=`go fmt ./...`; echo $GOFMT_RESULT; test -z "$GOFMT_RESULT"
|
||||
RUN go vet ./...
|
||||
RUN golint -set_exit_status ./...
|
||||
RUN GOOS=linux go build -a -installsuffix cgo -o kaspactl .
|
||||
|
||||
# --- multistage docker build: stage #2: runtime image
|
||||
FROM alpine
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk add --no-cache ca-certificates tini
|
||||
|
||||
COPY --from=build /go/src/github.com/kaspanet/kaspad/cmd/kaspactl/kaspactl /app/
|
||||
|
||||
USER nobody
|
||||
ENTRYPOINT [ "/sbin/tini", "--" ]
|
||||
@@ -12,9 +12,13 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// OnErrorHandler defines a handler function for when errors occur
|
||||
type OnErrorHandler func(err error)
|
||||
|
||||
// GRPCClient is a gRPC-based RPC client
|
||||
type GRPCClient struct {
|
||||
stream protowire.RPC_MessageStreamClient
|
||||
stream protowire.RPC_MessageStreamClient
|
||||
onErrorHandler OnErrorHandler
|
||||
}
|
||||
|
||||
// Connect connects to the RPC server with the given address
|
||||
@@ -41,6 +45,11 @@ func (c *GRPCClient) Disconnect() error {
|
||||
return c.stream.CloseSend()
|
||||
}
|
||||
|
||||
// SetOnErrorHandler sets the client's onErrorHandler
|
||||
func (c *GRPCClient) SetOnErrorHandler(onErrorHandler OnErrorHandler) {
|
||||
c.onErrorHandler = onErrorHandler
|
||||
}
|
||||
|
||||
// AttachRouter attaches the given router to the client and starts
|
||||
// sending/receiving messages via it
|
||||
func (c *GRPCClient) AttachRouter(router *router.Router) {
|
||||
@@ -101,5 +110,9 @@ func (c *GRPCClient) handleError(err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
if c.onErrorHandler != nil {
|
||||
c.onErrorHandler(err)
|
||||
return
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ type RPCClient struct {
|
||||
func NewRPCClient(rpcAddress string) (*RPCClient, error) {
|
||||
rpcClient, err := grpcclient.Connect(rpcAddress)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error connecting to address %s", rpcClient)
|
||||
return nil, errors.Wrapf(err, "error connecting to address %s", rpcAddress)
|
||||
}
|
||||
rpcRouter, err := buildRPCRouter()
|
||||
if err != nil {
|
||||
|
||||
@@ -224,7 +224,16 @@ func HashToBig(hash *Hash) *big.Int {
|
||||
// +1 if hash > target
|
||||
//
|
||||
func (hash *Hash) Cmp(target *Hash) int {
|
||||
return HashToBig(hash).Cmp(HashToBig(target))
|
||||
// We compare the hashes backwards because Hash is stored as a little endian byte array.
|
||||
for i := HashSize - 1; i >= 0; i-- {
|
||||
switch {
|
||||
case hash[i] < target[i]:
|
||||
return -1
|
||||
case hash[i] > target[i]:
|
||||
return 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Less returns true iff hash a is less than hash b
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
@@ -425,3 +426,43 @@ func TestSort(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func hashFlipBit(hash Hash, bit int) Hash {
|
||||
word := bit / 8
|
||||
bit = bit % 8
|
||||
hash[word] ^= 1 << bit
|
||||
return hash
|
||||
}
|
||||
|
||||
func TestHash_Cmp(t *testing.T) {
|
||||
r := rand.New(rand.NewSource(1))
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
hash := Hash{}
|
||||
n, err := r.Read(hash[:])
|
||||
if err != nil {
|
||||
t.Fatalf("Failed generating a random hash '%s'", err)
|
||||
} else if n != len(hash) {
|
||||
t.Fatalf("Failed generating a random hash, expected reading: %d. instead read: %d.", len(hash), n)
|
||||
|
||||
}
|
||||
hashBig := HashToBig(&hash)
|
||||
// Iterate bit by bit, flip it and compare.
|
||||
for bit := 0; bit < HashSize*8; bit++ {
|
||||
newHash := hashFlipBit(hash, bit)
|
||||
if hash.Cmp(&newHash) != hashBig.Cmp(HashToBig(&newHash)) {
|
||||
t.Errorf("Hash.Cmp disagrees with big.Int.Cmp newHash: %s, hash: %s", newHash, hash)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkHash_Cmp(b *testing.B) {
|
||||
hash0, err := NewHashFromStr("3333333333333333333333333333333333333333333333333333333333333333")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
for n := 0; n < b.N; n++ {
|
||||
hash0.Cmp(hash0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user