Skip to content

Commit

Permalink
fix: revert PR#140
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Oct 30, 2024
1 parent 1f2d2b9 commit 5c75104
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 116 deletions.
37 changes: 0 additions & 37 deletions bridgesync/bridge_contract.go

This file was deleted.

13 changes: 0 additions & 13 deletions bridgesync/bridge_contract_test.go

This file was deleted.

7 changes: 1 addition & 6 deletions bridgesync/bridgesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func NewL1(
retryAfterErrorPeriod time.Duration,
maxRetryAttemptsAfterError int,
originNetwork uint32,
bridgeContract BridgeContractor,
) (*BridgeSync, error) {
return newBridgeSync(
ctx,
Expand All @@ -60,7 +59,6 @@ func NewL1(
maxRetryAttemptsAfterError,
originNetwork,
false,
bridgeContract,
)
}

Expand All @@ -78,7 +76,6 @@ func NewL2(
retryAfterErrorPeriod time.Duration,
maxRetryAttemptsAfterError int,
originNetwork uint32,
bridgeContract BridgeContractor,
) (*BridgeSync, error) {
return newBridgeSync(
ctx,
Expand All @@ -95,7 +92,6 @@ func NewL2(
maxRetryAttemptsAfterError,
originNetwork,
true,
bridgeContract,
)
}

Expand All @@ -114,9 +110,8 @@ func newBridgeSync(
maxRetryAttemptsAfterError int,
originNetwork uint32,
syncFullClaims bool,
bridgeContract BridgeContractor,
) (*BridgeSync, error) {
processor, err := newProcessor(dbPath, l1OrL2ID, bridgeContract)
processor, err := newProcessor(dbPath, l1OrL2ID)
if err != nil {
return nil, err
}
Expand Down
3 changes: 0 additions & 3 deletions bridgesync/bridgesync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func TestNewLx(t *testing.T) {
originNetwork := uint32(1)

mockEthClient := mocksbridgesync.NewEthClienter(t)
mockBridgeContract := mocksbridgesync.NewBridgeContractor(t)
mockReorgDetector := mocksbridgesync.NewReorgDetector(t)

mockReorgDetector.EXPECT().Subscribe(mock.Anything).Return(nil, nil)
Expand All @@ -53,7 +52,6 @@ func TestNewLx(t *testing.T) {
retryAfterErrorPeriod,
maxRetryAttemptsAfterError,
originNetwork,
mockBridgeContract,
)

assert.NoError(t, err)
Expand All @@ -74,7 +72,6 @@ func TestNewLx(t *testing.T) {
retryAfterErrorPeriod,
maxRetryAttemptsAfterError,
originNetwork,
mockBridgeContract,
)

assert.NoError(t, err)
Expand Down
4 changes: 1 addition & 3 deletions bridgesync/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ func TestBridgeEventE2E(t *testing.T) {
go rd.Start(ctx) //nolint:errcheck

testClient := helpers.TestClient{ClientRenamed: client.Client()}
bridgeContract, err := bridgesync.NewBridgeContract(setup.EBZkevmBridgeAddr, testClient)
require.NoError(t, err)
syncer, err := bridgesync.NewL1(ctx, dbPathSyncer, setup.EBZkevmBridgeAddr, 10, etherman.LatestBlock, rd, testClient, 0, time.Millisecond*10, 0, 0, 1, bridgeContract)
syncer, err := bridgesync.NewL1(ctx, dbPathSyncer, setup.EBZkevmBridgeAddr, 10, etherman.LatestBlock, rd, testClient, 0, time.Millisecond*10, 0, 0, 1)
require.NoError(t, err)

go syncer.Start(ctx)
Expand Down
26 changes: 5 additions & 21 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, bridgeContract BridgeContractor) (*processor, error) {
func newProcessor(dbPath, loggerPrefix string) (*processor, error) {
err := migrations.RunMigrations(dbPath)
if err != nil {
return nil, err
Expand All @@ -121,31 +121,15 @@ func newProcessor(dbPath, loggerPrefix string, bridgeContract BridgeContractor)
logger := log.WithFields("bridge-syncer", loggerPrefix)
exitTree := tree.NewAppendOnlyTree(db, "")
return &processor{
db: db,
exitTree: exitTree,
log: logger,
bridgeContract: bridgeContract,
db: db,
exitTree: exitTree,
log: logger,
}, nil
}
func (p *processor) GetBridgesPublished(
ctx context.Context, fromBlock, toBlock uint64,
) ([]Bridge, error) {
allBridges, err := p.GetBridges(ctx, fromBlock, toBlock)
if err != nil {
return nil, err
}
lastCount, er := p.bridgeContract.LastUpdatedDepositCount(ctx, toBlock)
if er != nil {
return nil, er
}
p.log.Debugf("last updated deposit count: %d in block %d. Num bridges: %d", lastCount, toBlock, len(allBridges))
var bridges []Bridge
for _, bridge := range allBridges {
if bridge.DepositCount <= lastCount {
bridges = append(bridges, bridge)
}
}
return bridges, nil
return p.GetBridges(ctx, fromBlock, toBlock)
}

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

tx, err := p.db.BeginTx(context.Background(), nil)
Expand Down Expand Up @@ -853,14 +853,9 @@ func TestGetBridgesPublished(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

mockBridgeContract := &mockBridgeContract{
lastUpdatedDepositCount: tc.lastUpdatedDepositCount,
err: tc.expectedError,
}

path := path.Join(t.TempDir(), "file::memory:?cache=shared")
require.NoError(t, migrationsBridge.RunMigrations(path))
p, err := newProcessor(path, "foo", mockBridgeContract)
p, err := newProcessor(path, "foo")
require.NoError(t, err)

tx, err := p.db.BeginTx(context.Background(), nil)
Expand Down
5 changes: 1 addition & 4 deletions claimsponsor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ func TestE2EL1toEVML2(t *testing.T) {
env := aggoraclehelpers.SetupAggoracleWithEVMChain(t)
dbPathBridgeSyncL1 := path.Join(t.TempDir(), "file::memory:?cache=shared")
testClient := helpers.TestClient{ClientRenamed: env.L1Client.Client()}
bridgeContract, err := bridgesync.NewBridgeContract(env.BridgeL1Addr, testClient)
require.NoError(t, err)

bridgeSyncL1, err := bridgesync.NewL1(ctx, dbPathBridgeSyncL1, env.BridgeL1Addr, 10, etherman.LatestBlock, env.ReorgDetector, testClient, 0, time.Millisecond*10, 0, 0, 1, bridgeContract)
bridgeSyncL1, err := bridgesync.NewL1(ctx, dbPathBridgeSyncL1, env.BridgeL1Addr, 10, etherman.LatestBlock, env.ReorgDetector, testClient, 0, time.Millisecond*10, 0, 0, 1)
require.NoError(t, err)
go bridgeSyncL1.Start(ctx)

Expand Down
11 changes: 0 additions & 11 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,6 @@ func runBridgeSyncL1IfNeeded(
if !isNeeded([]string{cdkcommon.RPC}, components) {
return nil
}
bridgeContract, err := bridgesync.NewBridgeContract(cfg.BridgeAddr, l1Client)
if err != nil {
log.Fatalf("error creating L1 bridge contract: %s", err)
}
bridgeSyncL1, err := bridgesync.NewL1(
ctx,
cfg.DBPath,
Expand All @@ -709,7 +705,6 @@ func runBridgeSyncL1IfNeeded(
cfg.RetryAfterErrorPeriod.Duration,
cfg.MaxRetryAttemptsAfterError,
cfg.OriginNetwork,
bridgeContract,
)
if err != nil {
log.Fatalf("error creating bridgeSyncL1: %s", err)
Expand All @@ -730,11 +725,6 @@ func runBridgeSyncL2IfNeeded(
return nil
}

bridgeContract, err := bridgesync.NewBridgeContract(cfg.BridgeAddr, l2Client)
if err != nil {
log.Fatalf("error creating L2 bridge contract: %s", err)
}

bridgeSyncL2, err := bridgesync.NewL2(
ctx,
cfg.DBPath,
Expand All @@ -748,7 +738,6 @@ func runBridgeSyncL2IfNeeded(
cfg.RetryAfterErrorPeriod.Duration,
cfg.MaxRetryAttemptsAfterError,
cfg.OriginNetwork,
bridgeContract,
)
if err != nil {
log.Fatalf("error creating bridgeSyncL2: %s", err)
Expand Down
17 changes: 8 additions & 9 deletions l1infotree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,17 @@ func (mt *L1InfoTree) ComputeMerkleProof(gerIndex uint32, leaves [][32]byte) ([]
if len(leaves)%2 == 1 {
leaves = append(leaves, mt.zeroHashes[h])
}
if index%2 == 1 { //If it is odd
if index%2 == 1 { // If it is odd
siblings = append(siblings, leaves[index-1])
} else { // It is even
if len(leaves) > 1 {
if index >= uint32(len(leaves)) {
// siblings = append(siblings, mt.zeroHashes[h])
siblings = append(siblings, leaves[index-1])
} else {
siblings = append(siblings, leaves[index+1])
}
} else if len(leaves) > 1 { // It is even
if index >= uint32(len(leaves)) {
// siblings = append(siblings, mt.zeroHashes[h])
siblings = append(siblings, leaves[index-1])
} else {
siblings = append(siblings, leaves[index+1])
}
}

var (
nsi [][][]byte
hashes [][32]byte
Expand Down
1 change: 0 additions & 1 deletion l1infotree/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func TestAddLeaf2TestLastLeaf(t *testing.T) {
common.HexToHash("0x6a617315ffc0a6831d2de6331f8d3e053889e9385696c13f11853fdcba50e123"),
common.HexToHash("0x1cff355b898cf285bcc3f84a8d6ed51c19fe87ab654f4146f2dc7723a59fc741"),
}
//require.Equal(t, 26, len(leaves))
siblings, root, err := mt.ComputeMerkleProof(2, leaves)
require.NoError(t, err)
fmt.Printf("Root: %s\n", root.String())
Expand Down

0 comments on commit 5c75104

Please sign in to comment.