Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/claim sponsor #35

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bridgesync/bridgesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewL1(
rd sync.ReorgDetector,
ethClient EthClienter,
initialBlock uint64,
waitForNewBlocksPeriod time.Duration,
) (*BridgeSync, error) {
return new(
ctx,
Expand All @@ -49,6 +50,7 @@ func NewL1(
initialBlock,
dbPrefixL1,
reorgDetectorIDL1,
waitForNewBlocksPeriod,
)
}

Expand All @@ -62,6 +64,7 @@ func NewL2(
rd sync.ReorgDetector,
ethClient EthClienter,
initialBlock uint64,
waitForNewBlocksPeriod time.Duration,
) (*BridgeSync, error) {
return new(
ctx,
Expand All @@ -74,6 +77,7 @@ func NewL2(
initialBlock,
dbPrefixL1,
reorgDetectorIDL1,
waitForNewBlocksPeriod,
)
}

Expand All @@ -87,6 +91,7 @@ func new(
ethClient EthClienter,
initialBlock uint64,
dbPrefix, reorgDetectorID string,
waitForNewBlocksPeriod time.Duration,
) (*BridgeSync, error) {
processor, err := newProcessor(ctx, dbPath, dbPrefix)
if err != nil {
Expand Down Expand Up @@ -152,3 +157,7 @@ func (s *BridgeSync) GetBridgeIndexByRoot(ctx context.Context, root common.Hash)
func (s *BridgeSync) GetClaimsAndBridges(ctx context.Context, fromBlock, toBlock uint64) ([]Event, error) {
return s.processor.GetClaimsAndBridges(ctx, fromBlock, toBlock)
}

func (s *BridgeSync) GetProof(ctx context.Context, depositCount uint32, localExitRoot common.Hash) ([32]common.Hash, error) {
return s.processor.exitTree.GetProof(ctx, depositCount, localExitRoot)
}
5 changes: 0 additions & 5 deletions bridgesync/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bridgesync
import (
"fmt"
"math/big"
"time"

"github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygonzkevmbridge"
"github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygonzkevmbridgev2"
Expand All @@ -15,10 +14,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
)

const (
waitForNewBlocksPeriod = time.Millisecond * 100
)

var (
bridgeEventSignature = crypto.Keccak256Hash([]byte("BridgeEvent(uint8,uint32,address,uint32,address,uint256,bytes,uint32)"))
claimEventSignature = crypto.Keccak256Hash([]byte("ClaimEvent(uint256,uint32,address,address,uint256)"))
Expand Down
2 changes: 1 addition & 1 deletion bridgesync/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestBridgeEventE2E(t *testing.T) {
rd, err := reorgdetector.New(ctx, client.Client(), dbPathReorg)
go rd.Start(ctx)

syncer, err := bridgesync.NewL1(ctx, dbPathSyncer, bridgeAddr, 10, etherman.LatestBlock, rd, client.Client(), 0)
syncer, err := bridgesync.NewL1(ctx, dbPathSyncer, bridgeAddr, 10, etherman.LatestBlock, rd, client.Client(), 0, time.Millisecond*10)
require.NoError(t, err)
go syncer.Start(ctx)

Expand Down
18 changes: 18 additions & 0 deletions bridgesync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,21 @@ func (p *processor) updateLastProcessedBlock(tx kv.RwTx, blockNum uint64) error
blockNumBytes := dbCommon.Uint64ToBytes(blockNum)
return tx.Put(p.lastBlockTable, lastBlokcKey, blockNumBytes)
}

func GenerateGlobalIndex(mainnetFlag bool, rollupIndex uint, localExitRootIndex uint32) *big.Int {
var (
globalIndexBytes []byte
buf [4]byte
)
if mainnetFlag {
globalIndexBytes = append(globalIndexBytes, big.NewInt(1).Bytes()...)
ri := big.NewInt(0).FillBytes(buf[:])
globalIndexBytes = append(globalIndexBytes, ri...)
} else {
ri := big.NewInt(0).SetUint64(uint64(rollupIndex)).FillBytes(buf[:])
globalIndexBytes = append(globalIndexBytes, ri...)
}
leri := big.NewInt(0).SetUint64(uint64(localExitRootIndex)).FillBytes(buf[:])
globalIndexBytes = append(globalIndexBytes, leri...)
return big.NewInt(0).SetBytes(globalIndexBytes)
}
Loading
Loading