Skip to content

Commit

Permalink
feat: add logs to bridgesync creation
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Nov 27, 2024
1 parent 521b968 commit 144cfee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
11 changes: 10 additions & 1 deletion bridgesync/bridgesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/0xPolygon/cdk/etherman"
"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/cdk/sync"
tree "github.com/0xPolygon/cdk/tree/types"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -111,7 +112,8 @@ func newBridgeSync(
originNetwork uint32,
syncFullClaims bool,
) (*BridgeSync, error) {
processor, err := newProcessor(dbPath, l1OrL2ID)
logger := log.WithFields("bridge-syncer", l1OrL2ID)
processor, err := newProcessor(dbPath, logger)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -156,6 +158,13 @@ func newBridgeSync(
if err != nil {
return nil, err
}
logger.Infof("BridgeSyncer [%s] created: dbPath: %s initialBlock:%d bridgeAddr: %s, syncFullClaims: %d,"+
" maxRetryAttemptsAfterError:%d RetryAfterErrorPeriod:%s"+
"syncBlockChunkSize: %d, blockFinalityType: %s waitForNewBlocksPeriod: %s",
l1OrL2ID,
dbPath, initialBlock, bridge.String(), syncFullClaims,
maxRetryAttemptsAfterError, retryAfterErrorPeriod.String(),
syncBlockChunkSize, blockFinalityType, waitForNewBlocksPeriod.String())

return &BridgeSync{
processor: processor,
Expand Down
4 changes: 2 additions & 2 deletions bridgesync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type processor struct {
bridgeContract BridgeContractor
}

func newProcessor(dbPath, loggerPrefix string) (*processor, error) {
func newProcessor(dbPath string, logger *log.Logger) (*processor, error) {
err := migrations.RunMigrations(dbPath)
if err != nil {
return nil, err
Expand All @@ -118,7 +118,7 @@ func newProcessor(dbPath, loggerPrefix string) (*processor, error) {
if err != nil {
return nil, err
}
logger := log.WithFields("bridge-syncer", loggerPrefix)

exitTree := tree.NewAppendOnlyTree(db, "")
return &processor{
db: db,
Expand Down
9 changes: 6 additions & 3 deletions bridgesync/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func TestProceessor(t *testing.T) {
log.Debugf("sqlite path: %s", path)
err := migrationsBridge.RunMigrations(path)
require.NoError(t, err)
p, err := newProcessor(path, "foo")
logger := log.WithFields("bridge-syncer", "foo")
p, err := newProcessor(path, logger)
require.NoError(t, err)
actions := []processAction{
// processed: ~
Expand Down Expand Up @@ -735,7 +736,8 @@ func TestInsertAndGetClaim(t *testing.T) {
log.Debugf("sqlite path: %s", path)
err := migrationsBridge.RunMigrations(path)
require.NoError(t, err)
p, err := newProcessor(path, "foo")
logger := log.WithFields("bridge-syncer", "foo")
p, err := newProcessor(path, logger)
require.NoError(t, err)

tx, err := p.db.BeginTx(context.Background(), nil)
Expand Down Expand Up @@ -828,7 +830,8 @@ func TestGetBridgesPublished(t *testing.T) {

path := path.Join(t.TempDir(), "file::memory:?cache=shared")
require.NoError(t, migrationsBridge.RunMigrations(path))
p, err := newProcessor(path, "foo")
logger := log.WithFields("bridge-syncer", "foo")
p, err := newProcessor(path, logger)
require.NoError(t, err)

tx, err := p.db.BeginTx(context.Background(), nil)
Expand Down

0 comments on commit 144cfee

Please sign in to comment.