mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
replace errors.go with github.com/pkg/errors (1/2) (#3888)
* (1/2) of replace errors.go with github.com/pkg/errors ref #3862 - step one in removing instances of errors.go in favor of github.com/pkg/errors Signed-off-by: Marko Baricevic <marbar3778@yahoo.com> * gofmt * add in /store
This commit is contained in:
parent
d70135ec71
commit
8dc39b69b7
@ -6,13 +6,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/tendermint/tendermint/store"
|
"github.com/tendermint/tendermint/store"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
"github.com/tendermint/tendermint/mock"
|
"github.com/tendermint/tendermint/mock"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
@ -60,7 +60,7 @@ func newBlockchainReactor(logger log.Logger, genDoc *types.GenesisDoc, privVals
|
|||||||
proxyApp := proxy.NewAppConns(cc)
|
proxyApp := proxy.NewAppConns(cc)
|
||||||
err := proxyApp.Start()
|
err := proxyApp.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(cmn.ErrorWrap(err, "error start app"))
|
panic(errors.Wrap(err, "error start app"))
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDB := dbm.NewMemDB()
|
blockDB := dbm.NewMemDB()
|
||||||
@ -69,7 +69,7 @@ func newBlockchainReactor(logger log.Logger, genDoc *types.GenesisDoc, privVals
|
|||||||
|
|
||||||
state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
|
state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(cmn.ErrorWrap(err, "error constructing state from genesis file"))
|
panic(errors.Wrap(err, "error constructing state from genesis file"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the BlockchainReactor itself.
|
// Make the BlockchainReactor itself.
|
||||||
@ -103,7 +103,7 @@ func newBlockchainReactor(logger log.Logger, genDoc *types.GenesisDoc, privVals
|
|||||||
|
|
||||||
state, err = blockExec.ApplyBlock(state, blockID, thisBlock)
|
state, err = blockExec.ApplyBlock(state, blockID, thisBlock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(cmn.ErrorWrap(err, "error apply block"))
|
panic(errors.Wrap(err, "error apply block"))
|
||||||
}
|
}
|
||||||
|
|
||||||
blockStore.SaveBlock(thisBlock, thisParts, lastCommit)
|
blockStore.SaveBlock(thisBlock, thisParts, lastCommit)
|
||||||
|
@ -8,10 +8,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
"github.com/tendermint/tendermint/mock"
|
"github.com/tendermint/tendermint/mock"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
@ -78,7 +78,7 @@ func newBlockchainReactor(logger log.Logger, genDoc *types.GenesisDoc, privVals
|
|||||||
proxyApp := proxy.NewAppConns(cc)
|
proxyApp := proxy.NewAppConns(cc)
|
||||||
err := proxyApp.Start()
|
err := proxyApp.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(cmn.ErrorWrap(err, "error start app"))
|
panic(errors.Wrap(err, "error start app"))
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDB := dbm.NewMemDB()
|
blockDB := dbm.NewMemDB()
|
||||||
@ -87,7 +87,7 @@ func newBlockchainReactor(logger log.Logger, genDoc *types.GenesisDoc, privVals
|
|||||||
|
|
||||||
state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
|
state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(cmn.ErrorWrap(err, "error constructing state from genesis file"))
|
panic(errors.Wrap(err, "error constructing state from genesis file"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the BlockchainReactor itself.
|
// Make the BlockchainReactor itself.
|
||||||
@ -117,7 +117,7 @@ func newBlockchainReactor(logger log.Logger, genDoc *types.GenesisDoc, privVals
|
|||||||
|
|
||||||
state, err = blockExec.ApplyBlock(state, blockID, thisBlock)
|
state, err = blockExec.ApplyBlock(state, blockID, thisBlock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(cmn.ErrorWrap(err, "error apply block"))
|
panic(errors.Wrap(err, "error apply block"))
|
||||||
}
|
}
|
||||||
|
|
||||||
blockStore.SaveBlock(thisBlock, thisParts, lastCommit)
|
blockStore.SaveBlock(thisBlock, thisParts, lastCommit)
|
||||||
|
@ -3,7 +3,7 @@ package merkle
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
@ -44,11 +44,11 @@ func (poz ProofOperators) Verify(root []byte, keypath string, args [][]byte) (er
|
|||||||
key := op.GetKey()
|
key := op.GetKey()
|
||||||
if len(key) != 0 {
|
if len(key) != 0 {
|
||||||
if len(keys) == 0 {
|
if len(keys) == 0 {
|
||||||
return cmn.NewError("Key path has insufficient # of parts: expected no more keys but got %+v", string(key))
|
return errors.Errorf("Key path has insufficient # of parts: expected no more keys but got %+v", string(key))
|
||||||
}
|
}
|
||||||
lastKey := keys[len(keys)-1]
|
lastKey := keys[len(keys)-1]
|
||||||
if !bytes.Equal(lastKey, key) {
|
if !bytes.Equal(lastKey, key) {
|
||||||
return cmn.NewError("Key mismatch on operation #%d: expected %+v but got %+v", i, string(lastKey), string(key))
|
return errors.Errorf("Key mismatch on operation #%d: expected %+v but got %+v", i, string(lastKey), string(key))
|
||||||
}
|
}
|
||||||
keys = keys[:len(keys)-1]
|
keys = keys[:len(keys)-1]
|
||||||
}
|
}
|
||||||
@ -58,10 +58,10 @@ func (poz ProofOperators) Verify(root []byte, keypath string, args [][]byte) (er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !bytes.Equal(root, args[0]) {
|
if !bytes.Equal(root, args[0]) {
|
||||||
return cmn.NewError("Calculated root hash is invalid: expected %+v but got %+v", root, args[0])
|
return errors.Errorf("Calculated root hash is invalid: expected %+v but got %+v", root, args[0])
|
||||||
}
|
}
|
||||||
if len(keys) != 0 {
|
if len(keys) != 0 {
|
||||||
return cmn.NewError("Keypath not consumed all")
|
return errors.New("Keypath not consumed all")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ func (prt *ProofRuntime) RegisterOpDecoder(typ string, dec OpDecoder) {
|
|||||||
func (prt *ProofRuntime) Decode(pop ProofOp) (ProofOperator, error) {
|
func (prt *ProofRuntime) Decode(pop ProofOp) (ProofOperator, error) {
|
||||||
decoder := prt.decoders[pop.Type]
|
decoder := prt.decoders[pop.Type]
|
||||||
if decoder == nil {
|
if decoder == nil {
|
||||||
return nil, cmn.NewError("unrecognized proof type %v", pop.Type)
|
return nil, errors.Errorf("unrecognized proof type %v", pop.Type)
|
||||||
}
|
}
|
||||||
return decoder(pop)
|
return decoder(pop)
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ func (prt *ProofRuntime) DecodeProof(proof *Proof) (ProofOperators, error) {
|
|||||||
for _, pop := range proof.Ops {
|
for _, pop := range proof.Ops {
|
||||||
operator, err := prt.Decode(pop)
|
operator, err := prt.Decode(pop)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cmn.ErrorWrap(err, "decoding a proof operator")
|
return nil, errors.Wrap(err, "decoding a proof operator")
|
||||||
}
|
}
|
||||||
poz = append(poz, operator)
|
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) {
|
func (prt *ProofRuntime) Verify(proof *Proof, root []byte, keypath string, args [][]byte) (err error) {
|
||||||
poz, err := prt.DecodeProof(proof)
|
poz, err := prt.DecodeProof(proof)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cmn.ErrorWrap(err, "decoding proof")
|
return errors.Wrap(err, "decoding proof")
|
||||||
}
|
}
|
||||||
return poz.Verify(root, keypath, args)
|
return poz.Verify(root, keypath, args)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -87,7 +87,7 @@ func (pth KeyPath) String() string {
|
|||||||
// Each key must use a known encoding.
|
// Each key must use a known encoding.
|
||||||
func KeyPathToKeys(path string) (keys [][]byte, err error) {
|
func KeyPathToKeys(path string) (keys [][]byte, err error) {
|
||||||
if path == "" || path[0] != '/' {
|
if path == "" || path[0] != '/' {
|
||||||
return nil, cmn.NewError("key path string must start with a forward slash '/'")
|
return nil, errors.New("key path string must start with a forward slash '/'")
|
||||||
}
|
}
|
||||||
parts := strings.Split(path[1:], "/")
|
parts := strings.Split(path[1:], "/")
|
||||||
keys = make([][]byte, len(parts))
|
keys = make([][]byte, len(parts))
|
||||||
@ -96,13 +96,13 @@ func KeyPathToKeys(path string) (keys [][]byte, err error) {
|
|||||||
hexPart := part[2:]
|
hexPart := part[2:]
|
||||||
key, err := hex.DecodeString(hexPart)
|
key, err := hex.DecodeString(hexPart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cmn.ErrorWrap(err, "decoding hex-encoded part #%d: /%s", i, part)
|
return nil, errors.Wrapf(err, "decoding hex-encoded part #%d: /%s", i, part)
|
||||||
}
|
}
|
||||||
keys[i] = key
|
keys[i] = key
|
||||||
} else {
|
} else {
|
||||||
key, err := url.PathUnescape(part)
|
key, err := url.PathUnescape(part)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cmn.ErrorWrap(err, "decoding url-encoded part #%d: /%s", i, part)
|
return nil, errors.Wrapf(err, "decoding url-encoded part #%d: /%s", i, part)
|
||||||
}
|
}
|
||||||
keys[i] = []byte(key) // TODO Test this with random bytes, I'm not sure that it works for arbitrary bytes...
|
keys[i] = []byte(key) // TODO Test this with random bytes, I'm not sure that it works for arbitrary bytes...
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,9 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const ProofOpSimpleValue = "simple:v"
|
const ProofOpSimpleValue = "simple:v"
|
||||||
@ -39,12 +40,12 @@ func NewSimpleValueOp(key []byte, proof *SimpleProof) SimpleValueOp {
|
|||||||
|
|
||||||
func SimpleValueOpDecoder(pop ProofOp) (ProofOperator, error) {
|
func SimpleValueOpDecoder(pop ProofOp) (ProofOperator, error) {
|
||||||
if pop.Type != ProofOpSimpleValue {
|
if pop.Type != ProofOpSimpleValue {
|
||||||
return nil, cmn.NewError("unexpected ProofOp.Type; got %v, want %v", pop.Type, ProofOpSimpleValue)
|
return nil, errors.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.
|
var op SimpleValueOp // a bit strange as we'll discard this, but it works.
|
||||||
err := cdc.UnmarshalBinaryLengthPrefixed(pop.Data, &op)
|
err := cdc.UnmarshalBinaryLengthPrefixed(pop.Data, &op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cmn.ErrorWrap(err, "decoding ProofOp.Data into SimpleValueOp")
|
return nil, errors.Wrap(err, "decoding ProofOp.Data into SimpleValueOp")
|
||||||
}
|
}
|
||||||
return NewSimpleValueOp(pop.Key, op.Proof), nil
|
return NewSimpleValueOp(pop.Key, op.Proof), nil
|
||||||
}
|
}
|
||||||
@ -64,7 +65,7 @@ func (op SimpleValueOp) String() string {
|
|||||||
|
|
||||||
func (op SimpleValueOp) Run(args [][]byte) ([][]byte, error) {
|
func (op SimpleValueOp) Run(args [][]byte) ([][]byte, error) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, cmn.NewError("expected 1 arg, got %v", len(args))
|
return nil, errors.Errorf("expected 1 arg, got %v", len(args))
|
||||||
}
|
}
|
||||||
value := args[0]
|
value := args[0]
|
||||||
hasher := tmhash.New()
|
hasher := tmhash.New()
|
||||||
@ -78,7 +79,7 @@ func (op SimpleValueOp) Run(args [][]byte) ([][]byte, error) {
|
|||||||
kvhash := leafHash(bz.Bytes())
|
kvhash := leafHash(bz.Bytes())
|
||||||
|
|
||||||
if !bytes.Equal(kvhash, op.Proof.LeafHash) {
|
if !bytes.Equal(kvhash, op.Proof.LeafHash) {
|
||||||
return nil, cmn.NewError("leaf hash mismatch: want %X got %X", op.Proof.LeafHash, kvhash)
|
return nil, errors.Errorf("leaf hash mismatch: want %X got %X", op.Proof.LeafHash, kvhash)
|
||||||
}
|
}
|
||||||
|
|
||||||
return [][]byte{
|
return [][]byte{
|
||||||
|
@ -3,9 +3,9 @@ package merkle
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
amino "github.com/tendermint/go-amino"
|
amino "github.com/tendermint/go-amino"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const ProofOpDomino = "test:domino"
|
const ProofOpDomino = "test:domino"
|
||||||
@ -34,7 +34,7 @@ func DominoOpDecoder(pop ProofOp) (ProofOperator, error) {
|
|||||||
var op DominoOp // a bit strange as we'll discard this, but it works.
|
var op DominoOp // a bit strange as we'll discard this, but it works.
|
||||||
err := amino.UnmarshalBinaryLengthPrefixed(pop.Data, &op)
|
err := amino.UnmarshalBinaryLengthPrefixed(pop.Data, &op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cmn.ErrorWrap(err, "decoding ProofOp.Data into SimpleValueOp")
|
return nil, errors.Wrap(err, "decoding ProofOp.Data into SimpleValueOp")
|
||||||
}
|
}
|
||||||
return NewDominoOp(string(pop.Key), op.Input, op.Output), nil
|
return NewDominoOp(string(pop.Key), op.Input, op.Output), nil
|
||||||
}
|
}
|
||||||
@ -50,10 +50,10 @@ func (dop DominoOp) ProofOp() ProofOp {
|
|||||||
|
|
||||||
func (dop DominoOp) Run(input [][]byte) (output [][]byte, err error) {
|
func (dop DominoOp) Run(input [][]byte) (output [][]byte, err error) {
|
||||||
if len(input) != 1 {
|
if len(input) != 1 {
|
||||||
return nil, cmn.NewError("Expected input of length 1")
|
return nil, errors.New("Expected input of length 1")
|
||||||
}
|
}
|
||||||
if string(input[0]) != dop.Input {
|
if string(input[0]) != dop.Input {
|
||||||
return nil, cmn.NewError("Expected input %v, got %v",
|
return nil, errors.Errorf("Expected input %v, got %v",
|
||||||
dop.Input, string(input[0]))
|
dop.Input, string(input[0]))
|
||||||
}
|
}
|
||||||
return [][]byte{[]byte(dop.Output)}, nil
|
return [][]byte{[]byte(dop.Output)}, nil
|
||||||
|
@ -222,7 +222,7 @@ func (sw *Switch) OnStart() error {
|
|||||||
for _, reactor := range sw.reactors {
|
for _, reactor := range sw.reactors {
|
||||||
err := reactor.Start()
|
err := reactor.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cmn.ErrorWrap(err, "failed to start %v", reactor)
|
return errors.Wrapf(err, "failed to start %v", reactor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
@ -233,7 +235,7 @@ func testPeerConn(
|
|||||||
// Encrypt connection
|
// Encrypt connection
|
||||||
conn, err = upgradeSecretConn(conn, cfg.HandshakeTimeout, ourNodePrivKey)
|
conn, err = upgradeSecretConn(conn, cfg.HandshakeTimeout, ourNodePrivKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pc, cmn.ErrorWrap(err, "Error creating peer")
|
return pc, errors.Wrap(err, "Error creating peer")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only the information we already have
|
// Only the information we already have
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package privval
|
package privval
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
amino "github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
@ -4,7 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
dbm "github.com/tendermint/tm-db"
|
dbm "github.com/tendermint/tm-db"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
@ -67,7 +68,7 @@ func (bs *BlockStore) LoadBlock(height int64) *types.Block {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// NOTE: The existence of meta should imply the existence of the
|
// NOTE: The existence of meta should imply the existence of the
|
||||||
// block. So, make sure meta is only saved after blocks are saved.
|
// block. So, make sure meta is only saved after blocks are saved.
|
||||||
panic(cmn.ErrorWrap(err, "Error reading block"))
|
panic(errors.Wrap(err, "Error reading block"))
|
||||||
}
|
}
|
||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
@ -83,7 +84,7 @@ func (bs *BlockStore) LoadBlockPart(height int64, index int) *types.Part {
|
|||||||
}
|
}
|
||||||
err := cdc.UnmarshalBinaryBare(bz, part)
|
err := cdc.UnmarshalBinaryBare(bz, part)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(cmn.ErrorWrap(err, "Error reading block part"))
|
panic(errors.Wrap(err, "Error reading block part"))
|
||||||
}
|
}
|
||||||
return part
|
return part
|
||||||
}
|
}
|
||||||
@ -98,7 +99,7 @@ func (bs *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta {
|
|||||||
}
|
}
|
||||||
err := cdc.UnmarshalBinaryBare(bz, blockMeta)
|
err := cdc.UnmarshalBinaryBare(bz, blockMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(cmn.ErrorWrap(err, "Error reading block meta"))
|
panic(errors.Wrap(err, "Error reading block meta"))
|
||||||
}
|
}
|
||||||
return blockMeta
|
return blockMeta
|
||||||
}
|
}
|
||||||
@ -115,7 +116,7 @@ func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit {
|
|||||||
}
|
}
|
||||||
err := cdc.UnmarshalBinaryBare(bz, commit)
|
err := cdc.UnmarshalBinaryBare(bz, commit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(cmn.ErrorWrap(err, "Error reading block commit"))
|
panic(errors.Wrap(err, "Error reading block commit"))
|
||||||
}
|
}
|
||||||
return commit
|
return commit
|
||||||
}
|
}
|
||||||
@ -131,7 +132,7 @@ func (bs *BlockStore) LoadSeenCommit(height int64) *types.Commit {
|
|||||||
}
|
}
|
||||||
err := cdc.UnmarshalBinaryBare(bz, commit)
|
err := cdc.UnmarshalBinaryBare(bz, commit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(cmn.ErrorWrap(err, "Error reading block seen commit"))
|
panic(errors.Wrap(err, "Error reading block seen commit"))
|
||||||
}
|
}
|
||||||
return commit
|
return commit
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
db "github.com/tendermint/tm-db"
|
db "github.com/tendermint/tm-db"
|
||||||
dbm "github.com/tendermint/tm-db"
|
dbm "github.com/tendermint/tm-db"
|
||||||
|
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ func makeStateAndBlockStore(logger log.Logger) (sm.State, *BlockStore, cleanupFu
|
|||||||
stateDB := dbm.NewMemDB()
|
stateDB := dbm.NewMemDB()
|
||||||
state, err := sm.LoadStateFromDBOrGenesisFile(stateDB, config.GenesisFile())
|
state, err := sm.LoadStateFromDBOrGenesisFile(stateDB, config.GenesisFile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(cmn.ErrorWrap(err, "error constructing state from genesis file"))
|
panic(errors.Wrap(err, "error constructing state from genesis file"))
|
||||||
}
|
}
|
||||||
return state, NewBlockStore(blockDB), func() { os.RemoveAll(config.RootDir) }
|
return state, NewBlockStore(blockDB), func() { os.RemoveAll(config.RootDir) }
|
||||||
}
|
}
|
||||||
|
@ -748,7 +748,7 @@ func (sh SignedHeader) ValidateBasic(chainID string) error {
|
|||||||
// ValidateBasic on the Commit.
|
// ValidateBasic on the Commit.
|
||||||
err := sh.Commit.ValidateBasic()
|
err := sh.Commit.ValidateBasic()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cmn.ErrorWrap(err, "commit.ValidateBasic failed during SignedHeader.ValidateBasic")
|
return errors.Wrap(err, "commit.ValidateBasic failed during SignedHeader.ValidateBasic")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
tmtime "github.com/tendermint/tendermint/types/time"
|
tmtime "github.com/tendermint/tendermint/types/time"
|
||||||
@ -64,10 +66,10 @@ func (genDoc *GenesisDoc) ValidatorHash() []byte {
|
|||||||
// and fills in defaults for optional fields left empty
|
// and fills in defaults for optional fields left empty
|
||||||
func (genDoc *GenesisDoc) ValidateAndComplete() error {
|
func (genDoc *GenesisDoc) ValidateAndComplete() error {
|
||||||
if genDoc.ChainID == "" {
|
if genDoc.ChainID == "" {
|
||||||
return cmn.NewError("Genesis doc must include non-empty chain_id")
|
return errors.New("Genesis doc must include non-empty chain_id")
|
||||||
}
|
}
|
||||||
if len(genDoc.ChainID) > MaxChainIDLen {
|
if len(genDoc.ChainID) > MaxChainIDLen {
|
||||||
return cmn.NewError("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen)
|
return errors.Errorf("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
if genDoc.ConsensusParams == nil {
|
if genDoc.ConsensusParams == nil {
|
||||||
@ -78,10 +80,10 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
|
|||||||
|
|
||||||
for i, v := range genDoc.Validators {
|
for i, v := range genDoc.Validators {
|
||||||
if v.Power == 0 {
|
if v.Power == 0 {
|
||||||
return cmn.NewError("The genesis file cannot contain validators with no voting power: %v", v)
|
return errors.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) {
|
if len(v.Address) > 0 && !bytes.Equal(v.PubKey.Address(), v.Address) {
|
||||||
return cmn.NewError("Incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address())
|
return errors.Errorf("Incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address())
|
||||||
}
|
}
|
||||||
if len(v.Address) == 0 {
|
if len(v.Address) == 0 {
|
||||||
genDoc.Validators[i].Address = v.PubKey.Address()
|
genDoc.Validators[i].Address = v.PubKey.Address()
|
||||||
@ -117,11 +119,11 @@ func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
|
|||||||
func GenesisDocFromFile(genDocFile string) (*GenesisDoc, error) {
|
func GenesisDocFromFile(genDocFile string) (*GenesisDoc, error) {
|
||||||
jsonBlob, err := ioutil.ReadFile(genDocFile)
|
jsonBlob, err := ioutil.ReadFile(genDocFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cmn.ErrorWrap(err, "Couldn't read GenesisDoc file")
|
return nil, errors.Wrap(err, "Couldn't read GenesisDoc file")
|
||||||
}
|
}
|
||||||
genDoc, err := GenesisDocFromJSON(jsonBlob)
|
genDoc, err := GenesisDocFromJSON(jsonBlob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cmn.ErrorWrap(err, fmt.Sprintf("Error reading GenesisDoc at %v", genDocFile))
|
return nil, errors.Wrap(err, fmt.Sprintf("Error reading GenesisDoc at %v", genDocFile))
|
||||||
}
|
}
|
||||||
return genDoc, nil
|
return genDoc, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user