mirror of
https://github.com/tendermint/tendermint.git
synced 2026-05-01 12:55:44 +00:00
change use of errors.Wrap to fmt.Errorf with %w verb
Closes #4603 Commands used (VIM): ``` :args `rg -l errors.Wrap` :argdo normal @q | update ``` where q is a macros rewriting the `errors.Wrap` to `fmt.Errorf`.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package v0
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
@@ -64,7 +64,7 @@ func newBlockchainReactor(
|
||||
proxyApp := proxy.NewAppConns(cc)
|
||||
err := proxyApp.Start()
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "error start app"))
|
||||
panic(fmt.Errorf("error start app: %w", err))
|
||||
}
|
||||
|
||||
blockDB := dbm.NewMemDB()
|
||||
@@ -73,7 +73,7 @@ func newBlockchainReactor(
|
||||
|
||||
state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "error constructing state from genesis file"))
|
||||
panic(fmt.Errorf("error constructing state from genesis file: %w", err))
|
||||
}
|
||||
|
||||
// Make the BlockchainReactor itself.
|
||||
@@ -114,7 +114,7 @@ func newBlockchainReactor(
|
||||
|
||||
state, _, err = blockExec.ApplyBlock(state, blockID, thisBlock)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "error apply block"))
|
||||
panic(fmt.Errorf("error apply block: %w", err))
|
||||
}
|
||||
|
||||
blockStore.SaveBlock(thisBlock, thisParts, lastCommit)
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -94,7 +93,7 @@ func newBlockchainReactor(
|
||||
proxyApp := proxy.NewAppConns(cc)
|
||||
err := proxyApp.Start()
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "error start app"))
|
||||
panic(fmt.Errorf("error start app: %w", err))
|
||||
}
|
||||
|
||||
blockDB := dbm.NewMemDB()
|
||||
@@ -103,7 +102,7 @@ func newBlockchainReactor(
|
||||
|
||||
state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "error constructing state from genesis file"))
|
||||
panic(fmt.Errorf("error constructing state from genesis file: %w", err))
|
||||
}
|
||||
|
||||
// Make the BlockchainReactor itself.
|
||||
@@ -133,7 +132,7 @@ func newBlockchainReactor(
|
||||
|
||||
state, _, err = blockExec.ApplyBlock(state, blockID, thisBlock)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "error apply block"))
|
||||
panic(fmt.Errorf("error apply block: %w", err))
|
||||
}
|
||||
|
||||
blockStore.SaveBlock(thisBlock, thisParts, lastCommit)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"sort"
|
||||
@@ -8,7 +9,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
@@ -149,7 +149,7 @@ func newTestReactor(p testReactorParams) *BlockchainReactor {
|
||||
proxyApp := proxy.NewAppConns(cc)
|
||||
err := proxyApp.Start()
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "error start app"))
|
||||
panic(fmt.Errorf("error start app: %w", err))
|
||||
}
|
||||
db := dbm.NewMemDB()
|
||||
appl = sm.NewBlockExecutor(db, p.logger, proxyApp.Consensus(), mock.Mempool{}, sm.MockEvidencePool{})
|
||||
@@ -480,7 +480,7 @@ func newReactorStore(
|
||||
proxyApp := proxy.NewAppConns(cc)
|
||||
err := proxyApp.Start()
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "error start app"))
|
||||
panic(fmt.Errorf("error start app: %w", err))
|
||||
}
|
||||
|
||||
stateDB := dbm.NewMemDB()
|
||||
@@ -488,7 +488,7 @@ func newReactorStore(
|
||||
|
||||
state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "error constructing state from genesis file"))
|
||||
panic(fmt.Errorf("error constructing state from genesis file: %w", err))
|
||||
}
|
||||
|
||||
db := dbm.NewMemDB()
|
||||
@@ -524,7 +524,7 @@ func newReactorStore(
|
||||
|
||||
state, _, err = blockExec.ApplyBlock(state, blockID, thisBlock)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "error apply block"))
|
||||
panic(fmt.Errorf("error apply block: %w", err))
|
||||
}
|
||||
|
||||
blockStore.SaveBlock(thisBlock, thisParts, lastCommit)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package debug
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
@@ -55,13 +55,13 @@ func dumpCmdHandler(_ *cobra.Command, args []string) error {
|
||||
|
||||
if _, err := os.Stat(outDir); os.IsNotExist(err) {
|
||||
if err := os.Mkdir(outDir, os.ModePerm); err != nil {
|
||||
return errors.Wrap(err, "failed to create output directory")
|
||||
return fmt.Errorf("failed to create output directory: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
rpc, err := rpchttp.New(nodeRPCAddr, "/websocket")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create new http client")
|
||||
return fmt.Errorf("failed to create new http client: %w", err)
|
||||
}
|
||||
|
||||
home := viper.GetString(cli.HomeFlag)
|
||||
|
||||
@@ -3,14 +3,13 @@ package debug
|
||||
import (
|
||||
"archive/zip"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// zipDir zips all the contents found in src, including both files and
|
||||
@@ -110,7 +109,7 @@ func copyFile(src, dest string) error {
|
||||
func writeStateJSONToFile(state interface{}, dir, filename string) error {
|
||||
stateJSON, err := json.MarshalIndent(state, "", " ")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to encode state dump")
|
||||
return fmt.Errorf("failed to encode state dump: %w", err)
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(path.Join(dir, filename), stateJSON, os.ModePerm)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package debug
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -10,7 +11,6 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
@@ -46,7 +46,7 @@ func killCmdHandler(cmd *cobra.Command, args []string) error {
|
||||
|
||||
rpc, err := rpchttp.New(nodeRPCAddr, "/websocket")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create new http client")
|
||||
return fmt.Errorf("failed to create new http client: %w", err)
|
||||
}
|
||||
|
||||
home := viper.GetString(cli.HomeFlag)
|
||||
@@ -58,7 +58,7 @@ func killCmdHandler(cmd *cobra.Command, args []string) error {
|
||||
// relevant files and directories that will be compressed into a file.
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "tendermint_debug_tmp")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temporary directory")
|
||||
return fmt.Errorf("failed to create temporary directory: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
||||
)
|
||||
@@ -19,7 +17,7 @@ import (
|
||||
func dumpStatus(rpc *rpchttp.HTTP, dir, filename string) error {
|
||||
status, err := rpc.Status()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get node status")
|
||||
return fmt.Errorf("failed to get node status: %w", err)
|
||||
}
|
||||
|
||||
return writeStateJSONToFile(status, dir, filename)
|
||||
@@ -30,7 +28,7 @@ func dumpStatus(rpc *rpchttp.HTTP, dir, filename string) error {
|
||||
func dumpNetInfo(rpc *rpchttp.HTTP, dir, filename string) error {
|
||||
netInfo, err := rpc.NetInfo()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get node network information")
|
||||
return fmt.Errorf("failed to get node network information: %w", err)
|
||||
}
|
||||
|
||||
return writeStateJSONToFile(netInfo, dir, filename)
|
||||
@@ -41,7 +39,7 @@ func dumpNetInfo(rpc *rpchttp.HTTP, dir, filename string) error {
|
||||
func dumpConsensusState(rpc *rpchttp.HTTP, dir, filename string) error {
|
||||
consDump, err := rpc.DumpConsensusState()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get node consensus dump")
|
||||
return fmt.Errorf("failed to get node consensus dump: %w", err)
|
||||
}
|
||||
|
||||
return writeStateJSONToFile(consDump, dir, filename)
|
||||
@@ -70,13 +68,13 @@ func dumpProfile(dir, addr, profile string, debug int) error {
|
||||
|
||||
resp, err := http.Get(endpoint) // nolint: gosec
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to query for %s profile", profile)
|
||||
return fmt.Errorf("failed to query for %s profile: %w", profile, err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to read %s profile response body", profile)
|
||||
return fmt.Errorf("failed to read %s profile response body: %w", profile, err)
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(path.Join(dir, fmt.Sprintf("%s.out", profile)), body, os.ModePerm)
|
||||
|
||||
@@ -3,7 +3,6 @@ package commands
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
@@ -64,7 +63,7 @@ func initFilesWithConfig(config *cfg.Config) error {
|
||||
}
|
||||
pubKey, err := pv.GetPubKey()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "can't get pubkey")
|
||||
return fmt.Errorf("can't get pubkey: %w", err)
|
||||
}
|
||||
genDoc.Validators = []types.GenesisValidator{{
|
||||
Address: pubKey.Address(),
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/tendermint/go-amino"
|
||||
@@ -102,7 +102,7 @@ func runProxy(cmd *cobra.Command, args []string) error {
|
||||
|
||||
db, err := dbm.NewGoLevelDB("lite-client-db", home)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "new goleveldb")
|
||||
return fmt.Errorf("new goleveldb: %w", err)
|
||||
}
|
||||
|
||||
var c *lite.Client
|
||||
@@ -135,7 +135,7 @@ func runProxy(cmd *cobra.Command, args []string) error {
|
||||
|
||||
rpcClient, err := rpchttp.New(primaryAddr, "/websocket")
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "http client for %s", primaryAddr)
|
||||
return fmt.Errorf("http client for %s: %w", primaryAddr, err)
|
||||
}
|
||||
p := lproxy.Proxy{
|
||||
Addr: listenAddr,
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
@@ -138,18 +137,18 @@ func checkGenesisHash(config *cfg.Config) error {
|
||||
// Calculate SHA-256 hash of the genesis file.
|
||||
f, err := os.Open(config.GenesisFile())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "can't open genesis file")
|
||||
return fmt.Errorf("can't open genesis file: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
h := sha256.New()
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
return errors.Wrap(err, "error when hashing genesis file")
|
||||
return fmt.Errorf("error when hashing genesis file: %w", err)
|
||||
}
|
||||
actualHash := h.Sum(nil)
|
||||
|
||||
// Compare with the flag.
|
||||
if !bytes.Equal(genesisHash, actualHash) {
|
||||
return errors.Errorf(
|
||||
return fmt.Errorf(
|
||||
"--genesis_hash=%X does not match %s hash: %X",
|
||||
genesisHash, config.GenesisFile(), actualHash)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package commands
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
@@ -27,12 +26,12 @@ func showValidator(cmd *cobra.Command, args []string) error {
|
||||
|
||||
pubKey, err := pv.GetPubKey()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "can't get pubkey")
|
||||
return fmt.Errorf("can't get pubkey: %w", err)
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(pubKey)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to marshal private validator pubkey")
|
||||
return fmt.Errorf("failed to marshal private validator pubkey: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println(string(bz))
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
@@ -142,7 +141,7 @@ func testnetFiles(cmd *cobra.Command, args []string) error {
|
||||
|
||||
pubKey, err := pv.GetPubKey()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "can't get pubkey")
|
||||
return fmt.Errorf("can't get pubkey: %w", err)
|
||||
}
|
||||
genVals[i] = types.GenesisValidator{
|
||||
Address: pubKey.Address(),
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-kit/kit/log/term"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"path"
|
||||
@@ -92,7 +91,7 @@ func (vs *validatorStub) signVote(
|
||||
|
||||
pubKey, err := vs.PrivValidator.GetPubKey()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "can't get pubkey")
|
||||
return nil, fmt.Errorf("can't get pubkey: %w", err)
|
||||
}
|
||||
|
||||
vote := &types.Vote{
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package consensus
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
cstypes "github.com/tendermint/tendermint/consensus/types"
|
||||
@@ -1469,7 +1468,7 @@ func (m *NewValidBlockMessage) ValidateBasic() error {
|
||||
m.BlockPartsHeader.Total)
|
||||
}
|
||||
if m.BlockParts.Size() > types.MaxBlockPartsCount {
|
||||
return errors.Errorf("blockParts bit array is too big: %d, max: %d", m.BlockParts.Size(), types.MaxBlockPartsCount)
|
||||
return fmt.Errorf("blockParts bit array is too big: %d, max: %d", m.BlockParts.Size(), types.MaxBlockPartsCount)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1518,7 +1517,7 @@ func (m *ProposalPOLMessage) ValidateBasic() error {
|
||||
return errors.New("empty ProposalPOL bit array")
|
||||
}
|
||||
if m.ProposalPOL.Size() > types.MaxVotesCount {
|
||||
return errors.Errorf("ProposalPOL bit array is too big: %d, max: %d", m.ProposalPOL.Size(), types.MaxVotesCount)
|
||||
return fmt.Errorf("proposalPOL bit array is too big: %d, max: %d", m.ProposalPOL.Size(), types.MaxVotesCount)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -773,7 +773,7 @@ func TestProposalPOLMessageValidateBasic(t *testing.T) {
|
||||
{func(msg *ProposalPOLMessage) { msg.ProposalPOLRound = -1 }, "negative ProposalPOLRound"},
|
||||
{func(msg *ProposalPOLMessage) { msg.ProposalPOL = bits.NewBitArray(0) }, "empty ProposalPOL bit array"},
|
||||
{func(msg *ProposalPOLMessage) { msg.ProposalPOL = bits.NewBitArray(types.MaxVotesCount + 1) },
|
||||
"ProposalPOL bit array is too big: 10001, max: 10000"},
|
||||
"proposalPOL bit array is too big: 10001, max: 10000"},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
|
||||
@@ -3,13 +3,13 @@ package consensus
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
@@ -55,7 +55,7 @@ func (cs *State) ReplayFile(file string, console bool) error {
|
||||
ctx := context.Background()
|
||||
newStepSub, err := cs.eventBus.Subscribe(ctx, subscriber, types.EventQueryNewRoundStep)
|
||||
if err != nil {
|
||||
return errors.Errorf("failed to subscribe %s to %v", subscriber, types.EventQueryNewRoundStep)
|
||||
return fmt.Errorf("failed to subscribe %s to %v", subscriber, types.EventQueryNewRoundStep)
|
||||
}
|
||||
defer cs.eventBus.Unsubscribe(ctx, subscriber, types.EventQueryNewRoundStep)
|
||||
|
||||
|
||||
@@ -2,14 +2,13 @@ package consensus
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/fail"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
@@ -1738,7 +1737,7 @@ func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) {
|
||||
} else if voteErr, ok := err.(*types.ErrVoteConflictingVotes); ok {
|
||||
pubKey, err := cs.privValidator.GetPubKey()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "can't get pubkey")
|
||||
return false, fmt.Errorf("can't get pubkey: %w", err)
|
||||
}
|
||||
|
||||
if bytes.Equal(vote.ValidatorAddress, pubKey.Address()) {
|
||||
@@ -1945,7 +1944,7 @@ func (cs *State) signVote(
|
||||
|
||||
pubKey, err := cs.privValidator.GetPubKey()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "can't get pubkey")
|
||||
return nil, fmt.Errorf("can't get pubkey: %w", err)
|
||||
}
|
||||
addr := pubKey.Address()
|
||||
valIdx, _ := cs.Validators.GetByAddress(addr)
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
auto "github.com/tendermint/tendermint/libs/autofile"
|
||||
@@ -97,7 +95,7 @@ var _ WAL = &BaseWAL{}
|
||||
func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*BaseWAL, error) {
|
||||
err := tmos.EnsureDir(filepath.Dir(walFile), 0700)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to ensure WAL directory is in place")
|
||||
return nil, fmt.Errorf("failed to ensure WAL directory is in place: %w", err)
|
||||
}
|
||||
|
||||
group, err := auto.OpenGroup(walFile, groupOptions...)
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
db "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||
@@ -46,13 +44,13 @@ func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) {
|
||||
privValidator := privval.LoadOrGenFilePV(privValidatorKeyFile, privValidatorStateFile)
|
||||
genDoc, err := types.GenesisDocFromFile(config.GenesisFile())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read genesis file")
|
||||
return fmt.Errorf("failed to read genesis file: %w", err)
|
||||
}
|
||||
blockStoreDB := db.NewMemDB()
|
||||
stateDB := blockStoreDB
|
||||
state, err := sm.MakeGenesisState(genDoc)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to make genesis state")
|
||||
return fmt.Errorf("failed to make genesis state: %w", err)
|
||||
}
|
||||
state.Version.Consensus.App = kvstore.ProtocolVersion
|
||||
sm.SaveState(stateDB, state)
|
||||
@@ -61,14 +59,14 @@ func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) {
|
||||
proxyApp := proxy.NewAppConns(proxy.NewLocalClientCreator(app))
|
||||
proxyApp.SetLogger(logger.With("module", "proxy"))
|
||||
if err := proxyApp.Start(); err != nil {
|
||||
return errors.Wrap(err, "failed to start proxy app connections")
|
||||
return fmt.Errorf("failed to start proxy app connections: %w", err)
|
||||
}
|
||||
defer proxyApp.Stop()
|
||||
|
||||
eventBus := types.NewEventBus()
|
||||
eventBus.SetLogger(logger.With("module", "events"))
|
||||
if err := eventBus.Start(); err != nil {
|
||||
return errors.Wrap(err, "failed to start event bus")
|
||||
return fmt.Errorf("failed to start event bus: %w", err)
|
||||
}
|
||||
defer eventBus.Stop()
|
||||
mempool := emptyMempool{}
|
||||
@@ -91,7 +89,7 @@ func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) {
|
||||
consensusState.wal = wal
|
||||
|
||||
if err := consensusState.Start(); err != nil {
|
||||
return errors.Wrap(err, "failed to start consensus state")
|
||||
return fmt.Errorf("failed to start consensus state: %w", err)
|
||||
}
|
||||
|
||||
select {
|
||||
|
||||
@@ -2,8 +2,8 @@ package merkle
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
//----------------------------------------
|
||||
@@ -44,11 +44,11 @@ func (poz ProofOperators) Verify(root []byte, keypath string, args [][]byte) (er
|
||||
key := op.GetKey()
|
||||
if len(key) != 0 {
|
||||
if len(keys) == 0 {
|
||||
return errors.Errorf("key path has insufficient # of parts: expected no more keys but got %+v", string(key))
|
||||
return fmt.Errorf("key path has insufficient # of parts: expected no more keys but got %+v", string(key))
|
||||
}
|
||||
lastKey := keys[len(keys)-1]
|
||||
if !bytes.Equal(lastKey, key) {
|
||||
return errors.Errorf("key mismatch on operation #%d: expected %+v but got %+v", i, string(lastKey), string(key))
|
||||
return fmt.Errorf("key mismatch on operation #%d: expected %+v but got %+v", i, string(lastKey), string(key))
|
||||
}
|
||||
keys = keys[:len(keys)-1]
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func (poz ProofOperators) Verify(root []byte, keypath string, args [][]byte) (er
|
||||
}
|
||||
}
|
||||
if !bytes.Equal(root, args[0]) {
|
||||
return errors.Errorf("calculated root hash is invalid: expected %+v but got %+v", root, args[0])
|
||||
return fmt.Errorf("calculated root hash is invalid: expected %+v but got %+v", root, args[0])
|
||||
}
|
||||
if len(keys) != 0 {
|
||||
return errors.New("keypath not consumed all")
|
||||
@@ -92,7 +92,7 @@ func (prt *ProofRuntime) RegisterOpDecoder(typ string, dec OpDecoder) {
|
||||
func (prt *ProofRuntime) Decode(pop ProofOp) (ProofOperator, error) {
|
||||
decoder := prt.decoders[pop.Type]
|
||||
if decoder == nil {
|
||||
return nil, errors.Errorf("unrecognized proof type %v", pop.Type)
|
||||
return nil, fmt.Errorf("unrecognized proof type %v", pop.Type)
|
||||
}
|
||||
return decoder(pop)
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func (prt *ProofRuntime) DecodeProof(proof *Proof) (ProofOperators, error) {
|
||||
for _, pop := range proof.Ops {
|
||||
operator, err := prt.Decode(pop)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "decoding a proof operator")
|
||||
return nil, fmt.Errorf("decoding a proof operator: %w", err)
|
||||
}
|
||||
poz = append(poz, operator)
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func (prt *ProofRuntime) VerifyAbsence(proof *Proof, root []byte, keypath string
|
||||
func (prt *ProofRuntime) Verify(proof *Proof, root []byte, keypath string, args [][]byte) (err error) {
|
||||
poz, err := prt.DecodeProof(proof)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "decoding proof")
|
||||
return fmt.Errorf("decoding proof: %w", err)
|
||||
}
|
||||
return poz.Verify(root, keypath, args)
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@ package merkle
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -96,13 +95,13 @@ func KeyPathToKeys(path string) (keys [][]byte, err error) {
|
||||
hexPart := part[2:]
|
||||
key, err := hex.DecodeString(hexPart)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "decoding hex-encoded part #%d: /%s", i, part)
|
||||
return nil, fmt.Errorf("decoding hex-encoded part #%d: /%s: %w", i, part, err)
|
||||
}
|
||||
keys[i] = key
|
||||
} else {
|
||||
key, err := url.PathUnescape(part)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "decoding url-encoded part #%d: /%s", i, part)
|
||||
return nil, fmt.Errorf("decoding url-encoded part #%d: /%s: %w", i, part, err)
|
||||
}
|
||||
keys[i] = []byte(key) // TODO Test this with random bytes, I'm not sure that it works for arbitrary bytes...
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
)
|
||||
|
||||
@@ -40,12 +38,12 @@ func NewSimpleValueOp(key []byte, proof *SimpleProof) SimpleValueOp {
|
||||
|
||||
func SimpleValueOpDecoder(pop ProofOp) (ProofOperator, error) {
|
||||
if pop.Type != ProofOpSimpleValue {
|
||||
return nil, errors.Errorf("unexpected ProofOp.Type; got %v, want %v", pop.Type, ProofOpSimpleValue)
|
||||
return nil, fmt.Errorf("unexpected ProofOp.Type; got %v, want %v", pop.Type, ProofOpSimpleValue)
|
||||
}
|
||||
var op SimpleValueOp // a bit strange as we'll discard this, but it works.
|
||||
err := cdc.UnmarshalBinaryLengthPrefixed(pop.Data, &op)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "decoding ProofOp.Data into SimpleValueOp")
|
||||
return nil, fmt.Errorf("decoding ProofOp.Data into SimpleValueOp: %w", err)
|
||||
}
|
||||
return NewSimpleValueOp(pop.Key, op.Proof), nil
|
||||
}
|
||||
@@ -65,7 +63,7 @@ func (op SimpleValueOp) String() string {
|
||||
|
||||
func (op SimpleValueOp) Run(args [][]byte) ([][]byte, error) {
|
||||
if len(args) != 1 {
|
||||
return nil, errors.Errorf("expected 1 arg, got %v", len(args))
|
||||
return nil, fmt.Errorf("expected 1 arg, got %v", len(args))
|
||||
}
|
||||
value := args[0]
|
||||
hasher := tmhash.New()
|
||||
@@ -79,7 +77,7 @@ func (op SimpleValueOp) Run(args [][]byte) ([][]byte, error) {
|
||||
kvhash := leafHash(bz.Bytes())
|
||||
|
||||
if !bytes.Equal(kvhash, op.Proof.LeafHash) {
|
||||
return nil, errors.Errorf("leaf hash mismatch: want %X got %X", op.Proof.LeafHash, kvhash)
|
||||
return nil, fmt.Errorf("leaf hash mismatch: want %X got %X", op.Proof.LeafHash, kvhash)
|
||||
}
|
||||
|
||||
return [][]byte{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package merkle
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
)
|
||||
@@ -34,7 +35,7 @@ func DominoOpDecoder(pop ProofOp) (ProofOperator, error) {
|
||||
var op DominoOp // a bit strange as we'll discard this, but it works.
|
||||
err := amino.UnmarshalBinaryLengthPrefixed(pop.Data, &op)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "decoding ProofOp.Data into SimpleValueOp")
|
||||
return nil, fmt.Errorf("decoding ProofOp.Data into SimpleValueOp: %w", err)
|
||||
}
|
||||
return NewDominoOp(string(pop.Key), op.Input, op.Output), nil
|
||||
}
|
||||
@@ -53,7 +54,7 @@ func (dop DominoOp) Run(input [][]byte) (output [][]byte, err error) {
|
||||
return nil, errors.New("expected input of length 1")
|
||||
}
|
||||
if string(input[0]) != dop.Input {
|
||||
return nil, errors.Errorf("expected input %v, got %v",
|
||||
return nil, fmt.Errorf("expected input %v, got %v",
|
||||
dop.Input, string(input[0]))
|
||||
}
|
||||
return [][]byte{[]byte(dop.Output)}, nil
|
||||
|
||||
@@ -2,10 +2,9 @@ package merkle
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
)
|
||||
|
||||
@@ -58,11 +57,11 @@ func (sp *SimpleProof) Verify(rootHash []byte, leaf []byte) error {
|
||||
return errors.New("proof index cannot be negative")
|
||||
}
|
||||
if !bytes.Equal(sp.LeafHash, leafHash) {
|
||||
return errors.Errorf("invalid leaf hash: wanted %X got %X", leafHash, sp.LeafHash)
|
||||
return fmt.Errorf("invalid leaf hash: wanted %X got %X", leafHash, sp.LeafHash)
|
||||
}
|
||||
computedHash := sp.ComputeRootHash()
|
||||
if !bytes.Equal(computedHash, rootHash) {
|
||||
return errors.Errorf("invalid root hash: wanted %X got %X", rootHash, computedHash)
|
||||
return fmt.Errorf("invalid root hash: wanted %X got %X", rootHash, computedHash)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -103,14 +102,14 @@ func (sp *SimpleProof) ValidateBasic() error {
|
||||
return errors.New("negative Index")
|
||||
}
|
||||
if len(sp.LeafHash) != tmhash.Size {
|
||||
return errors.Errorf("expected LeafHash size to be %d, got %d", tmhash.Size, len(sp.LeafHash))
|
||||
return fmt.Errorf("expected LeafHash size to be %d, got %d", tmhash.Size, len(sp.LeafHash))
|
||||
}
|
||||
if len(sp.Aunts) > MaxAunts {
|
||||
return errors.Errorf("expected no more than %d aunts, got %d", MaxAunts, len(sp.Aunts))
|
||||
return fmt.Errorf("expected no more than %d aunts, got %d", MaxAunts, len(sp.Aunts))
|
||||
}
|
||||
for i, auntHash := range sp.Aunts {
|
||||
if len(auntHash) != tmhash.Size {
|
||||
return errors.Errorf("expected Aunts#%d size to be %d, got %d", i, tmhash.Size, len(auntHash))
|
||||
return fmt.Errorf("expected Aunts#%d size to be %d, got %d", i, tmhash.Size, len(auntHash))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -331,6 +331,7 @@ Put the following code into the "main.go" file:
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -339,7 +340,6 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/dgraph-io/badger"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@@ -393,13 +393,13 @@ func newTendermint(app abci.Application, configFile string) (*nm.Node, error) {
|
||||
config.RootDir = filepath.Dir(filepath.Dir(configFile))
|
||||
viper.SetConfigFile(configFile)
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
return nil, errors.Wrap(err, "viper failed to read config file")
|
||||
return nil, fmt.Errorf("viper failed to read config file: %w", err)
|
||||
}
|
||||
if err := viper.Unmarshal(config); err != nil {
|
||||
return nil, errors.Wrap(err, "viper failed to unmarshal config")
|
||||
return nil, fmt.Errorf("viper failed to unmarshal config: %w", err)
|
||||
}
|
||||
if err := config.ValidateBasic(); err != nil {
|
||||
return nil, errors.Wrap(err, "config is invalid")
|
||||
return nil, fmt.Errorf("config is invalid: %w", err)
|
||||
}
|
||||
|
||||
// create logger
|
||||
@@ -407,7 +407,7 @@ func newTendermint(app abci.Application, configFile string) (*nm.Node, error) {
|
||||
var err error
|
||||
logger, err = tmflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to parse log level")
|
||||
return nil, fmt.Errorf("failed to parse log level: %w", err)
|
||||
}
|
||||
|
||||
// read private validator
|
||||
@@ -419,7 +419,7 @@ func newTendermint(app abci.Application, configFile string) (*nm.Node, error) {
|
||||
// read node key
|
||||
nodeKey, err := p2p.LoadNodeKey(config.NodeKeyFile())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to load node's key")
|
||||
return nil, fmt.Errorf("failed to load node's key: %w", err)
|
||||
}
|
||||
|
||||
// create node
|
||||
@@ -433,7 +433,7 @@ func newTendermint(app abci.Application, configFile string) (*nm.Node, error) {
|
||||
nm.DefaultMetricsProvider(config.Instrumentation),
|
||||
logger)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create new Tendermint node")
|
||||
return nil, fmt.Errorf("failed to create new Tendermint node: %w", err)
|
||||
}
|
||||
|
||||
return node, nil
|
||||
@@ -485,7 +485,7 @@ node, err := nm.NewNode(
|
||||
nm.DefaultMetricsProvider(config.Instrumentation),
|
||||
logger)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create new Tendermint node")
|
||||
return nil, fmt.Errorf("failed to create new Tendermint node: %w", err)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -503,13 +503,13 @@ config := cfg.DefaultConfig()
|
||||
config.RootDir = filepath.Dir(filepath.Dir(configFile))
|
||||
viper.SetConfigFile(configFile)
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
return nil, errors.Wrap(err, "viper failed to read config file")
|
||||
return nil, fmt.Errorf("viper failed to read config file: %w", err)
|
||||
}
|
||||
if err := viper.Unmarshal(config); err != nil {
|
||||
return nil, errors.Wrap(err, "viper failed to unmarshal config")
|
||||
return nil, fmt.Errorf("viper failed to unmarshal config: %w", err)
|
||||
}
|
||||
if err := config.ValidateBasic(); err != nil {
|
||||
return nil, errors.Wrap(err, "config is invalid")
|
||||
return nil, fmt.Errorf("config is invalid: %w", err)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -530,7 +530,7 @@ pv := privval.LoadFilePV(
|
||||
```go
|
||||
nodeKey, err := p2p.LoadNodeKey(config.NodeKeyFile())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to load node's key")
|
||||
return nil, fmt.Errorf("failed to load node's key: %w", err)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -543,7 +543,7 @@ logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
||||
var err error
|
||||
logger, err = tmflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to parse log level")
|
||||
return nil, fmt.Errorf("failed to parse log level: %w", err)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package async
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
//----------------------------------------
|
||||
@@ -144,7 +143,7 @@ func Parallel(tasks ...Task) (trs *TaskResultSet, ok bool) {
|
||||
if pnk := recover(); pnk != nil {
|
||||
atomic.AddInt32(numPanics, 1)
|
||||
// Send panic to taskResultCh.
|
||||
taskResultCh <- TaskResult{nil, errors.Errorf("panic in task %v", pnk)}
|
||||
taskResultCh <- TaskResult{nil, fmt.Errorf("panic in task %v", pnk)}
|
||||
// Closing taskResultCh lets trs.Wait() work.
|
||||
close(taskResultCh)
|
||||
// Decrement waitgroup.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package async
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -125,7 +125,7 @@ func TestParallelRecover(t *testing.T) {
|
||||
// Verify task #0, #1, #2.
|
||||
checkResult(t, taskResultSet, 0, 0, nil, nil)
|
||||
checkResult(t, taskResultSet, 1, 1, errors.New("some error"), nil)
|
||||
checkResult(t, taskResultSet, 2, nil, nil, errors.Errorf("panic in task %v", 2).Error())
|
||||
checkResult(t, taskResultSet, 2, nil, nil, fmt.Errorf("panic in task %v", 2).Error())
|
||||
}
|
||||
|
||||
// Wait for result
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package bech32
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/btcsuite/btcutil/bech32"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
//ConvertAndEncode converts from a base64 encoded byte string to base32 encoded byte string and then to bech32
|
||||
func ConvertAndEncode(hrp string, data []byte) (string, error) {
|
||||
converted, err := bech32.ConvertBits(data, 8, 5, true)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "encoding bech32 failed")
|
||||
return "", fmt.Errorf("encoding bech32 failed: %w", err)
|
||||
}
|
||||
return bech32.Encode(hrp, converted)
|
||||
|
||||
@@ -19,11 +20,11 @@ func ConvertAndEncode(hrp string, data []byte) (string, error) {
|
||||
func DecodeAndConvert(bech string) (string, []byte, error) {
|
||||
hrp, data, err := bech32.Decode(bech)
|
||||
if err != nil {
|
||||
return "", nil, errors.Wrap(err, "decoding bech32 failed")
|
||||
return "", nil, fmt.Errorf("decoding bech32 failed: %w", err)
|
||||
}
|
||||
converted, err := bech32.ConvertBits(data, 5, 8, false)
|
||||
if err != nil {
|
||||
return "", nil, errors.Wrap(err, "decoding bech32 failed")
|
||||
return "", nil, fmt.Errorf("decoding bech32 failed: %w", err)
|
||||
}
|
||||
return hrp, converted, nil
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
)
|
||||
|
||||
@@ -51,7 +50,7 @@ func ParseLogLevel(lvl string, logger log.Logger, defaultLogLevelValue string) (
|
||||
if module == defaultLogLevelKey {
|
||||
option, err = log.AllowLevel(level)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, fmt.Sprintf("Failed to parse default log level (pair %s, list %s)", item, l))
|
||||
return nil, fmt.Errorf("failed to parse default log level (pair %s, list %s): %w", item, l, err)
|
||||
}
|
||||
options = append(options, option)
|
||||
isDefaultLogLevelSet = true
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@@ -89,7 +89,10 @@ func (e Executor) Execute() error {
|
||||
err := e.Command.Execute()
|
||||
if err != nil {
|
||||
if viper.GetBool(TraceFlag) {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %+v\n", err)
|
||||
const size = 64 << 10
|
||||
buf := make([]byte, size)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n%s\n", err, buf)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
|
||||
}
|
||||
@@ -151,7 +154,7 @@ func validateOutput(cmd *cobra.Command, args []string) error {
|
||||
switch output {
|
||||
case "text", "json":
|
||||
default:
|
||||
return errors.Errorf("unsupported output format: %s", output)
|
||||
return fmt.Errorf("unsupported output format: %s", output)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -201,10 +200,10 @@ func TestSetupTrace(t *testing.T) {
|
||||
long bool
|
||||
expected string
|
||||
}{
|
||||
{nil, nil, false, "Trace flag = false"},
|
||||
{[]string{"--trace"}, nil, true, "Trace flag = true"},
|
||||
{nil, nil, false, "trace flag = false"},
|
||||
{[]string{"--trace"}, nil, true, "trace flag = true"},
|
||||
{[]string{"--no-such-flag"}, nil, false, "unknown flag: --no-such-flag"},
|
||||
{nil, map[string]string{"DBG_TRACE": "true"}, true, "Trace flag = true"},
|
||||
{nil, map[string]string{"DBG_TRACE": "true"}, true, "trace flag = true"},
|
||||
}
|
||||
|
||||
for idx, tc := range cases {
|
||||
@@ -213,7 +212,7 @@ func TestSetupTrace(t *testing.T) {
|
||||
trace := &cobra.Command{
|
||||
Use: "trace",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return errors.Errorf("Trace flag = %t", viper.GetBool(TraceFlag))
|
||||
return fmt.Errorf("trace flag = %t", viper.GetBool(TraceFlag))
|
||||
},
|
||||
}
|
||||
cmd := PrepareBaseCmd(trace, "DBG", "/qwerty/asdfgh") // some missing dir..
|
||||
@@ -228,10 +227,11 @@ func TestSetupTrace(t *testing.T) {
|
||||
msg := strings.Split(stderr, "\n")
|
||||
desired := fmt.Sprintf("ERROR: %s", tc.expected)
|
||||
assert.Equal(t, desired, msg[0], i)
|
||||
t.Log(msg)
|
||||
if tc.long && assert.True(t, len(msg) > 2, i) {
|
||||
// the next line starts the stack trace...
|
||||
assert.Contains(t, msg[1], "TestSetupTrace", i)
|
||||
assert.Contains(t, msg[2], "setup_test.go", i)
|
||||
assert.Contains(t, stderr, "TestSetupTrace", i)
|
||||
assert.Contains(t, stderr, "setup_test.go", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ package pubsub
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/service"
|
||||
)
|
||||
|
||||
@@ -410,7 +410,7 @@ func (state *state) send(msg interface{}, events map[string][]string) error {
|
||||
|
||||
match, err := q.Matches(events)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to match against query %s", q.String())
|
||||
return fmt.Errorf("failed to match against query %s: %w", q.String(), err)
|
||||
}
|
||||
|
||||
if match {
|
||||
|
||||
@@ -15,8 +15,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -411,7 +409,7 @@ func matchValue(value string, op Operator, operand reflect.Value) (bool, error)
|
||||
v, err = time.Parse(DateLayout, value)
|
||||
}
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to convert value %v from event attribute to time.Time", value)
|
||||
return false, fmt.Errorf("failed to convert value %v from event attribute to time.Time: %w", value, err)
|
||||
}
|
||||
|
||||
switch op {
|
||||
@@ -436,7 +434,7 @@ func matchValue(value string, op Operator, operand reflect.Value) (bool, error)
|
||||
// try our best to convert value from tags to float64
|
||||
v, err := strconv.ParseFloat(filteredValue, 64)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to convert value %v from event attribute to float64", filteredValue)
|
||||
return false, fmt.Errorf("failed to convert value %v from event attribute to float64: %w", filteredValue, err)
|
||||
}
|
||||
|
||||
switch op {
|
||||
@@ -462,7 +460,7 @@ func matchValue(value string, op Operator, operand reflect.Value) (bool, error)
|
||||
if strings.ContainsAny(filteredValue, ".") {
|
||||
v1, err := strconv.ParseFloat(filteredValue, 64)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to convert value %v from event attribute to float64", filteredValue)
|
||||
return false, fmt.Errorf("failed to convert value %v from event attribute to float64: %w", filteredValue, err)
|
||||
}
|
||||
|
||||
v = int64(v1)
|
||||
@@ -471,7 +469,7 @@ func matchValue(value string, op Operator, operand reflect.Value) (bool, error)
|
||||
// try our best to convert value from tags to int64
|
||||
v, err = strconv.ParseInt(filteredValue, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to convert value %v from event attribute to int64", filteredValue)
|
||||
return false, fmt.Errorf("failed to convert value %v from event attribute to int64: %w", filteredValue, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package tempfile
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -4,7 +4,7 @@ package tempfile
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
fmt "fmt"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
testing "testing"
|
||||
|
||||
@@ -2,13 +2,12 @@ package lite
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
"github.com/tendermint/tendermint/lite2/provider"
|
||||
|
||||
@@ -2,11 +2,10 @@ package proxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
@@ -91,7 +90,7 @@ func (p *Proxy) listen() (net.Listener, *http.ServeMux, error) {
|
||||
// 3) Start a client.
|
||||
if !p.Client.IsRunning() {
|
||||
if err := p.Client.Start(); err != nil {
|
||||
return nil, mux, errors.Wrap(err, "Client#Start")
|
||||
return nil, mux, fmt.Errorf("can't start client: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tendermint/go-amino"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
@@ -58,12 +57,12 @@ func (s *dbs) SaveSignedHeaderAndValidatorSet(sh *types.SignedHeader, valSet *ty
|
||||
|
||||
shBz, err := s.cdc.MarshalBinaryLengthPrefixed(sh)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "marshalling header")
|
||||
return fmt.Errorf("marshalling header: %w", err)
|
||||
}
|
||||
|
||||
valSetBz, err := s.cdc.MarshalBinaryLengthPrefixed(valSet)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "marshalling validator set")
|
||||
return fmt.Errorf("marshalling validator set: %w", err)
|
||||
}
|
||||
|
||||
s.mtx.Lock()
|
||||
@@ -287,7 +286,7 @@ func (s *dbs) Prune(size uint16) error {
|
||||
s.size -= uint16(pruned)
|
||||
|
||||
if wErr := s.db.SetSync(sizeKey, marshalSize(s.size)); wErr != nil {
|
||||
return errors.Wrap(wErr, "failed to persist size")
|
||||
return fmt.Errorf("failed to persist size: %w", wErr)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package lite
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ func (opts TrustOptions) ValidateBasic() error {
|
||||
return errors.New("negative or zero height")
|
||||
}
|
||||
if len(opts.Hash) != tmhash.Size {
|
||||
return errors.Errorf("expected hash size to be %d bytes, got %d bytes",
|
||||
return fmt.Errorf("expected hash size to be %d bytes, got %d bytes",
|
||||
tmhash.Size,
|
||||
len(opts.Hash),
|
||||
)
|
||||
|
||||
@@ -2,10 +2,10 @@ package lite
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
@@ -119,7 +119,7 @@ func VerifyAdjacent(
|
||||
|
||||
// Check the validator hashes are the same
|
||||
if !bytes.Equal(untrustedHeader.ValidatorsHash, trustedHeader.NextValidatorsHash) {
|
||||
err := errors.Errorf("expected old header next validators (%X) to match those from new header (%X)",
|
||||
err := fmt.Errorf("expected old header next validators (%X) to match those from new header (%X)",
|
||||
trustedHeader.NextValidatorsHash,
|
||||
untrustedHeader.ValidatorsHash,
|
||||
)
|
||||
@@ -164,30 +164,30 @@ func verifyNewHeaderAndVals(
|
||||
maxClockDrift time.Duration) error {
|
||||
|
||||
if err := untrustedHeader.ValidateBasic(chainID); err != nil {
|
||||
return errors.Wrap(err, "untrustedHeader.ValidateBasic failed")
|
||||
return fmt.Errorf("untrustedHeader.ValidateBasic failed: %w", err)
|
||||
}
|
||||
|
||||
if untrustedHeader.Height <= trustedHeader.Height {
|
||||
return errors.Errorf("expected new header height %d to be greater than one of old header %d",
|
||||
return fmt.Errorf("expected new header height %d to be greater than one of old header %d",
|
||||
untrustedHeader.Height,
|
||||
trustedHeader.Height)
|
||||
}
|
||||
|
||||
if !untrustedHeader.Time.After(trustedHeader.Time) {
|
||||
return errors.Errorf("expected new header time %v to be after old header time %v",
|
||||
return fmt.Errorf("expected new header time %v to be after old header time %v",
|
||||
untrustedHeader.Time,
|
||||
trustedHeader.Time)
|
||||
}
|
||||
|
||||
if !untrustedHeader.Time.Before(now.Add(maxClockDrift)) {
|
||||
return errors.Errorf("new header has a time from the future %v (now: %v; max clock drift: %v)",
|
||||
return fmt.Errorf("new header has a time from the future %v (now: %v; max clock drift: %v)",
|
||||
untrustedHeader.Time,
|
||||
now,
|
||||
maxClockDrift)
|
||||
}
|
||||
|
||||
if !bytes.Equal(untrustedHeader.ValidatorsHash, untrustedVals.Hash()) {
|
||||
return errors.Errorf("expected new header validators (%X) to match those that were supplied (%X) at height %d",
|
||||
return fmt.Errorf("expected new header validators (%X) to match those that were supplied (%X) at height %d",
|
||||
untrustedHeader.ValidatorsHash,
|
||||
untrustedVals.Hash(),
|
||||
untrustedHeader.Height,
|
||||
@@ -204,7 +204,7 @@ func ValidateTrustLevel(lvl tmmath.Fraction) error {
|
||||
if lvl.Numerator*3 < lvl.Denominator || // < 1/3
|
||||
lvl.Numerator > lvl.Denominator || // > 1
|
||||
lvl.Denominator == 0 {
|
||||
return errors.Errorf("trustLevel must be within [1/3, 1], given %v", lvl)
|
||||
return fmt.Errorf("trustLevel must be within [1/3, 1], given %v", lvl)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -231,14 +231,14 @@ func VerifyBackwards(chainID string, untrustedHeader, trustedHeader *types.Signe
|
||||
|
||||
if !untrustedHeader.Time.Before(trustedHeader.Time) {
|
||||
return ErrInvalidHeader{
|
||||
errors.Errorf("expected older header time %v to be before new header time %v",
|
||||
fmt.Errorf("expected older header time %v to be before new header time %v",
|
||||
untrustedHeader.Time,
|
||||
trustedHeader.Time)}
|
||||
}
|
||||
|
||||
if !bytes.Equal(untrustedHeader.Hash(), trustedHeader.LastBlockID.Hash) {
|
||||
return ErrInvalidHeader{
|
||||
errors.Errorf("older header hash %X does not match trusted header's last block %X",
|
||||
fmt.Errorf("older header hash %X does not match trusted header's last block %X",
|
||||
untrustedHeader.Hash(),
|
||||
trustedHeader.LastBlockID.Hash)}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package mempool
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mempool
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -8,7 +9,6 @@ import (
|
||||
|
||||
"github.com/fortytw2/leaktest"
|
||||
"github.com/go-kit/kit/log/term"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||
|
||||
20
node/node.go
20
node/node.go
@@ -3,6 +3,7 @@ package node
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -10,7 +11,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/rs/cors"
|
||||
@@ -527,14 +527,14 @@ func createAddrBookAndSetOnSwitch(config *cfg.Config, sw *p2p.Switch,
|
||||
if config.P2P.ExternalAddress != "" {
|
||||
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(nodeKey.ID(), config.P2P.ExternalAddress))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "p2p.external_address is incorrect")
|
||||
return nil, fmt.Errorf("p2p.external_address is incorrect: %w", err)
|
||||
}
|
||||
addrBook.AddOurAddress(addr)
|
||||
}
|
||||
if config.P2P.ListenAddress != "" {
|
||||
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(nodeKey.ID(), config.P2P.ListenAddress))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "p2p.laddr is incorrect")
|
||||
return nil, fmt.Errorf("p2p.laddr is incorrect: %w", err)
|
||||
}
|
||||
addrBook.AddOurAddress(addr)
|
||||
}
|
||||
@@ -666,13 +666,13 @@ func NewNode(config *cfg.Config,
|
||||
// FIXME: we should start services inside OnStart
|
||||
privValidator, err = createAndStartPrivValidatorSocketClient(config.PrivValidatorListenAddr, logger)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error with private validator socket client")
|
||||
return nil, fmt.Errorf("error with private validator socket client: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
pubKey, err := privValidator.GetPubKey()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "can't get pubkey")
|
||||
return nil, fmt.Errorf("can't get pubkey: %w", err)
|
||||
}
|
||||
|
||||
// Determine whether we should do state and/or fast sync.
|
||||
@@ -724,7 +724,7 @@ func NewNode(config *cfg.Config,
|
||||
// Make BlockchainReactor. Don't start fast sync if we're doing a state sync first.
|
||||
bcReactor, err := createBlockchainReactor(config, state, blockExec, blockStore, fastSync && !stateSync, logger)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not create blockchain reactor")
|
||||
return nil, fmt.Errorf("could not create blockchain reactor: %w", err)
|
||||
}
|
||||
|
||||
// Make ConsensusReactor. Don't enable fully if doing a state sync and/or fast sync first.
|
||||
@@ -764,17 +764,17 @@ func NewNode(config *cfg.Config,
|
||||
|
||||
err = sw.AddPersistentPeers(splitAndTrimEmpty(config.P2P.PersistentPeers, ",", " "))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not add peers from persistent_peers field")
|
||||
return nil, fmt.Errorf("could not add peers from persistent_peers field: %w", err)
|
||||
}
|
||||
|
||||
err = sw.AddUnconditionalPeerIDs(splitAndTrimEmpty(config.P2P.UnconditionalPeerIDs, ",", " "))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not add peer ids from unconditional_peer_ids field")
|
||||
return nil, fmt.Errorf("could not add peer ids from unconditional_peer_ids field: %w", err)
|
||||
}
|
||||
|
||||
addrBook, err := createAddrBookAndSetOnSwitch(config, sw, p2pLogger, nodeKey)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not create addrbook")
|
||||
return nil, fmt.Errorf("could not create addrbook: %w", err)
|
||||
}
|
||||
|
||||
// Optionally, start the pex reactor
|
||||
@@ -890,7 +890,7 @@ func (n *Node) OnStart() error {
|
||||
// Always connect to persistent peers
|
||||
err = n.sw.DialPeersAsync(splitAndTrimEmpty(n.config.P2P.PersistentPeers, ",", " "))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not dial peers from persistent_peers field")
|
||||
return fmt.Errorf("could not dial peers from persistent_peers field: %w", err)
|
||||
}
|
||||
|
||||
// Run state sync
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"runtime/debug"
|
||||
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
@@ -13,8 +14,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
flow "github.com/tendermint/tendermint/libs/flowrate"
|
||||
@@ -331,7 +330,7 @@ func (c *MConnection) flush() {
|
||||
func (c *MConnection) _recover() {
|
||||
if r := recover(); r != nil {
|
||||
c.Logger.Error("MConnection panicked", "err", r, "stack", string(debug.Stack()))
|
||||
c.stopForError(errors.Errorf("recovered from panic: %v", r))
|
||||
c.stopForError(fmt.Errorf("recovered from panic: %v", r))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
crand "crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net"
|
||||
@@ -14,7 +16,6 @@ import (
|
||||
|
||||
"github.com/gtank/merlin"
|
||||
pool "github.com/libp2p/go-buffer-pool"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/crypto/chacha20poly1305"
|
||||
"golang.org/x/crypto/curve25519"
|
||||
"golang.org/x/crypto/hkdf"
|
||||
@@ -163,7 +164,7 @@ func MakeSecretConnection(conn io.ReadWriteCloser, locPrivKey crypto.PrivKey) (*
|
||||
|
||||
remPubKey, remSignature := authSigMsg.Key, authSigMsg.Sig
|
||||
if _, ok := remPubKey.(ed25519.PubKeyEd25519); !ok {
|
||||
return nil, errors.Errorf("expected ed25519 pubkey, got %T", remPubKey)
|
||||
return nil, fmt.Errorf("expected ed25519 pubkey, got %T", remPubKey)
|
||||
}
|
||||
if !remPubKey.VerifyBytes(challenge[:], remSignature) {
|
||||
return nil, errors.New("challenge verification failed")
|
||||
|
||||
@@ -6,14 +6,13 @@ package p2p
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// NetAddress defines information about a peer on the network
|
||||
@@ -217,7 +216,7 @@ func (na *NetAddress) Routable() bool {
|
||||
// address or one that matches the RFC3849 documentation address format.
|
||||
func (na *NetAddress) Valid() error {
|
||||
if err := validateID(na.ID); err != nil {
|
||||
return errors.Wrap(err, "invalid ID")
|
||||
return fmt.Errorf("invalid ID: %w", err)
|
||||
}
|
||||
|
||||
if na.IP == nil {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -114,13 +113,13 @@ func testOutboundPeerConn(
|
||||
var pc peerConn
|
||||
conn, err := testDial(addr, config)
|
||||
if err != nil {
|
||||
return pc, errors.Wrap(err, "Error creating peer")
|
||||
return pc, fmt.Errorf("error creating peer: %w", err)
|
||||
}
|
||||
|
||||
pc, err = testPeerConn(conn, config, true, persistent, ourNodePrivKey, addr)
|
||||
if err != nil {
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
return pc, errors.Wrap(err, cerr.Error())
|
||||
return pc, fmt.Errorf("%v: %w", cerr.Error(), err)
|
||||
}
|
||||
return pc, err
|
||||
}
|
||||
@@ -128,7 +127,7 @@ func testOutboundPeerConn(
|
||||
// ensure dialed ID matches connection ID
|
||||
if addr.ID != pc.ID() {
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
return pc, errors.Wrap(err, cerr.Error())
|
||||
return pc, fmt.Errorf("%v: %w", cerr.Error(), err)
|
||||
}
|
||||
return pc, ErrSwitchAuthenticationFailure{addr, pc.ID()}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package pex
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/cmap"
|
||||
@@ -569,7 +568,7 @@ func (r *Reactor) dialPeer(addr *p2p.NetAddress) error {
|
||||
default:
|
||||
r.attemptsToDial.Store(addr.DialString(), _attemptsToDial{attempts + 1, time.Now()})
|
||||
}
|
||||
return errors.Wrapf(err, "dialing failed (attempts: %d)", attempts+1)
|
||||
return fmt.Errorf("dialing failed (attempts: %d): %w", attempts+1, err)
|
||||
}
|
||||
|
||||
// cleanup any history
|
||||
@@ -604,7 +603,7 @@ func (r *Reactor) checkSeeds() (numOnline int, netAddrs []*p2p.NetAddress, err e
|
||||
case p2p.ErrNetAddressLookup:
|
||||
r.Logger.Error("Connecting to seed failed", "err", e)
|
||||
default:
|
||||
return 0, nil, errors.Wrap(e, "seed node configuration has error")
|
||||
return 0, nil, fmt.Errorf("seed node configuration has error: %w", e)
|
||||
}
|
||||
}
|
||||
return numOnline, netAddrs, nil
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/libs/cmap"
|
||||
"github.com/tendermint/tendermint/libs/rand"
|
||||
@@ -226,7 +224,7 @@ func (sw *Switch) OnStart() error {
|
||||
for _, reactor := range sw.reactors {
|
||||
err := reactor.Start()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to start %v", reactor)
|
||||
return fmt.Errorf("failed to start %v: %w", reactor, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,7 +441,7 @@ type privateAddr interface {
|
||||
}
|
||||
|
||||
func isPrivateAddr(err error) bool {
|
||||
te, ok := errors.Cause(err).(privateAddr)
|
||||
te, ok := err.(privateAddr)
|
||||
return ok && te.PrivateAddr()
|
||||
}
|
||||
|
||||
@@ -577,7 +575,7 @@ func (sw *Switch) AddUnconditionalPeerIDs(ids []string) error {
|
||||
for i, id := range ids {
|
||||
err := validateID(ID(id))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "wrong ID #%d", i)
|
||||
return fmt.Errorf("wrong ID #%d: %w", i, err)
|
||||
}
|
||||
sw.unconditionalPeerIDs[ID(id)] = struct{}{}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
@@ -245,7 +243,7 @@ func testPeerConn(
|
||||
// Encrypt connection
|
||||
conn, err = upgradeSecretConn(conn, cfg.HandshakeTimeout, ourNodePrivKey)
|
||||
if err != nil {
|
||||
return pc, errors.Wrap(err, "Error creating peer")
|
||||
return pc, fmt.Errorf("error creating peer: %w", err)
|
||||
}
|
||||
|
||||
// Only the information we already have
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/netutil"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
@@ -288,7 +287,7 @@ func (mt *MultiplexTransport) acceptPeers() {
|
||||
if r := recover(); r != nil {
|
||||
err := ErrRejected{
|
||||
conn: c,
|
||||
err: errors.Errorf("recovered from panic: %v", r),
|
||||
err: fmt.Errorf("recovered from panic: %v", r),
|
||||
isAuthFailure: true,
|
||||
}
|
||||
select {
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
@@ -23,7 +21,7 @@ var _ types.PrivValidator = (*SignerClient)(nil)
|
||||
func NewSignerClient(endpoint *SignerListenerEndpoint) (*SignerClient, error) {
|
||||
if !endpoint.IsRunning() {
|
||||
if err := endpoint.Start(); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to start listener endpoint")
|
||||
return nil, fmt.Errorf("failed to start listener endpoint: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,13 +70,13 @@ func (sc *SignerClient) GetPubKey() (crypto.PubKey, error) {
|
||||
response, err := sc.endpoint.SendRequest(&PubKeyRequest{})
|
||||
if err != nil {
|
||||
sc.endpoint.Logger.Error("SignerClient::GetPubKey", "err", err)
|
||||
return nil, errors.Wrap(err, "send")
|
||||
return nil, fmt.Errorf("send: %w", err)
|
||||
}
|
||||
|
||||
pubKeyResp, ok := response.(*PubKeyResponse)
|
||||
if !ok {
|
||||
sc.endpoint.Logger.Error("SignerClient::GetPubKey", "err", "response != PubKeyResponse")
|
||||
return nil, errors.Errorf("unexpected response type %T", response)
|
||||
return nil, fmt.Errorf("unexpected response type %T", response)
|
||||
}
|
||||
|
||||
if pubKeyResp.Error != nil {
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/service"
|
||||
)
|
||||
|
||||
@@ -100,9 +98,9 @@ func (se *signerEndpoint) ReadMessage() (msg SignerMessage, err error) {
|
||||
_, err = cdc.UnmarshalBinaryLengthPrefixedReader(se.conn, &msg, maxRemoteSignerMsgSize)
|
||||
if _, ok := err.(timeoutError); ok {
|
||||
if err != nil {
|
||||
err = errors.Wrap(ErrReadTimeout, err.Error())
|
||||
err = fmt.Errorf("%v: %w", err, ErrReadTimeout)
|
||||
} else {
|
||||
err = errors.Wrap(ErrReadTimeout, "Empty error")
|
||||
err = fmt.Errorf("empty error: %w", ErrReadTimeout)
|
||||
}
|
||||
se.Logger.Debug("Dropping [read]", "obj", se)
|
||||
se.dropConnection()
|
||||
@@ -117,7 +115,7 @@ func (se *signerEndpoint) WriteMessage(msg SignerMessage) (err error) {
|
||||
defer se.connMtx.Unlock()
|
||||
|
||||
if !se.isConnected() {
|
||||
return errors.Wrap(ErrNoConnection, "endpoint is not connected")
|
||||
return fmt.Errorf("endpoint is not connected: %w", ErrNoConnection)
|
||||
}
|
||||
|
||||
// Reset read deadline
|
||||
@@ -130,9 +128,9 @@ func (se *signerEndpoint) WriteMessage(msg SignerMessage) (err error) {
|
||||
_, err = cdc.MarshalBinaryLengthPrefixedWriter(se.conn, msg)
|
||||
if _, ok := err.(timeoutError); ok {
|
||||
if err != nil {
|
||||
err = errors.Wrap(ErrWriteTimeout, err.Error())
|
||||
err = fmt.Errorf("%v: %w", err, ErrWriteTimeout)
|
||||
} else {
|
||||
err = errors.Wrap(ErrWriteTimeout, "Empty error")
|
||||
err = fmt.Errorf("empty error: %w", ErrWriteTimeout)
|
||||
}
|
||||
se.dropConnection()
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package privval
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
tmnet "github.com/tendermint/tendermint/libs/net"
|
||||
p2pconn "github.com/tendermint/tendermint/p2p/conn"
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -44,6 +43,6 @@ func TestIsConnTimeoutForWrappedConnTimeouts(t *testing.T) {
|
||||
dialer := DialTCPFn(tcpAddr, time.Millisecond, ed25519.GenPrivKey())
|
||||
_, err := dialer()
|
||||
assert.Error(t, err)
|
||||
err = errors.Wrap(ErrConnectionTimeout, err.Error())
|
||||
err = fmt.Errorf("%v: %w", err, ErrConnectionTimeout)
|
||||
assert.True(t, IsConnTimeout(err))
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package privval
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmnet "github.com/tendermint/tendermint/libs/net"
|
||||
@@ -15,10 +14,11 @@ import (
|
||||
// report that a connection timeout occurred. This detects both fundamental
|
||||
// network timeouts, as well as ErrConnTimeout errors.
|
||||
func IsConnTimeout(err error) bool {
|
||||
switch errors.Cause(err).(type) {
|
||||
case EndpointTimeoutError:
|
||||
_, ok := errors.Unwrap(err).(timeoutError)
|
||||
switch {
|
||||
case errors.As(err, &EndpointTimeoutError{}):
|
||||
return true
|
||||
case timeoutError:
|
||||
case ok:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package privval
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIsConnTimeoutForNonTimeoutErrors(t *testing.T) {
|
||||
assert.False(t, IsConnTimeout(errors.Wrap(ErrDialRetryMax, "max retries exceeded")))
|
||||
assert.False(t, IsConnTimeout(fmt.Errorf("max retries exceeded: %w", ErrDialRetryMax)))
|
||||
assert.False(t, IsConnTimeout(errors.New("completely irrelevant error")))
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
abcicli "github.com/tendermint/tendermint/abci/client"
|
||||
"github.com/tendermint/tendermint/abci/example/counter"
|
||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||
@@ -55,7 +54,7 @@ func NewRemoteClientCreator(addr, transport string, mustConnect bool) ClientCrea
|
||||
func (r *remoteClientCreator) NewABCIClient() (abcicli.Client, error) {
|
||||
remoteApp, err := abcicli.NewClient(r.addr, r.transport, r.mustConnect)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Failed to connect to proxy")
|
||||
return nil, fmt.Errorf("failed to connect to proxy: %w", err)
|
||||
}
|
||||
return remoteApp, nil
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ type Waiter func(delta int64) (abort error)
|
||||
// but you can plug in another one
|
||||
func DefaultWaitStrategy(delta int64) (abort error) {
|
||||
if delta > 10 {
|
||||
return errors.Errorf("waiting for %d blocks... aborting", delta)
|
||||
return fmt.Errorf("waiting for %d blocks... aborting", delta)
|
||||
} else if delta > 0 {
|
||||
// estimate of wait time....
|
||||
// wait half a second for the next block (in progress)
|
||||
@@ -64,7 +64,7 @@ func WaitForOneEvent(c EventsClient, evtTyp string, timeout time.Duration) (type
|
||||
// register for the next event of this type
|
||||
eventCh, err := c.Subscribe(ctx, subscriber, types.QueryForEvent(evtTyp).String())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to subscribe")
|
||||
return nil, fmt.Errorf("failed to subscribe: %w", err)
|
||||
}
|
||||
// make sure to unregister after the test is over
|
||||
defer c.UnsubscribeAll(ctx, subscriber)
|
||||
|
||||
@@ -2,13 +2,12 @@ package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
@@ -308,7 +307,7 @@ func (c *baseRPCClient) ConsensusState() (*ctypes.ResultConsensusState, error) {
|
||||
result := new(ctypes.ResultConsensusState)
|
||||
_, err := c.caller.Call("consensus_state", map[string]interface{}{}, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "ConsensusState")
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
@@ -402,7 +401,7 @@ func (c *baseRPCClient) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
||||
}
|
||||
_, err := c.caller.Call("tx", params, result)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Tx")
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -2,10 +2,9 @@ package local
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
|
||||
@@ -177,7 +176,7 @@ func (c *Local) Subscribe(
|
||||
outCapacity ...int) (out <-chan ctypes.ResultEvent, err error) {
|
||||
q, err := tmquery.New(query)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to parse query")
|
||||
return nil, fmt.Errorf("failed to parse query: %w", err)
|
||||
}
|
||||
|
||||
outCap := 1
|
||||
@@ -192,7 +191,7 @@ func (c *Local) Subscribe(
|
||||
sub, err = c.EventBus.SubscribeUnbuffered(ctx, subscriber, q)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to subscribe")
|
||||
return nil, fmt.Errorf("failed to subscribe: %w", err)
|
||||
}
|
||||
|
||||
outc := make(chan ctypes.ResultEvent, outCap)
|
||||
@@ -256,7 +255,7 @@ func (c *Local) resubscribe(subscriber string, q tmpubsub.Query) types.Subscript
|
||||
func (c *Local) Unsubscribe(ctx context.Context, subscriber, query string) error {
|
||||
q, err := tmquery.New(query)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to parse query")
|
||||
return fmt.Errorf("failed to parse query: %w", err)
|
||||
}
|
||||
return c.EventBus.Unsubscribe(ctx, subscriber, q)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package mock_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
|
||||
tmquery "github.com/tendermint/tendermint/libs/pubsub/query"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
@@ -32,7 +30,7 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er
|
||||
|
||||
q, err := tmquery.New(query)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to parse query")
|
||||
return nil, fmt.Errorf("failed to parse query: %w", err)
|
||||
}
|
||||
|
||||
subCtx, cancel := context.WithTimeout(ctx.Context(), SubscribeTimeout)
|
||||
@@ -85,7 +83,7 @@ func Unsubscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultUnsubscribe
|
||||
logger.Info("Unsubscribe from query", "remote", addr, "query", query)
|
||||
q, err := tmquery.New(query)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to parse query")
|
||||
return nil, fmt.Errorf("failed to parse query: %w", err)
|
||||
}
|
||||
err = eventBus.Unsubscribe(context.Background(), addr, q)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,11 +2,10 @@ package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
mempl "github.com/tendermint/tendermint/mempool"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
@@ -68,7 +67,7 @@ func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadc
|
||||
q := types.EventQueryTxFor(tx)
|
||||
deliverTxSub, err := eventBus.Subscribe(subCtx, subscriber, q)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "failed to subscribe to tx")
|
||||
err = fmt.Errorf("failed to subscribe to tx: %w", err)
|
||||
logger.Error("Error on broadcast_tx_commit", "err", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
tmquery "github.com/tendermint/tendermint/libs/pubsub/query"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
|
||||
@@ -2,8 +2,8 @@ package rpcclient
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
@@ -21,7 +21,7 @@ func unmarshalResponseBytes(
|
||||
// into the correct type.
|
||||
response := &types.RPCResponse{}
|
||||
if err := json.Unmarshal(responseBytes, response); err != nil {
|
||||
return nil, errors.Wrap(err, "error unmarshalling")
|
||||
return nil, fmt.Errorf("error unmarshalling: %w", err)
|
||||
}
|
||||
|
||||
if response.Error != nil {
|
||||
@@ -29,12 +29,12 @@ func unmarshalResponseBytes(
|
||||
}
|
||||
|
||||
if err := validateAndVerifyID(response, expectedID); err != nil {
|
||||
return nil, errors.Wrap(err, "wrong ID")
|
||||
return nil, fmt.Errorf("wrong ID: %w", err)
|
||||
}
|
||||
|
||||
// Unmarshal the RawMessage into the result.
|
||||
if err := cdc.UnmarshalJSON(response.Result, result); err != nil {
|
||||
return nil, errors.Wrap(err, "error unmarshalling result")
|
||||
return nil, fmt.Errorf("error unmarshalling result: %w", err)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@@ -52,14 +52,14 @@ func unmarshalResponseBytesArray(
|
||||
)
|
||||
|
||||
if err := json.Unmarshal(responseBytes, &responses); err != nil {
|
||||
return nil, errors.Wrap(err, "error unmarshalling")
|
||||
return nil, fmt.Errorf("error unmarshalling: %w", err)
|
||||
}
|
||||
|
||||
// No response error checking here as there may be a mixture of successful
|
||||
// and unsuccessful responses.
|
||||
|
||||
if len(results) != len(responses) {
|
||||
return nil, errors.Errorf(
|
||||
return nil, fmt.Errorf(
|
||||
"expected %d result objects into which to inject responses, but got %d",
|
||||
len(responses),
|
||||
len(results),
|
||||
@@ -72,16 +72,16 @@ func unmarshalResponseBytesArray(
|
||||
for i, resp := range responses {
|
||||
ids[i], ok = resp.ID.(types.JSONRPCIntID)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("expected JSONRPCIntID, got %T", resp.ID)
|
||||
return nil, fmt.Errorf("expected JSONRPCIntID, got %T", resp.ID)
|
||||
}
|
||||
}
|
||||
if err := validateResponseIDs(ids, expectedIDs); err != nil {
|
||||
return nil, errors.Wrap(err, "wrong IDs")
|
||||
return nil, fmt.Errorf("wrong IDs: %w", err)
|
||||
}
|
||||
|
||||
for i := 0; i < len(responses); i++ {
|
||||
if err := cdc.UnmarshalJSON(responses[i].Result, results[i]); err != nil {
|
||||
return nil, errors.Wrapf(err, "error unmarshalling #%d result", i)
|
||||
return nil, fmt.Errorf("error unmarshalling #%d result: %w", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ func validateResponseIDs(ids, expectedIDs []types.JSONRPCIntID) error {
|
||||
if m[id] {
|
||||
delete(m, id)
|
||||
} else {
|
||||
return errors.Errorf("unsolicited ID #%d: %v", i, id)
|
||||
return fmt.Errorf("unsolicited ID #%d: %v", i, id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ func validateAndVerifyID(res *types.RPCResponse, expectedID types.JSONRPCIntID)
|
||||
return err
|
||||
}
|
||||
if expectedID != res.ID.(types.JSONRPCIntID) { // validateResponseID ensured res.ID has the right type
|
||||
return errors.Errorf("response ID (%d) does not match request ID (%d)", res.ID, expectedID)
|
||||
return fmt.Errorf("response ID (%d) does not match request ID (%d)", res.ID, expectedID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -123,7 +123,7 @@ func validateResponseID(id interface{}) error {
|
||||
}
|
||||
_, ok := id.(types.JSONRPCIntID)
|
||||
if !ok {
|
||||
return errors.Errorf("expected JSONRPCIntID, but got: %T", id)
|
||||
return fmt.Errorf("expected JSONRPCIntID, but got: %T", id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
types "github.com/tendermint/tendermint/rpc/lib/types"
|
||||
@@ -168,18 +167,18 @@ func (c *JSONRPCClient) Call(method string, params map[string]interface{}, resul
|
||||
|
||||
request, err := types.MapToRequest(c.cdc, id, method, params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to encode params")
|
||||
return nil, fmt.Errorf("failed to encode params: %w", err)
|
||||
}
|
||||
|
||||
requestBytes, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to marshal request")
|
||||
return nil, fmt.Errorf("failed to marshal request: %w", err)
|
||||
}
|
||||
|
||||
requestBuf := bytes.NewBuffer(requestBytes)
|
||||
httpRequest, err := http.NewRequest(http.MethodPost, c.address, requestBuf)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Request failed")
|
||||
return nil, fmt.Errorf("request failed: %w", err)
|
||||
}
|
||||
httpRequest.Header.Set("Content-Type", "text/json")
|
||||
if c.username != "" || c.password != "" {
|
||||
@@ -187,13 +186,13 @@ func (c *JSONRPCClient) Call(method string, params map[string]interface{}, resul
|
||||
}
|
||||
httpResponse, err := c.client.Do(httpRequest)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Post failed")
|
||||
return nil, fmt.Errorf("post failed: %w", err)
|
||||
}
|
||||
defer httpResponse.Body.Close() // nolint: errcheck
|
||||
|
||||
responseBytes, err := ioutil.ReadAll(httpResponse.Body)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to read response body")
|
||||
return nil, fmt.Errorf("failed to read response body: %w", err)
|
||||
}
|
||||
|
||||
return unmarshalResponseBytes(c.cdc, responseBytes, id, result)
|
||||
@@ -221,12 +220,12 @@ func (c *JSONRPCClient) sendBatch(requests []*jsonRPCBufferedRequest) ([]interfa
|
||||
// serialize the array of requests into a single JSON object
|
||||
requestBytes, err := json.Marshal(reqs)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to marshal requests")
|
||||
return nil, fmt.Errorf("failed to marshal requests: %w", err)
|
||||
}
|
||||
|
||||
httpRequest, err := http.NewRequest(http.MethodPost, c.address, bytes.NewBuffer(requestBytes))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Request failed")
|
||||
return nil, fmt.Errorf("request failed: %w", err)
|
||||
}
|
||||
httpRequest.Header.Set("Content-Type", "text/json")
|
||||
if c.username != "" || c.password != "" {
|
||||
@@ -234,13 +233,13 @@ func (c *JSONRPCClient) sendBatch(requests []*jsonRPCBufferedRequest) ([]interfa
|
||||
}
|
||||
httpResponse, err := c.client.Do(httpRequest)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Post failed")
|
||||
return nil, fmt.Errorf("post failed: %w", err)
|
||||
}
|
||||
defer httpResponse.Body.Close() // nolint: errcheck
|
||||
|
||||
responseBytes, err := ioutil.ReadAll(httpResponse.Body)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to read response body")
|
||||
return nil, fmt.Errorf("failed to read response body: %w", err)
|
||||
}
|
||||
|
||||
// collect ids to check responses IDs in unmarshalResponseBytesArray
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package rpcclient
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
types "github.com/tendermint/tendermint/rpc/lib/types"
|
||||
@@ -60,18 +59,18 @@ func NewURIClient(remote string) (*URIClient, error) {
|
||||
func (c *URIClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) {
|
||||
values, err := argsToURLValues(c.cdc, params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to encode params")
|
||||
return nil, fmt.Errorf("failed to encode params: %w", err)
|
||||
}
|
||||
|
||||
resp, err := c.client.PostForm(c.address+"/"+method, values)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "PostForm failed")
|
||||
return nil, fmt.Errorf("post form failed: %w", err)
|
||||
}
|
||||
defer resp.Body.Close() // nolint: errcheck
|
||||
|
||||
responseBytes, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to read response body")
|
||||
return nil, fmt.Errorf("failed to read response body: %w", err)
|
||||
}
|
||||
|
||||
return unmarshalResponseBytes(c.cdc, responseBytes, URIClientRequestID, result)
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/pkg/errors"
|
||||
metrics "github.com/rcrowley/go-metrics"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
@@ -315,7 +314,7 @@ func (c *WSClient) reconnect() error {
|
||||
attempt++
|
||||
|
||||
if attempt > c.maxReconnectAttempts {
|
||||
return errors.Wrap(err, "reached maximum reconnect attempts")
|
||||
return fmt.Errorf("reached maximum reconnect attempts: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"reflect"
|
||||
"sort"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
@@ -30,7 +28,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, cdc *amino.Codec, logger lo
|
||||
w,
|
||||
types.RPCInvalidRequestError(
|
||||
nil,
|
||||
errors.Wrap(err, "error reading request body"),
|
||||
fmt.Errorf("error reading request body: %w", err),
|
||||
),
|
||||
)
|
||||
return
|
||||
@@ -55,7 +53,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, cdc *amino.Codec, logger lo
|
||||
WriteRPCResponseHTTP(
|
||||
w,
|
||||
types.RPCParseError(
|
||||
errors.Wrap(err, "error unmarshalling request"),
|
||||
fmt.Errorf("error unmarshalling request: %w", err),
|
||||
),
|
||||
)
|
||||
return
|
||||
@@ -78,7 +76,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, cdc *amino.Codec, logger lo
|
||||
if len(r.URL.Path) > 1 {
|
||||
responses = append(
|
||||
responses,
|
||||
types.RPCInvalidRequestError(request.ID, errors.Errorf("path %s is invalid", r.URL.Path)),
|
||||
types.RPCInvalidRequestError(request.ID, fmt.Errorf("path %s is invalid", r.URL.Path)),
|
||||
)
|
||||
continue
|
||||
}
|
||||
@@ -94,7 +92,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, cdc *amino.Codec, logger lo
|
||||
if err != nil {
|
||||
responses = append(
|
||||
responses,
|
||||
types.RPCInvalidParamsError(request.ID, errors.Wrap(err, "error converting json params to arguments")),
|
||||
types.RPCInvalidParamsError(request.ID, fmt.Errorf("error converting json params to arguments: %w", err)),
|
||||
)
|
||||
continue
|
||||
}
|
||||
@@ -162,7 +160,7 @@ func arrayParamsToArgs(
|
||||
) ([]reflect.Value, error) {
|
||||
|
||||
if len(rpcFunc.argNames) != len(params) {
|
||||
return nil, errors.Errorf("expected %v parameters (%v), got %v (%v)",
|
||||
return nil, fmt.Errorf("expected %v parameters (%v), got %v (%v)",
|
||||
len(rpcFunc.argNames), rpcFunc.argNames, len(params), params)
|
||||
}
|
||||
|
||||
@@ -204,7 +202,7 @@ func jsonParamsToArgs(rpcFunc *RPCFunc, cdc *amino.Codec, raw []byte) ([]reflect
|
||||
}
|
||||
|
||||
// Otherwise, bad format, we cannot parse
|
||||
return nil, errors.Errorf("unknown type for JSON params: %v. Expected map or array", err)
|
||||
return nil, fmt.Errorf("unknown type for JSON params: %v. Expected map or array", err)
|
||||
}
|
||||
|
||||
// writes a list of available rpc endpoints as an html page
|
||||
|
||||
@@ -2,11 +2,10 @@ package rpcserver
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -41,7 +40,7 @@ func GetParamInt64(r *http.Request, param string) (int64, error) {
|
||||
s := GetParam(r, param)
|
||||
i, err := strconv.ParseInt(s, 10, 64)
|
||||
if err != nil {
|
||||
return 0, errors.Errorf(param, err.Error())
|
||||
return 0, fmt.Errorf(param, err.Error())
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
@@ -50,7 +49,7 @@ func GetParamInt32(r *http.Request, param string) (int32, error) {
|
||||
s := GetParam(r, param)
|
||||
i, err := strconv.ParseInt(s, 10, 32)
|
||||
if err != nil {
|
||||
return 0, errors.Errorf(param, err.Error())
|
||||
return 0, fmt.Errorf(param, err.Error())
|
||||
}
|
||||
return int32(i), nil
|
||||
}
|
||||
@@ -59,7 +58,7 @@ func GetParamUint64(r *http.Request, param string) (uint64, error) {
|
||||
s := GetParam(r, param)
|
||||
i, err := strconv.ParseUint(s, 10, 64)
|
||||
if err != nil {
|
||||
return 0, errors.Errorf(param, err.Error())
|
||||
return 0, fmt.Errorf(param, err.Error())
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
@@ -68,7 +67,7 @@ func GetParamUint(r *http.Request, param string) (uint, error) {
|
||||
s := GetParam(r, param)
|
||||
i, err := strconv.ParseUint(s, 10, 64)
|
||||
if err != nil {
|
||||
return 0, errors.Errorf(param, err.Error())
|
||||
return 0, fmt.Errorf(param, err.Error())
|
||||
}
|
||||
return uint(i), nil
|
||||
}
|
||||
@@ -76,7 +75,7 @@ func GetParamUint(r *http.Request, param string) (uint, error) {
|
||||
func GetParamRegexp(r *http.Request, param string, re *regexp.Regexp) (string, error) {
|
||||
s := GetParam(r, param)
|
||||
if !re.MatchString(s) {
|
||||
return "", errors.Errorf(param, "did not match regular expression %v", re.String())
|
||||
return "", fmt.Errorf(param, "did not match regular expression %v", re.String())
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
@@ -85,7 +84,7 @@ func GetParamFloat64(r *http.Request, param string) (float64, error) {
|
||||
s := GetParam(r, param)
|
||||
f, err := strconv.ParseFloat(s, 64)
|
||||
if err != nil {
|
||||
return 0, errors.Errorf(param, err.Error())
|
||||
return 0, fmt.Errorf(param, err.Error())
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package rpcserver
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -12,7 +13,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/netutil"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
@@ -241,7 +241,7 @@ func (h maxBytesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
func Listen(addr string, config *Config) (listener net.Listener, err error) {
|
||||
parts := strings.SplitN(addr, "://", 2)
|
||||
if len(parts) != 2 {
|
||||
return nil, errors.Errorf(
|
||||
return nil, fmt.Errorf(
|
||||
"invalid listening address %s (use fully formed addresses, including the tcp:// or unix:// prefix)",
|
||||
addr,
|
||||
)
|
||||
@@ -249,7 +249,7 @@ func Listen(addr string, config *Config) (listener net.Listener, err error) {
|
||||
proto, addr := parts[0], parts[1]
|
||||
listener, err = net.Listen(proto, addr)
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("failed to listen on %v: %v", addr, err)
|
||||
return nil, fmt.Errorf("failed to listen on %v: %v", addr, err)
|
||||
}
|
||||
if config.MaxOpenConnections > 0 {
|
||||
listener = netutil.LimitListener(listener, config.MaxOpenConnections)
|
||||
|
||||
@@ -2,12 +2,11 @@ package rpcserver
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
@@ -43,7 +42,7 @@ func makeHTTPHandler(rpcFunc *RPCFunc, cdc *amino.Codec, logger log.Logger) func
|
||||
w,
|
||||
types.RPCInvalidParamsError(
|
||||
dummyID,
|
||||
errors.Wrap(err, "error converting http params to arguments"),
|
||||
fmt.Errorf("error converting http params to arguments: %w", err),
|
||||
),
|
||||
)
|
||||
return
|
||||
@@ -165,7 +164,7 @@ func _nonJSONStringToArg(cdc *amino.Codec, rt reflect.Type, arg string) (reflect
|
||||
|
||||
if isHexString {
|
||||
if !expectingString && !expectingByteSlice {
|
||||
err := errors.Errorf("got a hex string arg, but expected '%s'",
|
||||
err := fmt.Errorf("got a hex string arg, but expected '%s'",
|
||||
rt.Kind().String())
|
||||
return reflect.ValueOf(nil), false, err
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package rpcserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
@@ -92,7 +91,7 @@ func funcReturnTypes(f interface{}) []reflect.Type {
|
||||
func unreflectResult(returns []reflect.Value) (interface{}, error) {
|
||||
errV := returns[1]
|
||||
if errV.Interface() != nil {
|
||||
return nil, errors.Errorf("%v", errV.Interface())
|
||||
return nil, fmt.Errorf("%v", errV.Interface())
|
||||
}
|
||||
rv := returns[0]
|
||||
// the result is a registered interface,
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
@@ -340,7 +339,7 @@ func (wsc *wsConnection) readRoutine() {
|
||||
var request types.RPCRequest
|
||||
err = json.Unmarshal(in, &request)
|
||||
if err != nil {
|
||||
wsc.WriteRPCResponse(types.RPCParseError(errors.Wrap(err, "error unmarshaling request")))
|
||||
wsc.WriteRPCResponse(types.RPCParseError(fmt.Errorf("error unmarshaling request: %w", err)))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -367,7 +366,7 @@ func (wsc *wsConnection) readRoutine() {
|
||||
fnArgs, err := jsonParamsToArgs(rpcFunc, wsc.cdc, request.Params)
|
||||
if err != nil {
|
||||
wsc.WriteRPCResponse(
|
||||
types.RPCInternalError(request.ID, errors.Wrap(err, "error converting json params to arguments")),
|
||||
types.RPCInternalError(request.ID, fmt.Errorf("error converting json params to arguments: %w", err)),
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
)
|
||||
|
||||
@@ -189,7 +187,7 @@ func NewRPCSuccessResponse(cdc *amino.Codec, id jsonrpcid, res interface{}) RPCR
|
||||
var js []byte
|
||||
js, err := cdc.MarshalJSON(res)
|
||||
if err != nil {
|
||||
return RPCInternalError(id, errors.Wrap(err, "Error marshalling response"))
|
||||
return RPCInternalError(id, fmt.Errorf("error marshalling response: %w", err))
|
||||
}
|
||||
rawMsg = json.RawMessage(js)
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@ package rpctypes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
)
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/pubsub/query"
|
||||
@@ -186,18 +184,18 @@ func (txi *TxIndex) Search(ctx context.Context, q *query.Query) ([]*types.TxResu
|
||||
// get a list of conditions (like "tx.height > 5")
|
||||
conditions, err := q.Conditions()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error during parsing conditions from query")
|
||||
return nil, fmt.Errorf("error during parsing conditions from query: %w", err)
|
||||
}
|
||||
|
||||
// if there is a hash condition, return the result immediately
|
||||
hash, ok, err := lookForHash(conditions)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error during searching for a hash in the query")
|
||||
return nil, fmt.Errorf("error during searching for a hash in the query: %w", err)
|
||||
} else if ok {
|
||||
res, err := txi.Get(hash)
|
||||
switch {
|
||||
case err != nil:
|
||||
return []*types.TxResult{}, errors.Wrap(err, "error while retrieving the result")
|
||||
return []*types.TxResult{}, fmt.Errorf("error while retrieving the result: %w", err)
|
||||
case res == nil:
|
||||
return []*types.TxResult{}, nil
|
||||
default:
|
||||
@@ -258,7 +256,7 @@ func (txi *TxIndex) Search(ctx context.Context, q *query.Query) ([]*types.TxResu
|
||||
for _, h := range filteredHashes {
|
||||
res, err := txi.Get(h)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get Tx{%X}", h)
|
||||
return nil, fmt.Errorf("failed to get Tx{%X}: %w", h, err)
|
||||
}
|
||||
results = append(results, res)
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
db "github.com/tendermint/tm-db"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
@@ -91,7 +89,7 @@ func (bs *BlockStore) LoadBlock(height int64) *types.Block {
|
||||
if err != nil {
|
||||
// NOTE: The existence of meta should imply the existence of the
|
||||
// block. So, make sure meta is only saved after blocks are saved.
|
||||
panic(errors.Wrap(err, "Error reading block"))
|
||||
panic(fmt.Sprintf("Error reading block: %v", err))
|
||||
}
|
||||
return block
|
||||
}
|
||||
@@ -112,7 +110,7 @@ func (bs *BlockStore) LoadBlockByHash(hash []byte) *types.Block {
|
||||
height, err := strconv.ParseInt(s, 10, 64)
|
||||
|
||||
if err != nil {
|
||||
panic(errors.Wrapf(err, "failed to extract height from %s", s))
|
||||
panic(fmt.Sprintf("failed to extract height from %s: %v", s, err))
|
||||
}
|
||||
return bs.LoadBlock(height)
|
||||
}
|
||||
@@ -131,7 +129,7 @@ func (bs *BlockStore) LoadBlockPart(height int64, index int) *types.Part {
|
||||
}
|
||||
err = cdc.UnmarshalBinaryBare(bz, part)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "Error reading block part"))
|
||||
panic(fmt.Sprintf("Error reading block part: %v", err))
|
||||
}
|
||||
return part
|
||||
}
|
||||
@@ -149,7 +147,7 @@ func (bs *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta {
|
||||
}
|
||||
err = cdc.UnmarshalBinaryBare(bz, blockMeta)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "Error reading block meta"))
|
||||
panic(fmt.Sprintf("Error reading block meta: %v", err))
|
||||
}
|
||||
return blockMeta
|
||||
}
|
||||
@@ -169,7 +167,7 @@ func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit {
|
||||
}
|
||||
err = cdc.UnmarshalBinaryBare(bz, commit)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "Error reading block commit"))
|
||||
panic(fmt.Sprintf("Error reading block commit: %v", err))
|
||||
}
|
||||
return commit
|
||||
}
|
||||
@@ -188,7 +186,7 @@ func (bs *BlockStore) LoadSeenCommit(height int64) *types.Commit {
|
||||
}
|
||||
err = cdc.UnmarshalBinaryBare(bz, commit)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "Error reading block seen commit"))
|
||||
panic(fmt.Sprintf("Error reading block seen commit: %v", err))
|
||||
}
|
||||
return commit
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
db "github.com/tendermint/tm-db"
|
||||
@@ -58,7 +57,7 @@ func makeStateAndBlockStore(logger log.Logger) (sm.State, *BlockStore, cleanupFu
|
||||
stateDB := dbm.NewMemDB()
|
||||
state, err := sm.LoadStateFromDBOrGenesisFile(stateDB, config.GenesisFile())
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "error constructing state from genesis file"))
|
||||
panic(fmt.Errorf("error constructing state from genesis file: %w", err))
|
||||
}
|
||||
return state, NewBlockStore(blockDB), func() { os.RemoveAll(config.RootDir) }
|
||||
}
|
||||
|
||||
@@ -2,13 +2,12 @@ package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/merkle"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
|
||||
@@ -2,8 +2,7 @@ package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// BlockMeta contains meta information.
|
||||
@@ -58,7 +57,7 @@ func (bm *BlockMeta) ValidateBasic() error {
|
||||
return err
|
||||
}
|
||||
if !bytes.Equal(bm.BlockID.Hash, bm.Header.Hash()) {
|
||||
return errors.Errorf("expected BlockID#Hash and Header#Hash to be the same, got %X != %X",
|
||||
return fmt.Errorf("expected BlockID#Hash and Header#Hash to be the same, got %X != %X",
|
||||
bm.BlockID.Hash, bm.Header.Hash())
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -2,12 +2,11 @@ package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
|
||||
@@ -485,7 +484,7 @@ func (ev ConflictingHeadersEvidence) VerifyComposite(committedHeader *Header, va
|
||||
// Max validator set size = 100 * 2 = 200 [fork?]
|
||||
maxNumValidators := valSet.Size() * 2
|
||||
if len(alternativeHeader.Commit.Signatures) > maxNumValidators {
|
||||
return errors.Errorf("alt commit contains too many signatures: %d, expected no more than %d",
|
||||
return fmt.Errorf("alt commit contains too many signatures: %d, expected no more than %d",
|
||||
len(alternativeHeader.Commit.Signatures),
|
||||
maxNumValidators)
|
||||
}
|
||||
@@ -496,7 +495,7 @@ func (ev ConflictingHeadersEvidence) VerifyComposite(committedHeader *Header, va
|
||||
alternativeHeader.ChainID,
|
||||
alternativeHeader.Commit,
|
||||
tmmath.Fraction{Numerator: 1, Denominator: 3}); err != nil {
|
||||
return errors.Wrap(err, "alt header does not have 1/3+ of voting power of our validator set")
|
||||
return fmt.Errorf("alt header does not have 1/3+ of voting power of our validator set: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -3,12 +3,11 @@ package types
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
@@ -70,7 +69,7 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
|
||||
return errors.New("genesis doc must include non-empty chain_id")
|
||||
}
|
||||
if len(genDoc.ChainID) > MaxChainIDLen {
|
||||
return errors.Errorf("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen)
|
||||
return fmt.Errorf("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen)
|
||||
}
|
||||
|
||||
if genDoc.ConsensusParams == nil {
|
||||
@@ -81,10 +80,10 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
|
||||
|
||||
for i, v := range genDoc.Validators {
|
||||
if v.Power == 0 {
|
||||
return errors.Errorf("the genesis file cannot contain validators with no voting power: %v", v)
|
||||
return fmt.Errorf("the genesis file cannot contain validators with no voting power: %v", v)
|
||||
}
|
||||
if len(v.Address) > 0 && !bytes.Equal(v.PubKey.Address(), v.Address) {
|
||||
return errors.Errorf("incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address())
|
||||
return fmt.Errorf("incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address())
|
||||
}
|
||||
if len(v.Address) == 0 {
|
||||
genDoc.Validators[i].Address = v.PubKey.Address()
|
||||
@@ -120,11 +119,11 @@ func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
|
||||
func GenesisDocFromFile(genDocFile string) (*GenesisDoc, error) {
|
||||
jsonBlob, err := ioutil.ReadFile(genDocFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Couldn't read GenesisDoc file")
|
||||
return nil, fmt.Errorf("couldn't read GenesisDoc file: %w", err)
|
||||
}
|
||||
genDoc, err := GenesisDocFromJSON(jsonBlob)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, fmt.Sprintf("Error reading GenesisDoc at %v", genDocFile))
|
||||
return nil, fmt.Errorf("error reading GenesisDoc at %s: %w", genDocFile, err)
|
||||
}
|
||||
return genDoc, nil
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
tmstrings "github.com/tendermint/tendermint/libs/strings"
|
||||
@@ -130,41 +130,41 @@ func (params *ValidatorParams) IsValidPubkeyType(pubkeyType string) bool {
|
||||
// allowed limits, and returns an error if they are not.
|
||||
func (params *ConsensusParams) Validate() error {
|
||||
if params.Block.MaxBytes <= 0 {
|
||||
return errors.Errorf("block.MaxBytes must be greater than 0. Got %d",
|
||||
return fmt.Errorf("block.MaxBytes must be greater than 0. Got %d",
|
||||
params.Block.MaxBytes)
|
||||
}
|
||||
if params.Block.MaxBytes > MaxBlockSizeBytes {
|
||||
return errors.Errorf("block.MaxBytes is too big. %d > %d",
|
||||
return fmt.Errorf("block.MaxBytes is too big. %d > %d",
|
||||
params.Block.MaxBytes, MaxBlockSizeBytes)
|
||||
}
|
||||
|
||||
if params.Block.MaxGas < -1 {
|
||||
return errors.Errorf("block.MaxGas must be greater or equal to -1. Got %d",
|
||||
return fmt.Errorf("block.MaxGas must be greater or equal to -1. Got %d",
|
||||
params.Block.MaxGas)
|
||||
}
|
||||
|
||||
if params.Block.TimeIotaMs <= 0 {
|
||||
return errors.Errorf("block.TimeIotaMs must be greater than 0. Got %v",
|
||||
return fmt.Errorf("block.TimeIotaMs must be greater than 0. Got %v",
|
||||
params.Block.TimeIotaMs)
|
||||
}
|
||||
|
||||
if params.Evidence.MaxAgeNumBlocks <= 0 {
|
||||
return errors.Errorf("evidenceParams.MaxAgeNumBlocks must be greater than 0. Got %d",
|
||||
return fmt.Errorf("evidenceParams.MaxAgeNumBlocks must be greater than 0. Got %d",
|
||||
params.Evidence.MaxAgeNumBlocks)
|
||||
}
|
||||
|
||||
if params.Evidence.MaxAgeDuration <= 0 {
|
||||
return errors.Errorf("evidenceParams.MaxAgeDuration must be grater than 0 if provided, Got %v",
|
||||
return fmt.Errorf("evidenceParams.MaxAgeDuration must be grater than 0 if provided, Got %v",
|
||||
params.Evidence.MaxAgeDuration)
|
||||
}
|
||||
|
||||
if params.Evidence.MaxNum > MaxEvidencePerBlock {
|
||||
return errors.Errorf("evidenceParams.MaxNumEvidence is greater than upper bound, %d > %d",
|
||||
return fmt.Errorf("evidenceParams.MaxNumEvidence is greater than upper bound, %d > %d",
|
||||
params.Evidence.MaxNum, MaxEvidencePerBlock)
|
||||
}
|
||||
|
||||
if int64(params.Evidence.MaxNum)*MaxEvidenceBytes > params.Block.MaxBytes {
|
||||
return errors.Errorf("total possible evidence size is bigger than block.MaxBytes, %d > %d",
|
||||
return fmt.Errorf("total possible evidence size is bigger than block.MaxBytes, %d > %d",
|
||||
int64(params.Evidence.MaxNum)*MaxEvidenceBytes, params.Block.MaxBytes)
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ func (params *ConsensusParams) Validate() error {
|
||||
for i := 0; i < len(params.Validator.PubKeyTypes); i++ {
|
||||
keyType := params.Validator.PubKeyTypes[i]
|
||||
if _, ok := ABCIPubKeyTypesToAminoNames[keyType]; !ok {
|
||||
return errors.Errorf("params.Validator.PubKeyTypes[%d], %s, is an unknown pubkey type",
|
||||
return fmt.Errorf("params.Validator.PubKeyTypes[%d], %s, is an unknown pubkey type",
|
||||
i, keyType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@ package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/merkle"
|
||||
"github.com/tendermint/tendermint/libs/bits"
|
||||
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
||||
@@ -31,10 +30,10 @@ func (part *Part) ValidateBasic() error {
|
||||
return errors.New("negative Index")
|
||||
}
|
||||
if len(part.Bytes) > BlockPartSizeBytes {
|
||||
return errors.Errorf("too big: %d bytes, max: %d", len(part.Bytes), BlockPartSizeBytes)
|
||||
return fmt.Errorf("too big: %d bytes, max: %d", len(part.Bytes), BlockPartSizeBytes)
|
||||
}
|
||||
if err := part.Proof.ValidateBasic(); err != nil {
|
||||
return errors.Wrap(err, "wrong Proof")
|
||||
return fmt.Errorf("wrong Proof: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -80,7 +79,7 @@ func (psh PartSetHeader) ValidateBasic() error {
|
||||
}
|
||||
// Hash can be empty in case of POLBlockID.PartsHeader in Proposal.
|
||||
if err := ValidateHash(psh.Hash); err != nil {
|
||||
return errors.Wrap(err, "Wrong Hash")
|
||||
return fmt.Errorf("wrong Hash: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func MakeCommit(blockID BlockID, height int64, round int,
|
||||
@@ -13,7 +12,7 @@ func MakeCommit(blockID BlockID, height int64, round int,
|
||||
for i := 0; i < len(validators); i++ {
|
||||
pubKey, err := validators[i].GetPubKey()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "can't get pubkey")
|
||||
return nil, fmt.Errorf("can't get pubkey: %w", err)
|
||||
}
|
||||
vote := &Vote{
|
||||
ValidatorAddress: pubKey.Address(),
|
||||
@@ -52,7 +51,7 @@ func MakeVote(
|
||||
) (*Vote, error) {
|
||||
pubKey, err := privVal.GetPubKey()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "can't get pubkey")
|
||||
return nil, fmt.Errorf("can't get pubkey: %w", err)
|
||||
}
|
||||
addr := pubKey.Address()
|
||||
idx, _ := valSet.GetByAddress(addr)
|
||||
|
||||
@@ -2,14 +2,13 @@ package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/merkle"
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
)
|
||||
@@ -751,7 +750,7 @@ func (vals *ValidatorSet) VerifyFutureCommit(newSet *ValidatorSet, chainID strin
|
||||
// Validate signature.
|
||||
voteSignBytes := commit.VoteSignBytes(chainID, idx)
|
||||
if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) {
|
||||
return errors.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature)
|
||||
return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature)
|
||||
}
|
||||
// Good!
|
||||
if blockID.Equals(commitSig.BlockID(commit.BlockID)) {
|
||||
@@ -805,14 +804,14 @@ func (vals *ValidatorSet) VerifyCommitTrusting(chainID string, commit *Commit, t
|
||||
// check for double vote of validator on the same commit
|
||||
if firstIndex, ok := seenVals[valIdx]; ok {
|
||||
secondIndex := idx
|
||||
return errors.Errorf("double vote from %v (%d and %d)", val, firstIndex, secondIndex)
|
||||
return fmt.Errorf("double vote from %v (%d and %d)", val, firstIndex, secondIndex)
|
||||
}
|
||||
seenVals[valIdx] = idx
|
||||
|
||||
// Validate signature.
|
||||
voteSignBytes := commit.VoteSignBytes(chainID, idx)
|
||||
if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) {
|
||||
return errors.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature)
|
||||
return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature)
|
||||
}
|
||||
|
||||
// Good!
|
||||
@@ -838,8 +837,7 @@ func (vals *ValidatorSet) VerifyCommitTrusting(chainID string, commit *Commit, t
|
||||
// IsErrNotEnoughVotingPowerSigned returns true if err is
|
||||
// ErrNotEnoughVotingPowerSigned.
|
||||
func IsErrNotEnoughVotingPowerSigned(err error) bool {
|
||||
_, ok := errors.Cause(err).(ErrNotEnoughVotingPowerSigned)
|
||||
return ok
|
||||
return errors.As(err, &ErrNotEnoughVotingPowerSigned{})
|
||||
}
|
||||
|
||||
// ErrNotEnoughVotingPowerSigned is returned when not enough validators signed
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/bits"
|
||||
)
|
||||
|
||||
@@ -160,33 +158,34 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {
|
||||
|
||||
// Ensure that validator index was set
|
||||
if valIndex < 0 {
|
||||
return false, errors.Wrap(ErrVoteInvalidValidatorIndex, "Index < 0")
|
||||
return false, fmt.Errorf("index < 0: %w", ErrVoteInvalidValidatorIndex)
|
||||
} else if len(valAddr) == 0 {
|
||||
return false, errors.Wrap(ErrVoteInvalidValidatorAddress, "Empty address")
|
||||
return false, fmt.Errorf("empty address: %w", ErrVoteInvalidValidatorAddress)
|
||||
}
|
||||
|
||||
// Make sure the step matches.
|
||||
if (vote.Height != voteSet.height) ||
|
||||
(vote.Round != voteSet.round) ||
|
||||
(vote.Type != voteSet.signedMsgType) {
|
||||
return false, errors.Wrapf(ErrVoteUnexpectedStep, "Expected %d/%d/%d, but got %d/%d/%d",
|
||||
return false, fmt.Errorf("expected %d/%d/%d, but got %d/%d/%d: %w",
|
||||
voteSet.height, voteSet.round, voteSet.signedMsgType,
|
||||
vote.Height, vote.Round, vote.Type)
|
||||
vote.Height, vote.Round, vote.Type, ErrVoteUnexpectedStep)
|
||||
}
|
||||
|
||||
// Ensure that signer is a validator.
|
||||
lookupAddr, val := voteSet.valSet.GetByIndex(valIndex)
|
||||
if val == nil {
|
||||
return false, errors.Wrapf(ErrVoteInvalidValidatorIndex,
|
||||
"Cannot find validator %d in valSet of size %d", valIndex, voteSet.valSet.Size())
|
||||
return false, fmt.Errorf(
|
||||
"cannot find validator %d in valSet of size %d: %w",
|
||||
valIndex, voteSet.valSet.Size(), ErrVoteInvalidValidatorIndex)
|
||||
}
|
||||
|
||||
// Ensure that the signer has the right address.
|
||||
if !bytes.Equal(valAddr, lookupAddr) {
|
||||
return false, errors.Wrapf(ErrVoteInvalidValidatorAddress,
|
||||
return false, fmt.Errorf(
|
||||
"vote.ValidatorAddress (%X) does not match address (%X) for vote.ValidatorIndex (%d)\n"+
|
||||
"Ensure the genesis file is correct across all validators.",
|
||||
valAddr, lookupAddr, valIndex)
|
||||
"Ensure the genesis file is correct across all validators: %w",
|
||||
valAddr, lookupAddr, valIndex, ErrVoteInvalidValidatorAddress)
|
||||
}
|
||||
|
||||
// If we already know of this vote, return false.
|
||||
@@ -194,12 +193,12 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {
|
||||
if bytes.Equal(existing.Signature, vote.Signature) {
|
||||
return false, nil // duplicate
|
||||
}
|
||||
return false, errors.Wrapf(ErrVoteNonDeterministicSignature, "Existing vote: %v; New vote: %v", existing, vote)
|
||||
return false, fmt.Errorf("existing vote: %v; new vote: %v: %w", existing, vote, ErrVoteNonDeterministicSignature)
|
||||
}
|
||||
|
||||
// Check signature.
|
||||
if err := vote.Verify(voteSet.chainID, val.PubKey); err != nil {
|
||||
return false, errors.Wrapf(err, "Failed to verify vote with ChainID %s and PubKey %s", voteSet.chainID, val.PubKey)
|
||||
return false, fmt.Errorf("failed to verify vote with ChainID %s and PubKey %s: %w", voteSet.chainID, val.PubKey, err)
|
||||
}
|
||||
|
||||
// Add vote and get conflicting vote if any.
|
||||
|
||||
Reference in New Issue
Block a user