Skip to content

Commit

Permalink
feat(db): Move epochLength from Application to NodeConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoura committed Aug 5, 2024
1 parent d1cb6c2 commit bc74f44
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 36 deletions.
11 changes: 0 additions & 11 deletions cmd/cartesi-rollups-cli/root/app/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var (
templateHash string
inputBoxDeploymentBlockNumber uint64
snapshotUri string
epochLength uint64
status string
)

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
}

Expand Down
1 change: 0 additions & 1 deletion docs/cli/cartesi-rollups-cli_app_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/node/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ type NodePersistentConfig struct {
InputBoxAddress Address
ChainId uint64
IConsensusAddress Address
EpochLength uint64
}

type Application struct {
Id uint64
ContractAddress Address
TemplateHash Hash
LastProcessedBlock uint64
EpochLength uint64
Status ApplicationStatus
}

Expand Down
14 changes: 5 additions & 9 deletions internal/repository/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand All @@ -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,
}

Expand Down Expand Up @@ -347,7 +347,6 @@ func (pg *Database) GetApplication(
contractAddress Address
templateHash Hash
lastProcessedBlock uint64
epochLength uint64
status ApplicationStatus
)

Expand All @@ -357,7 +356,6 @@ func (pg *Database) GetApplication(
contract_address,
template_hash,
last_processed_block,
epoch_length,
status
FROM
application
Expand All @@ -373,7 +371,6 @@ func (pg *Database) GetApplication(
&contractAddress,
&templateHash,
&lastProcessedBlock,
&epochLength,
&status,
)
if err != nil {
Expand All @@ -389,7 +386,6 @@ func (pg *Database) GetApplication(
ContractAddress: contractAddress,
TemplateHash: templateHash,
LastProcessedBlock: lastProcessedBlock,
EpochLength: epochLength,
Status: status,
}

Expand Down
5 changes: 1 addition & 4 deletions internal/repository/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -72,15 +73,13 @@ func (s *RepositorySuite) SetupDatabase() {
ContractAddress: common.HexToAddress("deadbeef"),
TemplateHash: common.HexToHash("deadbeef"),
LastProcessedBlock: 1,
EpochLength: 10,
Status: ApplicationStatusRunning,
}

app2 := Application{
ContractAddress: common.HexToAddress("feadbeef"),
TemplateHash: common.HexToHash("deadbeef"),
LastProcessedBlock: 1,
EpochLength: 10,
Status: ApplicationStatusNotRunning,
}

Expand Down Expand Up @@ -233,7 +232,6 @@ func (s *RepositorySuite) TestApplicationExists() {
ContractAddress: common.HexToAddress("deadbeef"),
TemplateHash: common.HexToHash("deadbeef"),
LastProcessedBlock: 1,
EpochLength: 10,
Status: ApplicationStatusRunning,
}

Expand All @@ -254,7 +252,6 @@ func (s *RepositorySuite) TestApplicationFailsDuplicateRow() {
ContractAddress: common.HexToAddress("deadbeef"),
TemplateHash: common.HexToHash("deadbeef"),
LastProcessedBlock: 1,
EpochLength: 10,
Status: ApplicationStatusRunning,
}

Expand Down
8 changes: 2 additions & 6 deletions internal/repository/evmreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func (pg *Database) getAllApplicationsByStatus(
contractAddress Address
templateHash Hash
lastProcessedBlock uint64
epochLength uint64
status ApplicationStatus
results []Application
)
Expand All @@ -113,7 +112,6 @@ func (pg *Database) getAllApplicationsByStatus(
contract_address,
template_hash,
last_processed_block,
epoch_length,
status
FROM
application
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion internal/repository/evmreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func (s *RepositorySuite) TestGetAllRunningApplications() {
ContractAddress: common.HexToAddress("deadbeef"),
TemplateHash: common.HexToHash("deadbeef"),
LastProcessedBlock: 1,
EpochLength: 10,
Status: ApplicationStatusRunning,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
Expand Down Expand Up @@ -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
);


Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ CREATE OR REPLACE VIEW graphql."applications" AS
"contract_address",
"template_hash",
"last_processed_block",
"epoch_length",
"status"
FROM
"application";
Expand Down

0 comments on commit bc74f44

Please sign in to comment.