Skip to content

Commit 1a8dca6

Browse files
committed
feat(prt): modify database and models to support PRT data
1 parent fe9c07f commit 1a8dca6

16 files changed

Lines changed: 119 additions & 35 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ deploy-echo-dapp: applications/echo-dapp ## Deploy echo-dapp test application
218218
@echo "Deploying echo-dapp test application"
219219
@./cartesi-rollups-cli deploy application echo-dapp applications/echo-dapp/
220220

221+
deploy-prt-echo-dapp: applications/echo-dapp ## Deploy echo-dapp test application
222+
@echo "Deploying echo-dapp test application"
223+
@./cartesi-rollups-cli deploy application prt-echo-dapp applications/echo-dapp/ --prt
224+
221225
# Temporary test dependencies target while we are not using distribution packages
222226
DOWNLOADS_DIR = test/downloads
223227
CARTESI_TEST_MACHINE_IMAGES = $(DOWNLOADS_DIR)/linux.bin

cmd/cartesi-rollups-cli/root/app/register/register.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var (
5252
inputBoxAddressFromEnv bool
5353
dataAvailability string
5454
enableMachineHashCheck bool
55+
applicationTypePRT bool
5556
disabled bool
5657
printAsJSON bool
5758
executionParametersFileParam string
@@ -75,7 +76,7 @@ func init() {
7576
"Application template hash. (DO NOT USE IN PRODUCTION)\nThis value is retrieved from the application contract",
7677
)
7778

78-
Cmd.Flags().Uint64VarP(&epochLength, "epoch-length", "e", 10, // nolint: mnd
79+
Cmd.Flags().Uint64VarP(&epochLength, "epoch-length", "e", 0, // nolint: mnd
7980
"Consensus Epoch length. (DO NOT USE IN PRODUCTION)\nThis value is retrieved from the consensus contract",
8081
)
8182

@@ -97,6 +98,8 @@ func init() {
9798
"Enable or disable machine hash check (DO NOT DISABLE IN PRODUCTION)")
9899
cobra.CheckErr(viper.BindPFlag(config.FEATURE_MACHINE_HASH_CHECK_ENABLED, Cmd.Flags().Lookup("machine-hash-check")))
99100

101+
Cmd.Flags().BoolVarP(&applicationTypePRT, "prt", "", false, "Register as PRT application.")
102+
100103
origHelpFunc := Cmd.HelpFunc()
101104
Cmd.SetHelpFunc(func(command *cobra.Command, strings []string) {
102105
command.Flags().Lookup("verbose").Hidden = false
@@ -181,7 +184,7 @@ func run(cmd *cobra.Command, args []string) {
181184
}
182185
}
183186

184-
if !cmd.Flags().Changed("epoch-length") {
187+
if !cmd.Flags().Changed("epoch-length") && !applicationTypePRT {
185188
epochLength, err = getEpochLength(ctx, consensus)
186189
if err != nil {
187190
fmt.Fprintf(os.Stderr, "Failed to get epoch length from consensus: %v\n", err)
@@ -226,6 +229,7 @@ func run(cmd *cobra.Command, args []string) {
226229
TemplateHash: parsedTemplateHash,
227230
EpochLength: epochLength,
228231
DataAvailability: encodedDA,
232+
DaveConsensus: applicationTypePRT,
229233
State: applicationState,
230234
IInputBoxBlock: inputBoxBlockNumber,
231235
LastInputCheckBlock: 0,

cmd/cartesi-rollups-cli/root/deploy/application.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ func runDeployApplication(cmd *cobra.Command, args []string) {
256256
application.EpochLength = res.ApplicationResult.Deployment.EpochLength
257257
application.DataAvailability = res.ApplicationResult.Deployment.DataAvailability
258258
application.IInputBoxBlock = res.ApplicationResult.Deployment.IInputBoxBlock
259+
application.DaveConsensus = true
259260
default:
260261
panic("unimplemented deployment type\n")
261262
}

internal/claimer/claimer.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import (
4545
"time"
4646

4747
"github.com/cartesi/rollups-node/internal/model"
48-
"github.com/cartesi/rollups-node/internal/repository"
4948
"github.com/cartesi/rollups-node/pkg/contracts/iconsensus"
5049

5150
"github.com/ethereum/go-ethereum/common"
@@ -58,8 +57,6 @@ var (
5857
)
5958

6059
type iclaimerRepository interface {
61-
ListApplications(ctx context.Context, f repository.ApplicationFilter, p repository.Pagination, descending bool) ([]*model.Application, uint64, error)
62-
6360
// key is model.Application.ID
6461
SelectSubmittedClaimPairsPerApp(ctx context.Context) (
6562
map[int64]*model.Epoch,

internal/claimer/claimer_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"time"
1414

1515
"github.com/cartesi/rollups-node/internal/model"
16-
"github.com/cartesi/rollups-node/internal/repository"
1716
"github.com/cartesi/rollups-node/pkg/contracts/iconsensus"
1817
"github.com/cartesi/rollups-node/pkg/service"
1918
"github.com/lmittmann/tint"
@@ -29,16 +28,6 @@ type claimerRepositoryMock struct {
2928
mock.Mock
3029
}
3130

32-
func (m *claimerRepositoryMock) ListApplications(
33-
ctx context.Context,
34-
f repository.ApplicationFilter,
35-
pagination repository.Pagination,
36-
descending bool,
37-
) ([]*model.Application, uint64, error) {
38-
args := m.Called(ctx, f, pagination, descending)
39-
return args.Get(0).([]*model.Application), args.Get(1).(uint64), args.Error(2)
40-
}
41-
4231
func (m *claimerRepositoryMock) SelectSubmittedClaimPairsPerApp(ctx context.Context) (
4332
map[int64]*model.Epoch,
4433
map[int64]*model.Epoch,

internal/evmreader/input.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,11 @@ func (r *Service) readAndStoreInputs(
275275
}
276276
return errors.New(reason)
277277
}
278+
currentEpoch.InputIndexUpperBound = input.Index + 1
278279
} else {
279280
if currentEpoch.Status == EpochStatus_Open {
280281
currentEpoch.Status = EpochStatus_Closed
282+
currentEpoch.InputIndexUpperBound = input.Index
281283
r.Logger.Info("Closing epoch",
282284
"application", app.application.Name,
283285
"address", address,
@@ -294,10 +296,12 @@ func (r *Service) readAndStoreInputs(
294296
}
295297
if currentEpoch == nil {
296298
currentEpoch = &Epoch{
297-
Index: inputEpochIndex,
298-
FirstBlock: inputEpochIndex * epochLength,
299-
LastBlock: (inputEpochIndex * epochLength) + epochLength - 1,
300-
Status: EpochStatus_Open,
299+
Index: inputEpochIndex,
300+
FirstBlock: inputEpochIndex * epochLength,
301+
LastBlock: (inputEpochIndex * epochLength) + epochLength - 1,
302+
InputIndexLowerBound: input.Index,
303+
InputIndexUpperBound: input.Index + 1,
304+
Status: EpochStatus_Open,
301305
}
302306
epochInputMap[currentEpoch] = []*Input{}
303307
}

internal/jsonrpc/jsonrpc-discover.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@
562562
"data_availability": {
563563
"$ref": "#/components/schemas/ByteArray"
564564
},
565+
"dave_consensus": {
566+
"type": "boolean"
567+
},
565568
"state": {
566569
"$ref": "#/components/schemas/ApplicationState"
567570
},
@@ -639,6 +642,16 @@
639642
"last_block": {
640643
"$ref": "#/components/schemas/UnsignedInteger"
641644
},
645+
"input_index_lower_bound": {
646+
"$ref": "#/components/schemas/UnsignedInteger"
647+
},
648+
"input_index_upper_bound": {
649+
"$ref": "#/components/schemas/UnsignedInteger"
650+
},
651+
"machine_hash": {
652+
"$ref": "#/components/schemas/Hash",
653+
"nullable": true
654+
},
642655
"claim_hash": {
643656
"$ref": "#/components/schemas/Hash",
644657
"nullable": true

internal/model/models.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Application struct {
2525
TemplateURI string `json:"-"`
2626
EpochLength uint64 `json:"epoch_length"`
2727
DataAvailability []byte `json:"data_availability"`
28+
DaveConsensus bool `json:"dave_consensus"`
2829
State ApplicationState `json:"state"`
2930
Reason *string `json:"reason"`
3031
IInputBoxBlock uint64 `json:"iinputbox_block"`
@@ -439,6 +440,9 @@ type Epoch struct {
439440
Index uint64 `sql:"primary_key" json:"index"`
440441
FirstBlock uint64 `json:"first_block"`
441442
LastBlock uint64 `json:"last_block"`
443+
InputIndexLowerBound uint64 `json:"input_index_lower_bound"`
444+
InputIndexUpperBound uint64 `json:"input_index_upper_bound"`
445+
MachineHash *common.Hash `json:"machine_hash"`
442446
ClaimHash *common.Hash `json:"claim_hash"`
443447
ClaimTransactionHash *common.Hash `json:"claim_transaction_hash"`
444448
Status EpochStatus `json:"status"`
@@ -452,17 +456,21 @@ func (e *Epoch) MarshalJSON() ([]byte, error) {
452456
type Alias Epoch
453457
// Define a new structure that embeds the alias but overrides the hex fields.
454458
aux := &struct {
455-
Index string `json:"index"`
456-
FirstBlock string `json:"first_block"`
457-
LastBlock string `json:"last_block"`
458-
VirtualIndex string `json:"virtual_index"`
459+
Index string `json:"index"`
460+
FirstBlock string `json:"first_block"`
461+
LastBlock string `json:"last_block"`
462+
InputIndexLowerBound string `json:"input_index_lower_bound"`
463+
InputIndexUpperBound string `json:"input_index_upper_bound"`
464+
VirtualIndex string `json:"virtual_index"`
459465
*Alias
460466
}{
461-
Index: fmt.Sprintf("0x%x", e.Index),
462-
FirstBlock: fmt.Sprintf("0x%x", e.FirstBlock),
463-
LastBlock: fmt.Sprintf("0x%x", e.LastBlock),
464-
VirtualIndex: fmt.Sprintf("0x%x", e.VirtualIndex),
465-
Alias: (*Alias)(e),
467+
Index: fmt.Sprintf("0x%x", e.Index),
468+
FirstBlock: fmt.Sprintf("0x%x", e.FirstBlock),
469+
LastBlock: fmt.Sprintf("0x%x", e.LastBlock),
470+
InputIndexLowerBound: fmt.Sprintf("0x%x", e.InputIndexLowerBound),
471+
InputIndexUpperBound: fmt.Sprintf("0x%x", e.InputIndexUpperBound),
472+
VirtualIndex: fmt.Sprintf("0x%x", e.VirtualIndex),
473+
Alias: (*Alias)(e),
466474
}
467475
return json.Marshal(aux)
468476
}

internal/repository/postgres/application.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func (r *PostgresRepository) CreateApplication(
3333
table.Application.TemplateURI,
3434
table.Application.EpochLength,
3535
table.Application.DataAvailability,
36+
table.Application.DaveConsensus,
3637
table.Application.State,
3738
table.Application.IinputboxBlock,
3839
table.Application.LastInputCheckBlock,
@@ -48,6 +49,7 @@ func (r *PostgresRepository) CreateApplication(
4849
app.TemplateURI,
4950
app.EpochLength,
5051
app.DataAvailability[:],
52+
app.DaveConsensus,
5153
app.State,
5254
app.IInputBoxBlock,
5355
app.LastInputCheckBlock,
@@ -110,6 +112,7 @@ func (r *PostgresRepository) GetApplication(
110112
table.Application.TemplateURI,
111113
table.Application.EpochLength,
112114
table.Application.DataAvailability,
115+
table.Application.DaveConsensus,
113116
table.Application.State,
114117
table.Application.Reason,
115118
table.Application.IinputboxBlock,
@@ -157,6 +160,7 @@ func (r *PostgresRepository) GetApplication(
157160
&app.TemplateURI,
158161
&app.EpochLength,
159162
&app.DataAvailability,
163+
&app.DaveConsensus,
160164
&app.State,
161165
&app.Reason,
162166
&app.IInputBoxBlock,
@@ -240,6 +244,7 @@ func (r *PostgresRepository) UpdateApplication(
240244
table.Application.TemplateURI,
241245
table.Application.EpochLength,
242246
table.Application.DataAvailability,
247+
table.Application.DaveConsensus,
243248
table.Application.State,
244249
table.Application.Reason,
245250
table.Application.IinputboxBlock,
@@ -256,6 +261,7 @@ func (r *PostgresRepository) UpdateApplication(
256261
app.TemplateURI,
257262
app.EpochLength,
258263
app.DataAvailability[:],
264+
app.DaveConsensus,
259265
app.State,
260266
app.Reason,
261267
app.IInputBoxBlock,
@@ -437,6 +443,7 @@ func (r *PostgresRepository) ListApplications(
437443
table.Application.TemplateURI,
438444
table.Application.EpochLength,
439445
table.Application.DataAvailability,
446+
table.Application.DaveConsensus,
440447
table.Application.State,
441448
table.Application.Reason,
442449
table.Application.IinputboxBlock,
@@ -520,6 +527,7 @@ func (r *PostgresRepository) ListApplications(
520527
&app.TemplateURI,
521528
&app.EpochLength,
522529
&app.DataAvailability,
530+
&app.DaveConsensus,
523531
&app.State,
524532
&app.Reason,
525533
&app.IInputBoxBlock,

internal/repository/postgres/bulk.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,12 @@ func updateEpochClaim(
291291

292292
updStmt := table.Epoch.
293293
UPDATE(
294+
table.Epoch.MachineHash,
294295
table.Epoch.ClaimHash,
295296
table.Epoch.Status,
296297
).
297298
SET(
299+
e.MachineHash,
298300
e.ClaimHash,
299301
postgres.NewEnumValue(model.EpochStatus_ClaimComputed.String()),
300302
).

0 commit comments

Comments
 (0)