Skip to content

Commit

Permalink
refactor: refactor advancer WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vfusco committed Oct 10, 2024
1 parent 6ceb3e4 commit 033f248
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 42 deletions.
4 changes: 2 additions & 2 deletions cmd/cartesi-rollups-advancer/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"os/signal"
"syscall"

"github.com/cartesi/rollups-node/internal/node/advancer"
"github.com/cartesi/rollups-node/internal/node/advancer/machines"
"github.com/cartesi/rollups-node/internal/advancer"
"github.com/cartesi/rollups-node/internal/advancer/machines"
"github.com/cartesi/rollups-node/internal/node/config"
"github.com/cartesi/rollups-node/internal/node/startup"
"github.com/cartesi/rollups-node/internal/repository"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"log/slog"
"time"

"github.com/cartesi/rollups-node/internal/node/advancer/machines"
"github.com/cartesi/rollups-node/internal/node/advancer/poller"
"github.com/cartesi/rollups-node/internal/advancer/machines"
"github.com/cartesi/rollups-node/internal/advancer/poller"
. "github.com/cartesi/rollups-node/internal/node/model"
"github.com/cartesi/rollups-node/internal/nodemachine"
)
Expand Down Expand Up @@ -48,7 +48,7 @@ func (advancer *Advancer) Poller(pollingInterval time.Duration) (*poller.Poller,
// Step steps the Advancer for one processing cycle.
// It gets unprocessed inputs from the repository,
// runs them through the cartesi machine,
// and updates the repository with the ouputs.
// and updates the repository with the outputs.
func (advancer *Advancer) Step(ctx context.Context) error {
apps := advancer.machines.Apps()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
mrand "math/rand"
"testing"

"github.com/cartesi/rollups-node/internal/node/advancer/machines"
"github.com/cartesi/rollups-node/internal/advancer/machines"
. "github.com/cartesi/rollups-node/internal/node/model"
"github.com/cartesi/rollups-node/internal/nodemachine"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"log/slog"
"os"
"sync"
"time"

. "github.com/cartesi/rollups-node/internal/node/model"

Expand All @@ -20,17 +19,6 @@ import (
cm "github.com/cartesi/rollups-node/pkg/rollupsmachine/cartesimachine"
)

type MachineConfig struct {
AppAddress Address
SnapshotPath string
SnapshotInputIndex *uint64
IncCycles uint64
MaxCycles uint64
AdvanceTimeout time.Duration
InspectTimeout time.Duration
MaxConcurrentInspects uint8
}

type Repository interface {
// GetMachineConfigurations retrieves a machine configuration for each application.
GetMachineConfigurations(context.Context) ([]*MachineConfig, error)
Expand Down Expand Up @@ -181,6 +169,8 @@ func createMachine(ctx context.Context,
verbosity cm.ServerVerbosity,
config *MachineConfig,
) (*nm.NodeMachine, error) {
slog.Info("creating machine", "application", config.AppAddress,
"template-path", config.SnapshotPath, "service", "advancer")
// Starts the server.
address, err := cm.StartServer(verbosity, 0, os.Stdout, os.Stderr)
if err != nil {
Expand Down Expand Up @@ -229,12 +219,17 @@ func catchUp(ctx context.Context,
firstInputIndexToProcess = *snapshotInputIndex + 1
}

slog.Info("catching up unprocessed inputs", "application", app, "service", "advancer")

inputs, err := repo.GetProcessedInputs(ctx, app, firstInputIndexToProcess)
if err != nil {
return err
}

for _, input := range inputs {
// FIXME epoch id to epoch index
slog.Info("advancing", "application", app, "epochId", input.EpochId,
"input-index", input.Index, "service", "advancer")
_, err := machine.Advance(ctx, input.RawData, input.Index)
if err != nil {
return err
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"log/slog"
"net/http"

"github.com/cartesi/rollups-node/internal/node/advancer/machines"
"github.com/cartesi/rollups-node/internal/advancer/machines"
. "github.com/cartesi/rollups-node/internal/node/model"
"github.com/cartesi/rollups-node/internal/nodemachine"
"github.com/ethereum/go-ethereum/common"
Expand Down
2 changes: 1 addition & 1 deletion internal/inspect/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"testing"
"time"

"github.com/cartesi/rollups-node/internal/node/advancer/machines"
"github.com/cartesi/rollups-node/internal/advancer/machines"
. "github.com/cartesi/rollups-node/internal/node/model"
"github.com/cartesi/rollups-node/internal/nodemachine"
"github.com/cartesi/rollups-node/internal/services"
Expand Down
13 changes: 13 additions & 0 deletions internal/node/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package model

import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)
Expand Down Expand Up @@ -61,6 +63,17 @@ type NodePersistentConfig struct {
ChainId uint64
}

type MachineConfig struct {
AppAddress Address
SnapshotPath string
SnapshotInputIndex *uint64
IncCycles uint64
MaxCycles uint64
AdvanceTimeout time.Duration
InspectTimeout time.Duration
MaxConcurrentInspects uint8
}

type Application struct {
Id uint64
ContractAddress Address
Expand Down
2 changes: 1 addition & 1 deletion internal/node/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"log/slog"
"os"

"github.com/cartesi/rollups-node/internal/advancer/machines"
evmreaderservice "github.com/cartesi/rollups-node/internal/evmreader/service"
"github.com/cartesi/rollups-node/internal/inspect"
"github.com/cartesi/rollups-node/internal/node/advancer/machines"
"github.com/cartesi/rollups-node/internal/node/config"
"github.com/cartesi/rollups-node/internal/repository"
"github.com/cartesi/rollups-node/internal/services"
Expand Down
29 changes: 9 additions & 20 deletions internal/repository/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"
"time"

"github.com/cartesi/rollups-node/internal/node/advancer/machines"
. "github.com/cartesi/rollups-node/internal/node/model"
"github.com/cartesi/rollups-node/internal/nodemachine"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -24,27 +23,17 @@ type MachineRepository struct{ *Database }

func (repo *MachineRepository) GetMachineConfigurations(
ctx context.Context,
) ([]*machines.MachineConfig, error) {
) ([]*MachineConfig, error) {
// TODO: Fetch from db and Rework tables. ref. backup/feature/advancer-repository
var myInt6 uint64 = 6
res := []*machines.MachineConfig{{
AppAddress: common.BytesToAddress([]byte("\xbe\xad")),
SnapshotPath: "path/to/template/uri/2",
res := []*MachineConfig{{
AppAddress: common.HexToAddress("0xD81aA03CBbA5236F6554592B33060706017FAec6"),
SnapshotPath: "applications/echo-dapp",
SnapshotInputIndex: nil,
IncCycles: 0,
MaxCycles: 0,
AdvanceTimeout: time.Duration(0),
InspectTimeout: time.Duration(0),
MaxConcurrentInspects: 0,
}, {
AppAddress: common.BytesToAddress([]byte("\xbe\xef")),
SnapshotPath: "path/to/snapshot/2",
SnapshotInputIndex: &myInt6,
IncCycles: 0,
MaxCycles: 0,
AdvanceTimeout: time.Duration(0),
InspectTimeout: time.Duration(0),
MaxConcurrentInspects: 0,
IncCycles: 1234234214124,
MaxCycles: 1234234214124,
AdvanceTimeout: time.Duration(60000000),
InspectTimeout: time.Duration(60000000),
MaxConcurrentInspects: 10,
}}
return res, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/rollupsmachine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (machine *rollupsMachine) lastRequestWasAccepted(ctx context.Context) (bool
}
}

// process processes a request, be it an avance-state or an inspect-state request.
// process processes a request, be it an advance-state or an inspect-state request.
// It returns the accepted state and any collected responses.
//
// It expects the machine to be ready to receive requests before execution,
Expand Down

0 comments on commit 033f248

Please sign in to comment.