From bc74f448aa64a2aa2880f5f83c414c786cdde5dd Mon Sep 17 00:00:00 2001 From: Francisco Moura Date: Fri, 2 Aug 2024 01:54:34 -0300 Subject: [PATCH] feat(db): Move epochLength from Application to NodeConfig --- cmd/cartesi-rollups-cli/root/app/add/add.go | 11 ----------- docs/cli/cartesi-rollups-cli_app_add.md | 1 - internal/node/model/models.go | 2 +- internal/repository/base.go | 14 +++++--------- internal/repository/base_test.go | 5 +---- internal/repository/evmreader.go | 8 ++------ internal/repository/evmreader_test.go | 1 - ...ion_input_claim_output_report_nodeconfig.up.sql | 6 ++++-- .../000002_create_postgraphile_view.up.sql | 1 - 9 files changed, 13 insertions(+), 36 deletions(-) diff --git a/cmd/cartesi-rollups-cli/root/app/add/add.go b/cmd/cartesi-rollups-cli/root/app/add/add.go index 3deff428b..53f2303d0 100644 --- a/cmd/cartesi-rollups-cli/root/app/add/add.go +++ b/cmd/cartesi-rollups-cli/root/app/add/add.go @@ -34,7 +34,6 @@ var ( templateHash string inputBoxDeploymentBlockNumber uint64 snapshotUri string - epochLength uint64 status string ) @@ -72,14 +71,6 @@ func init() { "Application snapshot URI", ) - Cmd.Flags().Uint64VarP( - &epochLength, - "epoch-length", - "e", - 1, - "Application epoch length in blocks", - ) - Cmd.Flags().StringVarP( &status, "status", @@ -113,8 +104,6 @@ func run(cmd *cobra.Command, args []string) { ContractAddress: common.HexToAddress(applicationAddress), TemplateHash: common.HexToHash(templateHash), LastProcessedBlock: inputBoxDeploymentBlockNumber, - SnapshotURI: snapshotUri, - EpochLength: epochLength, Status: applicationStatus, } diff --git a/docs/cli/cartesi-rollups-cli_app_add.md b/docs/cli/cartesi-rollups-cli_app_add.md index 669666d3e..8c4552420 100644 --- a/docs/cli/cartesi-rollups-cli_app_add.md +++ b/docs/cli/cartesi-rollups-cli_app_add.md @@ -17,7 +17,6 @@ cartesi-rollups-cli app add -a 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -n 10 ``` -a, --address string Application contract address - -e, --epoch-length uint Application epoch length in blocks (default 1) -h, --help help for add -n, --inputbox-block-number uint InputBox deployment block number -u, --snapshot-uri string Application snapshot URI diff --git a/internal/node/model/models.go b/internal/node/model/models.go index f22da0a70..c90fb772e 100644 --- a/internal/node/model/models.go +++ b/internal/node/model/models.go @@ -57,6 +57,7 @@ type NodePersistentConfig struct { InputBoxAddress Address ChainId uint64 IConsensusAddress Address + EpochLength uint64 } type Application struct { @@ -64,7 +65,6 @@ type Application struct { ContractAddress Address TemplateHash Hash LastProcessedBlock uint64 - EpochLength uint64 Status ApplicationStatus } diff --git a/internal/repository/base.go b/internal/repository/base.go index 6d1834533..538bc45ee 100644 --- a/internal/repository/base.go +++ b/internal/repository/base.go @@ -59,13 +59,15 @@ func (pg *Database) InsertNodeConfig( input_box_deployment_block, input_box_address, chain_id, - iconsensus_address) + iconsensus_address, + epoch_length) SELECT @defaultBlock, @deploymentBlock, @inputBoxAddress, @chainId, - @iConsensusAddress + @iConsensusAddress, + @epochLength WHERE NOT EXISTS (SELECT * FROM node_config)` args := pgx.NamedArgs{ @@ -74,6 +76,7 @@ func (pg *Database) InsertNodeConfig( "inputBoxAddress": config.InputBoxAddress, "chainId": config.ChainId, "iConsensusAddress": config.IConsensusAddress, + "epochLength": config.EpochLength, } _, err := pg.db.Exec(ctx, query, args) @@ -93,20 +96,17 @@ func (pg *Database) InsertApplication( (contract_address, template_hash, last_processed_block, - epoch_length, status) VALUES (@contractAddress, @templateHash, @lastProcessedBlock, - @epochLength, @status)` args := pgx.NamedArgs{ "contractAddress": app.ContractAddress, "templateHash": app.TemplateHash, "lastProcessedBlock": app.LastProcessedBlock, - "epochLength": app.EpochLength, "status": app.Status, } @@ -347,7 +347,6 @@ func (pg *Database) GetApplication( contractAddress Address templateHash Hash lastProcessedBlock uint64 - epochLength uint64 status ApplicationStatus ) @@ -357,7 +356,6 @@ func (pg *Database) GetApplication( contract_address, template_hash, last_processed_block, - epoch_length, status FROM application @@ -373,7 +371,6 @@ func (pg *Database) GetApplication( &contractAddress, &templateHash, &lastProcessedBlock, - &epochLength, &status, ) if err != nil { @@ -389,7 +386,6 @@ func (pg *Database) GetApplication( ContractAddress: contractAddress, TemplateHash: templateHash, LastProcessedBlock: lastProcessedBlock, - EpochLength: epochLength, Status: status, } diff --git a/internal/repository/base_test.go b/internal/repository/base_test.go index ea7245b34..258dcfb69 100644 --- a/internal/repository/base_test.go +++ b/internal/repository/base_test.go @@ -63,6 +63,7 @@ func (s *RepositorySuite) SetupDatabase() { InputBoxAddress: common.HexToAddress("deadbeef"), ChainId: 1, IConsensusAddress: common.HexToAddress("deadbeef"), + EpochLength: 10, } err := s.database.InsertNodeConfig(s.ctx, &config) @@ -72,7 +73,6 @@ func (s *RepositorySuite) SetupDatabase() { ContractAddress: common.HexToAddress("deadbeef"), TemplateHash: common.HexToHash("deadbeef"), LastProcessedBlock: 1, - EpochLength: 10, Status: ApplicationStatusRunning, } @@ -80,7 +80,6 @@ func (s *RepositorySuite) SetupDatabase() { ContractAddress: common.HexToAddress("feadbeef"), TemplateHash: common.HexToHash("deadbeef"), LastProcessedBlock: 1, - EpochLength: 10, Status: ApplicationStatusNotRunning, } @@ -233,7 +232,6 @@ func (s *RepositorySuite) TestApplicationExists() { ContractAddress: common.HexToAddress("deadbeef"), TemplateHash: common.HexToHash("deadbeef"), LastProcessedBlock: 1, - EpochLength: 10, Status: ApplicationStatusRunning, } @@ -254,7 +252,6 @@ func (s *RepositorySuite) TestApplicationFailsDuplicateRow() { ContractAddress: common.HexToAddress("deadbeef"), TemplateHash: common.HexToHash("deadbeef"), LastProcessedBlock: 1, - EpochLength: 10, Status: ApplicationStatusRunning, } diff --git a/internal/repository/evmreader.go b/internal/repository/evmreader.go index 2e13a3466..b98f088ad 100644 --- a/internal/repository/evmreader.go +++ b/internal/repository/evmreader.go @@ -102,7 +102,6 @@ func (pg *Database) getAllApplicationsByStatus( contractAddress Address templateHash Hash lastProcessedBlock uint64 - epochLength uint64 status ApplicationStatus results []Application ) @@ -113,7 +112,6 @@ func (pg *Database) getAllApplicationsByStatus( contract_address, template_hash, last_processed_block, - epoch_length, status FROM application @@ -131,16 +129,14 @@ func (pg *Database) getAllApplicationsByStatus( } _, err = pgx.ForEachRow(rows, - []any{&id, &contractAddress, &templateHash, &snapshotUri, - &lastProcessedBlock, &epochLength, &status}, + []any{&id, &contractAddress, &templateHash, + &lastProcessedBlock, &status}, func() error { app := Application{ Id: id, ContractAddress: contractAddress, TemplateHash: templateHash, - SnapshotURI: snapshotUri, LastProcessedBlock: lastProcessedBlock, - EpochLength: epochLength, Status: status, } results = append(results, app) diff --git a/internal/repository/evmreader_test.go b/internal/repository/evmreader_test.go index ad9e86f74..124bd5149 100644 --- a/internal/repository/evmreader_test.go +++ b/internal/repository/evmreader_test.go @@ -131,7 +131,6 @@ func (s *RepositorySuite) TestGetAllRunningApplications() { ContractAddress: common.HexToAddress("deadbeef"), TemplateHash: common.HexToHash("deadbeef"), LastProcessedBlock: 1, - EpochLength: 10, Status: ApplicationStatusRunning, } diff --git a/internal/repository/migrations/000001_create_application_input_claim_output_report_nodeconfig.up.sql b/internal/repository/migrations/000001_create_application_input_claim_output_report_nodeconfig.up.sql index 8be810120..7d259326a 100644 --- a/internal/repository/migrations/000001_create_application_input_claim_output_report_nodeconfig.up.sql +++ b/internal/repository/migrations/000001_create_application_input_claim_output_report_nodeconfig.up.sql @@ -21,7 +21,6 @@ CREATE TABLE "application" "template_hash" BYTEA NOT NULL, "last_processed_block" NUMERIC(20,0) NOT NULL CHECK ("last_processed_block" >= 0 AND "last_processed_block" <= f_maxuint64()), "status" "ApplicationStatus" NOT NULL, - "epoch_length" INT NOT NULL, CONSTRAINT "application_pkey" PRIMARY KEY ("id"), UNIQUE("contract_address") ); @@ -103,5 +102,8 @@ CREATE TABLE "node_config" "input_box_deployment_block" INT NOT NULL, "input_box_address" BYTEA NOT NULL, "chain_id" INT NOT NULL, - "iconsensus_address" BYTEA NOT NULL + "iconsensus_address" BYTEA NOT NULL, + "epoch_length" INT NOT NULL ); + + diff --git a/internal/repository/migrations/000002_create_postgraphile_view.up.sql b/internal/repository/migrations/000002_create_postgraphile_view.up.sql index 0e5b3171e..245fdd34c 100644 --- a/internal/repository/migrations/000002_create_postgraphile_view.up.sql +++ b/internal/repository/migrations/000002_create_postgraphile_view.up.sql @@ -9,7 +9,6 @@ CREATE OR REPLACE VIEW graphql."applications" AS "contract_address", "template_hash", "last_processed_block", - "epoch_length", "status" FROM "application";