Skip to content

Commit

Permalink
feat(db): Remove Claim
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoura committed Aug 5, 2024
1 parent 5af0f0e commit 60afdbf
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 157 deletions.
16 changes: 0 additions & 16 deletions internal/node/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type (
Address = common.Address
Bytes = hexutil.Bytes
InputCompletionStatus string
ClaimStatus string
ApplicationStatus string
DefaultBlock string
EpochStatus string
Expand All @@ -30,12 +29,6 @@ const (
InputStatusPayloadLengthLimitExceeded InputCompletionStatus = "PAYLOAD_LENGTH_LIMIT_EXCEEDED"
)

const (
ClaimStatusPending ClaimStatus = "PENDING"
ClaimStatusSubmitted ClaimStatus = "SUBMITTED"
ClaimStatusFinalized ClaimStatus = "FINALIZED"
)

const (
ApplicationStatusRunning ApplicationStatus = "RUNNING"
ApplicationStatusNotRunning ApplicationStatus = "NOT RUNNING"
Expand Down Expand Up @@ -114,15 +107,6 @@ type Report struct {
InputId uint64
}

type Claim struct {
Id uint64
Index uint64
Status ClaimStatus
OutputMerkleRootHash Hash
TransactionHash *Hash
AppAddress Address
}

type Snapshot struct {
Id uint64
InputId uint64
Expand Down
95 changes: 0 additions & 95 deletions internal/repository/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,40 +267,6 @@ func (pg *Database) InsertReport(
return nil
}

func (pg *Database) InsertClaim(
ctx context.Context,
claim *Claim,
) error {
query := `
INSERT INTO claim
(index,
output_merkle_root_hash,
transaction_hash,
status,
application_address)
VALUES
(@index,
@outputMerkleRootHash,
@transactionHash,
@status,
@applicationAddress)`

args := pgx.NamedArgs{
"index": claim.Index,
"outputMerkleRootHash": claim.OutputMerkleRootHash,
"transactionHash": claim.TransactionHash,
"status": claim.Status,
"applicationAddress": claim.AppAddress,
}

_, err := pg.db.Exec(ctx, query, args)
if err != nil {
return fmt.Errorf("%w: %w", ErrInsertRow, err)
}

return nil
}

func (pg *Database) InsertSnapshot(
ctx context.Context,
snapshot *Snapshot,
Expand Down Expand Up @@ -689,67 +655,6 @@ func (pg *Database) GetReport(
return &report, nil
}

func (pg *Database) GetClaim(
ctx context.Context,
appAddressKey Address,
indexKey uint64,
) (*Claim, error) {
var (
id uint64
index uint64
outputMerkleRootHash Hash
transactionHash *Hash
status ClaimStatus
address Address
)

query := `
SELECT
id,
index,
output_merkle_root_hash,
transaction_hash,
status,
application_address
FROM
claim
WHERE
application_address=@appAddress and index=@index`

args := pgx.NamedArgs{
"appAddress": appAddressKey,
"index": indexKey,
}

err := pg.db.QueryRow(ctx, query, args).Scan(
&id,
&index,
&outputMerkleRootHash,
&transactionHash,
&status,
&address,
)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
slog.Info("GetClaim returned no rows", "service", "repository")
return nil, nil
}
return nil, fmt.Errorf("GetClaim QueryRow failed: %w\n", err)
}

claim := Claim{
Id: id,
Index: index,
OutputMerkleRootHash: outputMerkleRootHash,
TransactionHash: transactionHash,
Status: status,
AppAddress: address,
}

return &claim, nil
}


func (pg *Database) GetSnapshot(
ctx context.Context,
inputIndexKey uint64,
Expand Down
11 changes: 0 additions & 11 deletions internal/repository/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,6 @@ func (s *RepositorySuite) SetupDatabase() {
err = s.database.InsertReport(s.ctx, &report)
s.Require().Nil(err)

claim := Claim{
Status: ClaimStatusPending,
Index: 1,
OutputMerkleRootHash: genericHash,
TransactionHash: &genericHash,
AppAddress: common.HexToAddress("deadbeef"),
}

err = s.database.InsertClaim(s.ctx, &claim)
s.Require().Nil(err)

snapshot := Snapshot{
InputId: 1,
AppAddress: app.ContractAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ DROP TABLE IF EXISTS "node_config";
DROP TABLE IF EXISTS "snapshot";
DROP TABLE IF EXISTS "report";
DROP TABLE IF EXISTS "output";
DROP TABLE IF EXISTS "claim";
DROP TABLE IF EXISTS "input";
DROP TABLE IF EXISTS "epoch";
DROP TABLE IF EXISTS "application";


DROP TYPE IF EXISTS "InputCompletionStatus";
DROP TYPE IF EXISTS "ClaimStatus";
DROP TYPE IF EXISTS "ApplicationStatus";
DROP TYPE IF EXISTS "DefaultBlock";
DROP TYPE IF EXISTS "EpochStatus";
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ CREATE TYPE "ApplicationStatus" AS ENUM ('RUNNING', 'NOT RUNNING');

CREATE TYPE "InputCompletionStatus" AS ENUM ('NONE', 'ACCEPTED', 'REJECTED', 'EXCEPTION', 'MACHINE_HALTED', 'CYCLE_LIMIT_EXCEEDED', 'TIME_LIMIT_EXCEEDED', 'PAYLOAD_LENGTH_LIMIT_EXCEEDED');

CREATE TYPE "ClaimStatus" AS ENUM ('PENDING', 'SUBMITTED', 'FINALIZED');

CREATE TYPE "DefaultBlock" AS ENUM ('FINALIZED', 'LATEST', 'PENDING', 'SAFE');

CREATE TYPE "EpochStatus" AS ENUM ('RECEIVING_INPUTS', 'RECEIVED_LAST_INPUT', 'PROCESSED_ALL_INPUTS', 'CALCULATED_CLAIM', 'SUBMITTED_CLAIM', 'ACCEPTED_CLAIM', 'REJECTED_CLAIM');
Expand Down Expand Up @@ -62,19 +60,6 @@ CREATE TABLE "input"

CREATE INDEX "input_idx" ON "input"("block_number");

CREATE TABLE "claim"
(
"id" BIGSERIAL,
"index" NUMERIC(20,0) NOT NULL CHECK ("index" >= 0 AND "index" <= f_maxuint64()),
"output_merkle_root_hash" BYTEA NOT NULL,
"transaction_hash" BYTEA,
"status" "ClaimStatus" NOT NULL,
"application_address" BYTEA NOT NULL,
CONSTRAINT "claim_pkey" PRIMARY KEY ("id"),
CONSTRAINT "claim_application_address_fkey" FOREIGN KEY ("application_address") REFERENCES "application"("contract_address"),
UNIQUE("index", "application_address")
);

CREATE TABLE "output"
(
"id" BIGSERIAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,6 @@ CREATE OR REPLACE VIEW graphql."reports" AS
INNER JOIN
"input" i on r."input_id"=i."id";

CREATE OR REPLACE VIEW graphql."claims" AS
SELECT
c."index",
c."output_merkle_root_hash",
c."status",
c."application_address",
o."index" as "output_index"
FROM
"claim" c
INNER JOIN
"application" a ON c."application_address"=a."contract_address"
INNER JOIN
"input" i ON a."contract_address"=i."application_address"
INNER JOIN
"output" o ON i."id"=o."input_id";

COMMENT ON VIEW graphql."inputs" is
E'@foreignKey (application_address) references applications(contract_address)|@fieldName applicationByApplicationAddress\n@foreignKey (epoch_index) references epochs(index)|@fieldName epochByEpochIndex';
Expand All @@ -87,8 +72,5 @@ COMMENT ON VIEW graphql."outputs" is
COMMENT ON VIEW graphql."reports" is
E'@foreignKey (input_index) references inputs(index)|@fieldName inputByInputIndex';

COMMENT ON VIEW graphql."claims" is
E'@foreignKey (output_index) references outputs(index)|@fieldName outputByOutputIndex\n@foreignKey (application_address) references applications(contract_address)|@fieldName applicationByApplicationAddress';

COMMENT ON VIEW graphql."epochs" is
E'@foreignKey (application_address) references applications(contract_address)|@fieldName applicationByApplicationAddress';

0 comments on commit 60afdbf

Please sign in to comment.