Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaubennassar committed Jul 24, 2024
1 parent 647023f commit 278459a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 36 deletions.
20 changes: 6 additions & 14 deletions aggoracle/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

Expand All @@ -29,7 +28,7 @@ func TestEVM(t *testing.T) {
sender := evmSetup(t)
oracle, err := aggoracle.New(sender, l1Client.Client(), syncer, etherman.LatestBlock)
require.NoError(t, err)
oracle.Start(ctx)
go oracle.Start(ctx)

runTest(t, gerL1Contract, sender, l1Client, authL1)
}
Expand All @@ -50,16 +49,14 @@ func commonSetup(t *testing.T) (
l1Client, gerL1Addr, gerL1Contract, err := newSimulatedL1(authL1)
require.NoError(t, err)
// Reorg detector
rdm := NewReorgDetectorMock(t)
rdm.On("Subscribe", mock.Anything).Return(&reorgdetector.Subscription{})
rdm.On("AddBlockToTrack", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
reorg, err := reorgdetector.New(ctx)
dbPathReorgDetector := t.TempDir()
reorg, err := reorgdetector.New(ctx, l1Client.Client(), dbPathReorgDetector)
require.NoError(t, err)
// Syncer
dbPath := t.TempDir()
syncer, err := l1infotreesync.New(ctx, dbPath, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), 32)
dbPathSyncer := t.TempDir()
syncer, err := l1infotreesync.New(ctx, dbPathSyncer, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), 32)
require.NoError(t, err)
syncer.Sync(ctx)
go syncer.Sync(ctx)

return l1Client, syncer, gerL1Contract, authL1
}
Expand Down Expand Up @@ -140,8 +137,3 @@ func runTest(
require.True(t, isInjected)
}
}

type ReorgDetector interface {
Subscribe(id string) *reorgdetector.Subscription
AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error
}
4 changes: 3 additions & 1 deletion aggoracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ func (a *AggOracle) Start(ctx context.Context) {
log.Debugf("GER %s already injected", gerToInject.Hex())
continue
}
log.Debugf("injecting new GER: %s", gerToInject.Hex())
if err := a.chainSender.UpdateGERWaitUntilMined(ctx, gerToInject); err != nil {
log.Error("error calling updateGERWaitUntilMined: ", err)
log.Errorf("error calling updateGERWaitUntilMined, when trying to inject GER %s: %v", gerToInject.Hex(), err)
continue
}
log.Debugf("GER %s injected", gerToInject.Hex())
case <-ctx.Done():
return
}
Expand Down
7 changes: 5 additions & 2 deletions l1infotreesync/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type processorInterface interface {
}

type ReorgDetector interface {
Subscribe(id string) *reorgdetector.Subscription
Subscribe(id string) (*reorgdetector.Subscription, error)
AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error
}

Expand All @@ -41,7 +41,10 @@ func newDriver(
processor processorInterface,
downloader downloaderFull,
) (*driver, error) {
reorgSub := reorgDetector.Subscribe(reorgDetectorID)
reorgSub, err := reorgDetector.Subscribe(reorgDetectorID)
if err != nil {
return nil, err
}
return &driver{
reorgDetector: reorgDetector,
reorgSub: reorgSub,
Expand Down
14 changes: 12 additions & 2 deletions l1infotreesync/mock_reorgdetector_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions localbridgesync/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type processorInterface interface {
}

type ReorgDetector interface {
Subscribe(id string) *reorgdetector.Subscription
Subscribe(id string) (*reorgdetector.Subscription, error)
AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error
}

Expand All @@ -41,7 +41,10 @@ func newDriver(
processor processorInterface,
downloader downloaderFull,
) (*driver, error) {
reorgSub := reorgDetector.Subscribe(reorgDetectorID)
reorgSub, err := reorgDetector.Subscribe(reorgDetectorID)
if err != nil {
return nil, err
}
return &driver{
reorgDetector: reorgDetector,
reorgSub: reorgSub,
Expand Down
14 changes: 12 additions & 2 deletions localbridgesync/mock_reorgdetector_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 6 additions & 13 deletions reorgdetector/mock_eth_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 278459a

Please sign in to comment.