prysmaticlabs / prysm

Go implementation of Ethereum proof of stake
https://www.offchainlabs.com
GNU General Public License v3.0
3.47k stars 1.01k forks source link

"Could not ssz marshal the genesis beacon state" when generating a genesis state #5201

Closed Leibniz137 closed 4 years ago

Leibniz137 commented 4 years ago

Problem Description:

I use the following script to (attempt to) generate a genesis state in ssz format:

#!/bin/bash

# run this in the root dir of this repo
set -e

docker run \
  --rm \
  -it \
  --entrypoint bazel \
  --workdir /src \
  -v $(pwd):/src \
  -v bazel:/root/.cache/bazel \
  gcr.io/prysmaticlabs/build-agent \
    run //tools/genesis-state-gen -- --output-ssz /src/genesis.ssz --num-validators 64 --genesis-time 1567542540

Which produces the following output:

Downloading https://releases.bazel.build/2.1.1/release/bazel-2.1.1-linux-x86_64...
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
DEBUG: Rule 'com_google_protobuf' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1580418511 -0800"
DEBUG: Call stack for the definition of repository 'com_google_protobuf' which is a git_repository (rule definition at /root/.cache/bazel/_bazel_root/f8087e59fd95af1ae29e8fcb7ff1a3dc/external/bazel_tools/tools/bu
ild_defs/repo/git.bzl:195:18):
 - /src/WORKSPACE:241:1
 - /src/WORKSPACE:241:1
DEBUG: /root/.cache/bazel/_bazel_root/f8087e59fd95af1ae29e8fcb7ff1a3dc/external/bazel_toolchains/rules/rbe_repo/checked_in.bzl:100:9: rbe_ubuntu_clang_gen not using checked in configs as user set attr to 'False'
DEBUG: /root/.cache/bazel/_bazel_root/f8087e59fd95af1ae29e8fcb7ff1a3dc/external/bazel_toolchains/rules/rbe_repo/checked_in.bzl:100:9: rbe_ubuntu_gcc_gen not using checked in configs as user set attr to 'False'
DEBUG: /root/.cache/bazel/_bazel_root/f8087e59fd95af1ae29e8fcb7ff1a3dc/external/bazel_gazelle/internal/go_repository.bzl:184:13: com_googlesource_roughtime_roughtime_git: gazelle: unrecognized import path "rought
ime.googlesource.com/go/client/monotime"
gazelle: unrecognized import path "roughtime.googlesource.com/go/config"
gazelle: unrecognized import path "roughtime.googlesource.com/go/protocol"
gazelle: unrecognized import path "roughtime.googlesource.com/go/config"
gazelle: unrecognized import path "roughtime.googlesource.com/go/protocol"
gazelle: unrecognized import path "roughtime.googlesource.com/go/config"
gazelle: unrecognized import path "roughtime.googlesource.com/go/protocol"
INFO: Analyzed target //tools/genesis-state-gen:genesis-state-gen (312 packages loaded, 9441 targets configured).
INFO: Found 1 target...
INFO: From Generating Descriptor Set proto_library @com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:proto:
eth/v1alpha1/beacon_chain.proto:21:1: warning: Import google/protobuf/any.proto is unused.
INFO: From Generating into bazel-out/k8-fastbuild/bin/external/com_github_prysmaticlabs_ethereumapis/eth/v1alpha1/linux_amd64_stripped/go_proto%/github.com/prysmaticlabs/ethereumapis/eth/v1alpha1:
eth/v1alpha1/beacon_chain.proto: warning: Import google/protobuf/any.proto is unused.
Target //tools/genesis-state-gen:genesis-state-gen up-to-date:
  bazel-bin/tools/genesis-state-gen/linux_amd64_stripped/genesis-state-gen
INFO: Elapsed time: 686.183s, Critical Path: 19.30s
INFO: 734 processes: 734 processwrapper-sandbox.
INFO: Build completed successfully, 762 total actions
INFO: Build completed successfully, 762 total actions
2020/03/25 04:04:17 Could not ssz marshal the genesis beacon state: incorrect vector marshalling

YAML works fine!

Interestingly, I am able to produce yaml genesis state:

#!/bin/bash

# this works fine!
set -e

docker run \
  --rm \
  -it \
  --entrypoint bazel \
  --workdir /src \
  -v $(pwd):/src \
  -v bazel:/root/.cache/bazel \
  gcr.io/prysmaticlabs/build-agent \
    run //tools/genesis-state-gen -- --output-yaml /src/genesis.yaml --num-validators 64 --genesis-time 1567542540

Looking at the source

It appears that the ssz.Marshal function doesn't like the genesis state that is produced:

encodedState, err := ssz.Marshal(genesisState)
if err != nil {
    log.Fatalf("Could not ssz marshal the genesis beacon state: %v", err)
}

https://github.com/prysmaticlabs/prysm/blob/master/tools/genesis-state-gen/main.go#L44

A temporary workaround would be great too. I hit this issue in the process of trying to create a genesis state for use in a toy-sized, standalone testnet (no eth1 chain).

🙏

rauljordan commented 4 years ago

Hi @Leibniz137 was able to reproduce and was able to fix by using the following flags:

bazel run //tools/genesis-state-gen --define=ssz=mainnet -- \
  --output-ssz /tmp/genesis.ssz \
  --num-validators 64 \
  --genesis-time 1567542540 \
  --mainnet-config

could you try that out?

Leibniz137 commented 4 years ago

yes that worked, thank you!