Skip to content

Commit

Permalink
feat use sqlite on claimsponsor
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaubennassar committed Oct 30, 2024
1 parent 33a6d4c commit 23856a6
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 293 deletions.
371 changes: 113 additions & 258 deletions claimsponsor/claimsponsor.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions claimsponsor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestE2EL1toEVML2(t *testing.T) {

// Request to sponsor claim
globalIndex := bridgesync.GenerateGlobalIndex(true, 0, uint32(i))
err = claimer.AddClaimToQueue(ctx, &claimsponsor.Claim{
err = claimer.AddClaimToQueue(&claimsponsor.Claim{
LeafType: 0,
ProofLocalExitRoot: localProof,
ProofRollupExitRoot: rollupProof,
Expand All @@ -90,7 +90,7 @@ func TestE2EL1toEVML2(t *testing.T) {
// Wait until success
succeed := false
for i := 0; i < 10; i++ {
claim, err := claimer.GetClaim(ctx, globalIndex)
claim, err := claimer.GetClaim(globalIndex)
require.NoError(t, err)
if claim.Status == claimsponsor.FailedClaimStatus {
require.NoError(t, errors.New("claim failed"))
Expand Down
2 changes: 1 addition & 1 deletion claimsponsor/evmclaimsponsor.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (c *EVMClaimSponsor) claimStatus(ctx context.Context, id string) (ClaimStat
switch res.Status {
case ethtxtypes.MonitoredTxStatusCreated,
ethtxtypes.MonitoredTxStatusSent:
return WIPStatus, nil
return WIPClaimStatus, nil
case ethtxtypes.MonitoredTxStatusFailed:
return FailedClaimStatus, nil
case ethtxtypes.MonitoredTxStatusMined,
Expand Down
20 changes: 20 additions & 0 deletions claimsponsor/migrations/claimsponsor0001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- +migrate Down
DROP TABLE IF EXISTS claim;

-- +migrate Up
CREATE TABLE claim (
leaf_type INT NOT NULL,
proof_local_exit_root VARCHAR NOT NULL,
proof_rollup_exit_root VARCHAR NOT NULL,
global_index VARCHAR NOT NULL,
mainnet_exit_root VARCHAR NOT NULL,
rollup_exit_root VARCHAR NOT NULL,
origin_network INT NOT NULL,
origin_token_address VARCHAR NOT NULL,
destination_network INT NOT NULL,
destination_address VARCHAR NOT NULL,
amount VARCHAR NOT NULL,
metadata VARCHAR NOT NULL,
status VARCHAR NOT NULL,
tx_id VARCHAR NOT NULL
);
23 changes: 23 additions & 0 deletions claimsponsor/migrations/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package migrations

import (
_ "embed"

"github.com/0xPolygon/cdk/db"
"github.com/0xPolygon/cdk/db/types"
treeMigrations "github.com/0xPolygon/cdk/tree/migrations"
)

//go:embed claimsponsor0001.sql
var mig001 string

func RunMigrations(dbPath string) error {
migrations := []types.Migration{
{
ID: "claimsponsor0001",
SQL: mig001,
},
}
migrations = append(migrations, treeMigrations.Migrations...)
return db.RunMigrations(dbPath, migrations)
}
4 changes: 2 additions & 2 deletions rpc/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (b *BridgeEndpoints) SponsorClaim(claim claimsponsor.Claim) (interface{}, r
fmt.Sprintf("this client only sponsors claims for network %d", b.networkID),
)
}
if err := b.sponsor.AddClaimToQueue(ctx, &claim); err != nil {
if err := b.sponsor.AddClaimToQueue(&claim); err != nil {
return zeroHex, rpc.NewRPCError(rpc.DefaultErrorCode, fmt.Sprintf("error adding claim to the queue %s", err))
}
return nil, nil
Expand All @@ -250,7 +250,7 @@ func (b *BridgeEndpoints) GetSponsoredClaimStatus(globalIndex *big.Int) (interfa
if b.sponsor == nil {
return zeroHex, rpc.NewRPCError(rpc.DefaultErrorCode, "this client does not support claim sponsoring")
}
claim, err := b.sponsor.GetClaim(ctx, globalIndex)
claim, err := b.sponsor.GetClaim(globalIndex)
if err != nil {
return zeroHex, rpc.NewRPCError(rpc.DefaultErrorCode, fmt.Sprintf("failed to get claim status, error: %s", err))
}
Expand Down
4 changes: 2 additions & 2 deletions rpc/bridge_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ type L1InfoTreer interface {
}

type ClaimSponsorer interface {
AddClaimToQueue(ctx context.Context, claim *claimsponsor.Claim) error
GetClaim(ctx context.Context, globalIndex *big.Int) (*claimsponsor.Claim, error)
AddClaimToQueue(claim *claimsponsor.Claim) error
GetClaim(globalIndex *big.Int) (*claimsponsor.Claim, error)
}
52 changes: 24 additions & 28 deletions rpc/mocks/claim_sponsorer.go

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

0 comments on commit 23856a6

Please sign in to comment.