Skip to content

Commit

Permalink
apply PR requests by Stefan-Ethernal
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaubennassar committed Aug 19, 2024
1 parent 9b2b245 commit 766aa4f
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.env
/dist/
cmd/__debug_bin
**__debug**
**__debug**
tmp
2 changes: 1 addition & 1 deletion bridgesync/bridgesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Config struct {
// BlockFinality indicates the status of the blocks that will be queried in order to sync
BlockFinality string `jsonschema:"enum=LatestBlock, enum=SafeBlock, enum=PendingBlock, enum=FinalizedBlock, enum=EarliestBlock" mapstructure:"BlockFinality"`
// InitialBlockNum is the first block that will be queried when starting the synchronization from scratch.
// It should be a number equal oir bellow the creation of the bridge contract
// It should be a number equal or bellow the creation of the bridge contract
InitialBlockNum uint64 `mapstructure:"InitialBlockNum"`
// BridgeAddr is the address of the bridge smart contract
BridgeAddr common.Address `mapstructure:"BridgeAddr"`
Expand Down
8 changes: 4 additions & 4 deletions bridgesync/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ func TestBridgeEventE2E(t *testing.T) {
// Wait for syncer to catch up
syncerUpToDate := false
var errMsg string
lb, err := client.Client().BlockNumber(ctx)
require.NoError(t, err)
for i := 0; i < 10; i++ {
lpb, err := syncer.GetLastProcessedBlock(ctx)
require.NoError(t, err)
lb, err := client.Client().BlockNumber(ctx)
require.NoError(t, err)
if lpb == lb {
syncerUpToDate = true
break
Expand All @@ -101,9 +101,9 @@ func TestBridgeEventE2E(t *testing.T) {
require.True(t, syncerUpToDate, errMsg)

// Get bridges
lastBlcok, err := client.Client().BlockNumber(ctx)
lastBlock, err := client.Client().BlockNumber(ctx)
require.NoError(t, err)
events, err := syncer.GetClaimsAndBridges(ctx, 0, lastBlcok)
events, err := syncer.GetClaimsAndBridges(ctx, 0, lastBlock)
require.NoError(t, err)
actualBridges := []bridgesync.Bridge{}
for _, event := range events {
Expand Down
2 changes: 1 addition & 1 deletion bridgesync/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func TestHashBridge(t *testing.T) {
require.True(t, err)

bridge := Bridge{
OriginNetwork: testVector.OriginalNetwork,
OriginNetwork: testVector.OriginNetwork,
OriginAddress: common.HexToAddress(testVector.TokenAddress),
Amount: amount,
DestinationNetwork: testVector.DestinationNetwork,
Expand Down
2 changes: 1 addition & 1 deletion l1bridge2infoindexsync/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newDownloader(
}
}

func (d *downloader) getLastFinalisedL1Block(ctx context.Context) (uint64, error) {
func (d *downloader) getLastFinalizedL1Block(ctx context.Context) (uint64, error) {
b, err := d.l1Client.BlockByNumber(ctx, big.NewInt(int64(rpc.FinalizedBlockNumber)))
if err != nil {
return 0, err
Expand Down
2 changes: 1 addition & 1 deletion l1bridge2infoindexsync/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (d *driver) sync(ctx context.Context) {
}

func (d *driver) getTargetSynchronizationBlock(ctx context.Context, lpbProcessor uint64) (syncUntilBlock uint64, shouldWait bool, err error) {
lastFinalised, err := d.downloader.getLastFinalisedL1Block(ctx) // TODO: configure finality, but then we need to deal with reorgs?
lastFinalised, err := d.downloader.getLastFinalizedL1Block(ctx) // TODO: configure finality, but then we need to deal with reorgs?
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion l1bridge2infoindexsync/l1bridge2infoindexsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ func (s *L1Bridge2InfoIndexSync) GetLastProcessedBlock(ctx context.Context) (uin
}

func (s *L1Bridge2InfoIndexSync) GetL1InfoTreeIndexByDepositCount(ctx context.Context, depositCount uint32) (uint32, error) {
return s.processor.getL1InfoTreeIndexByBrdigeIndex(ctx, depositCount)
return s.processor.getL1InfoTreeIndexByBridgeIndex(ctx, depositCount)
}
8 changes: 4 additions & 4 deletions l1bridge2infoindexsync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (p *processor) processUntilBlock(ctx context.Context, lastProcessedBlock ui
}

for _, relation := range relations {
if _, err := p.getL1InfoTreeIndexByBrdigeIndexWithTx(tx, relation.bridgeIndex); err != ErrNotFound {
if _, err := p.getL1InfoTreeIndexByBridgeIndexWithTx(tx, relation.bridgeIndex); err != ErrNotFound {
// Note that indexes could be repeated as the L1 Info tree update can be produced by a rollup and not mainnet.
// Hence if the index already exist, do not update as it's better to have the lowest index possible for the relation
continue
Expand Down Expand Up @@ -166,17 +166,17 @@ func (p *processor) processUntilBlock(ctx context.Context, lastProcessedBlock ui
return tx.Commit()
}

func (p *processor) getL1InfoTreeIndexByBrdigeIndex(ctx context.Context, depositCount uint32) (uint32, error) {
func (p *processor) getL1InfoTreeIndexByBridgeIndex(ctx context.Context, depositCount uint32) (uint32, error) {
tx, err := p.db.BeginRo(ctx)
if err != nil {
return 0, err
}
defer tx.Rollback()

return p.getL1InfoTreeIndexByBrdigeIndexWithTx(tx, depositCount)
return p.getL1InfoTreeIndexByBridgeIndexWithTx(tx, depositCount)
}

func (p *processor) getL1InfoTreeIndexByBrdigeIndexWithTx(tx kv.Tx, depositCount uint32) (uint32, error) {
func (p *processor) getL1InfoTreeIndexByBridgeIndexWithTx(tx kv.Tx, depositCount uint32) (uint32, error) {
indexBytes, err := tx.GetOne(relationTable, common.Uint32ToBytes(depositCount))
if err != nil {
return 0, err
Expand Down
2 changes: 1 addition & 1 deletion l1bridge2infoindexsync/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestDuplicatedKey(t *testing.T) {
require.NoError(t, err)
err = p.processUntilBlock(ctx, 7, []bridge2L1InfoRelation{{bridgeIndex: 2, l1InfoTreeIndex: 3}})
require.NoError(t, err)
l1InfoTreeIndex, err := p.getL1InfoTreeIndexByBrdigeIndex(ctx, 2)
l1InfoTreeIndex, err := p.getL1InfoTreeIndexByBridgeIndex(ctx, 2)
require.NoError(t, err)
require.Equal(t, uint32(2), l1InfoTreeIndex)
}
6 changes: 3 additions & 3 deletions l1infotreesync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,18 @@ func newProcessor(ctx context.Context, dbPath string) (*processor, error) {
func (p *processor) GetL1InfoTreeMerkleProof(ctx context.Context, index uint32) ([32]ethCommon.Hash, ethCommon.Hash, error) {
tx, err := p.db.BeginRo(ctx)
if err != nil {
return [32]ethCommon.Hash{}, ethCommon.Hash{}, err
return tree.EmptyProof, ethCommon.Hash{}, err
}
defer tx.Rollback()

root, err := p.l1InfoTree.GetRootByIndex(tx, index)
if err != nil {
return [32]ethCommon.Hash{}, ethCommon.Hash{}, err
return tree.EmptyProof, ethCommon.Hash{}, err
}

proof, err := p.l1InfoTree.GetProof(ctx, index, root)
if err != nil {
return [32]ethCommon.Hash{}, ethCommon.Hash{}, err
return tree.EmptyProof, ethCommon.Hash{}, err
}

// TODO: check if we need to return root or wat
Expand Down
2 changes: 1 addition & 1 deletion lastgersync/lastgersync.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Config struct {
// BlockFinality indicates the status of the blocks that will be queried in order to sync
BlockFinality string `jsonschema:"enum=LatestBlock, enum=SafeBlock, enum=PendingBlock, enum=FinalizedBlock, enum=EarliestBlock" mapstructure:"BlockFinality"`
// InitialBlockNum is the first block that will be queried when starting the synchronization from scratch.
// It should be a number equal oir bellow the creation of the bridge contract
// It should be a number equal or bellow the creation of the bridge contract
InitialBlockNum uint64 `mapstructure:"InitialBlockNum"`
// GlobalExitRootL2Addr is the address of the GER smart contract on L2
GlobalExitRootL2Addr common.Address `mapstructure:"GlobalExitRootL2Addr"`
Expand Down
4 changes: 2 additions & 2 deletions tree/testvectors/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// DepositVectorRaw represents the deposit vector
type DepositVectorRaw struct {
OriginalNetwork uint32 `json:"originNetwork"`
OriginNetwork uint32 `json:"originNetwork"`
TokenAddress string `json:"tokenAddress"`
Amount string `json:"amount"`
DestinationNetwork uint32 `json:"destinationNetwork"`
Expand All @@ -22,7 +22,7 @@ type DepositVectorRaw struct {

func (d *DepositVectorRaw) Hash() common.Hash {
origNet := make([]byte, 4) //nolint:gomnd
binary.BigEndian.PutUint32(origNet, d.OriginalNetwork)
binary.BigEndian.PutUint32(origNet, d.OriginNetwork)
destNet := make([]byte, 4) //nolint:gomnd
binary.BigEndian.PutUint32(destNet, d.DestinationNetwork)

Expand Down

0 comments on commit 766aa4f

Please sign in to comment.