mirror of
https://github.com/tendermint/tendermint.git
synced 2026-04-23 01:00:31 +00:00
lint
This commit is contained in:
@@ -218,7 +218,9 @@ func (bcR *Reactor) Receive(e p2p.Envelope) {
|
||||
|
||||
switch msg := e.Message.(type) {
|
||||
case *bcproto.BlockRequest:
|
||||
bcR.respondToPeer(msg, e.Src)
|
||||
if err := bcR.respondToPeer(msg, e.Src); err != nil {
|
||||
bcR.Logger.Error("responding to block request", "err", err)
|
||||
}
|
||||
case *bcproto.BlockResponse:
|
||||
block, err := types.BlockFromProto(msg.Block)
|
||||
if err != nil {
|
||||
|
||||
@@ -36,7 +36,9 @@ func initFilesWithConfig(config *cfg.Config) error {
|
||||
"stateFile", privValStateFile)
|
||||
} else {
|
||||
pv = privval.GenFilePV(privValKeyFile, privValStateFile)
|
||||
pv.Save()
|
||||
if err := pv.Save(); err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("Generated private validator", "keyFile", privValKeyFile,
|
||||
"stateFile", privValStateFile)
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ func resetFilePV(privValKeyFile, privValStateFile string, logger log.Logger) {
|
||||
)
|
||||
} else {
|
||||
pv := privval.GenFilePV(privValKeyFile, privValStateFile)
|
||||
pv.Save()
|
||||
_ = pv.Save()
|
||||
logger.Info(
|
||||
"Generated private validator file",
|
||||
"keyFile", privValKeyFile,
|
||||
|
||||
@@ -18,7 +18,7 @@ func Test_ResetAll(t *testing.T) {
|
||||
require.NoError(t, initFilesWithConfig(config))
|
||||
pv := privval.LoadFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
|
||||
pv.LastSignState.Height = 10
|
||||
pv.Save()
|
||||
require.NoError(t, pv.Save())
|
||||
require.NoError(t, resetAll(config.DBDir(), config.P2P.AddrBookFile(), config.PrivValidatorKeyFile(),
|
||||
config.PrivValidatorStateFile(), logger))
|
||||
require.DirExists(t, config.DBDir())
|
||||
@@ -39,7 +39,7 @@ func Test_ResetState(t *testing.T) {
|
||||
require.NoError(t, initFilesWithConfig(config))
|
||||
pv := privval.LoadFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
|
||||
pv.LastSignState.Height = 10
|
||||
pv.Save()
|
||||
require.NoError(t, pv.Save())
|
||||
require.NoError(t, resetState(config.DBDir(), logger))
|
||||
require.DirExists(t, config.DBDir())
|
||||
require.NoFileExists(t, filepath.Join(config.DBDir(), "block.db"))
|
||||
|
||||
@@ -459,6 +459,15 @@ func TestByzantineConflictingProposalsWithPartition(t *testing.T) {
|
||||
// }
|
||||
}
|
||||
|
||||
func getSwitchIndex(switches []*p2p.Switch, peer p2p.Peer) int {
|
||||
for i, s := range switches {
|
||||
if peer.NodeInfo().ID() == s.NodeInfo().ID() {
|
||||
return i
|
||||
}
|
||||
}
|
||||
panic("didnt find peer in switches")
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// byzantine consensus functions
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
mempl "github.com/tendermint/tendermint/mempool"
|
||||
mempoolv0 "github.com/tendermint/tendermint/mempool/v0"
|
||||
mempoolv1 "github.com/tendermint/tendermint/mempool/v1"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
"github.com/tendermint/tendermint/privval"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
"github.com/tendermint/tendermint/proxy"
|
||||
@@ -582,15 +581,6 @@ func makeNetwork(t *testing.T, args makeNetworkArgs) ([]*State, []types.PrivVali
|
||||
return css, privVals, args.config
|
||||
}
|
||||
|
||||
func getSwitchIndex(switches []*p2p.Switch, peer p2p.Peer) int {
|
||||
for i, s := range switches {
|
||||
if peer.NodeInfo().ID() == s.NodeInfo().ID() {
|
||||
return i
|
||||
}
|
||||
}
|
||||
panic("didnt find peer in switches")
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// genesis
|
||||
|
||||
@@ -922,22 +912,10 @@ func (m *mockTicker) Chan() <-chan timeoutInfo {
|
||||
|
||||
func (*mockTicker) SetLogger(log.Logger) {}
|
||||
|
||||
func newPersistentKVStore() abci.Application {
|
||||
dir, err := os.MkdirTemp("", "persistent-kvstore")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return kvstore.NewPersistentApplication(dir)
|
||||
}
|
||||
|
||||
func newKVStore() abci.Application {
|
||||
return kvstore.NewInMemoryApplication()
|
||||
}
|
||||
|
||||
func newPersistentKVStoreWithPath(dbDir string) abci.Application {
|
||||
return kvstore.NewPersistentApplication(dbDir)
|
||||
}
|
||||
|
||||
func signDataIsEqual(v1 *types.Vote, v2 *tmproto.Vote) bool {
|
||||
if v1 == nil || v2 == nil {
|
||||
return false
|
||||
|
||||
@@ -135,7 +135,7 @@ func (lss *FilePVLastSignState) CheckHRS(height int64, round int32, step int8) (
|
||||
func (lss *FilePVLastSignState) Save() error {
|
||||
outFile := lss.filePath
|
||||
if outFile == "" {
|
||||
panic("cannot save FilePVLastSignState: filePath not set")
|
||||
return errors.New("cannot save FilePVLastSignState: filePath not set")
|
||||
}
|
||||
jsonBytes, err := tmjson.MarshalIndent(lss, "", " ")
|
||||
if err != nil {
|
||||
@@ -237,7 +237,9 @@ func LoadOrGenFilePV(keyFilePath, stateFilePath string) *FilePV {
|
||||
pv = LoadFilePV(keyFilePath, stateFilePath)
|
||||
} else {
|
||||
pv = GenFilePV(keyFilePath, stateFilePath)
|
||||
pv.Save()
|
||||
if err := pv.Save(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return pv
|
||||
}
|
||||
@@ -273,16 +275,19 @@ func (pv *FilePV) SignProposal(chainID string, proposal *tmproto.Proposal) error
|
||||
}
|
||||
|
||||
// Save persists the FilePV to disk.
|
||||
func (pv *FilePV) Save() {
|
||||
func (pv *FilePV) Save() error {
|
||||
pv.Key.Save()
|
||||
pv.LastSignState.Save()
|
||||
return pv.LastSignState.Save()
|
||||
}
|
||||
|
||||
// Reset resets all fields in the FilePV.
|
||||
// NOTE: Unsafe!
|
||||
func (pv *FilePV) Reset() {
|
||||
pv.LastSignState.reset()
|
||||
pv.Save()
|
||||
err := pv.Save()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// String returns a string representation of the FilePV.
|
||||
@@ -411,7 +416,9 @@ func (pv *FilePV) signProposal(chainID string, proposal *tmproto.Proposal) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pv.saveSigned(height, round, step, signBytes, sig)
|
||||
if err := pv.saveSigned(height, round, step, signBytes, sig); err != nil {
|
||||
return err
|
||||
}
|
||||
proposal.Signature = sig
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestGenLoadValidator(t *testing.T) {
|
||||
|
||||
height := int64(100)
|
||||
privVal.LastSignState.Height = height
|
||||
privVal.Save()
|
||||
require.NoError(t, privVal.Save())
|
||||
addr := privVal.GetAddress()
|
||||
|
||||
privVal = LoadFilePV(tempKeyFile.Name(), tempStateFile.Name())
|
||||
|
||||
@@ -24,10 +24,6 @@ import (
|
||||
"github.com/tendermint/tendermint/version"
|
||||
)
|
||||
|
||||
// A cleanupFunc cleans up any config / test files created for a particular
|
||||
// test.
|
||||
type cleanupFunc func()
|
||||
|
||||
// make an extended commit with a single vote containing just the height and a
|
||||
// timestamp
|
||||
func makeTestExtCommit(height int64, timestamp time.Time) *types.ExtendedCommit {
|
||||
@@ -85,7 +81,7 @@ func TestLoadBlockStoreState(t *testing.T) {
|
||||
db := dbm.NewMemDB()
|
||||
batch := db.NewBatch()
|
||||
SaveBlockStoreState(batch, tc.bss)
|
||||
batch.WriteSync()
|
||||
require.NoError(t, batch.WriteSync())
|
||||
batch.Close()
|
||||
retrBSJ := LoadBlockStoreState(db)
|
||||
assert.Equal(t, tc.want, retrBSJ, "expected the retrieved DBs to match: %s", tc.testName)
|
||||
|
||||
@@ -105,17 +105,23 @@ func Setup(testnet *e2e.Testnet, infp infra.Provider) error {
|
||||
return err
|
||||
}
|
||||
|
||||
(privval.NewFilePV(node.PrivvalKey,
|
||||
err = (privval.NewFilePV(node.PrivvalKey,
|
||||
filepath.Join(nodeDir, PrivvalKeyFile),
|
||||
filepath.Join(nodeDir, PrivvalStateFile),
|
||||
)).Save()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set up a dummy validator. Tendermint requires a file PV even when not used, so we
|
||||
// give it a dummy such that it will fail if it actually tries to use it.
|
||||
(privval.NewFilePV(ed25519.GenPrivKey(),
|
||||
err = (privval.NewFilePV(ed25519.GenPrivKey(),
|
||||
filepath.Join(nodeDir, PrivvalDummyKeyFile),
|
||||
filepath.Join(nodeDir, PrivvalDummyStateFile),
|
||||
)).Save()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user