From b541ddfb966a2291ac07801eea063d779b4e3f70 Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Fri, 24 May 2024 14:22:00 +0200 Subject: [PATCH 01/13] Add the WriteToFile method. This method just writes the ValidationInputs to a file called block_inputs_${BLOCK_ID}.json in the working directory. This isn't super-useful on its own. But, it can be used as-is in tests to get validation inputs for use with the arbitraror's benchbin binary which can validate a block. --- validator/client/validation_client.go | 1 + validator/server_api/json.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/validator/client/validation_client.go b/validator/client/validation_client.go index 38f044ab89..f436f0ba14 100644 --- a/validator/client/validation_client.go +++ b/validator/client/validation_client.go @@ -158,6 +158,7 @@ func (c *ExecutionClient) LatestWasmModuleRoot() containers.PromiseInterface[com func (c *ExecutionClient) WriteToFile(input *validator.ValidationInput, expOut validator.GoGlobalState, moduleRoot common.Hash) containers.PromiseInterface[struct{}] { jsonInput := server_api.ValidationInputToJson(input) + jsonInput.WriteToFile() return stopwaiter.LaunchPromiseThread[struct{}](c, func(ctx context.Context) (struct{}, error) { err := c.client.CallContext(ctx, nil, server_api.Namespace+"_writeToFile", jsonInput, expOut, moduleRoot) return struct{}{}, err diff --git a/validator/server_api/json.go b/validator/server_api/json.go index e30a4c72f7..3cec92418f 100644 --- a/validator/server_api/json.go +++ b/validator/server_api/json.go @@ -5,7 +5,9 @@ package server_api import ( "encoding/base64" + "encoding/json" "fmt" + "os" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" @@ -64,6 +66,17 @@ type InputJSON struct { DebugChain bool } +func (i *InputJSON) WriteToFile() error { + contents, err := json.MarshalIndent(i, "", " ") + if err != nil { + return err + } + if err = os.WriteFile(fmt.Sprintf("block_inputs_%d.json", i.Id), contents, 0644); err != nil { + return err + } + return nil +} + type UserWasmJson struct { Module string Asm string From c295c88f411fabb20f2342d5d1dd8e5b3cc7efba Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Thu, 30 May 2024 11:00:46 +0200 Subject: [PATCH 02/13] Fix lint errors. --- validator/client/validation_client.go | 6 +++++- validator/server_api/json.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/validator/client/validation_client.go b/validator/client/validation_client.go index f436f0ba14..fa6b9000f2 100644 --- a/validator/client/validation_client.go +++ b/validator/client/validation_client.go @@ -158,7 +158,11 @@ func (c *ExecutionClient) LatestWasmModuleRoot() containers.PromiseInterface[com func (c *ExecutionClient) WriteToFile(input *validator.ValidationInput, expOut validator.GoGlobalState, moduleRoot common.Hash) containers.PromiseInterface[struct{}] { jsonInput := server_api.ValidationInputToJson(input) - jsonInput.WriteToFile() + if err := jsonInput.WriteToFile(); err != nil { + return stopwaiter.LaunchPromiseThread[struct{}](c, func(ctx context.Context) (struct{}, error) { + return struct{}{}, err + }) + } return stopwaiter.LaunchPromiseThread[struct{}](c, func(ctx context.Context) (struct{}, error) { err := c.client.CallContext(ctx, nil, server_api.Namespace+"_writeToFile", jsonInput, expOut, moduleRoot) return struct{}{}, err diff --git a/validator/server_api/json.go b/validator/server_api/json.go index 3cec92418f..3dd817d5ae 100644 --- a/validator/server_api/json.go +++ b/validator/server_api/json.go @@ -71,7 +71,7 @@ func (i *InputJSON) WriteToFile() error { if err != nil { return err } - if err = os.WriteFile(fmt.Sprintf("block_inputs_%d.json", i.Id), contents, 0644); err != nil { + if err = os.WriteFile(fmt.Sprintf("block_inputs_%d.json", i.Id), contents, 0600); err != nil { return err } return nil From 18c4ba03861843d549dc5d2c9532e4c95c589ee1 Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Thu, 30 May 2024 17:37:56 +0200 Subject: [PATCH 03/13] Add tests to check errors are logged when context is cancelled --- validator/valnode/redis/consumer.go | 6 ++--- validator/valnode/redis/consumer_test.go | 29 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 validator/valnode/redis/consumer_test.go diff --git a/validator/valnode/redis/consumer.go b/validator/valnode/redis/consumer.go index 3569e78b5c..016f30bd61 100644 --- a/validator/valnode/redis/consumer.go +++ b/validator/valnode/redis/consumer.go @@ -70,7 +70,7 @@ func (s *ValidationServer) Start(ctx_in context.Context) { } select { case <-ctx.Done(): - log.Info("Context done", "error", ctx.Err().Error()) + log.Info("Context done while checking redis stream existance", "error", ctx.Err().Error()) return case <-time.After(time.Millisecond * 100): } @@ -79,7 +79,7 @@ func (s *ValidationServer) Start(ctx_in context.Context) { s.StopWaiter.LaunchThread(func(ctx context.Context) { select { case <-ctx.Done(): - log.Info("Context done", "error", ctx.Err().Error()) + log.Info("Context done while waiting a redis stream to be ready", "error", ctx.Err().Error()) return case <-ready: // Wait until the stream exists and start consuming iteratively. } @@ -116,7 +116,7 @@ func (s *ValidationServer) Start(ctx_in context.Context) { case <-time.After(s.streamTimeout): log.Error("Waiting for redis streams timed out") case <-ctx.Done(): - log.Info(("Context expired, failed to start")) + log.Info("Context done while waiting redis streams to be ready, failed to start") return } } diff --git a/validator/valnode/redis/consumer_test.go b/validator/valnode/redis/consumer_test.go new file mode 100644 index 0000000000..e7ecb40c8a --- /dev/null +++ b/validator/valnode/redis/consumer_test.go @@ -0,0 +1,29 @@ +package redis + +import ( + "context" + "testing" + "time" + + "github.com/ethereum/go-ethereum/log" + "github.com/offchainlabs/nitro/util/redisutil" + "github.com/offchainlabs/nitro/util/testhelpers" +) + +func TestTimeout(t *testing.T) { + handler := testhelpers.InitTestLog(t, log.LevelInfo) + ctx, cancel := context.WithCancel(context.Background()) + redisURL := redisutil.CreateTestRedis(ctx, t) + TestValidationServerConfig.RedisURL = redisURL + TestValidationServerConfig.ModuleRoots = []string{"0x123"} + vs, err := NewValidationServer(&TestValidationServerConfig, nil) + if err != nil { + t.Fatalf("NewValidationSever() unexpected error: %v", err) + } + vs.Start(ctx) + cancel() + time.Sleep(time.Second) + if !handler.WasLogged("Context done while waiting redis streams to be ready") { + t.Errorf("Context cancelled but error was not logged") + } +} From 388f08db02d77921f38c0c644601a41af30404ad Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Fri, 31 May 2024 08:48:21 +0200 Subject: [PATCH 04/13] Check timeout logs --- validator/valnode/redis/consumer_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/valnode/redis/consumer_test.go b/validator/valnode/redis/consumer_test.go index e7ecb40c8a..6dd2395cf2 100644 --- a/validator/valnode/redis/consumer_test.go +++ b/validator/valnode/redis/consumer_test.go @@ -24,6 +24,6 @@ func TestTimeout(t *testing.T) { cancel() time.Sleep(time.Second) if !handler.WasLogged("Context done while waiting redis streams to be ready") { - t.Errorf("Context cancelled but error was not logged") + t.Errorf("Waiting for redis streams timed out") } } From f12bc4e9f54d06d369282e4c5000405b4fc0e50c Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Fri, 31 May 2024 15:15:10 +0200 Subject: [PATCH 05/13] Word test error message clearer --- validator/valnode/redis/consumer_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/valnode/redis/consumer_test.go b/validator/valnode/redis/consumer_test.go index 6dd2395cf2..e25169a79e 100644 --- a/validator/valnode/redis/consumer_test.go +++ b/validator/valnode/redis/consumer_test.go @@ -24,6 +24,6 @@ func TestTimeout(t *testing.T) { cancel() time.Sleep(time.Second) if !handler.WasLogged("Context done while waiting redis streams to be ready") { - t.Errorf("Waiting for redis streams timed out") + t.Error("Expected message about stream time-outs was not logged") } } From c621a9cb41d3b061018ffe1608adaa282522ff71 Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Mon, 3 Jun 2024 12:48:38 +0200 Subject: [PATCH 06/13] Fix test --- validator/valnode/redis/consumer_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/validator/valnode/redis/consumer_test.go b/validator/valnode/redis/consumer_test.go index e25169a79e..0ebd697f16 100644 --- a/validator/valnode/redis/consumer_test.go +++ b/validator/valnode/redis/consumer_test.go @@ -16,14 +16,15 @@ func TestTimeout(t *testing.T) { redisURL := redisutil.CreateTestRedis(ctx, t) TestValidationServerConfig.RedisURL = redisURL TestValidationServerConfig.ModuleRoots = []string{"0x123"} + TestValidationServerConfig.StreamTimeout = 100 * time.Millisecond vs, err := NewValidationServer(&TestValidationServerConfig, nil) if err != nil { t.Fatalf("NewValidationSever() unexpected error: %v", err) } vs.Start(ctx) - cancel() time.Sleep(time.Second) - if !handler.WasLogged("Context done while waiting redis streams to be ready") { + if !handler.WasLogged("Waiting for redis streams timed out") { t.Error("Expected message about stream time-outs was not logged") } + cancel() } From 08498040145bebeef71a1765789735b2eb619fe5 Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Mon, 3 Jun 2024 14:14:13 +0200 Subject: [PATCH 07/13] Use latest version of go1.21 in docker --- Dockerfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 88c34cec44..52326032d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -64,7 +64,11 @@ COPY --from=wasm-libs-builder /workspace/ / FROM wasm-base as wasm-bin-builder # pinned go version -RUN curl -L https://golang.org/dl/go1.21.7.linux-`dpkg --print-architecture`.tar.gz | tar -C /usr/local -xzf - + + # Use latest go1.21 version. +RUN LATEST_GO=$(curl -s https://go.dev/dl/?mode=json | jq -r '[.[] | select(.version | startswith("go1.21"))] | .[0].version') && \ + curl -L https://golang.org/dl/${LATEST_GO}.linux-`dpkg --print-architecture`.tar.gz | tar -C /usr/local -xzf - + COPY ./Makefile ./go.mod ./go.sum ./ COPY ./arbcompress ./arbcompress COPY ./arbos ./arbos From a524dba9aa47e0a55eff6a91d5c1827dbeb48af7 Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Mon, 3 Jun 2024 14:50:04 +0200 Subject: [PATCH 08/13] Add jq in apt-get install --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 52326032d3..f250798ea7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,7 +37,7 @@ RUN . ~/.bashrc && NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-solidity FROM debian:bookworm-20231218 as wasm-base WORKDIR /workspace -RUN apt-get update && apt-get install -y curl build-essential=12.9 +RUN apt-get update && apt-get install -y curl jq build-essential=12.9 FROM wasm-base as wasm-libs-builder # clang / lld used by soft-float wasm From b23657e6cd56a7332c21707ca1da7fb4d575dcb0 Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Mon, 3 Jun 2024 15:33:43 +0200 Subject: [PATCH 09/13] Print out Go version in build logs --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f250798ea7..00bf999513 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,7 +67,8 @@ FROM wasm-base as wasm-bin-builder # Use latest go1.21 version. RUN LATEST_GO=$(curl -s https://go.dev/dl/?mode=json | jq -r '[.[] | select(.version | startswith("go1.21"))] | .[0].version') && \ - curl -L https://golang.org/dl/${LATEST_GO}.linux-`dpkg --print-architecture`.tar.gz | tar -C /usr/local -xzf - + curl -L https://golang.org/dl/${LATEST_GO}.linux-`dpkg --print-architecture`.tar.gz | tar -C /usr/local -xzf - && \ + echo "Installed Go version: ${LATEST_GO}" COPY ./Makefile ./go.mod ./go.sum ./ COPY ./arbcompress ./arbcompress From dfaac799a23f7c3d9cb7ad6904dcd0e580c33e83 Mon Sep 17 00:00:00 2001 From: finaltrip Date: Mon, 3 Jun 2024 23:14:18 +0800 Subject: [PATCH 10/13] chore: fix some function names Signed-off-by: finaltrip --- util/arbmath/math.go | 2 +- wsbroadcastserver/clientconnection.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/util/arbmath/math.go b/util/arbmath/math.go index d7a0d1f523..7413955409 100644 --- a/util/arbmath/math.go +++ b/util/arbmath/math.go @@ -305,7 +305,7 @@ func SaturatingUSub[T Unsigned](a, b T) T { return a - b } -// SaturatingMul multiply two integers without over/underflow +// SaturatingUMul multiply two integers without over/underflow func SaturatingUMul[T Unsigned](a, b T) T { product := a * b if b != 0 && product/b != a { diff --git a/wsbroadcastserver/clientconnection.go b/wsbroadcastserver/clientconnection.go index 6f5bf54e4d..ba70756c98 100644 --- a/wsbroadcastserver/clientconnection.go +++ b/wsbroadcastserver/clientconnection.go @@ -302,7 +302,7 @@ func (cc *ClientConnection) Receive(ctx context.Context, timeout time.Duration) return msg, op, err } -// readRequests reads json-rpc request from connection. +// readRequest reads json-rpc request from connection. func (cc *ClientConnection) readRequest(ctx context.Context, timeout time.Duration) ([]byte, ws.OpCode, error) { cc.ioMutex.Lock() defer cc.ioMutex.Unlock() From c22a4cab942250294881231190ba99a11112b11c Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Mon, 3 Jun 2024 17:47:00 +0200 Subject: [PATCH 11/13] Pin both docker and go version in docker file --- Dockerfile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 00bf999513..b6f20f9533 100644 --- a/Dockerfile +++ b/Dockerfile @@ -63,13 +63,8 @@ FROM scratch as wasm-libs-export COPY --from=wasm-libs-builder /workspace/ / FROM wasm-base as wasm-bin-builder - # pinned go version - - # Use latest go1.21 version. -RUN LATEST_GO=$(curl -s https://go.dev/dl/?mode=json | jq -r '[.[] | select(.version | startswith("go1.21"))] | .[0].version') && \ - curl -L https://golang.org/dl/${LATEST_GO}.linux-`dpkg --print-architecture`.tar.gz | tar -C /usr/local -xzf - && \ - echo "Installed Go version: ${LATEST_GO}" - +# pinned go version +RUN curl -L https://golang.org/dl/go1.21.10.linux-`dpkg --print-architecture`.tar.gz | tar -C /usr/local -xzf - COPY ./Makefile ./go.mod ./go.sum ./ COPY ./arbcompress ./arbcompress COPY ./arbos ./arbos @@ -211,7 +206,7 @@ COPY ./scripts/download-machine.sh . #RUN ./download-machine.sh consensus-v20 0x8b104a2e80ac6165dc58b9048de12f301d70b02a0ab51396c22b4b4b802a16a4 RUN ./download-machine.sh consensus-v30-rc.2 0xb0de9cb89e4d944ae6023a3b62276e54804c242fd8c4c2d8e6cc4450f5fa8b1b -FROM golang:1.21-bookworm as node-builder +FROM golang:1.21.10-bookworm as node-builder WORKDIR /workspace ARG version="" ARG datetime="" From a9d2808a2a1a3aaa5eb703e5ba49090bad47c8d1 Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Mon, 3 Jun 2024 17:51:19 +0200 Subject: [PATCH 12/13] Drop jq as it's not used anymore --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b6f20f9533..0595291a7e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,7 +37,7 @@ RUN . ~/.bashrc && NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-solidity FROM debian:bookworm-20231218 as wasm-base WORKDIR /workspace -RUN apt-get update && apt-get install -y curl jq build-essential=12.9 +RUN apt-get update && apt-get install -y curl build-essential=12.9 FROM wasm-base as wasm-libs-builder # clang / lld used by soft-float wasm From e8fba1a59264cecb068da95d72f2f75acf002842 Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Mon, 3 Jun 2024 18:23:13 +0200 Subject: [PATCH 13/13] Disable profiling sequencer by default --- execution/gethexec/sequencer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/execution/gethexec/sequencer.go b/execution/gethexec/sequencer.go index db3daca61d..a0623a8aed 100644 --- a/execution/gethexec/sequencer.go +++ b/execution/gethexec/sequencer.go @@ -132,7 +132,7 @@ var DefaultSequencerConfig = SequencerConfig{ NonceFailureCacheExpiry: time.Second, ExpectedSurplusSoftThreshold: "default", ExpectedSurplusHardThreshold: "default", - EnableProfiling: true, + EnableProfiling: false, } var TestSequencerConfig = SequencerConfig{