Update go-randomx, bump dependencies and use hashicorp LRU to remove golang.org/x/text, github.com/bahlo/generic-list-go dependencies

This commit is contained in:
DataHoarder 2024-04-13 00:26:21 +02:00
parent ad17d3724a
commit dbeb877d6c
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
5 changed files with 38 additions and 30 deletions

8
go.mod
View file

@ -4,14 +4,14 @@ go 1.22
require ( require (
git.gammaspectra.live/P2Pool/edwards25519 v0.0.0-20240405085108-e2f706cb5c00 git.gammaspectra.live/P2Pool/edwards25519 v0.0.0-20240405085108-e2f706cb5c00
git.gammaspectra.live/P2Pool/go-randomx/v2 v2.0.0 git.gammaspectra.live/P2Pool/go-randomx/v2 v2.1.0
git.gammaspectra.live/P2Pool/monero-base58 v1.0.0 git.gammaspectra.live/P2Pool/monero-base58 v1.0.0
git.gammaspectra.live/P2Pool/randomx-go-bindings v1.0.0 git.gammaspectra.live/P2Pool/randomx-go-bindings v1.0.0
git.gammaspectra.live/P2Pool/sha3 v0.17.0 git.gammaspectra.live/P2Pool/sha3 v0.17.0
github.com/dolthub/swiss v0.2.2-0.20240312182618-f4b2babd2bc1 github.com/dolthub/swiss v0.2.2-0.20240312182618-f4b2babd2bc1
github.com/floatdrop/lru v1.3.0
github.com/go-zeromq/zmq4 v0.16.1-0.20240124085909-e75c615ba1b3 github.com/go-zeromq/zmq4 v0.16.1-0.20240124085909-e75c615ba1b3
github.com/goccy/go-json v0.10.2 github.com/goccy/go-json v0.10.2
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc
golang.org/x/sync v0.7.0 golang.org/x/sync v0.7.0
golang.org/x/sys v0.19.0 golang.org/x/sys v0.19.0
@ -19,12 +19,10 @@ require (
) )
require ( require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/dolthub/maphash v0.1.0 // indirect github.com/dolthub/maphash v0.1.0 // indirect
golang.org/x/crypto v0.22.0 // indirect golang.org/x/crypto v0.22.0 // indirect
golang.org/x/text v0.14.0 // indirect
) )
replace github.com/goccy/go-json => github.com/WeebDataHoarder/go-json v0.0.0-20230730135821-d8f6463bb887 replace github.com/goccy/go-json => github.com/WeebDataHoarder/go-json v0.0.0-20230730135821-d8f6463bb887
replace github.com/go-zeromq/zmq4 => git.gammaspectra.live/P2Pool/zmq4 v0.16.1-0.20240407153747-7f7d531f586e replace github.com/go-zeromq/zmq4 => git.gammaspectra.live/P2Pool/zmq4 v0.16.1-0.20240412221749-a35fa84ca9f4

16
go.sum
View file

@ -1,27 +1,25 @@
git.gammaspectra.live/P2Pool/edwards25519 v0.0.0-20240405085108-e2f706cb5c00 h1:mDQY337iKB+kle5RYWL5CoAz+3DmnkAh/B2XD8B+PFk= git.gammaspectra.live/P2Pool/edwards25519 v0.0.0-20240405085108-e2f706cb5c00 h1:mDQY337iKB+kle5RYWL5CoAz+3DmnkAh/B2XD8B+PFk=
git.gammaspectra.live/P2Pool/edwards25519 v0.0.0-20240405085108-e2f706cb5c00/go.mod h1:FZsrMWGucMP3SZamzrd7m562geIs5zp1O/9MGoiAKH0= git.gammaspectra.live/P2Pool/edwards25519 v0.0.0-20240405085108-e2f706cb5c00/go.mod h1:FZsrMWGucMP3SZamzrd7m562geIs5zp1O/9MGoiAKH0=
git.gammaspectra.live/P2Pool/go-randomx/v2 v2.0.0 h1:lHi2z8Nz3H1Xpu1p53TYccz072BDhbJGNHquiX9orCM= git.gammaspectra.live/P2Pool/go-randomx/v2 v2.1.0 h1:L1fV2XBYFmpFU+JKP/7fsgDm2Lfh9yFlS+800v+3OsM=
git.gammaspectra.live/P2Pool/go-randomx/v2 v2.0.0/go.mod h1:vNmHlEIRAcU/bA85mxbUKEiBYtrtS4MVwozf29KmoHM= git.gammaspectra.live/P2Pool/go-randomx/v2 v2.1.0/go.mod h1:vNmHlEIRAcU/bA85mxbUKEiBYtrtS4MVwozf29KmoHM=
git.gammaspectra.live/P2Pool/monero-base58 v1.0.0 h1:s8LZxVNc93YEs2NCCNWZ7CKr8RbEb031y6Wkvhn+TS4= git.gammaspectra.live/P2Pool/monero-base58 v1.0.0 h1:s8LZxVNc93YEs2NCCNWZ7CKr8RbEb031y6Wkvhn+TS4=
git.gammaspectra.live/P2Pool/monero-base58 v1.0.0/go.mod h1:WWEJy/AdWKxKAruvlKI82brw+DtVlePy0ct3ZiBlc68= git.gammaspectra.live/P2Pool/monero-base58 v1.0.0/go.mod h1:WWEJy/AdWKxKAruvlKI82brw+DtVlePy0ct3ZiBlc68=
git.gammaspectra.live/P2Pool/randomx-go-bindings v1.0.0 h1:tajr4QFSPrb8NtHmU14JaXdhr+z+0RbOBLIgUDI5Tow= git.gammaspectra.live/P2Pool/randomx-go-bindings v1.0.0 h1:tajr4QFSPrb8NtHmU14JaXdhr+z+0RbOBLIgUDI5Tow=
git.gammaspectra.live/P2Pool/randomx-go-bindings v1.0.0/go.mod h1:S17NNidG5hxqaVLsSykKqDBg/hTPSzP0KcSwXfH8WIA= git.gammaspectra.live/P2Pool/randomx-go-bindings v1.0.0/go.mod h1:S17NNidG5hxqaVLsSykKqDBg/hTPSzP0KcSwXfH8WIA=
git.gammaspectra.live/P2Pool/sha3 v0.17.0 h1:CZpB466LPbNVQrUNjQTtQScGDc30xSMkZ6Bmw0W9VuM= git.gammaspectra.live/P2Pool/sha3 v0.17.0 h1:CZpB466LPbNVQrUNjQTtQScGDc30xSMkZ6Bmw0W9VuM=
git.gammaspectra.live/P2Pool/sha3 v0.17.0/go.mod h1:HmrrYa97BZTKklUk2n/wAY+wrY0gHhoSGRd2+lIqXq8= git.gammaspectra.live/P2Pool/sha3 v0.17.0/go.mod h1:HmrrYa97BZTKklUk2n/wAY+wrY0gHhoSGRd2+lIqXq8=
git.gammaspectra.live/P2Pool/zmq4 v0.16.1-0.20240407153747-7f7d531f586e h1:U6zpCbwIW1Pr4wyLjbbRNa3aJcCXwnWOPsJmiHGFKsY= git.gammaspectra.live/P2Pool/zmq4 v0.16.1-0.20240412221749-a35fa84ca9f4 h1:K34kPogf+BpaLkUYQJSM1icWU69TL2ISrmx9u977zvw=
git.gammaspectra.live/P2Pool/zmq4 v0.16.1-0.20240407153747-7f7d531f586e/go.mod h1:AOWpIfDC+phUiEeiZRXf5oth8YLsfLtflF+6BJNagi4= git.gammaspectra.live/P2Pool/zmq4 v0.16.1-0.20240412221749-a35fa84ca9f4/go.mod h1:G/caphb5HAHcnNIIDDgOqJ3HN6r4rnTP14Q621H4rK4=
github.com/WeebDataHoarder/go-json v0.0.0-20230730135821-d8f6463bb887 h1:P01nqSM+0b6zlPasOFYsqnQSP2dTRVZkanAnY9q/Bcc= github.com/WeebDataHoarder/go-json v0.0.0-20230730135821-d8f6463bb887 h1:P01nqSM+0b6zlPasOFYsqnQSP2dTRVZkanAnY9q/Bcc=
github.com/WeebDataHoarder/go-json v0.0.0-20230730135821-d8f6463bb887/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/WeebDataHoarder/go-json v0.0.0-20230730135821-d8f6463bb887/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ= github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ=
github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4= github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4=
github.com/dolthub/swiss v0.2.2-0.20240312182618-f4b2babd2bc1 h1:F7u1ZVCidajlPuJJzdL5REPHfLO/O6xLQRUw/YMxrkM= github.com/dolthub/swiss v0.2.2-0.20240312182618-f4b2babd2bc1 h1:F7u1ZVCidajlPuJJzdL5REPHfLO/O6xLQRUw/YMxrkM=
github.com/dolthub/swiss v0.2.2-0.20240312182618-f4b2babd2bc1/go.mod h1:8AhKZZ1HK7g18j7v7k6c5cYIGEZJcPn0ARsai8cUrh0= github.com/dolthub/swiss v0.2.2-0.20240312182618-f4b2babd2bc1/go.mod h1:8AhKZZ1HK7g18j7v7k6c5cYIGEZJcPn0ARsai8cUrh0=
github.com/floatdrop/lru v1.3.0 h1:83abtaKjXcWrPmtzTAk2Ggq8DUKqI29YzrTrB8+vu0c= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/floatdrop/lru v1.3.0/go.mod h1:83zlXKA06Bm32JImNINCiTr0ldadvdAjUe5jSwIaw0s= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
@ -34,8 +32,6 @@ golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
lukechampine.com/uint128 v1.3.0 h1:cDdUVfRwDUDovz610ABgFD17nXD4/uDgVHl2sC3+sbo= lukechampine.com/uint128 v1.3.0 h1:cDdUVfRwDUDovz610ABgFD17nXD4/uDgVHl2sC3+sbo=

View file

@ -9,7 +9,7 @@ import (
"git.gammaspectra.live/P2Pool/consensus/v3/monero/transaction" "git.gammaspectra.live/P2Pool/consensus/v3/monero/transaction"
"git.gammaspectra.live/P2Pool/consensus/v3/types" "git.gammaspectra.live/P2Pool/consensus/v3/types"
"git.gammaspectra.live/P2Pool/consensus/v3/utils" "git.gammaspectra.live/P2Pool/consensus/v3/utils"
"github.com/floatdrop/lru" "github.com/hashicorp/golang-lru/v2"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -55,7 +55,7 @@ type Client struct {
c *rpc.Client c *rpc.Client
d *daemon.Client d *daemon.Client
coinbaseTransactionCache *lru.LRU[types.Hash, *transaction.CoinbaseTransaction] coinbaseTransactionCache *lru.Cache[types.Hash, *transaction.CoinbaseTransaction]
throttler <-chan time.Time throttler <-chan time.Time
} }
@ -65,10 +65,16 @@ func NewClient(address string) (*Client, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
cache, err := lru.New[types.Hash, *transaction.CoinbaseTransaction](1024)
if err != nil {
return nil, err
}
return &Client{ return &Client{
c: c, c: c,
d: daemon.NewClient(c), d: daemon.NewClient(c),
coinbaseTransactionCache: lru.New[types.Hash, *transaction.CoinbaseTransaction](1024), coinbaseTransactionCache: cache,
throttler: time.Tick(time.Second / 8), throttler: time.Tick(time.Second / 8),
}, nil }, nil
} }
@ -126,7 +132,7 @@ func (c *Client) GetTransactions(txIds ...types.Hash) (data [][]byte, jsonTx []*
} }
func (c *Client) GetCoinbaseTransaction(txId types.Hash) (*transaction.CoinbaseTransaction, error) { func (c *Client) GetCoinbaseTransaction(txId types.Hash) (*transaction.CoinbaseTransaction, error) {
if tx := c.coinbaseTransactionCache.Get(txId); tx == nil { if tx, ok := c.coinbaseTransactionCache.Get(txId); !ok || tx == nil {
<-c.throttler <-c.throttler
if result, err := c.d.GetTransactions(context.Background(), []types.Hash{txId}); err != nil { if result, err := c.d.GetTransactions(context.Background(), []types.Hash{txId}); err != nil {
return nil, err return nil, err
@ -144,12 +150,12 @@ func (c *Client) GetCoinbaseTransaction(txId types.Hash) (*transaction.CoinbaseT
return nil, fmt.Errorf("expected %s, got %s", txId.String(), tx.CalculateId().String()) return nil, fmt.Errorf("expected %s, got %s", txId.String(), tx.CalculateId().String())
} }
c.coinbaseTransactionCache.Set(txId, tx) c.coinbaseTransactionCache.Add(txId, tx)
return tx, nil return tx, nil
} }
} else { } else {
return *tx, nil return tx, nil
} }
} }

View file

@ -9,7 +9,7 @@ import (
p2pooltypes "git.gammaspectra.live/P2Pool/consensus/v3/p2pool/types" p2pooltypes "git.gammaspectra.live/P2Pool/consensus/v3/p2pool/types"
"git.gammaspectra.live/P2Pool/consensus/v3/types" "git.gammaspectra.live/P2Pool/consensus/v3/types"
"git.gammaspectra.live/P2Pool/consensus/v3/utils" "git.gammaspectra.live/P2Pool/consensus/v3/utils"
"github.com/floatdrop/lru" "github.com/hashicorp/golang-lru/v2"
"io" "io"
"net/http" "net/http"
"net/netip" "net/netip"
@ -24,17 +24,21 @@ type P2PoolApi struct {
Client *http.Client Client *http.Client
consensus atomic.Pointer[sidechain.Consensus] consensus atomic.Pointer[sidechain.Consensus]
derivationCache sidechain.DerivationCacheInterface derivationCache sidechain.DerivationCacheInterface
difficultyByHeightCache *lru.LRU[uint64, types.Difficulty] difficultyByHeightCache *lru.Cache[uint64, types.Difficulty]
} }
func NewP2PoolApi(host string) *P2PoolApi { func NewP2PoolApi(host string) *P2PoolApi {
cache, err := lru.New[uint64, types.Difficulty](1024)
if err != nil {
return nil
}
return &P2PoolApi{ return &P2PoolApi{
Host: host, Host: host,
Client: &http.Client{ Client: &http.Client{
Timeout: time.Second * 15, Timeout: time.Second * 15,
}, },
derivationCache: sidechain.NewDerivationLRUCache(), derivationCache: sidechain.NewDerivationLRUCache(),
difficultyByHeightCache: lru.New[uint64, types.Difficulty](1024), difficultyByHeightCache: cache,
} }
} }

View file

@ -1,7 +1,7 @@
package utils package utils
import ( import (
"github.com/floatdrop/lru" "github.com/hashicorp/golang-lru/v2"
"sync" "sync"
"sync/atomic" "sync/atomic"
) )
@ -15,7 +15,7 @@ type Cache[K comparable, T any] interface {
} }
type LRUCache[K comparable, T any] struct { type LRUCache[K comparable, T any] struct {
values atomic.Pointer[lru.LRU[K, T]] values atomic.Pointer[lru.Cache[K, T]]
hits, misses atomic.Uint64 hits, misses atomic.Uint64
size int size int
} }
@ -29,9 +29,9 @@ func NewLRUCache[K comparable, T any](size int) *LRUCache[K, T] {
} }
func (c *LRUCache[K, T]) Get(key K) (value T, ok bool) { func (c *LRUCache[K, T]) Get(key K) (value T, ok bool) {
if v := c.values.Load().Get(key); v != nil { if value, ok = c.values.Load().Get(key); !ok {
c.hits.Add(1) c.hits.Add(1)
return *v, true return value, true
} else { } else {
c.misses.Add(1) c.misses.Add(1)
return value, false return value, false
@ -39,7 +39,7 @@ func (c *LRUCache[K, T]) Get(key K) (value T, ok bool) {
} }
func (c *LRUCache[K, T]) Set(key K, value T) { func (c *LRUCache[K, T]) Set(key K, value T) {
c.values.Load().Set(key, value) c.values.Load().Add(key, value)
} }
func (c *LRUCache[K, T]) Delete(key K) { func (c *LRUCache[K, T]) Delete(key K) {
@ -47,7 +47,11 @@ func (c *LRUCache[K, T]) Delete(key K) {
} }
func (c *LRUCache[K, T]) Clear() { func (c *LRUCache[K, T]) Clear() {
c.values.Store(lru.New[K, T](c.size)) cache, err := lru.New[K, T](c.size)
if err != nil {
panic(err)
}
c.values.Store(cache)
} }
func (c *LRUCache[K, T]) Stats() (hits, misses uint64) { func (c *LRUCache[K, T]) Stats() (hits, misses uint64) {