Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to keep server_api json.go in sync with parse_inputs.rs #2723

Merged
merged 29 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
798d717
Add a test to keep server_api json.go in sync with parse_inputs.rs
ganeshvanahalli Oct 4, 2024
115afdc
Jit prover should accept InputJSON format and execute a full block
ganeshvanahalli Oct 9, 2024
3a6e868
fix clippy error
ganeshvanahalli Oct 9, 2024
c4bb3e0
Merge branch 'master' into testcompatibility-goinputjson-rustfiledata
ganeshvanahalli Oct 10, 2024
16f981f
Merge branch 'master' into jitprover-inputjson-compatibility
ganeshvanahalli Oct 10, 2024
be58669
change implimentation and add CI step to execute arbitrator prover us…
ganeshvanahalli Oct 10, 2024
f0d14fb
fix ci step and comment other steps in test(defaults) to speedup veri…
ganeshvanahalli Oct 10, 2024
d50926e
fix gotestsum invocation
ganeshvanahalli Oct 10, 2024
a1cb06d
uncomment CI steps
ganeshvanahalli Oct 10, 2024
94cd9b4
change base branch and address PR comments
ganeshvanahalli Oct 10, 2024
70c5b3f
add ci step to run jit binary on the block input json file
ganeshvanahalli Oct 10, 2024
62d76d0
check if theres a local target mismatch on go and rust side
ganeshvanahalli Oct 10, 2024
93fca3d
add more debug info
ganeshvanahalli Oct 10, 2024
5e355bc
check if jit proving succeeds in CI
ganeshvanahalli Oct 10, 2024
7259ae1
remove debug statements and comments
ganeshvanahalli Oct 10, 2024
bb5e8b7
address PR comments
ganeshvanahalli Oct 10, 2024
034a504
Merge branch 'master' into testcompatibility-goinputjson-rustfiledata
ganeshvanahalli Oct 11, 2024
f83a10f
use inputs.Writer to generate the json file
ganeshvanahalli Oct 11, 2024
05be76e
use inputs.Writer to generate the json file
ganeshvanahalli Oct 11, 2024
37551f3
resolve conflicts
ganeshvanahalli Oct 11, 2024
ceb785e
typo fix
ganeshvanahalli Oct 11, 2024
5aa0230
Merge branch 'testcompatibility-goinputjson-rustfiledata' into jitpro…
ganeshvanahalli Oct 11, 2024
4a7ff01
Merge branch 'master' into testcompatibility-goinputjson-rustfiledata
ganeshvanahalli Oct 15, 2024
eb2c5be
address PR comments
ganeshvanahalli Oct 15, 2024
2b1d7a2
prioritize test flag over the test's decision to record a block
ganeshvanahalli Oct 15, 2024
80872b4
Merge branch 'master' into testcompatibility-goinputjson-rustfiledata
ganeshvanahalli Oct 15, 2024
2f0eefb
merge upstream and resolve conflicts
ganeshvanahalli Oct 15, 2024
c5087d9
Merge pull request #2730 from OffchainLabs/jitprover-inputjson-compat…
eljobe Oct 15, 2024
92bf520
Merge branch 'master' into testcompatibility-goinputjson-rustfiledata
ganeshvanahalli Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ jobs:
run: |
echo "Running redis tests" >> full.log
TEST_REDIS=redis://localhost:6379/0 gotestsum --format short-verbose -- -p 1 -run TestRedis ./arbnode/... ./system_tests/... -coverprofile=coverage-redis.txt -covermode=atomic -coverpkg=./...

- name: create block input json file
if: matrix.test-mode == 'defaults'
run: |
gotestsum --format short-verbose -- -run TestProgramStorage$ ./system_tests/... --count 1 --recordBlockInputs.WithBaseDir="${{ github.workspace }}/target" --recordBlockInputs.WithTimestampDirEnabled=false --recordBlockInputs.WithBlockIdInFileNameEnabled=false

- name: run arbitrator prover on block input json
if: matrix.test-mode == 'defaults'
run: |
make build-prover-bin
target/bin/prover target/machines/latest/machine.wavm.br -b --json-inputs="${{ github.workspace }}/target/TestProgramStorage/block_inputs.json"

- name: run challenge tests
if: matrix.test-mode == 'challenge'
Expand Down
22 changes: 21 additions & 1 deletion system_tests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/binary"
"encoding/hex"
"encoding/json"
"flag"
"io"
"math/big"
"net"
Expand Down Expand Up @@ -1716,6 +1717,14 @@ func logParser[T any](t *testing.T, source string, name string) func(*types.Log)
}
}

var (
recordBlockInputsEnable = flag.Bool("recordBlockInputs.enable", true, "Whether to record block inputs as a json file")
recordBlockInputsWithSlug = flag.String("recordBlockInputs.WithSlug", "", "Slug directory for validationInputsWriter")
recordBlockInputsWithBaseDir = flag.String("recordBlockInputs.WithBaseDir", "", "Base directory for validationInputsWriter")
recordBlockInputsWithTimestampDirEnabled = flag.Bool("recordBlockInputs.WithTimestampDirEnabled", true, "Whether to add timestamp directory while recording block inputs")
recordBlockInputsWithBlockIdInFileNameEnabled = flag.Bool("recordBlockInputs.WithBlockIdInFileNameEnabled", true, "Whether to record block inputs using test specific block_id")
)

// recordBlock writes a json file with all of the data needed to validate a block.
//
// This can be used as an input to the arbitrator prover to validate a block.
Expand All @@ -1733,7 +1742,18 @@ func recordBlock(t *testing.T, block uint64, builder *NodeBuilder) {
break
}
}
validationInputsWriter, err := inputs.NewWriter(inputs.WithSlug(t.Name()))
var options []inputs.WriterOption
options = append(options, inputs.WithTimestampDirEnabled(*recordBlockInputsWithTimestampDirEnabled))
options = append(options, inputs.WithBlockIdInFileNameEnabled(*recordBlockInputsWithBlockIdInFileNameEnabled))
if *recordBlockInputsWithBaseDir != "" {
options = append(options, inputs.WithBaseDir(*recordBlockInputsWithBaseDir))
}
if *recordBlockInputsWithSlug != "" {
options = append(options, inputs.WithSlug(*recordBlockInputsWithSlug))
} else {
options = append(options, inputs.WithSlug(t.Name()))
}
validationInputsWriter, err := inputs.NewWriter(options...)
Require(t, err)
inputJson, err := builder.L2.ConsensusNode.StatelessBlockValidator.ValidationInputsAt(ctx, inboxPos, rawdb.TargetWavm)
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions system_tests/program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bytes"
"context"
"encoding/binary"
"flag"
"fmt"
"math"
"math/big"
Expand Down Expand Up @@ -423,9 +424,12 @@ func storageTest(t *testing.T, jit bool) {

validateBlocks(t, 2, jit, builder)

// Captures a block_input_<id>.json file for the block that included the
// storage write transaction.
recordBlock(t, receipt.BlockNumber.Uint64(), builder)
// Captures a block_inputs json file for the block that included the
// storage write transaction. Include wasm targets necessary for arbitrator prover and jit binaries
flag.Parse()
ganeshvanahalli marked this conversation as resolved.
Show resolved Hide resolved
if *recordBlockInputsEnable {
recordBlock(t, receipt.BlockNumber.Uint64(), builder)
}
}

func TestProgramTransientStorage(t *testing.T) {
Expand Down
44 changes: 30 additions & 14 deletions validator/inputs/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,37 @@ import (
//
// The path can be nested under a slug directory so callers can provide a
// recognizable name to differentiate various contexts in which the InputJSON
// is being written. If the Writer is configured by calling SetSlug, then the
// is being written. If the Writer is configured by calling WithSlug, then the
// path will be like:
//
// $HOME/.arbuitrum/validation-inputs/<slug>/<YYYMMDD_HHMMSS>/block_inputs_<id>.json
//
// The inclusion of BlockId in the file's name is on by default, however that can be disabled
// by calling WithBlockIdInFileNameEnabled(false). In which case, the path will be like:
//
// $HOME/.arbuitrum/validation-inputs/<slug>/<YYYMMDD_HHMMSS>/block_inputs.json
//
// The inclusion of a timestamp directory is on by default to avoid conflicts which
// would result in files being overwritten. However, the Writer can be configured
// to not use a timestamp directory. If the Writer is configured by calling
// SetUseTimestampDir(false), then the path will be like:
// WithTimestampDirEnabled(false), then the path will be like:
//
// $HOME/.arbuitrum/validation-inputs/<slug>/block_inputs_<id>.json
//
// Finally, to give complete control to the clients, the base directory can be
// set directly with SetBaseDir. In which case, the path will be like:
// set directly with WithBaseDir. In which case, the path will be like:
//
// <baseDir>/block_inputs_<id>.json
// or
// <baseDir>/<slug>/block_inputs_<id>.json
// or
// <baseDir>/<slug>/<YYYMMDD_HHMMSS>/block_inputs_<id>.json
type Writer struct {
clock Clock
baseDir string
slug string
useTimestampDir bool
clock Clock
baseDir string
slug string
useTimestampDir bool
useBlockIdInFileName bool
}

// WriterOption is a function that configures a Writer.
Expand All @@ -66,10 +72,11 @@ func NewWriter(options ...WriterOption) (*Writer, error) {
}
baseDir := filepath.Join(homeDir, ".arbitrum", "validation-inputs")
w := &Writer{
clock: realClock{},
baseDir: baseDir,
slug: "",
useTimestampDir: true,
clock: realClock{},
baseDir: baseDir,
slug: "",
useTimestampDir: true,
useBlockIdInFileName: true,
}
for _, o := range options {
o(w)
Expand Down Expand Up @@ -114,6 +121,13 @@ func WithTimestampDirEnabled(useTimestampDir bool) WriterOption {
}
}

// WithBlockIdInFileNameEnabled controls the inclusion of Block Id in the input json file's name
func WithBlockIdInFileNameEnabled(useBlockIdInFileName bool) WriterOption {
return func(w *Writer) {
w.useBlockIdInFileName = useBlockIdInFileName
}
}

// Write writes the given InputJSON to a file in JSON format.
func (w *Writer) Write(json *server_api.InputJSON) error {
dir := w.baseDir
Expand All @@ -132,9 +146,11 @@ func (w *Writer) Write(json *server_api.InputJSON) error {
if err != nil {
return err
}
if err = os.WriteFile(
filepath.Join(dir, fmt.Sprintf("block_inputs_%d.json", json.Id)),
contents, 0600); err != nil {
fileName := "block_inputs.json"
if w.useBlockIdInFileName {
fileName = fmt.Sprintf("block_inputs_%d.json", json.Id)
}
if err = os.WriteFile(filepath.Join(dir, fileName), contents, 0600); err != nil {
return err
}
return nil
Expand Down
Loading