mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-20 22:26:15 +00:00
* ci: Fix linter complaint (#9645)
Fixes a very silly linter complaint that makes absolutely no sense and is blocking the merging of several PRs.
---
#### PR checklist
- [x] Tests written/updated, or no tests needed
- [x] `CHANGELOG_PENDING.md` updated, or no changelog entry needed
- [x] Updated relevant documentation (`docs/`) and code comments, or no
documentation updates needed
(cherry picked from commit 83b7f4ad5b)
# Conflicts:
# .github/workflows/lint.yml
# .golangci.yml
# cmd/tendermint/commands/debug/util.go
* Resolve conflicts
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* ci: Sync golangci-lint config with main
Minus the spelling configuration that restricts spelling to US English
only.
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* make format
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* Remove usage of deprecated io/ioutil package
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* Remove unused mockBlockStore
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* blockchain/v2: Remove unused method
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* Bulk fix lints
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* lint: Ignore auto-generated query PEG
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
This commit is contained in:
co-authored by
Thane Thomson
parent
a6dd0d270a
commit
e914fe40ec
@@ -1,11 +1,9 @@
|
||||
// nolint: gosec
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -30,7 +28,7 @@ type SnapshotStore struct {
|
||||
// NewSnapshotStore creates a new snapshot store.
|
||||
func NewSnapshotStore(dir string) (*SnapshotStore, error) {
|
||||
store := &SnapshotStore{dir: dir}
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := store.loadMetadata(); err != nil {
|
||||
@@ -45,7 +43,7 @@ func (s *SnapshotStore) loadMetadata() error {
|
||||
file := filepath.Join(s.dir, "metadata.json")
|
||||
metadata := []abci.Snapshot{}
|
||||
|
||||
bz, err := ioutil.ReadFile(file)
|
||||
bz, err := os.ReadFile(file)
|
||||
switch {
|
||||
case errors.Is(err, os.ErrNotExist):
|
||||
case err != nil:
|
||||
@@ -72,7 +70,7 @@ func (s *SnapshotStore) saveMetadata() error {
|
||||
// save the file to a new file and move it to make saving atomic.
|
||||
newFile := filepath.Join(s.dir, "metadata.json.new")
|
||||
file := filepath.Join(s.dir, "metadata.json")
|
||||
err = ioutil.WriteFile(newFile, bz, 0644) //nolint: gosec
|
||||
err = os.WriteFile(newFile, bz, 0o644) //nolint: gosec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -93,7 +91,8 @@ func (s *SnapshotStore) Create(state *State) (abci.Snapshot, error) {
|
||||
Hash: hashItems(state.Values),
|
||||
Chunks: byteChunks(bz),
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(s.dir, fmt.Sprintf("%v.json", state.Height)), bz, 0644)
|
||||
//nolint:gosec // G306: Expect WriteFile permissions to be 0600 or less
|
||||
err = os.WriteFile(filepath.Join(s.dir, fmt.Sprintf("%v.json", state.Height)), bz, 0o644)
|
||||
if err != nil {
|
||||
return abci.Snapshot{}, err
|
||||
}
|
||||
@@ -122,7 +121,7 @@ func (s *SnapshotStore) LoadChunk(height uint64, format uint32, chunk uint32) ([
|
||||
defer s.RUnlock()
|
||||
for _, snapshot := range s.metadata {
|
||||
if snapshot.Height == height && snapshot.Format == format {
|
||||
bz, err := ioutil.ReadFile(filepath.Join(s.dir, fmt.Sprintf("%v.json", height)))
|
||||
bz, err := os.ReadFile(filepath.Join(s.dir, fmt.Sprintf("%v.json", height)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// nolint: gosec
|
||||
package app
|
||||
|
||||
import (
|
||||
@@ -6,15 +5,16 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const stateFileName = "app_state.json"
|
||||
const prevStateFileName = "prev_app_state.json"
|
||||
const (
|
||||
stateFileName = "app_state.json"
|
||||
prevStateFileName = "prev_app_state.json"
|
||||
)
|
||||
|
||||
// State is the application state.
|
||||
type State struct {
|
||||
@@ -52,11 +52,11 @@ func NewState(dir string, persistInterval uint64) (*State, error) {
|
||||
// load loads state from disk. It does not take out a lock, since it is called
|
||||
// during construction.
|
||||
func (s *State) load() error {
|
||||
bz, err := ioutil.ReadFile(s.currentFile)
|
||||
bz, err := os.ReadFile(s.currentFile)
|
||||
if err != nil {
|
||||
// if the current state doesn't exist then we try recover from the previous state
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
bz, err = ioutil.ReadFile(s.previousFile)
|
||||
bz, err = os.ReadFile(s.previousFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read both current and previous state (%q): %w",
|
||||
s.previousFile, err)
|
||||
@@ -82,7 +82,8 @@ func (s *State) save() error {
|
||||
// We write the state to a separate file and move it to the destination, to
|
||||
// make it atomic.
|
||||
newFile := fmt.Sprintf("%v.new", s.currentFile)
|
||||
err = ioutil.WriteFile(newFile, bz, 0644)
|
||||
//nolint:gosec // G306: Expect WriteFile permissions to be 0600 or less
|
||||
err = os.WriteFile(newFile, bz, 0o644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to write state to %q: %w", s.currentFile, err)
|
||||
}
|
||||
@@ -160,7 +161,7 @@ func (s *State) Commit() (uint64, []byte, error) {
|
||||
}
|
||||
|
||||
func (s *State) Rollback() error {
|
||||
bz, err := ioutil.ReadFile(s.previousFile)
|
||||
bz, err := os.ReadFile(s.previousFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read state from %q: %w", s.previousFile, err)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// nolint: gosec
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -58,11 +57,12 @@ func NewCLI() *CLI {
|
||||
|
||||
// generate generates manifests in a directory.
|
||||
func (cli *CLI) generate(dir string, groups int) error {
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
err := os.MkdirAll(dir, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//nolint:gosec // G404: Use of weak random number generator (math/rand instead of crypto/rand)
|
||||
manifests, err := Generate(rand.New(rand.NewSource(randomSeed)))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// nolint: goconst
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -56,6 +55,8 @@ func LoadConfig(file string) (*Config, error) {
|
||||
|
||||
// Validate validates the configuration. We don't do exhaustive config
|
||||
// validation here, instead relying on Testnet.Validate() to handle it.
|
||||
//
|
||||
//nolint:goconst
|
||||
func (cfg Config) Validate() error {
|
||||
switch {
|
||||
case cfg.ChainID == "":
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// nolint: gosec
|
||||
package e2e
|
||||
|
||||
import (
|
||||
@@ -26,9 +25,11 @@ const (
|
||||
networkIPv6 = "fd80:b10c::/48"
|
||||
)
|
||||
|
||||
type Mode string
|
||||
type Protocol string
|
||||
type Perturbation string
|
||||
type (
|
||||
Mode string
|
||||
Protocol string
|
||||
Perturbation string
|
||||
)
|
||||
|
||||
const (
|
||||
ModeValidator Mode = "validator"
|
||||
@@ -415,6 +416,7 @@ func (t Testnet) ArchiveNodes() []*Node {
|
||||
// RandomNode returns a random non-seed node.
|
||||
func (t Testnet) RandomNode() *Node {
|
||||
for {
|
||||
//nolint:gosec // G404: Use of weak random number generator (math/rand instead of crypto/rand)
|
||||
node := t.Nodes[rand.Intn(len(t.Nodes))]
|
||||
if node.Mode != ModeSeed {
|
||||
return node
|
||||
@@ -491,7 +493,7 @@ type keyGenerator struct {
|
||||
|
||||
func newKeyGenerator(seed int64) *keyGenerator {
|
||||
return &keyGenerator{
|
||||
random: rand.New(rand.NewSource(seed)),
|
||||
random: rand.New(rand.NewSource(seed)), //nolint:gosec
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// nolint: gosec
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -10,6 +9,7 @@ import (
|
||||
|
||||
// execute executes a shell command.
|
||||
func exec(args ...string) error {
|
||||
//nolint:gosec // G204: Subprocess launched with a potential tainted input or cmd arguments
|
||||
cmd := osexec.Command(args[0], args[1:]...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
switch err := err.(type) {
|
||||
@@ -24,6 +24,7 @@ func exec(args ...string) error {
|
||||
|
||||
// execVerbose executes a shell command while displaying its output.
|
||||
func execVerbose(args ...string) error {
|
||||
//nolint:gosec // G204: Subprocess launched with a potential tainted input or cmd arguments
|
||||
cmd := osexec.Command(args[0], args[1:]...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
//nolint: gosec
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -7,7 +6,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@@ -53,7 +51,8 @@ func Setup(testnet *e2e.Testnet) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(testnet.Dir, "docker-compose.yml"), compose, 0644)
|
||||
//nolint:gosec // G306: Expect WriteFile permissions to be 0600 or less
|
||||
err = os.WriteFile(filepath.Join(testnet.Dir, "docker-compose.yml"), compose, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -76,7 +75,7 @@ func Setup(testnet *e2e.Testnet) error {
|
||||
if node.Mode == e2e.ModeLight && strings.Contains(dir, "app") {
|
||||
continue
|
||||
}
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
err := os.MkdirAll(dir, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -92,7 +91,8 @@ func Setup(testnet *e2e.Testnet) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(nodeDir, "config", "app.toml"), appCfg, 0644)
|
||||
//nolint:gosec // G306: Expect WriteFile permissions to be 0600 or less
|
||||
err = os.WriteFile(filepath.Join(nodeDir, "config", "app.toml"), appCfg, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -401,11 +401,12 @@ func UpdateConfigStateSync(node *e2e.Node, height int64, hash []byte) error {
|
||||
|
||||
// FIXME Apparently there's no function to simply load a config file without
|
||||
// involving the entire Viper apparatus, so we'll just resort to regexps.
|
||||
bz, err := ioutil.ReadFile(cfgPath)
|
||||
bz, err := os.ReadFile(cfgPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bz = regexp.MustCompile(`(?m)^trust_height =.*`).ReplaceAll(bz, []byte(fmt.Sprintf(`trust_height = %v`, height)))
|
||||
bz = regexp.MustCompile(`(?m)^trust_hash =.*`).ReplaceAll(bz, []byte(fmt.Sprintf(`trust_hash = "%X"`, hash)))
|
||||
return ioutil.WriteFile(cfgPath, bz, 0644)
|
||||
//nolint:gosec // G306: Expect WriteFile permissions to be 0600 or less
|
||||
return os.WriteFile(cfgPath, bz, 0o644)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package v0_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
mempoolv0 "github.com/tendermint/tendermint/test/fuzz/mempool/v0"
|
||||
)
|
||||
|
||||
@@ -25,7 +26,7 @@ func TestMempoolTestdataCases(t *testing.T) {
|
||||
}()
|
||||
f, err := os.Open(filepath.Join(testdataCasesDir, entry.Name()))
|
||||
require.NoError(t, err)
|
||||
input, err := ioutil.ReadAll(f)
|
||||
input, err := io.ReadAll(f)
|
||||
require.NoError(t, err)
|
||||
mempoolv0.Fuzz(input)
|
||||
})
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package v1_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
mempoolv1 "github.com/tendermint/tendermint/test/fuzz/mempool/v1"
|
||||
)
|
||||
|
||||
@@ -25,7 +26,7 @@ func TestMempoolTestdataCases(t *testing.T) {
|
||||
}()
|
||||
f, err := os.Open(filepath.Join(testdataCasesDir, entry.Name()))
|
||||
require.NoError(t, err)
|
||||
input, err := ioutil.ReadAll(f)
|
||||
input, err := io.ReadAll(f)
|
||||
require.NoError(t, err)
|
||||
mempoolv1.Fuzz(input)
|
||||
})
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
//nolint: gosec
|
||||
package addr
|
||||
|
||||
import (
|
||||
@@ -25,6 +24,7 @@ func Fuzz(data []byte) int {
|
||||
}
|
||||
|
||||
// Also, make sure PickAddress always returns a non-nil address.
|
||||
//nolint:gosec // G404: Use of weak random number generator (math/rand instead of crypto/rand)
|
||||
bias := rand.Intn(100)
|
||||
if p := addrBook.PickAddress(bias); p == nil {
|
||||
panic(fmt.Sprintf("picked a nil address (bias: %d, addrBook size: %v)",
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
//nolint: gosec
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
@@ -27,7 +25,7 @@ func initCorpus(baseDir string) {
|
||||
|
||||
// create "corpus" directory
|
||||
corpusDir := filepath.Join(baseDir, "corpus")
|
||||
if err := os.MkdirAll(corpusDir, 0755); err != nil {
|
||||
if err := os.MkdirAll(corpusDir, 0o755); err != nil {
|
||||
log.Fatalf("Creating %q err: %v", corpusDir, err)
|
||||
}
|
||||
|
||||
@@ -49,7 +47,8 @@ func initCorpus(baseDir string) {
|
||||
log.Fatalf("can't marshal %v: %v", addr, err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(filename, bz, 0644); err != nil {
|
||||
//nolint:gosec // G306: Expect WriteFile permissions to be 0600 or less
|
||||
if err := os.WriteFile(filename, bz, 0o644); err != nil {
|
||||
log.Fatalf("can't write %v to %q: %v", addr, filename, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
//nolint: gosec
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
@@ -22,11 +20,12 @@ func main() {
|
||||
initCorpus(*baseDir)
|
||||
}
|
||||
|
||||
//nolint:gosec
|
||||
func initCorpus(rootDir string) {
|
||||
log.SetFlags(0)
|
||||
|
||||
corpusDir := filepath.Join(rootDir, "corpus")
|
||||
if err := os.MkdirAll(corpusDir, 0755); err != nil {
|
||||
if err := os.MkdirAll(corpusDir, 0o755); err != nil {
|
||||
log.Fatalf("Creating %q err: %v", corpusDir, err)
|
||||
}
|
||||
sizes := []int{0, 1, 2, 17, 5, 31}
|
||||
@@ -73,7 +72,7 @@ func initCorpus(rootDir string) {
|
||||
|
||||
filename := filepath.Join(rootDir, "corpus", fmt.Sprintf("%d", n))
|
||||
|
||||
if err := ioutil.WriteFile(filename, bz, 0644); err != nil {
|
||||
if err := os.WriteFile(filename, bz, 0o644); err != nil {
|
||||
log.Fatalf("can't write %X to %q: %v", bz, filename, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
//nolint: gosec
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -21,7 +19,7 @@ func initCorpus(baseDir string) {
|
||||
log.SetFlags(0)
|
||||
|
||||
corpusDir := filepath.Join(baseDir, "corpus")
|
||||
if err := os.MkdirAll(corpusDir, 0755); err != nil {
|
||||
if err := os.MkdirAll(corpusDir, 0o755); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -39,7 +37,8 @@ func initCorpus(baseDir string) {
|
||||
for i, datum := range data {
|
||||
filename := filepath.Join(corpusDir, fmt.Sprintf("%d", i))
|
||||
|
||||
if err := ioutil.WriteFile(filename, []byte(datum), 0644); err != nil {
|
||||
//nolint:gosec // G306: Expect WriteFile permissions to be 0600 or less
|
||||
if err := os.WriteFile(filename, []byte(datum), 0o644); err != nil {
|
||||
log.Fatalf("can't write %v to %q: %v", datum, filename, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package handler
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
||||
@@ -29,7 +29,7 @@ func Fuzz(data []byte) int {
|
||||
rec := httptest.NewRecorder()
|
||||
mux.ServeHTTP(rec, req)
|
||||
res := rec.Result()
|
||||
blob, err := ioutil.ReadAll(res.Body)
|
||||
blob, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/informalsystems/tm-load-test/pkg/loadtest"
|
||||
|
||||
"github.com/tendermint/tendermint/test/loadtime/payload"
|
||||
)
|
||||
|
||||
|
||||
@@ -9,9 +9,10 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/tendermint/tendermint/store"
|
||||
"github.com/tendermint/tendermint/test/loadtime/report"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/tendermint/tendermint/test/loadtime/payload"
|
||||
)
|
||||
|
||||
|
||||
@@ -6,9 +6,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"gonum.org/v1/gonum/stat"
|
||||
|
||||
"github.com/tendermint/tendermint/test/loadtime/payload"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"gonum.org/v1/gonum/stat"
|
||||
)
|
||||
|
||||
// BlockStore defines the set of methods needed by the report generator from
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
"github.com/tendermint/tendermint/test/loadtime/payload"
|
||||
"github.com/tendermint/tendermint/test/loadtime/report"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
type mockBlockStore struct {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
@@ -350,12 +350,12 @@ func (cs *State) enterPrecommit(height int64, round int32) {
|
||||
} else {
|
||||
defaultEnterPrecommit(cs, height, round)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (cs *State) addVote(
|
||||
vote *types.Vote,
|
||||
peerID p2p.ID) (added bool, err error) {
|
||||
peerID p2p.ID,
|
||||
) (added bool, err error) {
|
||||
cs.Logger.Debug(
|
||||
"addVote",
|
||||
"voteHeight",
|
||||
@@ -448,9 +448,7 @@ var (
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
var (
|
||||
msgQueueSize = 1000
|
||||
)
|
||||
var msgQueueSize = 1000
|
||||
|
||||
// msgs from the reactor which may update the state
|
||||
type msgInfo struct {
|
||||
@@ -732,7 +730,6 @@ func (cs *State) AddVote(vote *types.Vote, peerID p2p.ID) (added bool, err error
|
||||
|
||||
// SetProposal inputs a proposal.
|
||||
func (cs *State) SetProposal(proposal *types.Proposal, peerID p2p.ID) error {
|
||||
|
||||
if peerID == "" {
|
||||
cs.internalMsgQueue <- msgInfo{&tmcon.ProposalMessage{Proposal: proposal}, ""}
|
||||
} else {
|
||||
@@ -745,7 +742,6 @@ func (cs *State) SetProposal(proposal *types.Proposal, peerID p2p.ID) error {
|
||||
|
||||
// AddProposalBlockPart inputs a part of the proposal block.
|
||||
func (cs *State) AddProposalBlockPart(height int64, round int32, part *types.Part, peerID p2p.ID) error {
|
||||
|
||||
if peerID == "" {
|
||||
cs.internalMsgQueue <- msgInfo{&tmcon.BlockPartMessage{Height: height, Round: round, Part: part}, ""}
|
||||
} else {
|
||||
@@ -1073,7 +1069,6 @@ func (cs *State) handleTimeout(ti timeoutInfo, rs cstypes.RoundState) {
|
||||
default:
|
||||
panic(fmt.Sprintf("Invalid timeout step: %v", ti.Step))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (cs *State) handleTxsAvailable() {
|
||||
@@ -1253,7 +1248,6 @@ func (cs *State) isProposalComplete() bool {
|
||||
}
|
||||
// if this is false the proposer is lying or we haven't received the POL yet
|
||||
return cs.Votes.Prevotes(cs.Proposal.POLRound).HasTwoThirdsMajority()
|
||||
|
||||
}
|
||||
|
||||
// Create the next block to propose and return it. Returns nil block upon error.
|
||||
@@ -1716,12 +1710,12 @@ func (cs *State) addProposalBlockPart(msg *tmcon.BlockPartMessage, peerID p2p.ID
|
||||
)
|
||||
}
|
||||
if added && cs.ProposalBlockParts.IsComplete() {
|
||||
bz, err := ioutil.ReadAll(cs.ProposalBlockParts.GetReader())
|
||||
bz, err := io.ReadAll(cs.ProposalBlockParts.GetReader())
|
||||
if err != nil {
|
||||
return added, err
|
||||
}
|
||||
|
||||
var pbb = new(tmproto.Block)
|
||||
pbb := new(tmproto.Block)
|
||||
err = proto.Unmarshal(bz, pbb)
|
||||
if err != nil {
|
||||
return added, err
|
||||
|
||||
+23
-25
@@ -62,7 +62,7 @@ import (
|
||||
// a map of misbehaviors to be executed by the maverick node
|
||||
func ParseMisbehaviors(str string) (map[int64]cs.Misbehavior, error) {
|
||||
// check if string is empty in which case we run a normal node
|
||||
var misbehaviors = make(map[int64]cs.Misbehavior)
|
||||
misbehaviors := make(map[int64]cs.Misbehavior)
|
||||
if str == "" {
|
||||
return misbehaviors, nil
|
||||
}
|
||||
@@ -141,7 +141,6 @@ func DefaultNewNode(config *cfg.Config, logger log.Logger, misbehaviors map[int6
|
||||
logger,
|
||||
misbehaviors,
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
// MetricsProvider returns a consensus, p2p and mempool Metrics.
|
||||
@@ -300,7 +299,6 @@ func createAndStartIndexerService(
|
||||
eventBus *types.EventBus,
|
||||
logger log.Logger,
|
||||
) (*txindex.IndexerService, txindex.TxIndexer, indexer.BlockIndexer, error) {
|
||||
|
||||
var (
|
||||
txIndexer txindex.TxIndexer
|
||||
blockIndexer indexer.BlockIndexer
|
||||
@@ -337,8 +335,8 @@ func doHandshake(
|
||||
genDoc *types.GenesisDoc,
|
||||
eventBus types.BlockEventPublisher,
|
||||
proxyApp proxy.AppConns,
|
||||
consensusLogger log.Logger) error {
|
||||
|
||||
consensusLogger log.Logger,
|
||||
) error {
|
||||
handshaker := cs.NewHandshaker(stateStore, state, blockStore, genDoc)
|
||||
handshaker.SetLogger(consensusLogger)
|
||||
handshaker.SetEventBus(eventBus)
|
||||
@@ -382,8 +380,8 @@ func onlyValidatorIsUs(state sm.State, pubKey crypto.PubKey) bool {
|
||||
}
|
||||
|
||||
func createMempoolAndMempoolReactor(config *cfg.Config, proxyApp proxy.AppConns,
|
||||
state sm.State, memplMetrics *mempl.Metrics, logger log.Logger) (p2p.Reactor, mempl.Mempool) {
|
||||
|
||||
state sm.State, memplMetrics *mempl.Metrics, logger log.Logger,
|
||||
) (p2p.Reactor, mempl.Mempool) {
|
||||
switch config.Mempool.Version {
|
||||
case cfg.MempoolV1:
|
||||
mp := mempoolv1.NewTxMempool(
|
||||
@@ -435,8 +433,8 @@ func createMempoolAndMempoolReactor(config *cfg.Config, proxyApp proxy.AppConns,
|
||||
}
|
||||
|
||||
func createEvidenceReactor(config *cfg.Config, dbProvider DBProvider,
|
||||
stateDB dbm.DB, blockStore *store.BlockStore, logger log.Logger) (*evidence.Reactor, *evidence.Pool, error) {
|
||||
|
||||
stateDB dbm.DB, blockStore *store.BlockStore, logger log.Logger,
|
||||
) (*evidence.Reactor, *evidence.Pool, error) {
|
||||
evidenceDB, err := dbProvider(&DBContext{"evidence", config})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -459,8 +457,8 @@ func createBlockchainReactor(config *cfg.Config,
|
||||
blockExec *sm.BlockExecutor,
|
||||
blockStore *store.BlockStore,
|
||||
fastSync bool,
|
||||
logger log.Logger) (bcReactor p2p.Reactor, err error) {
|
||||
|
||||
logger log.Logger,
|
||||
) (bcReactor p2p.Reactor, err error) {
|
||||
switch config.FastSync.Version {
|
||||
case "v0":
|
||||
bcReactor = bcv0.NewBlockchainReactor(state.Copy(), blockExec, blockStore, fastSync)
|
||||
@@ -487,8 +485,8 @@ func createConsensusReactor(config *cfg.Config,
|
||||
waitSync bool,
|
||||
eventBus *types.EventBus,
|
||||
consensusLogger log.Logger,
|
||||
misbehaviors map[int64]cs.Misbehavior) (*cs.Reactor, *cs.State) {
|
||||
|
||||
misbehaviors map[int64]cs.Misbehavior,
|
||||
) (*cs.Reactor, *cs.State) {
|
||||
consensusState := cs.NewState(
|
||||
config.Consensus,
|
||||
state.Copy(),
|
||||
@@ -591,8 +589,8 @@ func createSwitch(config *cfg.Config,
|
||||
evidenceReactor *evidence.Reactor,
|
||||
nodeInfo p2p.NodeInfo,
|
||||
nodeKey *p2p.NodeKey,
|
||||
p2pLogger log.Logger) *p2p.Switch {
|
||||
|
||||
p2pLogger log.Logger,
|
||||
) *p2p.Switch {
|
||||
sw := p2p.NewSwitch(
|
||||
config.P2P,
|
||||
transport,
|
||||
@@ -614,8 +612,8 @@ func createSwitch(config *cfg.Config,
|
||||
}
|
||||
|
||||
func createAddrBookAndSetOnSwitch(config *cfg.Config, sw *p2p.Switch,
|
||||
p2pLogger log.Logger, nodeKey *p2p.NodeKey) (pex.AddrBook, error) {
|
||||
|
||||
p2pLogger log.Logger, nodeKey *p2p.NodeKey,
|
||||
) (pex.AddrBook, error) {
|
||||
addrBook := pex.NewAddrBook(config.P2P.AddrBookFile(), config.P2P.AddrBookStrict)
|
||||
addrBook.SetLogger(p2pLogger.With("book", config.P2P.AddrBookFile()))
|
||||
|
||||
@@ -641,8 +639,8 @@ func createAddrBookAndSetOnSwitch(config *cfg.Config, sw *p2p.Switch,
|
||||
}
|
||||
|
||||
func createPEXReactorAndAddToSwitch(addrBook pex.AddrBook, config *cfg.Config,
|
||||
sw *p2p.Switch, logger log.Logger) *pex.Reactor {
|
||||
|
||||
sw *p2p.Switch, logger log.Logger,
|
||||
) *pex.Reactor {
|
||||
// TODO persistent peers ? so we can have their DNS addrs saved
|
||||
pexReactor := pex.NewReactor(addrBook,
|
||||
&pex.ReactorConfig{
|
||||
@@ -664,7 +662,8 @@ func createPEXReactorAndAddToSwitch(addrBook pex.AddrBook, config *cfg.Config,
|
||||
// startStateSync starts an asynchronous state sync process, then switches to fast sync mode.
|
||||
func startStateSync(ssR *statesync.Reactor, bcR fastSyncReactor, conR *cs.Reactor,
|
||||
stateProvider statesync.StateProvider, config *cfg.StateSyncConfig, fastSync bool,
|
||||
stateStore sm.Store, blockStore *store.BlockStore, state sm.State) error {
|
||||
stateStore sm.Store, blockStore *store.BlockStore, state sm.State,
|
||||
) error {
|
||||
ssR.Logger.Info("Starting state sync")
|
||||
|
||||
if stateProvider == nil {
|
||||
@@ -727,8 +726,8 @@ func NewNode(config *cfg.Config,
|
||||
metricsProvider MetricsProvider,
|
||||
logger log.Logger,
|
||||
misbehaviors map[int64]cs.Misbehavior,
|
||||
options ...Option) (*Node, error) {
|
||||
|
||||
options ...Option,
|
||||
) (*Node, error) {
|
||||
blockStore, stateDB, err := initDBs(config, dbProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -908,6 +907,7 @@ func NewNode(config *cfg.Config,
|
||||
if config.RPC.PprofListenAddress != "" {
|
||||
go func() {
|
||||
logger.Info("Starting pprof server", "laddr", config.RPC.PprofListenAddress)
|
||||
//nolint:gosec,nolintlint // G114: Use of net/http serve function that has no support for setting timeouts
|
||||
logger.Error("pprof server error", "err", http.ListenAndServe(config.RPC.PprofListenAddress, nil))
|
||||
}()
|
||||
}
|
||||
@@ -1381,9 +1381,7 @@ func makeNodeInfo(
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
var (
|
||||
genesisDocKey = []byte("genesisDoc")
|
||||
)
|
||||
var genesisDocKey = []byte("genesisDoc")
|
||||
|
||||
// LoadStateFromDBOrGenesisDocProvider attempts to load the state from the
|
||||
// database, or creates one using the given genesisDocProvider and persists the
|
||||
|
||||
@@ -3,7 +3,7 @@ package node
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
@@ -62,11 +62,10 @@ func (pvKey FilePVKey) Save() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = tempfile.WriteFileAtomic(outFile, jsonBytes, 0600)
|
||||
err = tempfile.WriteFileAtomic(outFile, jsonBytes, 0o600)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
@@ -90,7 +89,6 @@ type FilePVLastSignState struct {
|
||||
// we have already signed for this HRS, and can reuse the existing signature).
|
||||
// It panics if the HRS matches the arguments, there's a SignBytes, but no Signature.
|
||||
func (lss *FilePVLastSignState) CheckHRS(height int64, round int32, step int8) (bool, error) {
|
||||
|
||||
if lss.Height > height {
|
||||
return false, fmt.Errorf("height regression. Got %v, last height %v", height, lss.Height)
|
||||
}
|
||||
@@ -133,7 +131,7 @@ func (lss *FilePVLastSignState) Save() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = tempfile.WriteFileAtomic(outFile, jsonBytes, 0600)
|
||||
err = tempfile.WriteFileAtomic(outFile, jsonBytes, 0o600)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -185,7 +183,7 @@ func LoadFilePVEmptyState(keyFilePath, stateFilePath string) *FilePV {
|
||||
|
||||
// If loadState is true, we load from the stateFilePath. Otherwise, we use an empty LastSignState.
|
||||
func loadFilePV(keyFilePath, stateFilePath string, loadState bool) *FilePV {
|
||||
keyJSONBytes, err := ioutil.ReadFile(keyFilePath)
|
||||
keyJSONBytes, err := os.ReadFile(keyFilePath)
|
||||
if err != nil {
|
||||
tmos.Exit(err.Error())
|
||||
}
|
||||
@@ -203,7 +201,7 @@ func loadFilePV(keyFilePath, stateFilePath string, loadState bool) *FilePV {
|
||||
pvState := FilePVLastSignState{}
|
||||
|
||||
if loadState {
|
||||
stateJSONBytes, err := ioutil.ReadFile(stateFilePath)
|
||||
stateJSONBytes, err := os.ReadFile(stateFilePath)
|
||||
if err != nil {
|
||||
tmos.Exit(err.Error())
|
||||
}
|
||||
@@ -347,8 +345,8 @@ func (pv *FilePV) signProposal(chainID string, proposal *tmproto.Proposal) error
|
||||
|
||||
// Persist height/round/step and signature
|
||||
func (pv *FilePV) saveSigned(height int64, round int32, step int8,
|
||||
signBytes []byte, sig []byte) {
|
||||
|
||||
signBytes []byte, sig []byte,
|
||||
) {
|
||||
pv.LastSignState.Height = height
|
||||
pv.LastSignState.Round = round
|
||||
pv.LastSignState.Step = step
|
||||
|
||||
Reference in New Issue
Block a user