Skip to content

Commit

Permalink
add migrations for eal tables (#10976)
Browse files Browse the repository at this point in the history
* add migrations for eal tables

* fix formatting

* bump migration number

* define job spec model

* remove ccip chain selector from EAL job model
  • Loading branch information
jinhoonbang authored Oct 20, 2023
1 parent 4288e07 commit bf469b7
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
32 changes: 32 additions & 0 deletions core/services/job/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ type Job struct {
BootstrapSpecID *int32
GatewaySpec *GatewaySpec
GatewaySpecID *int32
EALSpec *EALSpec
EALSpecID *int32
PipelineSpecID int32
PipelineSpec *pipeline.Spec
JobSpecErrors []SpecError
Expand Down Expand Up @@ -772,3 +774,33 @@ func (s *GatewaySpec) SetID(value string) error {
s.ID = int32(ID)
return nil
}

// EALSpec defines the job spec for the gas station.
type EALSpec struct {
ID int32

// ForwarderAddress is the address of EIP2771 forwarder that verifies signature
// and forwards requests to target contracts
ForwarderAddress ethkey.EIP55Address `toml:"forwarderAddress"`

// EVMChainID defines the chain ID from which the meta-transaction request originates.
EVMChainID *utils.Big `toml:"evmChainID"`

// FromAddress is the sender address that should be used to send meta-transactions
FromAddresses []ethkey.EIP55Address `toml:"fromAddresses"`

// LookbackBlocks defines the maximum age of blocks to lookback in status tracker
LookbackBlocks int32 `toml:"lookbackBlocks"`

// PollPeriod defines how frequently EAL status tracker runs
PollPeriod time.Duration `toml:"pollPeriod"`

// RunTimeout defines the timeout for a single run of EAL status tracker
RunTimeout time.Duration `toml:"runTimeout"`

// CreatedAt is the time this job was created.
CreatedAt time.Time `toml:"-"`

// UpdatedAt is the time this job was last updated.
UpdatedAt time.Time `toml:"-"`
}
97 changes: 97 additions & 0 deletions core/store/migrate/migrations/0204_create_eal_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
-- +goose Up
CREATE TABLE eal_specs (
id BIGSERIAL PRIMARY KEY,
forwarder_address BYTEA NOT NULL,
evm_chain_id NUMERIC(78) NOT NULL,
from_addresses BYTEA[] DEFAULT '{}' NOT NULL,
lookback_blocks BIGINT NOT NULL,
poll_period BIGINT NOT NULL,
run_timeout BIGINT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
CONSTRAINT forwarder_address_len_chk CHECK (
octet_length(forwarder_address) = 20
)
);

ALTER TABLE
jobs
ADD
COLUMN eal_spec_id INT REFERENCES eal_specs (id),
DROP
CONSTRAINT chk_only_one_spec,
ADD
CONSTRAINT chk_only_one_spec CHECK (
num_nonnulls(
ocr_oracle_spec_id, ocr2_oracle_spec_id,
direct_request_spec_id, flux_monitor_spec_id,
keeper_spec_id, cron_spec_id, webhook_spec_id,
vrf_spec_id, blockhash_store_spec_id,
block_header_feeder_spec_id, bootstrap_spec_id,
gateway_spec_id,
legacy_gas_station_server_spec_id,
legacy_gas_station_sidecar_spec_id,
eal_spec_id
) = 1
);

CREATE TABLE eal_txs (
request_id TEXT PRIMARY KEY,
forwarder_address BYTEA NOT NULL,
from_address BYTEA NOT NULL,
target_address BYTEA NOT NULL,
evm_chain_id NUMERIC(78) NOT NULL,
payload BYTEA NOT NULL,
tx_status TEXT NOT NULL,
gas_limit BIGINT NOT NULL,
ccip_message_id BYTEA,
failure_reason TEXT,
status_update_url TEXT,
tx_hash BYTEA,
tx_id BIGINT REFERENCES txes INITIALLY DEFERRED,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
CONSTRAINT forwarder_address_len_chk CHECK (
octet_length(forwarder_address) = 20
),
CONSTRAINT target_address_len_chk CHECK (
octet_length(target_address) = 20
),
CONSTRAINT from_address_len_chk CHECK (
octet_length(from_address) = 20
),
CONSTRAINT ccip_message_id_len_chk CHECK (
octet_length(ccip_message_id) = 32
),
CONSTRAINT tx_hash_len_chk CHECK (
octet_length(tx_hash) = 32
)
);
CREATE INDEX idx_eal_txs_chain_id_tx_status ON eal_txs(evm_chain_id, tx_status);

-- +goose Down
ALTER TABLE
jobs
DROP
CONSTRAINT chk_only_one_spec,
ADD
CONSTRAINT chk_only_one_spec CHECK (
num_nonnulls(
ocr_oracle_spec_id, ocr2_oracle_spec_id,
direct_request_spec_id, flux_monitor_spec_id,
keeper_spec_id, cron_spec_id, webhook_spec_id,
vrf_spec_id, blockhash_store_spec_id,
block_header_feeder_spec_id, bootstrap_spec_id,
gateway_spec_id,
legacy_gas_station_server_spec_id,
legacy_gas_station_sidecar_spec_id
) = 1
);
ALTER TABLE
jobs
DROP
COLUMN eal_spec_id;
DROP
TABLE IF EXISTS eal_specs;
DROP
TABLE IF EXISTS eal_txs;

0 comments on commit bf469b7

Please sign in to comment.