From 4cae1b94e977707ca4a5c7277dc0c1a6c1b6bd48 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Mon, 6 Feb 2023 10:15:52 +0700 Subject: [PATCH] switch sentinel to native go errors (#6782) --- cl/cltypes/block_requests.go | 7 ++++--- cmd/sentinel/sentinel/config.go | 3 +-- cmd/sentinel/sentinel/discovery.go | 4 ++-- cmd/sentinel/sentinel/sentinel.go | 3 +-- cmd/sentinel/sentinel/utils.go | 13 ++++++------- go.mod | 12 ++++++------ go.sum | 20 ++++++++++---------- 7 files changed, 30 insertions(+), 32 deletions(-) diff --git a/cl/cltypes/block_requests.go b/cl/cltypes/block_requests.go index 3d90f6cf4..7f762f5fe 100644 --- a/cl/cltypes/block_requests.go +++ b/cl/cltypes/block_requests.go @@ -1,8 +1,9 @@ package cltypes import ( + "fmt" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" - "github.com/pkg/errors" ) const ( @@ -30,7 +31,7 @@ func (r *BeaconBlocksByRootRequest) HashSSZ() ([32]byte, error) { // EncodeSSZ Marshals the block by roots request type into the serialized object. func (r *BeaconBlocksByRootRequest) EncodeSSZ(dst []byte) ([]byte, error) { if len(*r) > maxRequestBlocks { - return nil, errors.Errorf("beacon block by roots request exceeds max size: %d > %d", len(*r), maxRequestBlocks) + return nil, fmt.Errorf("beacon block by roots request exceeds max size: %d > %d", len(*r), maxRequestBlocks) } buf := make([]byte, 0, r.EncodingSizeSSZ()) for _, r := range *r { @@ -50,7 +51,7 @@ func (r *BeaconBlocksByRootRequest) DecodeSSZ(buf []byte) error { bufLen := len(buf) maxLength := maxRequestBlocks * rootLength if bufLen > maxLength { - return errors.Errorf("expected buffer with length of upto %d but received length %d", maxLength, bufLen) + return fmt.Errorf("expected buffer with length of upto %d but received length %d", maxLength, bufLen) } if bufLen%rootLength != 0 { return ssz_utils.ErrBufferNotRounded diff --git a/cmd/sentinel/sentinel/config.go b/cmd/sentinel/sentinel/config.go index e80384758..22385135d 100644 --- a/cmd/sentinel/sentinel/config.go +++ b/cmd/sentinel/sentinel/config.go @@ -26,7 +26,6 @@ import ( "github.com/libp2p/go-libp2p/p2p/security/noise" "github.com/libp2p/go-libp2p/p2p/transport/tcp" "github.com/multiformats/go-multiaddr" - "github.com/pkg/errors" ) type SentinelConfig struct { @@ -68,7 +67,7 @@ func privKeyOption(privkey *ecdsa.PrivateKey) libp2p.Option { func multiAddressBuilder(ipAddr string, port uint) (multiaddr.Multiaddr, error) { parsedIP := net.ParseIP(ipAddr) if parsedIP.To4() == nil && parsedIP.To16() == nil { - return nil, errors.Errorf("invalid ip address provided: %s", ipAddr) + return nil, fmt.Errorf("invalid ip address provided: %s", ipAddr) } if parsedIP.To4() != nil { return multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d", ipAddr, port)) diff --git a/cmd/sentinel/sentinel/discovery.go b/cmd/sentinel/sentinel/discovery.go index 7775df408..8a7964fb2 100644 --- a/cmd/sentinel/sentinel/discovery.go +++ b/cmd/sentinel/sentinel/discovery.go @@ -15,6 +15,7 @@ package sentinel import ( "context" + "fmt" "time" "github.com/ledgerwatch/erigon/cl/clparams" @@ -26,7 +27,6 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/multiformats/go-multiaddr" - "github.com/pkg/errors" "github.com/prysmaticlabs/go-bitfield" ) @@ -35,7 +35,7 @@ func (s *Sentinel) connectWithPeer(ctx context.Context, info peer.AddrInfo, skip return nil } if s.peers.IsBadPeer(info.ID) { - return errors.New("refused to connect to bad peer") + return fmt.Errorf("refused to connect to bad peer") } ctxWithTimeout, cancel := context.WithTimeout(ctx, clparams.MaxDialTimeout) defer cancel() diff --git a/cmd/sentinel/sentinel/sentinel.go b/cmd/sentinel/sentinel/sentinel.go index 81dcbebb5..37af0202f 100644 --- a/cmd/sentinel/sentinel/sentinel.go +++ b/cmd/sentinel/sentinel/sentinel.go @@ -37,7 +37,6 @@ import ( pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/p2p/protocol/identify" - "github.com/pkg/errors" ) type Sentinel struct { @@ -65,7 +64,7 @@ func (s *Sentinel) createLocalNode( ) (*enode.LocalNode, error) { db, err := enode.OpenDB("") if err != nil { - return nil, errors.Wrap(err, "could not open node's peer database") + return nil, fmt.Errorf("could not open node's peer database: %w", err) } localNode := enode.NewLocalNode(db, privKey) diff --git a/cmd/sentinel/sentinel/utils.go b/cmd/sentinel/sentinel/utils.go index a67422160..39a1afe39 100644 --- a/cmd/sentinel/sentinel/utils.go +++ b/cmd/sentinel/sentinel/utils.go @@ -28,18 +28,17 @@ import ( "github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/peer" "github.com/multiformats/go-multiaddr" - "github.com/pkg/errors" ) func convertToInterfacePubkey(pubkey *ecdsa.PublicKey) (crypto.PubKey, error) { xVal, yVal := new(btcec.FieldVal), new(btcec.FieldVal) overflows := xVal.SetByteSlice(pubkey.X.Bytes()) if overflows { - return nil, errors.Errorf("X value overflows") + return nil, fmt.Errorf("X value overflows") } overflows = yVal.SetByteSlice(pubkey.Y.Bytes()) if overflows { - return nil, errors.Errorf("Y value overflows") + return nil, fmt.Errorf("Y value overflows") } newKey := crypto.PubKey((*crypto.Secp256k1PublicKey)(btcec.NewPublicKey(xVal, yVal))) // Zero out temporary values. @@ -64,11 +63,11 @@ func convertToSingleMultiAddr(node *enode.Node) (multiaddr.Multiaddr, error) { pubkey := node.Pubkey() assertedKey, err := convertToInterfacePubkey(pubkey) if err != nil { - return nil, errors.Wrap(err, "could not get pubkey") + return nil, fmt.Errorf("could not get pubkey: %w", err) } id, err := peer.IDFromPublicKey(assertedKey) if err != nil { - return nil, errors.Wrap(err, "could not get peer id") + return nil, fmt.Errorf("could not get peer id: %w", err) } return multiAddressBuilderWithID(node.IP().String(), "tcp", uint(node.TCP()), id) } @@ -76,10 +75,10 @@ func convertToSingleMultiAddr(node *enode.Node) (multiaddr.Multiaddr, error) { func multiAddressBuilderWithID(ipAddr, protocol string, port uint, id peer.ID) (multiaddr.Multiaddr, error) { parsedIP := net.ParseIP(ipAddr) if parsedIP.To4() == nil && parsedIP.To16() == nil { - return nil, errors.Errorf("invalid ip address provided: %s", ipAddr) + return nil, fmt.Errorf("invalid ip address provided: %s", ipAddr) } if id.String() == "" { - return nil, errors.New("empty peer id given") + return nil, fmt.Errorf("empty peer id given") } if parsedIP.To4() != nil { return multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/%s/%d/p2p/%s", ipAddr, protocol, port, id.String())) diff --git a/go.mod b/go.mod index 2789ce7be..146dbb1ae 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon go 1.18 require ( - github.com/ledgerwatch/erigon-lib v0.0.0-20230203104538-738655e9e695 + github.com/ledgerwatch/erigon-lib v0.0.0-20230206025430-9d7928f2d3b1 github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230120022649-cd9409a200da github.com/ledgerwatch/log/v3 v3.7.0 github.com/ledgerwatch/secp256k1 v1.0.0 @@ -51,7 +51,7 @@ require ( github.com/json-iterator/go v1.1.12 github.com/julienschmidt/httprouter v1.3.0 github.com/kevinburke/go-bindata v3.21.0+incompatible - github.com/klauspost/compress v1.15.10 + github.com/klauspost/compress v1.15.15 github.com/libp2p/go-libp2p v0.23.2 github.com/libp2p/go-libp2p-core v0.20.1 github.com/libp2p/go-libp2p-pubsub v0.8.1 @@ -63,12 +63,11 @@ require ( github.com/pelletier/go-toml v1.9.5 github.com/pelletier/go-toml/v2 v2.0.6 github.com/pion/stun v0.3.5 - github.com/pkg/errors v0.9.1 github.com/prysmaticlabs/fastssz v0.0.0-20220628121656-93dfe28febab github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7 github.com/prysmaticlabs/gohashtree v0.0.2-alpha github.com/quasilyte/go-ruleguard/dsl v0.3.22 - github.com/rs/cors v1.8.2 + github.com/rs/cors v1.8.3 github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.1 @@ -84,7 +83,7 @@ require ( go.uber.org/atomic v1.10.0 go.uber.org/zap v1.23.0 golang.org/x/crypto v0.5.0 - golang.org/x/exp v0.0.0-20230118134722-a68e582fa157 + golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9 golang.org/x/net v0.5.0 golang.org/x/sync v0.1.0 golang.org/x/sys v0.4.0 @@ -95,7 +94,7 @@ require ( gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c gopkg.in/yaml.v2 v2.4.0 modernc.org/sqlite v1.20.3 - pgregory.net/rapid v0.5.3 + pgregory.net/rapid v0.5.5 ) require ( @@ -217,6 +216,7 @@ require ( github.com/pion/turn/v2 v2.0.8 // indirect github.com/pion/udp v0.1.1 // indirect github.com/pion/webrtc/v3 v3.1.42 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.13.0 // indirect github.com/prometheus/client_model v0.2.0 // indirect diff --git a/go.sum b/go.sum index c533fd39a..40b1edeb3 100644 --- a/go.sum +++ b/go.sum @@ -529,8 +529,8 @@ github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQL github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= -github.com/klauspost/compress v1.15.10 h1:Ai8UzuomSCDw90e1qNMtb15msBXsNpH6gzkkENQNcJo= -github.com/klauspost/compress v1.15.10/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= +github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw= +github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4= github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.1.1 h1:t0wUqjowdm8ezddV5k0tLWVklVuvLJpoHeb4WBdydm0= @@ -555,8 +555,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= -github.com/ledgerwatch/erigon-lib v0.0.0-20230203104538-738655e9e695 h1:y/Ct3sY3GK3fK8dR/moLhQpoNKuOqcvcaMbE30qLx4I= -github.com/ledgerwatch/erigon-lib v0.0.0-20230203104538-738655e9e695/go.mod h1:cJSGIvVSkCmqdwOjskY+WnugOz5NVFs0EllQ4UN+rr4= +github.com/ledgerwatch/erigon-lib v0.0.0-20230206025430-9d7928f2d3b1 h1:skPfNvfGT8Bwid9x0egUVXOyEsAqBqA4DGqLwp9imIc= +github.com/ledgerwatch/erigon-lib v0.0.0-20230206025430-9d7928f2d3b1/go.mod h1:cJSGIvVSkCmqdwOjskY+WnugOz5NVFs0EllQ4UN+rr4= github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230120022649-cd9409a200da h1:lQQBOHzAUThkymfXJj/m07vAjyMx9XoMMy3OomaeOrA= github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230120022649-cd9409a200da/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo= github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og= @@ -858,8 +858,8 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U= -github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= +github.com/rs/cors v1.8.3 h1:O+qNyWn7Z+F9M0ILBHgMVPuB1xTOucVd5gtaYyXBpRo= +github.com/rs/cors v1.8.3/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417 h1:Lt9DzQALzHoDwMBGJ6v8ObDPR0dzr2a6sXTB1Fq7IHs= github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417/go.mod h1:qe5TWALJ8/a1Lqznoc5BDHpYX/8HU60Hm2AwRmqzxqA= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= @@ -1056,8 +1056,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20230118134722-a68e582fa157 h1:fiNkyhJPUvxbRPbCqY/D9qdjmPzfHcpK3P4bM4gioSY= -golang.org/x/exp v0.0.0-20230118134722-a68e582fa157/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9 h1:frX3nT9RkKybPnjyI+yvZh6ZucTZatCCEm9D47sZ2zo= +golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -1488,8 +1488,8 @@ modernc.org/tcl v1.15.0 h1:oY+JeD11qVVSgVvodMJsu7Edf8tr5E/7tuhF5cNYz34= modernc.org/token v1.0.1 h1:A3qvTqOwexpfZZeyI0FeGPDlSWX5pjZu9hF4lU+EKWg= modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= modernc.org/z v1.7.0 h1:xkDw/KepgEjeizO2sNco+hqYkU12taxQFqPEmgm1GWE= -pgregory.net/rapid v0.5.3 h1:163N50IHFqr1phZens4FQOdPgfJscR7a562mjQqeo4M= -pgregory.net/rapid v0.5.3/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= +pgregory.net/rapid v0.5.5 h1:jkgx1TjbQPD/feRoK+S/mXw9e1uj6WilpHrXJowi6oA= +pgregory.net/rapid v0.5.5/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=