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

feat: use sqlite on claimsponsor #157

Merged
merged 8 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
375 changes: 117 additions & 258 deletions claimsponsor/claimsponsor.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions claimsponsor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestE2EL1toEVML2(t *testing.T) {
go bridgeSyncL1.Start(ctx)

// start claim sponsor
dbPathClaimSponsor := t.TempDir()
dbPathClaimSponsor := path.Join(t.TempDir(), "file::memory:?cache=shared")
claimer, err := claimsponsor.NewEVMClaimSponsor(
log.GetDefaultLogger(),
dbPathClaimSponsor,
Expand Down 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,
status VARCHAR NOT NULL,
tx_id VARCHAR NOT NULL
);
21 changes: 21 additions & 0 deletions claimsponsor/migrations/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package migrations

import (
_ "embed"

"github.com/0xPolygon/cdk/db"
"github.com/0xPolygon/cdk/db/types"
)

//go:embed claimsponsor0001.sql
var mig001 string

func RunMigrations(dbPath string) error {
migrations := []types.Migration{
{
ID: "claimsponsor0001",
SQL: mig001,
},
}
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.

Loading