Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Check out source
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
- name: Install Linters
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.3"
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.2.2"
- name: Build
run: go build ./...
- name: Test
Expand Down
16 changes: 10 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
version: 2

run:
deadline: 10m
timeout: 10m

linters:
disable-all: true
default: none
enable:
- staticcheck
- asciicheck
- bidichk
- bodyclose
- gofmt
- goimports
Comment on lines -10 to -11
Copy link
Copy Markdown
Member Author

@amass01 amass01 Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added as formatters

- gosimple
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's part of staticcheck

- govet
- grouper
- ineffassign
Expand All @@ -20,6 +20,10 @@ linters:
- rowserrcheck
- sqlclosecheck
- tparallel
- typecheck
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's part of govet

- unconvert
- unused

formatters:
enable:
- gofmt
- goimports
44 changes: 22 additions & 22 deletions cmd/dcrtime/dcrtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func downloadV1(questions []string) error {
for _, digest := range v.CollectionInformation.Digests {
d, ok := convertDigest(digest)
if !ok {
return fmt.Errorf("Invalid digest "+
return fmt.Errorf("invalid digest "+
"server response for "+
"timestamp: %v",
v.ServerTimestamp)
Expand Down Expand Up @@ -469,7 +469,7 @@ func verifyTimestamps(vt []v2.VerifyTimestamp) error {
for _, digest := range t.CollectionInformation.Digests {
d, ok := convertDigest(digest)
if !ok {
return fmt.Errorf("Invalid digest "+
return fmt.Errorf("invalid digest "+
"server response for "+
"timestamp: %v",
t.ServerTimestamp)
Expand Down Expand Up @@ -568,7 +568,7 @@ func uploadV1(digests []string, exists map[string]string) error {
var tsReply v1.TimestampReply
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(&tsReply); err != nil {
return fmt.Errorf("Could node decode TimestampReply: %v", err)
return fmt.Errorf("could not decode TimestampReply: %v", err)
}

// Print human readable results.
Expand Down Expand Up @@ -638,7 +638,7 @@ func uploadV2Batch(digests []string, exists map[string]string) error {
var tsReply v2.TimestampBatchReply
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(&tsReply); err != nil {
return fmt.Errorf("Could node decode TimestampReply: %v", err)
return fmt.Errorf("could not decode TimestampReply: %v", err)
}

// Print human readable results.
Expand Down Expand Up @@ -704,7 +704,7 @@ func uploadV2Single(digest string, exists map[string]string) error {
var tsReply v2.TimestampReply
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(&tsReply); err != nil {
return fmt.Errorf("Could node decode TimestampReply: %v", err)
return fmt.Errorf("could not decode TimestampReply: %v", err)
}

// Print human readable results.
Expand Down Expand Up @@ -770,18 +770,18 @@ func showWalletBalanceV1() error {
if response.StatusCode != http.StatusOK {
e, err := getError(response.Body)
if err != nil {
return fmt.Errorf("Retrieve wallet balance failed: %v",
return fmt.Errorf("retrieve wallet balance failed: %v",
response.Status)
}
return fmt.Errorf("Retrieve wallet balance failed - %v: %v",
return fmt.Errorf("retrieve wallet balance failed - %v: %v",
response.Status, e)
}

// Decode the response from dcrtimed
var balance v1.WalletBalanceReply
jsonDecoder := json.NewDecoder(response.Body)
if err := jsonDecoder.Decode(&balance); err != nil {
return fmt.Errorf("Could not decode WalletBalanceReply: %v", err)
return fmt.Errorf("could not decode WalletBalanceReply: %v", err)
}

if *verbose {
Expand Down Expand Up @@ -832,18 +832,18 @@ func showWalletBalanceV2() error {
if response.StatusCode != http.StatusOK {
e, err := getError(response.Body)
if err != nil {
return fmt.Errorf("Retrieve wallet balance failed: %v",
return fmt.Errorf("retrieve wallet balance failed: %v",
response.Status)
}
return fmt.Errorf("Retrieve wallet balance failed - %v: %v",
return fmt.Errorf("retrieve wallet balance failed - %v: %v",
response.Status, e)
}

// Decode the response from dcrtimed
var balance v2.WalletBalanceReply
jsonDecoder := json.NewDecoder(response.Body)
if err := jsonDecoder.Decode(&balance); err != nil {
return fmt.Errorf("Could not decode WalletBalanceReply: %v", err)
return fmt.Errorf("could not decode WalletBalanceReply: %v", err)
}

if *verbose {
Expand Down Expand Up @@ -891,18 +891,18 @@ func lastAnchorV1() error {
if response.StatusCode != http.StatusOK {
e, err := getError(response.Body)
if err != nil {
return fmt.Errorf("Retrieve last anchor info failed: %v",
return fmt.Errorf("retrieve last anchor info failed: %v",
response.Status)
}
return fmt.Errorf("Retrieve last anchor info failed - %v: %v",
return fmt.Errorf("retrieve last anchor info failed - %v: %v",
response.Status, e)
}

// Decode the response from dcrtimed
var anchor v1.LastAnchorReply
jsonDecoder := json.NewDecoder(response.Body)
if err := jsonDecoder.Decode(&anchor); err != nil {
return fmt.Errorf("Could not decode LastAnchorReply: %v", err)
return fmt.Errorf("could not decode LastAnchorReply: %v", err)
}

fmt.Printf(
Expand Down Expand Up @@ -946,18 +946,18 @@ func lastAnchorV2() error {
if response.StatusCode != http.StatusOK {
e, err := getError(response.Body)
if err != nil {
return fmt.Errorf("Retrieve last anchor info failed: %v",
return fmt.Errorf("retrieve last anchor info failed: %v",
response.Status)
}
return fmt.Errorf("Retrieve last anchor info failed - %v: %v",
return fmt.Errorf("retrieve last anchor info failed - %v: %v",
response.Status, e)
}

// Decode the response from dcrtimed
var anchor v2.LastAnchorReply
jsonDecoder := json.NewDecoder(response.Body)
if err := jsonDecoder.Decode(&anchor); err != nil {
return fmt.Errorf("Could not decode LastAnchorReply: %v", err)
return fmt.Errorf("could not decode LastAnchorReply: %v", err)
}

fmt.Printf(
Expand Down Expand Up @@ -1018,18 +1018,18 @@ func lastDigestsV2(n int32) error {
if r.StatusCode != http.StatusOK {
e, err := getError(r.Body)
if err != nil {
return fmt.Errorf("Retrieve last %d digests info failed: %v", n,
return fmt.Errorf("retrieve last %d digests info failed: %v", n,
r.Status)
}
return fmt.Errorf("Retrieve last %d digests info failed - %v: %v",
return fmt.Errorf("retrieve last %d digests info failed - %v: %v",
n, r.Status, e)
}

// Decode the r from dcrtimed
var ldr v2.LastDigestsReply
jsonDecoder := json.NewDecoder(r.Body)
if err := jsonDecoder.Decode(&ldr); err != nil {
return fmt.Errorf("Could not decode LastDigestsReply: %v", err)
return fmt.Errorf("could not decode LastDigestsReply: %v", err)
}

fmt.Printf(
Expand Down Expand Up @@ -1074,7 +1074,7 @@ func loadCredentialsIfRequired() error {
// Token not provided via command line. Try to load via config file.
config, err := loadConfig()
if err != nil {
return fmt.Errorf("Attempt to load api token "+
return fmt.Errorf("attempt to load api token "+
"from configuration file failed: %v", err)
}

Expand Down Expand Up @@ -1134,7 +1134,7 @@ func _main() error {
lastAnchorInfo = lastAnchorV2
lastDigestsInfo = lastDigestsV2
default:
return fmt.Errorf("Invalid API version %v", *apiVersion)
return fmt.Errorf("invalid API version %v", *apiVersion)
}

if *host == "" {
Expand Down
6 changes: 3 additions & 3 deletions cmd/dcrtime_checker/dcrtime_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func verifyV2(digest string, fProof *os.File) error {
var vr v2.VerifyBatchReply
decoder := json.NewDecoder(fProof)
if err := decoder.Decode(&vr); err != nil {
return fmt.Errorf("Could node decode VerifyBatchReply: %v", err)
return fmt.Errorf("could not decode VerifyBatchReply: %v", err)
}

// Ensure file digest exists in the proof and that the saved answer was
Expand Down Expand Up @@ -97,7 +97,7 @@ func verifyV1(digest string, fProof *os.File) error {
var vr v1.VerifyReply
decoder := json.NewDecoder(fProof)
if err := decoder.Decode(&vr); err != nil {
return fmt.Errorf("Could node decode VerifyReply: %v", err)
return fmt.Errorf("could not decode VerifyReply: %v", err)
}

// Ensure file digest exists in the proof and that the saved answer was
Expand Down Expand Up @@ -178,7 +178,7 @@ func _main() error {
case v2.APIVersion:
verify = verifyV2
default:
return fmt.Errorf("Invalid API version %v", *apiVersion)
return fmt.Errorf("invalid API version %v", *apiVersion)
}

// require -f
Expand Down
29 changes: 19 additions & 10 deletions dcrtimed/backend/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,17 @@ func (fs *FileSystem) getTimestamp(timestamp int64) (backend.TimestampResult, er
if fr.ChainTimestamp == 0 && !fs.testing {
lfr, err := fs.lazyFlush(timestamp, fr)
if err != nil {
if err == errNotEnoughConfirmation {
switch {
case errors.Is(err, errNotEnoughConfirmation):
gtme.Confirmations = &lfr.Confirmations
gtme.MinConfirmations = fs.confirmations
} else if err == errInvalidConfirmations {

case errors.Is(err, errInvalidConfirmations):
log.Errorf("%v: Confirmations = -1",
fr.Tx.String())
return gtme, err
} else {

default:
return gtme, err
}
}
Expand Down Expand Up @@ -549,23 +552,29 @@ func (fs *FileSystem) getDigest(now time.Time, current *leveldb.DB, digest [sha2
gdme.Timestamp = fr.ServerTimestamp
gdme.FlushTimestamp = fr.FlushTimestamp

switch {
// Override error code during testing
if fs.testing {
case fs.testing:
gdme.ErrorCode = foundGlobal
} else if gdme.AnchoredTimestamp == 0 {

case gdme.AnchoredTimestamp == 0:
lfr, err := fs.lazyFlush(dbts, fr)
if err != nil {
if err == errNotEnoughConfirmation {
switch {
case errors.Is(err, errNotEnoughConfirmation):
gdme.Confirmations = &lfr.Confirmations
gdme.MinConfirmations = fs.confirmations
} else if err == errInvalidConfirmations {

case errors.Is(err, errInvalidConfirmations):
log.Errorf("%v: Confirmations = -1",
fr.Tx.String())
return gdme, err
} else {

default:
return gdme, err
}
}

gdme.AnchoredTimestamp = fr.ChainTimestamp
}

Expand Down Expand Up @@ -755,7 +764,7 @@ func (fs *FileSystem) GetTimestamps(timestamps []int64) ([]backend.TimestampResu
// Get the last n digests in the added to the Backend
func (fs *FileSystem) LastDigests(n int32) ([]backend.GetResult, error) {
if n > fs.maxDigests {
return nil, fmt.Errorf("Invalid number %d of digests requested. Max is: %d", n, fs.maxDigests)
return nil, fmt.Errorf("invalid number %d of digests requested. Max is: %d", n, fs.maxDigests)
}

results := make([]backend.GetResult, 0)
Expand All @@ -776,7 +785,7 @@ func (fs *FileSystem) LastDigests(n int32) ([]backend.GetResult, error) {
break
}
if !files[i].IsDir() {
return nil, fmt.Errorf("Unexpected file %v",
return nil, fmt.Errorf("unexpected file %v",
filepath.Join(fs.root, files[i].Name()))
}

Expand Down
12 changes: 6 additions & 6 deletions dcrtimed/backend/filesystem/fsck.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/binary"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -316,7 +317,7 @@ func (fs *FileSystem) fsckTimestamp(options *backend.FsckOptions, ts int64, empt

gdbts, err := fs.db.Get(key, nil)
if err != nil {
if err == leveldb.ErrNotFound {
if errors.Is(err, leveldb.ErrNotFound) {
continue
}
return fmt.Errorf(" *** ERROR found in db: %v %v",
Expand Down Expand Up @@ -376,7 +377,7 @@ func (fs *FileSystem) fsckTimestamps(options *backend.FsckOptions, empties map[i

for _, fi := range files {
if !fi.IsDir() {
return fmt.Errorf("Unexpected file %v",
return fmt.Errorf("unexpected file %v",
filepath.Join(fs.root, fi.Name()))
}
if fi.Name() == globalDBDir {
Expand Down Expand Up @@ -453,9 +454,8 @@ func (fs *FileSystem) fsckGlobal(options *backend.FsckOptions, empties map[int64
// At this point we treat this as fatal because there
// is no need to write code for theoretical issues that
// should not have happned.
return fmt.Errorf(" *** ERROR hash not found in "+
"timestamp : %v %v\n", filepath.Join(fs.root,
ts2dirname(value)), key)
return fmt.Errorf("hash not found in timestamp : %v %v", filepath.Join(
fs.root, ts2dirname(value)), key)
}

// Check to see if this timestamp exists in the empties map.
Expand Down Expand Up @@ -618,7 +618,7 @@ func (fs *FileSystem) fsckDups(options *backend.FsckOptions) error {
digests := make(map[string]int64)
for _, fi := range files {
if !fi.IsDir() {
return fmt.Errorf("Unexpected file %v",
return fmt.Errorf("unexpected file %v",
filepath.Join(fs.root, fi.Name()))
}
if fi.Name() == globalDBDir {
Expand Down
Loading
Loading