Skip to content

Commit

Permalink
pass linter
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaubennassar committed Sep 13, 2024
1 parent ecbb8e0 commit db74b4c
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 844 deletions.
3 changes: 2 additions & 1 deletion aggoracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/big"
"time"

"github.com/0xPolygon/cdk/db"
"github.com/0xPolygon/cdk/etherman"
"github.com/0xPolygon/cdk/l1infotreesync"
"github.com/0xPolygon/cdk/log"
Expand Down Expand Up @@ -65,7 +66,7 @@ func (a *AggOracle) Start(ctx context.Context) {
if err != nil {
if errors.Is(err, l1infotreesync.ErrBlockNotProcessed) {
log.Debugf("syncer is not ready for the block %d", blockNumToFetch)
} else if errors.Is(err, l1infotreesync.ErrNotFound) {
} else if errors.Is(err, db.ErrNotFound) {
blockNumToFetch = 0
log.Debugf("syncer has not found any GER until block %d", blockNumToFetch)
} else {
Expand Down
3 changes: 2 additions & 1 deletion bridgesync/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygonzkevmbridge"
"github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygonzkevmbridgev2"
rpcTypes "github.com/0xPolygon/cdk-rpc/types"
"github.com/0xPolygon/cdk/db"
"github.com/0xPolygon/cdk/sync"
tree "github.com/0xPolygon/cdk/tree/types"
"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -181,7 +182,7 @@ func setClaimCalldata(client EthClienter, bridge common.Address, txHash common.H
callStack.Push(c)
}
}
return ErrNotFound
return db.ErrNotFound
}

func setClaimIfFoundOnInput(input []byte, claim *Claim) (bool, error) {
Expand Down
3 changes: 1 addition & 2 deletions bridgesync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
var (
// ErrBlockNotProcessed indicates that the given block(s) have not been processed yet.
ErrBlockNotProcessed = errors.New("given block(s) have not been processed yet")
ErrNotFound = errors.New("not found")
)

// Bridge is the representation of a bridge event
Expand Down Expand Up @@ -184,7 +183,7 @@ func (p *processor) queryBlockRange(tx db.Querier, fromBlock, toBlock uint64, ta
`, table), fromBlock, toBlock)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, ErrNotFound
return nil, db.ErrNotFound
}
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions claimsponsor/claimsponsor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

dbCommon "github.com/0xPolygon/cdk/common"
"github.com/0xPolygon/cdk/db"
"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/cdk/sync"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -31,7 +32,6 @@ const (

var (
ErrInvalidClaim = errors.New("invalid claim")
ErrNotFound = errors.New("not found")
)

// Claim representation of a claim event
Expand Down Expand Up @@ -129,7 +129,7 @@ func (c *ClaimSponsor) Start(ctx context.Context) {
if err2 != nil {
err = err2
tx.Rollback()
if errors.Is(err, ErrNotFound) {
if errors.Is(err, db.ErrNotFound) {
log.Debugf("queue is empty")
err = nil
time.Sleep(c.waitOnEmptyQueue)
Expand Down Expand Up @@ -250,7 +250,7 @@ func (c *ClaimSponsor) AddClaimToQueue(ctx context.Context, claim *Claim) error
}

_, err = getClaim(tx, claim.GlobalIndex)
if !errors.Is(err, ErrNotFound) {
if !errors.Is(err, db.ErrNotFound) {
if err != nil {
tx.Rollback()

Expand All @@ -271,7 +271,7 @@ func (c *ClaimSponsor) AddClaimToQueue(ctx context.Context, claim *Claim) error

var queuePosition uint64
lastQueuePosition, _, err := getLastQueueIndex(tx)
if errors.Is(err, ErrNotFound) {
if errors.Is(err, db.ErrNotFound) {
queuePosition = 0
} else if err != nil {
tx.Rollback()
Expand Down Expand Up @@ -311,7 +311,7 @@ func (c *ClaimSponsor) getClaimByQueueIndex(ctx context.Context, queueIndex uint
return nil, err
}
if globalIndexBytes == nil {
return nil, ErrNotFound
return nil, db.ErrNotFound
}

return getClaim(tx, new(big.Int).SetBytes(globalIndexBytes))
Expand Down Expand Up @@ -349,7 +349,7 @@ func getIndex(iter iter.KV) (uint64, *big.Int, error) {
return 0, nil, err
}
if k == nil {
return 0, nil, ErrNotFound
return 0, nil, db.ErrNotFound
}
globalIndex := new(big.Int).SetBytes(v)

Expand All @@ -372,7 +372,7 @@ func getClaim(tx kv.Tx, globalIndex *big.Int) (*Claim, error) {
return nil, err
}
if claimBytes == nil {
return nil, ErrNotFound
return nil, db.ErrNotFound
}
claim := &Claim{}
err = json.Unmarshal(claimBytes, claim)
Expand Down
4 changes: 3 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func start(cliCtx *cli.Context) error {
claimSponsor := runClaimSponsorIfNeeded(cliCtx.Context, components, l2Client, c.ClaimSponsor)
l1BridgeSync := runBridgeSyncL1IfNeeded(cliCtx.Context, components, c.BridgeL1Sync, reorgDetectorL1, l1Client)
l2BridgeSync := runBridgeSyncL2IfNeeded(cliCtx.Context, components, c.BridgeL2Sync, reorgDetectorL2, l2Client)
lastGERSync := runLastGERSyncIfNeeded(cliCtx.Context, components, c.LastGERSync, reorgDetectorL2, l2Client, l1InfoTreeSync)
lastGERSync := runLastGERSyncIfNeeded(
cliCtx.Context, components, c.LastGERSync, reorgDetectorL2, l2Client, l1InfoTreeSync,
)

for _, component := range components {
switch component {
Expand Down
7 changes: 5 additions & 2 deletions db/meddler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func initMeddler() {
meddler.Register("address", AddressMeddler{})
}

func SQLiteErr(err error) (sqlite.Error, bool) {
func SQLiteErr(err error) (*sqlite.Error, bool) {
sqliteErr := &sqlite.Error{}
if ok := errors.As(err, sqliteErr); ok {
return sqliteErr, true
Expand Down Expand Up @@ -189,7 +189,10 @@ func (b AddressMeddler) PreRead(fieldAddr interface{}) (scanTarget interface{},

// PostRead is called after a Scan operation for fields that have the ProofMeddler
func (b AddressMeddler) PostRead(fieldPtr, scanTarget interface{}) error {
ptr := scanTarget.(*string)
ptr, ok := scanTarget.(*string)
if !ok {
return errors.New("scanTarget is not *string")
}
if ptr == nil {
return errors.New("AddressMeddler.PostRead: nil pointer")
}
Expand Down
4 changes: 4 additions & 0 deletions db/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
_ "github.com/mattn/go-sqlite3"
)

const (
UniqueConstrain = 1555
)

var (
ErrNotFound = errors.New("not found")
)
Expand Down
70 changes: 0 additions & 70 deletions l1bridge2infoindexsync/downloader.go

This file was deleted.

Loading

0 comments on commit db74b4c

Please sign in to comment.