Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rachit77 committed Sep 6, 2024
1 parent e592f70 commit 74cd236
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 18 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Lint
on:
push:
branches:
- main
- develop
- update-external-dependencies
- 'release/**'
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v3
- name: Lint
run: |
make install-linter
make lint
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ linters:
- prealloc # Finds slice declarations that could potentially be pre-allocated
- predeclared # Finds code that shadows one of Go's predeclared identifiers
- nolintlint # Ill-formed or insufficient nolint directives
- nlreturn # Checks for a new line before return and branch statements to increase code clarity
# - nlreturn # Checks for a new line before return and branch statements to increase code clarity
- misspell # Misspelled English words in comments
- makezero # Finds slice declarations with non-zero initial length
- lll # Long lines
Expand All @@ -37,12 +37,12 @@ linters:
- 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
# - 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
- gocritic # gocritic is a Go source code linter that maintains checks that are not in other linters
- errcheck # Errcheck is a go lint rule for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- godox # Godox is a linter for TODOs and FIXMEs left in the code
# - godox # Godox is a linter for TODOs and FIXMEs left in the code
- gci # Gci is a linter for checking the consistency of the code with the go code style guide
- gomnd # Gomnd is a linter for magic numbers
# - revive
Expand Down
2 changes: 1 addition & 1 deletion aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (a *Aggregator) handleRollbackBatches(rollbackData synchronizer.RollbackBat
a.halted.Store(true)
for {
log.Errorf("Halting the aggregator due to an error handling rollback batches event: %v", err)
time.Sleep(10 * time.Second) // nolint:gomnd
time.Sleep(10 * time.Second) //nolint:gomnd
}
}
}
Expand Down
65 changes: 51 additions & 14 deletions bridgesync/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ func buildAppender(client EthClienter, bridge common.Address, syncFullClaims boo
Amount: claimEvent.Amount,
}
if syncFullClaims {
setClaimCalldata(client, bridge, l.TxHash, claim)
if err := setClaimCalldata(client, bridge, l.TxHash, claim); err != nil {
return err
}
}
b.Events = append(b.Events, Event{Claim: claim})
return nil
Expand All @@ -111,7 +113,9 @@ func buildAppender(client EthClienter, bridge common.Address, syncFullClaims boo
Amount: claimEvent.Amount,
}
if syncFullClaims {
setClaimCalldata(client, bridge, l.TxHash, claim)
if err := setClaimCalldata(client, bridge, l.TxHash, claim); err != nil {
return err
}
}
b.Events = append(b.Events, Event{Claim: claim})
return nil
Expand Down Expand Up @@ -148,7 +152,13 @@ func setClaimCalldata(client EthClienter, bridge common.Address, txHash common.H
if callStack.Len() == 0 {
break
}
currentCall := callStack.Pop().(call)

currentCallInterface := callStack.Pop()
currentCall, ok := currentCallInterface.(call)
if !ok {
return fmt.Errorf("unexpected type for 'currentCall'. Expected 'call', got '%T'", currentCallInterface)
}

if currentCall.To == bridge {
found, err := setClaimIfFoundOnInput(
currentCall.Input,
Expand All @@ -173,9 +183,9 @@ func setClaimIfFoundOnInput(input []byte, claim *Claim) (bool, error) {
if err != nil {
return false, err
}
methodId := input[:4]
methodID := input[:4]
// Recover Method from signature and ABI
method, err := smcAbi.MethodById(methodId)
method, err := smcAbi.MethodById(methodID)
if err != nil {
return false, err
}
Expand All @@ -184,13 +194,13 @@ func setClaimIfFoundOnInput(input []byte, claim *Claim) (bool, error) {
return false, err
}
// Ignore other methods
if bytes.Equal(methodId, methodIDClaimAsset) || bytes.Equal(methodId, methodIDClaimMessage) {
if bytes.Equal(methodID, methodIDClaimAsset) || bytes.Equal(methodID, methodIDClaimMessage) {
found, err := decodeClaimCallDataAndSetIfFound(data, claim)
if err != nil {
return false, err
}
if found {
if bytes.Equal(methodId, methodIDClaimMessage) {
if bytes.Equal(methodID, methodIDClaimMessage) {
claim.IsMessage = true
}
return true, nil
Expand Down Expand Up @@ -232,25 +242,52 @@ func decodeClaimCallDataAndSetIfFound(data []interface{}, claim *Claim) (bool, e
10: metadata,
)
*/
actualGlobalIndex := data[2].(*big.Int)
actualGlobalIndex, ok := data[2].(*big.Int)
if !ok {
return false, fmt.Errorf("unexpected type for actualGlobalIndex, expected *big.Int got '%T'", data[2])
}
if actualGlobalIndex.Cmp(claim.GlobalIndex) != 0 {
// not the claim we're looking for
return false, nil
} else {
proofLER := [tree.DefaultHeight]common.Hash{}
proofLERBytes := data[0].([32][32]byte)
proofLERBytes, ok := data[0].([32][32]byte)
if !ok {
return false, fmt.Errorf("unexpected type for proofLERBytes, expected [32][32]byte got '%T'", data[0])
}

proofRER := [tree.DefaultHeight]common.Hash{}
proofRERBytes := data[1].([32][32]byte)
proofRERBytes, ok := data[1].([32][32]byte)
if !ok {
return false, fmt.Errorf("unexpected type for proofRERBytes, expected [32][32]byte got '%T'", data[1])
}

for i := 0; i < int(tree.DefaultHeight); i++ {
proofLER[i] = proofLERBytes[i]
proofRER[i] = proofRERBytes[i]
}
claim.ProofLocalExitRoot = proofLER
claim.ProofRollupExitRoot = proofRER
claim.MainnetExitRoot = data[3].([32]byte)
claim.RollupExitRoot = data[4].([32]byte)
claim.DestinationNetwork = data[7].(uint32)
claim.Metadata = data[10].([]byte)

claim.MainnetExitRoot, ok = data[3].([32]byte)
if !ok {
return false, fmt.Errorf("unexpected type for 'MainnetExitRoot'. Expected '[32]byte', got '%T'", data[3])
}

claim.RollupExitRoot, ok = data[4].([32]byte)
if !ok {
return false, fmt.Errorf("unexpected type for 'RollupExitRoot'. Expected '[32]byte', got '%T'", data[4])
}

claim.DestinationNetwork, ok = data[7].(uint32)
if !ok {
return false, fmt.Errorf("unexpected type for 'DestinationNetwork'. Expected 'uint32', got '%T'", data[7])
}
claim.Metadata, ok = data[10].([]byte)
if !ok {
return false, fmt.Errorf("unexpected type for 'claim Metadata'. Expected '[]byte', got '%T'", data[10])
}

return true, nil
}
}

0 comments on commit 74cd236

Please sign in to comment.