Skip to content

Commit

Permalink
Drop source code locally
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Jul 24, 2024
1 parent 535e9d4 commit d3a9179
Show file tree
Hide file tree
Showing 23 changed files with 300 additions and 185 deletions.
8 changes: 0 additions & 8 deletions .github/goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ dockers:
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
extra_files:
- scripts
- use: buildx
dockerfile: Dockerfile.release
goos: linux
Expand All @@ -75,8 +73,6 @@ dockers:
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
extra_files:
- scripts
- use: buildx
dockerfile: Dockerfile.release
goos: linux
Expand All @@ -91,8 +87,6 @@ dockers:
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
extra_files:
- scripts
- use: buildx
dockerfile: Dockerfile.release
goos: linux
Expand All @@ -107,8 +101,6 @@ dockers:
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
extra_files:
- scripts

docker_manifests:
# https://goreleaser.com/customization/docker_manifest/
Expand Down
88 changes: 79 additions & 9 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,62 @@
run:
timeout: 5m
concurrency: 8
timeout: 10m
issue-exit-code: 1
tests: true
skip-dirs-use-default: true
modules-download-mode: readonly
allow-parallel-runners: false
go: ""

service:
golangci-lint-version: latest
output:
uniq-by-line: false
path-prefix: ""
sort-results: true

issues:
max-issues-per-linter: 0
max-same-issues: 0
new: false
fix: false
exclude-rules:
- path: (.+)_test.go
linters:
- nilnil
- gosec

linters:
fast: false
disable-all: true
enable:
- asasalint # Check for pass []any as any in variadic func(...any)
- asciicheck # Detects funky ASCII characters
- bidichk # Checks for dangerous unicode character sequences
- durationcheck # Check for two durations multiplied together
- errcheck # Forces to not skip error check
- exportloopref # Checks for pointers to enclosing loop variables
- gocritic # Bundles different linting checks
- godot # Checks for periods at the end of comments
- gomoddirectives # Allow or ban replace directives in go.mod
- gosimple # Code simplification
- govet # Official Go tool
- ineffassign # Detects when assignments to existing variables are not used
- nakedret # Finds naked/bare returns and requires change them
- nilerr # Requires explicit returns
- nilnil # Requires explicit returns
- promlinter # Lints Prometheus metrics names
- reassign # Checks that package variables are not reassigned
- revive # Drop-in replacement for golint
- tenv # Detects using os.Setenv instead of t.Setenv
- testableexamples # Checks if examples are testable (have expected output)
- unparam # Finds unused params
- usestdlibvars # Detects the possibility to use variables/constants from stdlib
- wastedassign # Finds wasted assignment statements
- loggercheck # Checks the odd number of key and value pairs for common logger libraries
- nestif # Finds deeply nested if statements
- nonamedreturns # Reports all named returns
- decorder # Check declaration order of types, consts, vars and funcs
- gocheckcompilerdirectives # Checks that compiler directive comments (//go:) are valid
- gochecknoinits # Checks for init methods
- whitespace # Tool for detection of leading and trailing whitespace
- wsl # Forces you to use empty lines
- unconvert # Unnecessary type conversions
Expand All @@ -25,22 +73,44 @@ linters:
- importas # Enforces consistent import aliases
- gosec # Security problems
- gofmt # Whether the code was gofmt-ed
- gofumpt # Stricter gofmt
- goimports # Unused imports
- goconst # Repeated strings that could be replaced by a constant
- forcetypeassert # Finds forced type assertions
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
- dupl # Code clone detection
- errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13
- unused # Checks Go code for unused constants, variables, functions and types

issues:
exclude-files:
- tools/tools.go

linters-settings:
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- hugeParam
- rangeExprCopy
- rangeValCopy
- importShadow
- unnamedResult
errcheck:
check-type-assertions: false
check-blank: true
exclude-functions:
- io/ioutil.ReadFile
- io.Copy(*bytes.Buffer)
- io.Copy(os.Stdout)
nakedret:
max-func-lines: 1
govet:
enable-all: true
gofmt:
simplify: true
goconst:
min-len: 3
min-occurrences: 3
godot:
scope: all
period: false
1 change: 0 additions & 1 deletion Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
FROM scratch
COPY scripts /scripts
COPY supernova /
ENTRYPOINT [ "/supernova" ]
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ test:
.PHONY: lint
lint:
$(golangci_lint) run --config .golangci.yaml

.PHONY: gofumpt
gofumpt:
go install mvdan.cc/gofumpt@latest
gofumpt -l -w .

.PHONY: fixalign
fixalign:
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
fieldalignment -fix $(filter-out $@,$(MAKECMDGOALS)) # the full package name (not path!)
8 changes: 4 additions & 4 deletions internal/batcher/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func prepareTransactions(txs []*std.Tx) ([][]byte, error) {

marshalledTxs[index] = txBin

_ = bar.Add(1)
_ = bar.Add(1) //nolint:errcheck // No need to check
}

return marshalledTxs, nil
Expand Down Expand Up @@ -117,7 +117,7 @@ func (b *Batcher) generateBatches(txs [][]byte, batchSize int) ([]common.Batch,

readyBatches[index] = cliBatch

_ = bar.Add(1)
_ = bar.Add(1) //nolint:errcheck // No need to check
}

return readyBatches, nil
Expand All @@ -142,7 +142,7 @@ func sendBatches(readyBatches []common.Batch) ([][]any, error) {

batchResults[index] = batchResult

_ = bar.Add(1)
_ = bar.Add(1) //nolint:errcheck // No need to check
}

fmt.Printf("✅ Successfully sent %d batches\n", numBatches)
Expand Down Expand Up @@ -184,7 +184,7 @@ func parseBatchResults(batchResults [][]any, numTx int) ([][]byte, error) {
txHashes[index] = txResult.Hash
index++

_ = bar.Add(1)
_ = bar.Add(1) //nolint:errcheck // No need to check
}
}

Expand Down
1 change: 0 additions & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (h *Client) GetAccount(address string) (*gnoland.GnoAccount, error) {
fmt.Sprintf("auth/accounts/%s", address),
[]byte{},
)

if err != nil {
return nil, fmt.Errorf("unable to fetch account %s, %w", address, err)
}
Expand Down
8 changes: 3 additions & 5 deletions internal/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
"github.com/schollz/progressbar/v3"
)

var (
errTimeout = errors.New("collector timed out")
)
var errTimeout = errors.New("collector timed out")

// Collector is the transaction / block stat
// collector.
Expand Down Expand Up @@ -86,7 +84,7 @@ func (c *Collector) GetRunResult(
}

processed += belong
_ = bar.Add(belong)
_ = bar.Add(belong) //nolint:errcheck // No need to check

// Fetch the total gas used by transactions
blockGasUsed, err := c.cli.GetBlockGasUsed(blockNum)
Expand Down Expand Up @@ -159,7 +157,7 @@ func (t *txLookup) anyBelong(txs types.Txs) int {

// calculateTPS calculates the TPS for the sequence
func calculateTPS(startTime time.Time, totalTx int) float64 {
diff := time.Now().Sub(startTime).Seconds()
diff := time.Since(startTime).Seconds()

return float64(totalTx) / diff
}
4 changes: 2 additions & 2 deletions internal/collector/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ type Client interface {

// RunResult is the complete test-run result
type RunResult struct {
AverageTPS float64 `json:"averageTPS"`
Blocks []*BlockResult `json:"blocks"`
AverageTPS float64 `json:"averageTPS"`
}

// BlockResult is the single-block test run result
type BlockResult struct {
Number int64 `json:"blockNumber"`
Time time.Time `json:"created"`
Number int64 `json:"blockNumber"`
Transactions int64 `json:"numTransactions"`
GasUsed int64 `json:"gasUsed"`
GasLimit int64 `json:"gasLimit"`
Expand Down
4 changes: 2 additions & 2 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ var (

var (
// httpRegex is used for verifying the cluster's JSON-RPC HTTP endpoint
httpRegex = regexp.MustCompile(`(https?://.*)(:(\d*)\/?(.*))?`)
httpRegex = regexp.MustCompile(`(https?://.*)(:(\d*)/?(.*))?`)

// wsRegex is used for verifying the cluster's JSON-RPC WS endpoint
wsRegex = regexp.MustCompile(`(wss?://.*)(:(\d*)\/?(.*))?`)
wsRegex = regexp.MustCompile(`(wss?://.*)(:(\d*)/?(.*))?`)
)

// Config is the central pipeline configuration
Expand Down
8 changes: 3 additions & 5 deletions internal/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
"github.com/schollz/progressbar/v3"
)

var (
errInsufficientFunds = errors.New("insufficient distributor funds")
)
var errInsufficientFunds = errors.New("insufficient distributor funds")

type Client interface {
GetAccount(address string) (*gnoland.GnoAccount, error)
Expand Down Expand Up @@ -89,8 +87,8 @@ func (d *Distributor) fundAccounts(
chainID string,
) ([]std.Account, error) {
type shortAccount struct {
address crypto.Address
missingFunds std.Coin
address crypto.Address
}

var (
Expand Down Expand Up @@ -232,7 +230,7 @@ func (d *Distributor) fundAccounts(
// Mark the account as funded
readyAccounts = append(readyAccounts, nodeAccount)

_ = bar.Add(1)
_ = bar.Add(1) //nolint:errcheck // No need to check
}

fmt.Printf("✅ Successfully funded %d accounts\n", len(shortAccounts))
Expand Down
18 changes: 8 additions & 10 deletions internal/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@ func displayResults(result *collector.RunResult) {
w := tabwriter.NewWriter(os.Stdout, 10, 20, 2, ' ', 0)

// TPS //
_, _ = fmt.Fprintln(w, fmt.Sprintf("\nTPS: %.2f", result.AverageTPS))
_, _ = fmt.Fprintf(w, "\nTPS: %.2f\n", result.AverageTPS)

// Block info //
_, _ = fmt.Fprintln(w, "\nBlock #\tGas Used\tGas Limit\tTransactions\tUtilization")
for _, block := range result.Blocks {
_, _ = fmt.Fprintln(
_, _ = fmt.Fprintf(
w,
fmt.Sprintf(
"Block #%d\t%d\t%d\t%d\t%.2f%%",
block.Number,
block.GasUsed,
block.GasLimit,
block.Transactions,
(float64(block.GasUsed)/float64(block.GasLimit))*100,
),
"Block #%d\t%d\t%d\t%d\t%.2f%%\n",
block.Number,
block.GasUsed,
block.GasLimit,
block.Transactions,
(float64(block.GasUsed)/float64(block.GasLimit))*100,
)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (p *Pipeline) initializeAccounts() []crypto.PrivKey {
// Register the accounts with the keybase
for i := 0; i < int(p.cfg.SubAccounts)+1; i++ {
accounts[i] = signer.GenerateKeyFromSeed(seed, uint32(i))
_ = bar.Add(1)
_ = bar.Add(1) //nolint:errcheck // No need to check
}

fmt.Printf("✅ Successfully generated %d accounts\n", len(accounts))
Expand Down Expand Up @@ -218,7 +218,7 @@ func prepareRuntime(
return fmt.Errorf("unable to broadcast predeploy tx, %w", err)
}

_ = bar.Add(1)
_ = bar.Add(1) //nolint:errcheck // No need to check
}

fmt.Printf("✅ Successfully predeployed %d transactions\n", len(predeployTxs))
Expand Down
Loading

0 comments on commit d3a9179

Please sign in to comment.