Skip to content
Merged
11 changes: 5 additions & 6 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # version v3.0.2
uses: actions/checkout@v4
with:
fetch-depth: 0 # required for new-from-rev option in .golangci.yml
- name: Setup GO
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f # version v3.3.0
- uses: ./.github/actions/setup-go
- name: Run golangci-lint
uses: golangci/golangci-lint-action@537aa1903e5d359d0b27dbc19ddd22c5087f3fbc # version v3.2.0
uses: golangci/golangci-lint-action@v7
with:
version: v1.52.2 # this is the golangci-lint version
args: --issues-exit-code=0 # exit without errors for now - won't fail the build
version: v2.1.6
args: -v --issues-exit-code=0 --config=.golangci.yml # exit without errors for now - won't fail the build
github-token: ${{ secrets.GITHUB_TOKEN }}
only-new-issues: true

Expand Down
176 changes: 71 additions & 105 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,129 +1,95 @@
linters-settings:
depguard:
list-type: denylist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
gomnd:
# don't include the "operation" and "assign"
checks:
- argument
- case
- condition
- return
ignored-numbers:
- '0'
- '1'
- '2'
- '3'
ignored-functions:
- strings.SplitN

govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

version: "2"
linters:
disable-all: true
default: none
enable:
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- funlen
- gochecknoinits
- goconst
#- gocritic
- gocyclo
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- mnd
- nakedret
- noctx
- nolintlint
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
#- whitespace

# don't enable:
# - asciicheck
# - scopelint
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - interfacer
# - maligned
# - nestif
# - prealloc
# - testpackage
# - revive
# - wsl

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- govet

run:
timeout: 5m
skip-dirs:
- docs
- vendor
settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 3
gocritic:
disabled-checks:
- dupImport
- ifElseChain
- octalLiteral
- whyNoLint
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
gocyclo:
min-complexity: 15
govet:
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
misspell:
locale: US
nolintlint:
require-explanation: false
require-specific: false
allow-unused: false
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- govet
path: _test\.go
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- github.com/golangci/golangci-lint
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/adjust/goautoneg v0.0.0-20150426214442-d788f35a0315
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
github.com/aws/aws-sdk-go v1.45.27
github.com/creachadair/jrpc2 v1.2.0
github.com/djherbis/fscache v0.10.1
github.com/elazarl/go-bindata-assetfs v1.0.1
github.com/getsentry/raven-go v0.2.0
Expand Down Expand Up @@ -58,6 +57,7 @@ require (

require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/creachadair/jrpc2 v1.2.0
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da
github.com/docker/docker v27.3.1+incompatible
github.com/docker/go-connections v0.5.0
Expand Down
37 changes: 18 additions & 19 deletions ingest/ledgerbackend/rpc_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ func (e *RPCLedgerMissingError) Error() string {
return fmt.Sprintf("ledger %d was not present on rpc", e.Sequence)
}

type RPCLedgerBeyondLatestError struct {
Sequence uint32
LatestLedger uint32
}
type rpcLedgerBeyondLatestError struct{}

func (e *RPCLedgerBeyondLatestError) Error() string {
return fmt.Sprintf("ledger %d is beyond the RPC latest ledger is %d", e.Sequence, e.LatestLedger)
func (e rpcLedgerBeyondLatestError) Error() string {
return "ledger is not available on the RPC server yet"
}

// The minimum required RPC client methods used by RPCLedgerBackend.
type RPCLedgerGetter interface {
GetLedgers(ctx context.Context, req protocol.GetLedgersRequest) (protocol.GetLedgersResponse, error)
GetHealth(ctx context.Context) (protocol.GetHealthResponse, error) // <-- Added
}

type RPCLedgerBackend struct {
Expand Down Expand Up @@ -146,8 +144,8 @@ func (b *RPCLedgerBackend) GetLedger(ctx context.Context, sequence uint32) (xdr.
return lcm, nil
}

_, isBeyondErr := err.(*RPCLedgerBeyondLatestError)
if !isBeyondErr {
var beyondErr *rpcLedgerBeyondLatestError
if !(errors.As(err, &beyondErr)) {
return xdr.LedgerCloseMeta{}, err
}

Expand Down Expand Up @@ -182,7 +180,7 @@ func (b *RPCLedgerBackend) PrepareRange(ctx context.Context, ledgerRange Range)
_, err := b.getBufferedLedger(ctx, ledgerRange.from)
if err != nil {
// beyond latest is handled later in GetLedger
var beyondErr *RPCLedgerBeyondLatestError
var beyondErr *rpcLedgerBeyondLatestError
if !(errors.As(err, &beyondErr)) {
return err
}
Expand Down Expand Up @@ -240,7 +238,16 @@ func (b *RPCLedgerBackend) getBufferedLedger(ctx context.Context, sequence uint3
return lcm, nil
}

// Ledger not in buffer, fetch a small batch from RPC starting from the requested sequence
// Check if requested ledger is beyond the RPC retention window using GetHealth
health, err := b.client.GetHealth(ctx)
if err != nil {
return xdr.LedgerCloseMeta{}, fmt.Errorf("failed to get health from RPC: %w", err)
}
if sequence > health.LatestLedger {
return xdr.LedgerCloseMeta{}, &rpcLedgerBeyondLatestError{}
}

// attempt to fetch a small batch from RPC starting from the requested sequence
req := protocol.GetLedgersRequest{
StartLedger: sequence,
Pagination: &protocol.LedgerPaginationOptions{
Expand All @@ -250,19 +257,11 @@ func (b *RPCLedgerBackend) getBufferedLedger(ctx context.Context, sequence uint3

ledgers, err := b.client.GetLedgers(ctx, req)
if err != nil {
return xdr.LedgerCloseMeta{}, fmt.Errorf("failed to get ledgers starting from %d: %w", sequence, err)
return xdr.LedgerCloseMeta{}, err
}

b.initBuffer()

// Check if requested ledger is beyond the RPC retention window
if sequence > ledgers.LatestLedger {
return xdr.LedgerCloseMeta{}, &RPCLedgerBeyondLatestError{
Sequence: sequence,
LatestLedger: ledgers.LatestLedger,
}
}

// Populate buffer with new ledgers
for _, ledger := range ledgers.Ledgers {
var lcm xdr.LedgerCloseMeta
Expand Down
Loading
Loading