Skip to content

Commit

Permalink
Merge pull request #118 from vegaprotocol/chore/shotgun-cleanup
Browse files Browse the repository at this point in the history
Basic (shotgun) cleanup
  • Loading branch information
daniel1302 committed Apr 2, 2024
2 parents 988317a + 5536b4b commit 22e1199
Show file tree
Hide file tree
Showing 191 changed files with 762 additions and 3,022 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---

name: Go linters
"on":
push:
tags:
- v*
branches:
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21.5'
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.7.0
with:
version: v1.55.2
args: --config .golangci.toml
42 changes: 42 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[run]
allow-parallel-runners = true
print-linter-name = true
timeout = '15m0s'

[issues]
max-issues-per-linter = 0
max-same-issues = 0

[linters]
disable-all = true
enable = [
"exhaustive",
"gofumpt",
"govet",
"gci",
"ineffassign",
"staticcheck",
"unconvert",
"unparam",
"unused",
"wastedassign",
"whitespace",
]

[linters-settings.gci]
custom-order = true
sections = [
"standard", # Standard section: captures all standard packages.
"prefix(github.com/vegaprotocol/devopstools)", # Custom section: groups all imports with the specified Prefix.
"prefix(code.vegaprotocol.io/vega)", # Custom section: groups all imports with the specified Prefix.
"default", # Default section: contains all imports that could not be matched to another section type.
"blank", # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
"dot",
]

# protoc doesn't want us copying protobuf messages because they can have some internal state
# that shouldn't be copied; but we do it a lot. see below for details
# https://stackoverflow.com/questions/64183794/why-do-the-go-generated-protobuf-files-contain-mutex-locks
[[issues.exclude-rules]]
linters = ["govet"]
text = "impl.MessageState contains sync.Mutex"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ We want to minimise usage of `bash` and replace it with `Golang`.

We assume that:
- we have `Go` installed on every machine
- we run our scripts `go run main.go ...` fashion, ineased of: `tag version`->`complie`->`publish`->`download`->`run`
- we run our scripts `go run main.go ...` fashion, instead of: `tag version`->`complie`->`publish`->`download`->`run`
- we use `cobra` to manage all CLI aspects

### Usual use-case
Expand Down
4 changes: 2 additions & 2 deletions backup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"os/exec"
"time"

"github.com/pelletier/go-toml"
"github.com/vegaprotocol/devopstools/tools"

"github.com/pelletier/go-toml"
)

type S3Config struct {
Expand Down Expand Up @@ -76,7 +77,6 @@ func LoadConfig(filePath string) (*Config, error) {

func (conf Config) Marshal() (string, error) {
str, err := toml.Marshal(conf)

if err != nil {
return "", fmt.Errorf("failed to marshal config: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/vegaprotocol/devopstools/secrets/hcvault"
"github.com/vegaprotocol/devopstools/smartcontracts"
"github.com/vegaprotocol/devopstools/wallet"

"go.uber.org/zap"
)

Expand Down Expand Up @@ -37,7 +38,6 @@ func (ra *RootArgs) getHCVaultSecretStore() (*hcvault.HCVaultSecretStore, error)
}
}
return ra.hcVaultSecretStore, nil

}

func (ra *RootArgs) GetNodeSecretStore() (secrets.NodeSecretStore, error) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/backup/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"strings"
"time"

"github.com/spf13/cobra"
"go.uber.org/zap"

"github.com/vegaprotocol/devopstools/backup"
"github.com/vegaprotocol/devopstools/tools"

"github.com/spf13/cobra"
"go.uber.org/zap"
)

type CreateArgs struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/backup/print_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package backup
import (
"fmt"

"github.com/spf13/cobra"
"github.com/vegaprotocol/devopstools/backup"

"github.com/spf13/cobra"
"go.uber.org/zap"
)

Expand All @@ -21,7 +22,6 @@ var printConfigCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
conf := backup.DefaultConfig()
confStr, err := conf.Marshal()

if err != nil {
printConfigArgs.Logger.Fatal("failed to marshal config", zap.Error(err))
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/backup/root.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package backup

import (
"github.com/spf13/cobra"
rootCmd "github.com/vegaprotocol/devopstools/cmd"

"github.com/spf13/cobra"
)

type BackupArgs struct {
Expand Down
6 changes: 4 additions & 2 deletions cmd/batch/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"log"
"time"

walletpb "code.vegaprotocol.io/vega/protos/vega/wallet/v1"
"github.com/spf13/cobra"
rootCmd "github.com/vegaprotocol/devopstools/cmd"
"github.com/vegaprotocol/devopstools/governance"
"github.com/vegaprotocol/devopstools/tools"

walletpb "code.vegaprotocol.io/vega/protos/vega/wallet/v1"

"github.com/spf13/cobra"
)

type BatchArgs struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/benchmark/eth-rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func SubscribeToEvents(endpoints []RPCEndpoint) {
evtNoPerBlock := make(map[uint64]int)
for _, vLog := range logs {
evtNoPerBlock[vLog.BlockNumber] += 1
//fmt.Printf("%s: %s: %s\n", time.Now().Format(time.RFC850), endpoint.URL, vLog.TxHash)
// fmt.Printf("%s: %s: %s\n", time.Now().Format(time.RFC850), endpoint.URL, vLog.TxHash)
}

sortedBlocks := make([]uint64, 0, len(evtNoPerBlock))
Expand Down
3 changes: 2 additions & 1 deletion cmd/benchmark/root.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package benchmark

import (
"github.com/spf13/cobra"
rootCmd "github.com/vegaprotocol/devopstools/cmd"

"github.com/spf13/cobra"
)

type BenchmarkArgs struct {
Expand Down
3 changes: 2 additions & 1 deletion cmd/bot/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/vegaprotocol/devopstools/bots"

"github.com/spf13/cobra"
"go.uber.org/zap"
)

Expand Down
33 changes: 12 additions & 21 deletions cmd/bot/referral.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ import (
"strings"
"time"

"golang.org/x/exp/slices"

commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
walletpb "code.vegaprotocol.io/vega/protos/vega/wallet/v1"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/spf13/cobra"
"github.com/vegaprotocol/devopstools/bots"
"github.com/vegaprotocol/devopstools/ethutils"
"github.com/vegaprotocol/devopstools/generate"
"github.com/vegaprotocol/devopstools/governance"
"github.com/vegaprotocol/devopstools/vegaapi"
"github.com/vegaprotocol/devopstools/veganetwork"
"github.com/vegaprotocol/devopstools/wallet"

commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
walletpb "code.vegaprotocol.io/vega/protos/vega/wallet/v1"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/spf13/cobra"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

const waitTimeout = 5 * time.Minute
Expand Down Expand Up @@ -166,8 +167,8 @@ func runReferral(args ReferralArgs) error {
logger.Info("Teams created")

logger.Info("Waiting for referral set to be created")
if err := waitForReferralSets(logger, teams, network.DataNodeClient, !args.SetupBotsInReferralProgram, waitTimeout); err != nil {
return fmt.Errorf("failed to wait for referral sets: %w")
if err := waitForReferralSets(logger, teams, network.DataNodeClient, waitTimeout); err != nil {
return fmt.Errorf("failed to wait for referral sets: %w", err)
}
logger.Info("All referral sets are ready")

Expand All @@ -180,13 +181,7 @@ func runReferral(args ReferralArgs) error {
return nil
}

func waitForReferralSets(
logger *zap.Logger,
teams []Team,
dataNodeClient vegaapi.DataNodeClient,
dryRun bool,
timeout time.Duration,
) error {
func waitForReferralSets(logger *zap.Logger, teams []Team, dataNodeClient vegaapi.DataNodeClient, timeout time.Duration) error {
wantedTeamsLeaderPubKeys := make([]string, len(teams))
for _, team := range teams {
wantedTeamsLeaderPubKeys = append(wantedTeamsLeaderPubKeys, team.Leader.Wallet.PublicKey)
Expand Down Expand Up @@ -236,8 +231,6 @@ func waitForReferralSets(
return fmt.Errorf("timeout exceeded")
}
}

return nil
}

// prepareTeams should generate deterministic teams based on the response from the /traders endpoint
Expand Down Expand Up @@ -389,7 +382,6 @@ func joinMemberTeams(
dataNodeClient vegaapi.DataNodeClient,
dryRun bool,
) error {

logger.Info("Join Referral Sets (teams)")
referralSets, err := dataNodeClient.GetReferralSets()
if err != nil {
Expand Down Expand Up @@ -475,7 +467,7 @@ func stakeToTeamLeaders(
for _, team := range teams {
currentStake, err := dataNodeClient.GetPartyTotalStake(team.Leader.Wallet.PublicKey)
if err != nil {
return fmt.Errorf("failed to create referral sets, failed to get stake for %: %w", team.Leader.Wallet.PublicKey, err)
return fmt.Errorf("failed to create referral sets, failed to get stake for %q: %w", team.Leader.Wallet.PublicKey, err)
}
if currentStake.Cmp(minStake) < 0 {
// rand stake
Expand Down Expand Up @@ -662,7 +654,6 @@ func doStake(
}
logger.Info("successfully increased allowance", zap.String("ethWallet", wallet.Address.Hex()),
zap.String("tokenAddress", vegaToken.Address.Hex()))

} else {
logger.Info("no need to increase allowance", zap.String("tokenAddress", vegaToken.Address.Hex()),
zap.String("ethWallet", wallet.Address.Hex()),
Expand Down
3 changes: 2 additions & 1 deletion cmd/bot/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package bot
import (
"log"

"github.com/spf13/cobra"
rootCmd "github.com/vegaprotocol/devopstools/cmd"

"github.com/spf13/cobra"
)

type BotArgs struct {
Expand Down
54 changes: 0 additions & 54 deletions cmd/erc20token/info.go

This file was deleted.

Loading

0 comments on commit 22e1199

Please sign in to comment.