diff --git a/build/docker-bake.hcl b/build/docker-bake.hcl index 2c2025ca7..fba676b46 100644 --- a/build/docker-bake.hcl +++ b/build/docker-bake.hcl @@ -21,8 +21,8 @@ target "common" { RUST_VERSION = "1.78.0" GO_VERSION = "1.22.1" FOUNDRY_NIGHTLY_VERSION = "293fad73670b7b59ca901c7f2105bf7a29165a90" - MACHINE_EMULATOR_VERSION = "0.17.0" - MACHINE_TOOLS_VERSION = "0.15.0" + MACHINE_EMULATOR_VERSION = "0.18.1" + MACHINE_TOOLS_VERSION = "0.16.1" MACHINE_IMAGE_KERNEL_VERSION = "0.20.0" MACHINE_KERNEL_VERSION = "6.5.13" MACHINE_XGENEXT2FS_VERSION = "1.5.6" diff --git a/pkg/emulator/emulator_test.go b/pkg/emulator/emulator_test.go index c92b59a09..ce09a58b3 100644 --- a/pkg/emulator/emulator_test.go +++ b/pkg/emulator/emulator_test.go @@ -16,7 +16,7 @@ import ( var ( imagesPath = "/usr/share/cartesi-machine/images/" - address = "localhost:8081" + address = "127.0.0.1:8081" ) func init() { diff --git a/pkg/emulator/remote.go b/pkg/emulator/remote.go index 024e180a8..cad2a1562 100644 --- a/pkg/emulator/remote.go +++ b/pkg/emulator/remote.go @@ -12,7 +12,7 @@ import ( // A connection to the remote jsonrpc machine manager. type RemoteMachineManager struct { - c *C.cm_jsonrpc_mg_mgr + c *C.cm_jsonrpc_mgr Address string } @@ -22,13 +22,13 @@ func NewRemoteMachineManager(address string) (*RemoteMachineManager, error) { cRemoteAddress := C.CString(address) defer C.free(unsafe.Pointer(cRemoteAddress)) var msg *C.char - code := C.cm_create_jsonrpc_mg_mgr(cRemoteAddress, &manager.c, &msg) + code := C.cm_create_jsonrpc_mgr(cRemoteAddress, &manager.c, &msg) return manager, newError(code, msg) } func (remote *RemoteMachineManager) Delete() { if remote.c != nil { - C.cm_delete_jsonrpc_mg_mgr(remote.c) + C.cm_delete_jsonrpc_mgr(remote.c) remote.c = nil } } diff --git a/pkg/rollupsmachine/abi.json b/pkg/rollupsmachine/abi.json index 8e84bb97a..41ff52ec1 100644 --- a/pkg/rollupsmachine/abi.json +++ b/pkg/rollupsmachine/abi.json @@ -8,6 +8,7 @@ { "type" : "uint256" }, { "type" : "uint256" }, { "type" : "uint256" }, + { "type" : "uint256" }, { "type" : "bytes" } ] }, { diff --git a/pkg/rollupsmachine/io.go b/pkg/rollupsmachine/io.go index f25f6b0f8..84c4a2f21 100644 --- a/pkg/rollupsmachine/io.go +++ b/pkg/rollupsmachine/io.go @@ -35,9 +35,9 @@ type Input struct { Sender Address BlockNumber uint64 BlockTimestamp uint64 - // PrevRandao uint64 - Index uint64 - Data []byte + PrevRandao uint64 + Index uint64 + Data []byte } // A Query is sent by a inspect-state request. @@ -64,10 +64,10 @@ func (input Input) Encode() ([]byte, error) { sender := common.BytesToAddress(input.Sender[:]) blockNumber := new(big.Int).SetUint64(input.BlockNumber) blockTimestamp := new(big.Int).SetUint64(input.BlockTimestamp) - // prevRandao := new(big.Int).SetUint64(input.PrevRandao) + prevRandao := new(big.Int).SetUint64(input.PrevRandao) index := new(big.Int).SetUint64(input.Index) return ioABI.Pack("EvmAdvance", chainId, appContract, sender, blockNumber, blockTimestamp, - index, input.Data) + prevRandao, index, input.Data) } // DecodeOutput decodes an output into either a voucher or a notice. diff --git a/pkg/rollupsmachine/machine_test.go b/pkg/rollupsmachine/machine_test.go index 04f2c285a..611756051 100644 --- a/pkg/rollupsmachine/machine_test.go +++ b/pkg/rollupsmachine/machine_test.go @@ -46,6 +46,7 @@ func (s *RollupsMachineSuite) TestNew() { suite.Run(s.T(), new(NewSuite)) } func (s *RollupsMachineSuite) TestFork() { suite.Run(s.T(), new(ForkSuite)) } func (s *RollupsMachineSuite) TestAdvance() { suite.Run(s.T(), new(AdvanceSuite)) } func (s *RollupsMachineSuite) TestInspect() { suite.Run(s.T(), new(InspectSuite)) } +func (s *RollupsMachineSuite) TestUnit() { suite.Run(s.T(), new(UnitSuite)) } // ------------------------------------------------------------------------------------------------ @@ -97,7 +98,7 @@ func (s *NewSuite) TestOkAccept() { config := &emulator.MachineRuntimeConfig{} cartesiMachine, err := cartesimachine.Load(s.acceptSnapshot.Path(), s.address, config) require.NotNil(cartesiMachine) - require.Nil(err) + require.Nil(err, "%v", err) rollupsMachine, err := New(cartesiMachine, defaultInc, defaultMax) require.NotNil(rollupsMachine) @@ -421,10 +422,6 @@ func expectNotice(t *testing.T, output Output) *Notice { // Unit tests // ------------------------------------------------------------------------------------------------ -func TestRollupsMachineUnit(t *testing.T) { - suite.Run(t, new(UnitSuite)) -} - type UnitSuite struct{ suite.Suite } func (_ *UnitSuite) newMachines() (*CartesiMachineMock, *RollupsMachine) { @@ -631,9 +628,13 @@ func (s *UnitSuite) TestClose() { }) } -func (s *UnitSuite) TestLastRequestWasAccepted() {} +func (s *UnitSuite) TestLastRequestWasAccepted() { + s.T().Skip("TODO") +} -func (s *UnitSuite) TestProcess() {} +func (s *UnitSuite) TestProcess() { + s.T().Skip("TODO") +} func (s *UnitSuite) TestRun() { newMachines := func() (*CartesiMachineMock, *RollupsMachine) { diff --git a/pkg/rollupsmachine/server.go b/pkg/rollupsmachine/server.go deleted file mode 100644 index ddf499ab9..000000000 --- a/pkg/rollupsmachine/server.go +++ /dev/null @@ -1,126 +0,0 @@ -// (c) Cartesi and individual authors (see AUTHORS) -// SPDX-License-Identifier: Apache-2.0 (see LICENSE) - -package rollupsmachine - -import ( - "fmt" - "io" - "log/slog" - "os/exec" - "regexp" - "strconv" - - "github.com/cartesi/rollups-node/internal/linewriter" - "github.com/cartesi/rollups-node/pkg/emulator" -) - -type ServerVerbosity string - -const ( - ServerVerbosityTrace ServerVerbosity = "trace" - ServerVerbosityDebug ServerVerbosity = "debug" - ServerVerbosityInfo ServerVerbosity = "info" - ServerVerbosityWarn ServerVerbosity = "warn" - ServerVerbosityError ServerVerbosity = "error" - ServerVerbosityFatal ServerVerbosity = "fatal" -) - -// StartServer starts a JSON RPC remote cartesi machine server. -// -// It configures the server's logging verbosity and initializes its address to localhost:port. -// If verbosity is an invalid LogLevel, a default value will be used instead. -// If port is 0, a random valid port will be used instead. -// -// StartServer also redirects the server's stdout and stderr to the provided io.Writers. -// -// It returns the server's address. -func StartServer(verbosity ServerVerbosity, port uint32, stdout, stderr io.Writer) (string, error) { - // Configures the command's arguments. - args := []string{} - if verbosity.valid() { - args = append(args, "--log-level="+string(verbosity)) - } - if port != 0 { - args = append(args, fmt.Sprintf("--server-address=localhost:%d", port)) - } - - // Creates the command. - cmd := exec.Command("jsonrpc-remote-cartesi-machine", args...) - - // Redirects stdout and stderr. - interceptor := portInterceptor{ - inner: stderr, - port: make(chan uint32), - found: new(bool), - } - cmd.Stdout = stdout - cmd.Stderr = linewriter.New(interceptor) - - // Starts the server. - slog.Info("running", "command", cmd.String()) - if err := cmd.Start(); err != nil { - return "", err - } - - // Waits for the interceptor to write the port to the channel. - if actualPort := <-interceptor.port; port == 0 { - port = actualPort - } else if port != actualPort { - panic(fmt.Sprintf("mismatching ports (%d != %d)", port, actualPort)) - } - - return fmt.Sprintf("localhost:%d", port), nil -} - -// StopServer shuts down the JSON RPC remote cartesi machine server hosted at address. -func StopServer(address string) error { - slog.Info("Stopping server at", "address", address) - remote, err := emulator.NewRemoteMachineManager(address) - if err != nil { - return err - } - defer remote.Delete() - return remote.Shutdown() -} - -// ------------------------------------------------------------------------------------------------ - -func (verbosity ServerVerbosity) valid() bool { - return verbosity == ServerVerbosityTrace || - verbosity == ServerVerbosityDebug || - verbosity == ServerVerbosityInfo || - verbosity == ServerVerbosityWarn || - verbosity == ServerVerbosityError || - verbosity == ServerVerbosityFatal -} - -// portInterceptor sends the server's port through the port channel as soon as it reads it. -// It then closes the channel and keeps on writing to the inner writer. -// -// It expects to be wrapped by a linewriter.LineWriter. -type portInterceptor struct { - inner io.Writer - port chan uint32 - found *bool -} - -var portRegex = regexp.MustCompile("initial server bound to port ([0-9]+)") - -func (writer portInterceptor) Write(p []byte) (n int, err error) { - if *writer.found { - return writer.inner.Write(p) - } else { - matches := portRegex.FindStringSubmatch(string(p)) - if matches != nil { - port, err := strconv.ParseUint(matches[1], 10, 32) - if err != nil { - return 0, err - } - *writer.found = true - writer.port <- uint32(port) - close(writer.port) - } - return writer.inner.Write(p) - } -}