From 8d56c8d4f425a679fb80da59965c4146bcee964a Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Fri, 29 Jul 2022 20:08:12 +0200 Subject: [PATCH 1/3] More --- e2e/framework/chaintime.go | 106 ++++++++++++++++++ e2e/framework/context.go | 4 + e2e/framework/framework.go | 38 +++++++ e2e/single/single.go | 68 ++++++++++++ e2e/tests.go | 5 + go.sum | 4 - internal/cmd/commands.go | 6 ++ internal/cmd/e2e_run.go | 38 +++++++ internal/docker/docker.go | 4 + internal/http/http.go | 13 +++ internal/server/proto/service.pb.go | 160 +++++++++++++++------------- internal/server/proto/service.proto | 1 + internal/server/proto/utils.go | 5 + internal/server/server.go | 1 + internal/spec/spec.go | 1 + 15 files changed, 378 insertions(+), 76 deletions(-) create mode 100644 e2e/framework/chaintime.go create mode 100644 e2e/framework/context.go create mode 100644 e2e/framework/framework.go create mode 100644 e2e/single/single.go create mode 100644 e2e/tests.go create mode 100644 internal/cmd/e2e_run.go diff --git a/e2e/framework/chaintime.go b/e2e/framework/chaintime.go new file mode 100644 index 0000000..36ab91c --- /dev/null +++ b/e2e/framework/chaintime.go @@ -0,0 +1,106 @@ +package framework + +import ( + "time" +) + +type chainTime struct { + genesisTime time.Time + secondsPerSlot uint64 + slotsPerEpoch uint64 + ResCh chan SlotResult + CloseCh chan struct{} + ReadyCh chan struct{} + startEpoch uint64 +} + +func NewChainTime(genesisTime time.Time, secondsPerSlot, slotsPerEpoch uint64) *chainTime { + return &chainTime{ + genesisTime: genesisTime, + secondsPerSlot: secondsPerSlot, + slotsPerEpoch: slotsPerEpoch, + ReadyCh: make(chan struct{}), + CloseCh: make(chan struct{}), + ResCh: make(chan SlotResult), + } +} + +type SlotResult struct { + Epoch uint64 + StartTime time.Time + GenesisTime time.Time + SecondsPerSlot uint64 + + FirstSlot uint64 + LastSlot uint64 +} + +func (s *SlotResult) AtSlot(slot uint64) time.Time { + return s.GenesisTime.Add(time.Duration(slot*s.SecondsPerSlot) * time.Second) +} + +func (s *SlotResult) AtSlotAndStage(slot uint64) time.Time { + return s.GenesisTime.Add(time.Duration(slot*s.SecondsPerSlot) * time.Second) +} + +func (b *chainTime) Run() { + secondsPerEpoch := time.Duration(b.secondsPerSlot*b.slotsPerEpoch) * time.Second + + // time since genesis + currentTime := time.Now() + timeSinceGenesis := currentTime.Sub(b.genesisTime) + + if timeSinceGenesis < 0 { + // wait until the chain has started + timeUntilGenesis := b.genesisTime.Sub(currentTime) + select { + case <-time.After(timeUntilGenesis): + timeSinceGenesis = 0 + + case <-b.CloseCh: + return + } + } + + nextTick := timeSinceGenesis.Truncate(secondsPerEpoch) + secondsPerEpoch + epoch := uint64(nextTick / secondsPerEpoch) + nextTickTime := b.genesisTime.Add(nextTick) + + b.startEpoch = epoch + + // close the ready channel to notify that the + // chain has started + close(b.ReadyCh) + + emitEpoch := func(epoch uint64) { + startTime := b.genesisTime.Add(time.Duration(epoch*b.slotsPerEpoch*b.secondsPerSlot) * time.Second) + + firstSlot := epoch * b.slotsPerEpoch + lastSlot := epoch*b.slotsPerEpoch + b.slotsPerEpoch + + b.ResCh <- SlotResult{ + Epoch: epoch, + StartTime: startTime, + SecondsPerSlot: b.secondsPerSlot, + GenesisTime: b.genesisTime, + FirstSlot: firstSlot, + LastSlot: lastSlot, + } + } + + emitEpoch(epoch - 1) + + for { + timeToWait := nextTickTime.Sub(time.Now()) + + select { + case <-time.After(timeToWait): + case <-b.CloseCh: + return + } + + emitEpoch(epoch) + epoch++ + nextTickTime = nextTickTime.Add(secondsPerEpoch) + } +} diff --git a/e2e/framework/context.go b/e2e/framework/context.go new file mode 100644 index 0000000..0eed18f --- /dev/null +++ b/e2e/framework/context.go @@ -0,0 +1,4 @@ +package framework + +type F struct { +} diff --git a/e2e/framework/framework.go b/e2e/framework/framework.go new file mode 100644 index 0000000..c816af4 --- /dev/null +++ b/e2e/framework/framework.go @@ -0,0 +1,38 @@ +package framework + +import "fmt" + +var pkgSuites []*TestSuite + +func AddSuites(s *TestSuite) { + pkgSuites = append(pkgSuites, s) +} + +type TestSuite struct { + Cases []TestCase +} + +type TestCase interface { + Run(f *F) +} + +type Framework struct { + suites []*TestSuite +} + +func New() *Framework { + f := &Framework{ + suites: pkgSuites, + } + return f +} + +func (f *Framework) Run() { + fmt.Println(f.suites, pkgSuites) + for _, s := range f.suites { + for _, c := range s.Cases { + f := &F{} + c.Run(f) + } + } +} diff --git a/e2e/single/single.go b/e2e/single/single.go new file mode 100644 index 0000000..3420b39 --- /dev/null +++ b/e2e/single/single.go @@ -0,0 +1,68 @@ +package single + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/go-hclog" + "github.com/umbracle/viewpoint/e2e/framework" + "github.com/umbracle/viewpoint/internal/http" + "github.com/umbracle/viewpoint/internal/server" + "github.com/umbracle/viewpoint/internal/server/proto" +) + +func init() { + framework.AddSuites(&framework.TestSuite{ + Cases: []framework.TestCase{new(SingleDeployment)}, + }) +} + +type SingleDeployment struct { +} + +func (s *SingleDeployment) Run(f *framework.F) { + genesisTime := time.Now().Add(10 * time.Second) + + config := server.DefaultConfig() + config.NumGenesisValidators = 10 + config.NumTranches = 1 + config.Spec.MinGenesisValidatorCount = 10 + config.Spec.MinGenesisTime = int(genesisTime.Unix()) + + srv, err := server.NewServer(hclog.NewNullLogger(), config) + if err != nil { + panic(err) + } + + resp, err := srv.NodeDeploy(context.Background(), &proto.NodeDeployRequest{ + NodeClient: proto.NodeClient_Lighthouse, + NodeType: &proto.NodeDeployRequest_Validator_{ + Validator: &proto.NodeDeployRequest_Validator{ + NumTranch: 0, + WithBeacon: true, + BeaconCount: 2, + }, + }, + }) + if err != nil { + panic(err) + } + + timer := framework.NewChainTime(genesisTime, uint64(config.Spec.SecondsPerSlot), uint64(config.Spec.SlotsPerEpoch)) + go timer.Run() + + for c := range timer.ResCh { + if c.Epoch == 2 { + break + } + } + + fmt.Println("- done -") + for _, node := range resp.Nodes { + if node.Type == proto.NodeType_Beacon { + client := http.NewHttpClient(node.GetAddr(proto.NodePortHttp)) + fmt.Println(client.NodeIdentity()) + } + } +} diff --git a/e2e/tests.go b/e2e/tests.go new file mode 100644 index 0000000..09bbc5c --- /dev/null +++ b/e2e/tests.go @@ -0,0 +1,5 @@ +package framework + +import ( + _ "github.com/umbracle/viewpoint/e2e/single" +) diff --git a/go.sum b/go.sum index c4c4597..4a701dc 100644 --- a/go.sum +++ b/go.sum @@ -70,8 +70,6 @@ github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go. github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/ferranbt/fastssz v0.1.0 h1:IXYgeThN82mYwjuSfGj6sYNpJol4wNnyeeQLjlmW8i8= -github.com/ferranbt/fastssz v0.1.0/go.mod h1:S8yiDeAXy8f88W4Ul+0dBMPx49S05byYbmZD6Uv94K4= github.com/ferranbt/fastssz v0.1.1 h1:hBYNxKu51wjPC9sQYCjicmy5wtJqubENp3IiRVcdJBM= github.com/ferranbt/fastssz v0.1.1/go.mod h1:U2ZsxlYyvGeQGmadhz8PlEqwkBzDIhHwd3xuKrg2JIs= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -94,7 +92,6 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -159,7 +156,6 @@ github.com/mitchellh/cli v1.1.4 h1:qj8czE26AU4PbiaPXK5uVmMSM+V5BYsFBiM9HhGRLUA= github.com/mitchellh/cli v1.1.4/go.mod h1:vTLESy5mRhKOs9KDp0/RATawxP1UqBmdrpVRMnpcvKQ= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= -github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= diff --git a/internal/cmd/commands.go b/internal/cmd/commands.go index f53d1dd..b1ff397 100755 --- a/internal/cmd/commands.go +++ b/internal/cmd/commands.go @@ -7,6 +7,7 @@ import ( "github.com/mitchellh/cli" "github.com/ryanuber/columnize" + _ "github.com/umbracle/viewpoint/e2e" "github.com/umbracle/viewpoint/internal/cmd/server" "github.com/umbracle/viewpoint/internal/server/proto" "google.golang.org/grpc" @@ -61,6 +62,11 @@ func Commands() map[string]cli.CommandFactory { Meta: meta, }, nil }, + "e2e run": func() (cli.Command, error) { + return &E2ERunCommand{ + UI: ui, + }, nil + }, "version": func() (cli.Command, error) { return &VersionCommand{ UI: ui, diff --git a/internal/cmd/e2e_run.go b/internal/cmd/e2e_run.go new file mode 100644 index 0000000..8c0a497 --- /dev/null +++ b/internal/cmd/e2e_run.go @@ -0,0 +1,38 @@ +package cmd + +import ( + "flag" + + "github.com/mitchellh/cli" + "github.com/umbracle/viewpoint/e2e/framework" +) + +// E2ERunCommand is the command to deploy an e2e network +type E2ERunCommand struct { + UI cli.Ui +} + +// Help implements the cli.Command interface +func (c *E2ERunCommand) Help() string { + return "" +} + +// Synopsis implements the cli.Command interface +func (c *E2ERunCommand) Synopsis() string { + return "" +} + +// Run implements the cli.Command interface +func (c *E2ERunCommand) Run(args []string) int { + flags := flag.NewFlagSet("e2e run", flag.ContinueOnError) + + if err := flags.Parse(args); err != nil { + c.UI.Error(err.Error()) + return 1 + } + + f := framework.New() + f.Run() + + return 0 +} diff --git a/internal/docker/docker.go b/internal/docker/docker.go index e0b3679..cadce95 100644 --- a/internal/docker/docker.go +++ b/internal/docker/docker.go @@ -198,6 +198,10 @@ func (d *Docker) Deploy(spec *spec.Spec) (*node, error) { return n, nil } +func (n *node) GetPorts() map[string]uint64 { + return n.ports +} + func (n *node) Spec() *spec.Spec { return n.opts } diff --git a/internal/http/http.go b/internal/http/http.go index ab57e51..7bb0a74 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -53,3 +53,16 @@ func (h *HttpClient) NodeIdentity() (*Identity, error) { err := h.get("/eth/v1/node/identity", &out) return out, err } + +type Syncing struct { + HeadSlot string + SyncDistance string + IsSyncing bool + IsOptimisitic bool +} + +func (h *HttpClient) Syncing() (*Syncing, error) { + var out *Syncing + err := h.get("/eth/v1/node/syncing", &out) + return out, err +} diff --git a/internal/server/proto/service.pb.go b/internal/server/proto/service.pb.go index 485e351..b22444c 100644 --- a/internal/server/proto/service.pb.go +++ b/internal/server/proto/service.pb.go @@ -704,6 +704,7 @@ type Node struct { Type NodeType `protobuf:"varint,2,opt,name=type,proto3,enum=proto.NodeType" json:"type,omitempty"` Client NodeClient `protobuf:"varint,3,opt,name=client,proto3,enum=proto.NodeClient" json:"client,omitempty"` Labels map[string]string `protobuf:"bytes,4,rep,name=labels,proto3" json:"labels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Ports map[string]uint64 `protobuf:"bytes,5,rep,name=ports,proto3" json:"ports,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` } func (x *Node) Reset() { @@ -766,6 +767,13 @@ func (x *Node) GetLabels() map[string]string { return nil } +func (x *Node) GetPorts() map[string]uint64 { + if x != nil { + return x.Ports + } + return nil +} + type AccountStub struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1072,7 +1080,7 @@ var file_internal_server_proto_service_proto_rawDesc = []byte{ 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x6e, 0x6f, 0x64, - 0x65, 0x22, 0xd6, 0x01, 0x0a, 0x04, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, + 0x65, 0x22, 0xbe, 0x02, 0x0a, 0x04, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, @@ -1081,59 +1089,65 @@ var file_internal_server_proto_service_proto_rawDesc = []byte{ 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x2f, 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x2e, 0x4c, 0x61, 0x62, 0x65, - 0x6c, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x1a, - 0x39, 0x0a, 0x0b, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, - 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, - 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x3f, 0x0a, 0x0b, 0x41, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x75, 0x62, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x69, - 0x76, 0x4b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x69, 0x76, - 0x4b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x75, 0x62, 0x4b, 0x65, 0x79, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x75, 0x62, 0x4b, 0x65, 0x79, 0x22, 0x7b, 0x0a, 0x0b, 0x54, - 0x72, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x53, 0x74, 0x75, 0x62, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, - 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, - 0x12, 0x2e, 0x0a, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, - 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x2a, 0x42, 0x0a, 0x08, 0x4e, 0x6f, 0x64, 0x65, - 0x54, 0x79, 0x70, 0x65, 0x12, 0x0d, 0x0a, 0x09, 0x4f, 0x74, 0x68, 0x65, 0x72, 0x54, 0x79, 0x70, - 0x65, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x42, 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x10, 0x01, 0x12, - 0x0d, 0x0a, 0x09, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x10, 0x02, 0x12, 0x0c, - 0x0a, 0x08, 0x42, 0x6f, 0x6f, 0x74, 0x6e, 0x6f, 0x64, 0x65, 0x10, 0x03, 0x2a, 0x42, 0x0a, 0x0a, - 0x4e, 0x6f, 0x64, 0x65, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x0f, 0x0a, 0x0b, 0x4f, 0x74, - 0x68, 0x65, 0x72, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x50, - 0x72, 0x79, 0x73, 0x6d, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x65, 0x6b, 0x75, 0x10, 0x02, - 0x12, 0x0e, 0x0a, 0x0a, 0x4c, 0x69, 0x67, 0x68, 0x74, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x10, 0x03, - 0x2a, 0x29, 0x0a, 0x04, 0x46, 0x6f, 0x72, 0x6b, 0x12, 0x0a, 0x0a, 0x06, 0x50, 0x68, 0x61, 0x73, - 0x65, 0x30, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x41, 0x6c, 0x74, 0x61, 0x69, 0x72, 0x10, 0x01, - 0x12, 0x09, 0x0a, 0x05, 0x4d, 0x65, 0x72, 0x67, 0x65, 0x10, 0x02, 0x32, 0xe1, 0x02, 0x0a, 0x0a, - 0x45, 0x32, 0x45, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x4a, 0x0a, 0x0d, 0x44, 0x65, - 0x70, 0x6f, 0x73, 0x69, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x1b, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, 0x0a, 0x0b, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, - 0x74, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, - 0x70, 0x6f, 0x73, 0x69, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, - 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0a, - 0x4e, 0x6f, 0x64, 0x65, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, - 0x65, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x3b, 0x0a, 0x08, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x16, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, - 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0a, - 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, - 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, - 0x18, 0x5a, 0x16, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x73, 0x65, 0x72, - 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x6c, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x12, + 0x2c, 0x0a, 0x05, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x16, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x2e, 0x50, 0x6f, 0x72, 0x74, + 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x1a, 0x39, 0x0a, + 0x0b, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x38, 0x0a, 0x0a, 0x50, 0x6f, 0x72, 0x74, + 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, + 0x38, 0x01, 0x22, 0x3f, 0x0a, 0x0b, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x75, + 0x62, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x69, 0x76, 0x4b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x69, 0x76, 0x4b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x70, + 0x75, 0x62, 0x4b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x75, 0x62, + 0x4b, 0x65, 0x79, 0x22, 0x7b, 0x0a, 0x0b, 0x54, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x53, 0x74, + 0x75, 0x62, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x04, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x2e, 0x0a, 0x08, 0x61, 0x63, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, + 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, + 0x70, 0x61, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, + 0x2a, 0x42, 0x0a, 0x08, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0d, 0x0a, 0x09, + 0x4f, 0x74, 0x68, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x42, + 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x56, 0x61, 0x6c, 0x69, 0x64, + 0x61, 0x74, 0x6f, 0x72, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x42, 0x6f, 0x6f, 0x74, 0x6e, 0x6f, + 0x64, 0x65, 0x10, 0x03, 0x2a, 0x42, 0x0a, 0x0a, 0x4e, 0x6f, 0x64, 0x65, 0x43, 0x6c, 0x69, 0x65, + 0x6e, 0x74, 0x12, 0x0f, 0x0a, 0x0b, 0x4f, 0x74, 0x68, 0x65, 0x72, 0x43, 0x6c, 0x69, 0x65, 0x6e, + 0x74, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x50, 0x72, 0x79, 0x73, 0x6d, 0x10, 0x01, 0x12, 0x08, + 0x0a, 0x04, 0x54, 0x65, 0x6b, 0x75, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x4c, 0x69, 0x67, 0x68, + 0x74, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x10, 0x03, 0x2a, 0x29, 0x0a, 0x04, 0x46, 0x6f, 0x72, 0x6b, + 0x12, 0x0a, 0x0a, 0x06, 0x50, 0x68, 0x61, 0x73, 0x65, 0x30, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, + 0x41, 0x6c, 0x74, 0x61, 0x69, 0x72, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x4d, 0x65, 0x72, 0x67, + 0x65, 0x10, 0x02, 0x32, 0xe1, 0x02, 0x0a, 0x0a, 0x45, 0x32, 0x45, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x12, 0x4a, 0x0a, 0x0d, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x12, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x70, 0x6f, + 0x73, 0x69, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, + 0x0a, 0x0b, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x19, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x4c, 0x69, 0x73, + 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0a, 0x4e, 0x6f, 0x64, 0x65, 0x44, 0x65, 0x70, 0x6c, + 0x6f, 0x79, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x44, + 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x4e, 0x6f, 0x64, 0x65, 0x4c, + 0x69, 0x73, 0x74, 0x12, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, + 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0a, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x18, 0x5a, 0x16, 0x2f, 0x69, 0x6e, 0x74, 0x65, + 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1149,7 +1163,7 @@ func file_internal_server_proto_service_proto_rawDescGZIP() []byte { } var file_internal_server_proto_service_proto_enumTypes = make([]protoimpl.EnumInfo, 3) -var file_internal_server_proto_service_proto_msgTypes = make([]protoimpl.MessageInfo, 16) +var file_internal_server_proto_service_proto_msgTypes = make([]protoimpl.MessageInfo, 17) var file_internal_server_proto_service_proto_goTypes = []interface{}{ (NodeType)(0), // 0: proto.NodeType (NodeClient)(0), // 1: proto.NodeClient @@ -1170,6 +1184,7 @@ var file_internal_server_proto_service_proto_goTypes = []interface{}{ (*NodeDeployRequest_Beacon)(nil), // 16: proto.NodeDeployRequest.Beacon (*NodeDeployRequest_Validator)(nil), // 17: proto.NodeDeployRequest.Validator nil, // 18: proto.Node.LabelsEntry + nil, // 19: proto.Node.PortsEntry } var file_internal_server_proto_service_proto_depIdxs = []int32{ 15, // 0: proto.DepositListResponse.tranches:type_name -> proto.TrancheStub @@ -1183,22 +1198,23 @@ var file_internal_server_proto_service_proto_depIdxs = []int32{ 0, // 8: proto.Node.type:type_name -> proto.NodeType 1, // 9: proto.Node.client:type_name -> proto.NodeClient 18, // 10: proto.Node.labels:type_name -> proto.Node.LabelsEntry - 14, // 11: proto.TrancheStub.accounts:type_name -> proto.AccountStub - 5, // 12: proto.E2EService.DepositCreate:input_type -> proto.DepositCreateRequest - 3, // 13: proto.E2EService.DepositList:input_type -> proto.DepositListRequest - 7, // 14: proto.E2EService.NodeDeploy:input_type -> proto.NodeDeployRequest - 9, // 15: proto.E2EService.NodeList:input_type -> proto.NodeListRequest - 11, // 16: proto.E2EService.NodeStatus:input_type -> proto.NodeStatusRequest - 6, // 17: proto.E2EService.DepositCreate:output_type -> proto.DepositCreateResponse - 4, // 18: proto.E2EService.DepositList:output_type -> proto.DepositListResponse - 8, // 19: proto.E2EService.NodeDeploy:output_type -> proto.NodeDeployResponse - 10, // 20: proto.E2EService.NodeList:output_type -> proto.NodeListResponse - 12, // 21: proto.E2EService.NodeStatus:output_type -> proto.NodeStatusResponse - 17, // [17:22] is the sub-list for method output_type - 12, // [12:17] is the sub-list for method input_type - 12, // [12:12] is the sub-list for extension type_name - 12, // [12:12] is the sub-list for extension extendee - 0, // [0:12] is the sub-list for field type_name + 19, // 11: proto.Node.ports:type_name -> proto.Node.PortsEntry + 14, // 12: proto.TrancheStub.accounts:type_name -> proto.AccountStub + 5, // 13: proto.E2EService.DepositCreate:input_type -> proto.DepositCreateRequest + 3, // 14: proto.E2EService.DepositList:input_type -> proto.DepositListRequest + 7, // 15: proto.E2EService.NodeDeploy:input_type -> proto.NodeDeployRequest + 9, // 16: proto.E2EService.NodeList:input_type -> proto.NodeListRequest + 11, // 17: proto.E2EService.NodeStatus:input_type -> proto.NodeStatusRequest + 6, // 18: proto.E2EService.DepositCreate:output_type -> proto.DepositCreateResponse + 4, // 19: proto.E2EService.DepositList:output_type -> proto.DepositListResponse + 8, // 20: proto.E2EService.NodeDeploy:output_type -> proto.NodeDeployResponse + 10, // 21: proto.E2EService.NodeList:output_type -> proto.NodeListResponse + 12, // 22: proto.E2EService.NodeStatus:output_type -> proto.NodeStatusResponse + 18, // [18:23] is the sub-list for method output_type + 13, // [13:18] is the sub-list for method input_type + 13, // [13:13] is the sub-list for extension type_name + 13, // [13:13] is the sub-list for extension extendee + 0, // [0:13] is the sub-list for field type_name } func init() { file_internal_server_proto_service_proto_init() } @@ -1398,7 +1414,7 @@ func file_internal_server_proto_service_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_internal_server_proto_service_proto_rawDesc, NumEnums: 3, - NumMessages: 16, + NumMessages: 17, NumExtensions: 0, NumServices: 1, }, diff --git a/internal/server/proto/service.proto b/internal/server/proto/service.proto index 462b601..d0f6b79 100644 --- a/internal/server/proto/service.proto +++ b/internal/server/proto/service.proto @@ -74,6 +74,7 @@ message Node { NodeType type = 2; NodeClient client = 3; map labels = 4; + map ports = 5; } enum NodeType { diff --git a/internal/server/proto/utils.go b/internal/server/proto/utils.go index e488beb..96925d8 100644 --- a/internal/server/proto/utils.go +++ b/internal/server/proto/utils.go @@ -2,6 +2,7 @@ package proto import ( "encoding/hex" + "fmt" "strings" "github.com/umbracle/ethgo/wallet" @@ -49,6 +50,10 @@ const ( NodePortBootnode = "eth.bootnode" ) +func (n *Node) GetAddr(name string) string { + return fmt.Sprintf("http://127.0.0.1:%d", n.Ports[name]) +} + func (n NodePort) IsTCP() bool { return n != NodePortBootnode } diff --git a/internal/server/server.go b/internal/server/server.go index 2f4a34d..c395d89 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -591,6 +591,7 @@ func specNodeToNode(n spec.Node) (*proto.Node, error) { Type: typ, Client: clt, Labels: spec.Labels, + Ports: n.GetPorts(), } return resp, nil } diff --git a/internal/spec/spec.go b/internal/spec/spec.go index 65093a8..3c1dba5 100644 --- a/internal/spec/spec.go +++ b/internal/spec/spec.go @@ -9,6 +9,7 @@ import ( type Node interface { GetAddr(port string) string GetLogs() (string, error) + GetPorts() map[string]uint64 Spec() *Spec Stop() error } From 968d618270ff82a14f1887ff0bfa4d01b37dc2ec Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Sat, 6 Aug 2022 18:00:32 +0200 Subject: [PATCH 2/3] Clean more code --- Makefile | 4 - e2e/single/single.go | 6 +- go.mod | 4 +- go.sum | 10 +- internal/genesis/genesis.go | 86 +- internal/genesis/structs.go | 228 -- internal/genesis/structs_encoding.go | 4734 -------------------------- internal/http/http.go | 68 - 8 files changed, 78 insertions(+), 5062 deletions(-) delete mode 100644 internal/genesis/structs.go delete mode 100644 internal/genesis/structs_encoding.go delete mode 100644 internal/http/http.go diff --git a/Makefile b/Makefile index e937e44..4e2f355 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,3 @@ -sszgen: - sszgen --path internal/server/proto/structs.go - sszgen --path internal/genesis/structs.go - protoc: protoc --go_out=. --go-grpc_out=. ./internal/server/proto/*.proto diff --git a/e2e/single/single.go b/e2e/single/single.go index 3420b39..1fc05f2 100644 --- a/e2e/single/single.go +++ b/e2e/single/single.go @@ -6,8 +6,8 @@ import ( "time" "github.com/hashicorp/go-hclog" + "github.com/umbracle/go-eth-consensus/http" "github.com/umbracle/viewpoint/e2e/framework" - "github.com/umbracle/viewpoint/internal/http" "github.com/umbracle/viewpoint/internal/server" "github.com/umbracle/viewpoint/internal/server/proto" ) @@ -61,8 +61,8 @@ func (s *SingleDeployment) Run(f *framework.F) { fmt.Println("- done -") for _, node := range resp.Nodes { if node.Type == proto.NodeType_Beacon { - client := http.NewHttpClient(node.GetAddr(proto.NodePortHttp)) - fmt.Println(client.NodeIdentity()) + client := http.New(node.GetAddr(proto.NodePortHttp)) + fmt.Println(client.Node().Identity()) } } } diff --git a/go.mod b/go.mod index 8da67b4..c274bc7 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/ryanuber/columnize v2.1.2+incompatible github.com/stretchr/testify v1.8.0 github.com/umbracle/ethgo v0.1.3 - github.com/umbracle/go-eth-consensus v0.1.0 + github.com/umbracle/go-eth-consensus v0.1.1-0.20220804213956-353d32a1ea06 google.golang.org/grpc v1.47.0 google.golang.org/protobuf v1.28.0 ) @@ -57,6 +57,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/posener/complete v1.1.1 // indirect + github.com/r3labs/sse v0.0.0-20210224172625-26fe804710bc // indirect github.com/shopspring/decimal v1.2.0 // indirect github.com/sirupsen/logrus v1.4.2 // indirect github.com/spf13/cast v1.3.1 // indirect @@ -72,6 +73,7 @@ require ( golang.org/x/text v0.3.3 // indirect golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect + gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gotest.tools/v3 v3.2.0 // indirect diff --git a/go.sum b/go.sum index 2ff2efa..4e25f36 100644 --- a/go.sum +++ b/go.sum @@ -173,6 +173,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/r3labs/sse v0.0.0-20210224172625-26fe804710bc h1:zAsgcP8MhzAbhMnB1QQ2O7ZhWYVGYSR2iVcjzQuPV+o= +github.com/r3labs/sse v0.0.0-20210224172625-26fe804710bc/go.mod h1:S8xSOnV3CgpNrWd0GQ/OoQfMtlg2uPRSuTzcSGrzwK8= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/ryanuber/columnize v2.1.2+incompatible h1:C89EOx/XBWwIXl8wm8OPJBd7kPF25UfsK2X7Ph/zCAk= github.com/ryanuber/columnize v2.1.2+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= @@ -188,6 +190,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -202,10 +205,10 @@ github.com/umbracle/ethgo v0.1.3 h1:s8D7Rmphnt71zuqrgsGTMS5gTNbueGO1zKLh7qsFzTM= github.com/umbracle/ethgo v0.1.3/go.mod h1:g9zclCLixH8liBI27Py82klDkW7Oo33AxUOr+M9lzrU= github.com/umbracle/fastrlp v0.0.0-20220527094140-59d5dd30e722 h1:10Nbw6cACsnQm7r34zlpJky+IzxVLRk6MKTS2d3Vp0E= github.com/umbracle/fastrlp v0.0.0-20220527094140-59d5dd30e722/go.mod h1:c8J0h9aULj2i3umrfyestM6jCq0LK0U6ly6bWy96nd4= -github.com/umbracle/go-eth-consensus v0.0.0-20220729142744-8aee439e6678 h1:Fk8HaNRXCqTpef1AmANX9tbNaR7yWKc0K71MZ0XtAAg= -github.com/umbracle/go-eth-consensus v0.0.0-20220729142744-8aee439e6678/go.mod h1:OTPUHe4DsFq5pM9Lke1EwkhgJDXMnK+iAwTCoyrB2+Q= github.com/umbracle/go-eth-consensus v0.1.0 h1:xm/0HCvFxrIHeiVfYoMJ9ZLbMe7IghWA52eWB2Rtfag= github.com/umbracle/go-eth-consensus v0.1.0/go.mod h1:qEdbWIH3Ud7mRhUlOxNfScXX1JjcqHOqP355Ei14G3s= +github.com/umbracle/go-eth-consensus v0.1.1-0.20220804213956-353d32a1ea06 h1:1/OT5qmvr4nQBHMQnqpZJsc33iln/NLRjT7vO/lxI+E= +github.com/umbracle/go-eth-consensus v0.1.1-0.20220804213956-353d32a1ea06/go.mod h1:qEdbWIH3Ud7mRhUlOxNfScXX1JjcqHOqP355Ei14G3s= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.4.0 h1:PuaTGZIw3mjYhhhbVbCQp8aciRZN9YdoB7MGX9Ko76A= @@ -240,6 +243,7 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= @@ -317,6 +321,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y= +gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= diff --git a/internal/genesis/genesis.go b/internal/genesis/genesis.go index 8b6fb9c..e0482db 100644 --- a/internal/genesis/genesis.go +++ b/internal/genesis/genesis.go @@ -5,6 +5,7 @@ import ( ssz "github.com/ferranbt/fastssz" "github.com/umbracle/ethgo" + consensus "github.com/umbracle/go-eth-consensus" "github.com/umbracle/viewpoint/internal/server/proto" ) @@ -18,22 +19,25 @@ type Input struct { ForkVersion [4]byte } +var depositRoot [32]byte + +func init() { + depositRoot = ethgo.HexToHash("d70a234731285c6804c2a4f56711ddb8c82c99740f207854891028af34e27e5e") +} + func GenerateGenesis(input *Input) (ssz.Marshaler, error) { if uint64(input.GenesisTime) < input.Eth1Block.Timestamp { return nil, fmt.Errorf("low timestamp") } - depositRoot := ethgo.HexToHash("d70a234731285c6804c2a4f56711ddb8c82c99740f207854891028af34e27e5e") - - validators := []*Validator{} + validators := []*consensus.Validator{} balances := []uint64{} for _, val := range input.InitialValidator { pubKey := val.Bls.PubKey() - validators = append(validators, &Validator{ - Pubkey: pubKey[:], - WithdrawalCredentials: make([]byte, 32), + validators = append(validators, &consensus.Validator{ + Pubkey: pubKey, ActivationEligibilityEpoch: 0, ActivationEpoch: 0, EffectiveBalance: minValidatorBalance, @@ -57,28 +61,28 @@ func GenerateGenesis(input *Input) (ssz.Marshaler, error) { slashings = append(slashings, 0) } - fork := &Fork{ + fork := &consensus.Fork{ CurrentVersion: input.ForkVersion, } var state ssz.Marshaler if input.Fork == proto.Fork_Phase0 { - body := BeaconBlockBodyPhase0{ - Eth1Data: &Eth1Data{}, + body := consensus.BeaconBlockBodyPhase0{ + Eth1Data: &consensus.Eth1Data{}, } bodyRoot, err := body.HashTreeRoot() if err != nil { return nil, err } - state = &BeaconStatePhase0{ - GenesisTime: uint64(input.GenesisTime), // + 1 minute - GenesisValidatorsRoot: genesisValidatorRoot, + state = &consensus.BeaconStatePhase0{ + GenesisTime: uint64(input.GenesisTime), + GenesisValidatorsRoot: genesisValidatorRoot[:], Fork: fork, - LatestBlockHeader: &BeaconBlockHeader{ + LatestBlockHeader: &consensus.BeaconBlockHeader{ BodyRoot: bodyRoot, }, - Eth1Data: &Eth1Data{ + Eth1Data: &consensus.Eth1Data{ DepositRoot: depositRoot, BlockHash: input.Eth1Block.Hash, }, @@ -87,23 +91,23 @@ func GenerateGenesis(input *Input) (ssz.Marshaler, error) { Slashings: slashings, } } else if input.Fork == proto.Fork_Altair { - body := BeaconBlockBodyAltair{ - Eth1Data: &Eth1Data{}, - SyncAggregate: &SyncAggregate{}, + body := consensus.BeaconBlockBodyAltair{ + Eth1Data: &consensus.Eth1Data{}, + SyncAggregate: &consensus.SyncAggregate{}, } bodyRoot, err := body.HashTreeRoot() if err != nil { return nil, err } - state = &BeaconStateAltair{ - GenesisTime: uint64(input.GenesisTime), // + 1 minute - GenesisValidatorsRoot: genesisValidatorRoot, + state = &consensus.BeaconStateAltair{ + GenesisTime: uint64(input.GenesisTime), + GenesisValidatorsRoot: genesisValidatorRoot[:], Fork: fork, - LatestBlockHeader: &BeaconBlockHeader{ + LatestBlockHeader: &consensus.BeaconBlockHeader{ BodyRoot: bodyRoot, }, - Eth1Data: &Eth1Data{ + Eth1Data: &consensus.Eth1Data{ DepositRoot: depositRoot, BlockHash: input.Eth1Block.Hash, }, @@ -115,3 +119,41 @@ func GenerateGenesis(input *Input) (ssz.Marshaler, error) { return state, nil } + +type ValidatorSet struct { + Set []*consensus.Validator `ssz-max:"1099511627776"` +} + +// HashTreeRoot ssz hashes the ValidatorSet object +func (v *ValidatorSet) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(v) +} + +// HashTreeRootWith ssz hashes the ValidatorSet object with a hasher +func (v *ValidatorSet) HashTreeRootWith(hh ssz.HashWalker) (err error) { + indx := hh.Index() + + // Field (0) 'Set' + { + subIndx := hh.Index() + num := uint64(len(v.Set)) + if num > 1099511627776 { + err = ssz.ErrIncorrectListSize + return + } + for _, elem := range v.Set { + if err = elem.HashTreeRootWith(hh); err != nil { + return + } + } + hh.MerkleizeWithMixin(subIndx, num, 1099511627776) + } + + hh.Merkleize(indx) + return +} + +// GetTree ssz hashes the ValidatorSet object +func (v *ValidatorSet) GetTree() (*ssz.Node, error) { + return ssz.ProofTree(v) +} diff --git a/internal/genesis/structs.go b/internal/genesis/structs.go deleted file mode 100644 index 6d896c9..0000000 --- a/internal/genesis/structs.go +++ /dev/null @@ -1,228 +0,0 @@ -package genesis - -type AggregateAndProof struct { - Index uint64 `json:"aggregator_index"` - Aggregate *Attestation `json:"aggregate"` - SelectionProof []byte `json:"selection_proof" ssz-size:"96"` -} - -type Checkpoint struct { - Epoch uint64 `json:"epoch"` - Root [32]byte `json:"root" ssz-size:"32"` -} - -type AttestationData struct { - Slot uint32 `json:"slot"` - Index uint64 `json:"index"` - BeaconBlockHash [32]byte `json:"beacon_block_root" ssz-size:"32"` - Source *Checkpoint `json:"source"` - Target *Checkpoint `json:"target"` -} - -type Attestation struct { - AggregationBits []byte `json:"aggregation_bits" ssz:"bitlist" ssz-max:"2048"` - Data *AttestationData `json:"data"` - Signature []byte `json:"signature" ssz-size:"96"` -} - -type DepositData struct { - Pubkey [48]byte `json:"pubkey" ssz-size:"48"` - WithdrawalCredentials [32]byte `json:"withdrawal_credentials" ssz-size:"32"` - Amount uint64 `json:"amount"` - Signature []byte `json:"signature" ssz-size:"96"` - Root [32]byte `ssz:"-"` -} - -type Deposit struct { - Proof [][]byte `ssz-size:"33,32"` - Data *DepositData -} - -type DepositMessage struct { - Pubkey []byte `json:"pubkey" ssz-size:"48"` - WithdrawalCredentials []byte `json:"withdrawal_credentials" ssz-size:"32"` - Amount uint64 `json:"amount"` -} - -type IndexedAttestation struct { - AttestationIndices []uint64 `json:"attesting_indices" ssz-max:"2048"` - Data *AttestationData `json:"data"` - Signature []byte `json:"signature" ssz-size:"96"` -} - -type PendingAttestation struct { - AggregationBits []byte `json:"aggregation_bits" ssz:"bitlist" ssz-max:"2048"` - Data *AttestationData `json:"data"` - InclusionDelay uint64 `json:"inclusion_delay"` - ProposerIndex uint64 `json:"proposer_index"` -} - -type Fork struct { - PreviousVersion [4]byte `json:"previous_version" ssz-size:"4"` - CurrentVersion [4]byte `json:"current_version" ssz-size:"4"` - Epoch uint64 `json:"epoch"` -} - -type Validator struct { - Pubkey []byte `json:"pubkey" ssz-size:"48"` - WithdrawalCredentials []byte `json:"withdrawal_credentials" ssz-size:"32"` - EffectiveBalance uint64 `json:"effective_balance"` - Slashed bool `json:"slashed"` - ActivationEligibilityEpoch uint64 `json:"activation_eligibility_epoch"` - ActivationEpoch uint64 `json:"activation_epoch"` - ExitEpoch uint64 `json:"exit_epoch"` - WithdrawableEpoch uint64 `json:"withdrawable_epoch"` -} - -type ValidatorSet struct { - Set []*Validator `ssz-max:"1099511627776"` -} - -type VoluntaryExit struct { - Epoch uint64 `json:"epoch"` - ValidatorIndex uint64 `json:"validator_index"` -} - -type SignedVoluntaryExit struct { - Exit *VoluntaryExit `json:"message"` - Signature [96]byte `json:"signature" ssz-size:"96"` -} - -type Eth1Block struct { - Timestamp uint64 `json:"timestamp"` - DepositRoot []byte `json:"deposit_root" ssz-size:"32"` - DepositCount uint64 `json:"deposit_count" ssz-size:"32"` -} - -type Eth1Data struct { - DepositRoot [32]byte `json:"deposit_root" ssz-size:"32"` - DepositCount uint64 `json:"deposit_count"` - BlockHash [32]byte `json:"block_hash" ssz-size:"32"` -} - -type SigningRoot struct { - ObjectRoot []byte `json:"object_root" ssz-size:"32"` - Domain []byte `json:"domain" ssz-size:"8"` -} - -type HistoricalBatch struct { - BlockRoots [][32]byte `json:"block_roots" ssz-size:"8192,32"` - StateRoots [][32]byte `json:"state_roots" ssz-size:"8192,32"` -} - -type ProposerSlashing struct { - Header1 *SignedBeaconBlockHeader `json:"signed_header_1"` - Header2 *SignedBeaconBlockHeader `json:"signed_header_2"` -} - -type AttesterSlashing struct { - Attestation1 *IndexedAttestation `json:"attestation_1"` - Attestation2 *IndexedAttestation `json:"attestation_2"` -} - -type Transfer struct { - Sender uint64 `json:"sender"` - Recipient uint64 `json:"recipient"` - Amount uint64 `json:"amount"` - Fee uint64 `json:"fee"` - Slot uint64 `json:"slot"` - Pubkey []byte `json:"pubkey" ssz-size:"48"` - Signature []byte `json:"signature" ssz-size:"96"` -} - -type BeaconStatePhase0 struct { - GenesisTime uint64 `json:"genesis_time"` - GenesisValidatorsRoot [32]byte `json:"genesis_validators_root" ssz-size:"32"` - Slot uint64 `json:"slot"` - Fork *Fork `json:"fork"` - LatestBlockHeader *BeaconBlockHeader `json:"latest_block_header"` - BlockRoots [8192][32]byte `json:"block_roots" ssz-size:"8192,32"` - StateRoots [8192][32]byte `json:"state_roots" ssz-size:"8192,32"` - HistoricalRoots [][32]byte `json:"historical_roots" ssz-max:"16777216" ssz-size:"?,32"` - Eth1Data *Eth1Data `json:"eth1_data"` - Eth1DataVotes []*Eth1Data `json:"eth1_data_votes" ssz-max:"2048"` - Eth1DepositIndex uint64 `json:"eth1_deposit_index"` - Validators []*Validator `json:"validators" ssz-max:"1099511627776"` - Balances []uint64 `json:"balances" ssz-max:"1099511627776"` - RandaoMixes [65536][32]byte `json:"randao_mixes" ssz-size:"65536,32"` - Slashings []uint64 `json:"slashings" ssz-size:"8192"` - PreviousEpochAttestations []*PendingAttestation `json:"previous_epoch_attestations" ssz-max:"4096"` - CurrentEpochAttestations []*PendingAttestation `json:"current_epoch_attestations" ssz-max:"4096"` - JustificationBits [1]byte `json:"justification_bits" ssz-size:"1"` - PreviousJustifiedCheckpoint *Checkpoint `json:"previous_justified_checkpoint"` - CurrentJustifiedCheckpoint *Checkpoint `json:"current_justified_checkpoint"` - FinalizedCheckpoint *Checkpoint `json:"finalized_checkpoint"` -} - -type BeaconBlockBodyPhase0 struct { - RandaoReveal [96]byte `json:"randao_reveal" ssz-size:"96"` - Eth1Data *Eth1Data `json:"eth1_data"` - Graffiti [32]byte `json:"graffiti" ssz-size:"32"` - ProposerSlashings []*ProposerSlashing `json:"proposer_slashings" ssz-max:"16"` - AttesterSlashings []*AttesterSlashing `json:"attester_slashings" ssz-max:"2"` - Attestations []*Attestation `json:"attestations" ssz-max:"128"` - Deposits []*Deposit `json:"deposits" ssz-max:"16"` - VoluntaryExits []*SignedVoluntaryExit `json:"voluntary_exits" ssz-max:"16"` -} - -type BeaconStateAltair struct { - GenesisTime uint64 `json:"genesis_time"` - GenesisValidatorsRoot [32]byte `json:"genesis_validators_root" ssz-size:"32"` - Slot uint64 `json:"slot"` - Fork *Fork `json:"fork"` - LatestBlockHeader *BeaconBlockHeader `json:"latest_block_header"` - BlockRoots [8192][32]byte `json:"block_roots" ssz-size:"8192,32"` - StateRoots [8192][32]byte `json:"state_roots" ssz-size:"8192,32"` - HistoricalRoots [][32]byte `json:"historical_roots" ssz-max:"16777216" ssz-size:"?,32"` - Eth1Data *Eth1Data `json:"eth1_data"` - Eth1DataVotes []*Eth1Data `json:"eth1_data_votes" ssz-max:"2048"` - Eth1DepositIndex uint64 `json:"eth1_deposit_index"` - Validators []*Validator `json:"validators" ssz-max:"1099511627776"` - Balances []uint64 `json:"balances" ssz-max:"1099511627776"` - RandaoMixes [65536][32]byte `json:"randao_mixes" ssz-size:"65536,32"` - Slashings []uint64 `json:"slashings" ssz-size:"8192"` - PreviousEpochParticipation []byte `json:"previous_epoch_participation" ssz-max:"1099511627776"` - CurrentEpochParticipation []byte `json:"current_epoch_participation" ssz-max:"1099511627776"` - JustificationBits [1]byte `json:"justification_bits" ssz-size:"1"` - PreviousJustifiedCheckpoint *Checkpoint `json:"previous_justified_checkpoint"` - CurrentJustifiedCheckpoint *Checkpoint `json:"current_justified_checkpoint"` - FinalizedCheckpoint *Checkpoint `json:"finalized_checkpoint"` - InactivityScores []uint64 `json:"inactivity_scores" ssz-max:"1099511627776"` - CurrentSyncCommittee *SyncCommittee `json:"current_sync_committee"` - NextSyncCommittee *SyncCommittee `json:"next_sync_committee"` -} - -type BeaconBlockBodyAltair struct { - RandaoReveal [96]byte `json:"randao_reveal" ssz-size:"96"` - Eth1Data *Eth1Data `json:"eth1_data"` - Graffiti [32]byte `json:"graffiti" ssz-size:"32"` - ProposerSlashings []*ProposerSlashing `json:"proposer_slashings" ssz-max:"16"` - AttesterSlashings []*AttesterSlashing `json:"attester_slashings" ssz-max:"2"` - Attestations []*Attestation `json:"attestations" ssz-max:"128"` - Deposits []*Deposit `json:"deposits" ssz-max:"16"` - VoluntaryExits []*SignedVoluntaryExit `json:"voluntary_exits" ssz-max:"16"` - SyncAggregate *SyncAggregate `json:"sync_aggregate"` -} - -type SignedBeaconBlockHeader struct { - Header *BeaconBlockHeader `json:"message"` - Signature []byte `json:"signature" ssz-size:"96"` -} - -type BeaconBlockHeader struct { - Slot uint64 `json:"slot"` - ProposerIndex uint64 `json:"proposer_index"` - ParentRoot [32]byte `json:"parent_root" ssz-size:"32"` - StateRoot [32]byte `json:"state_root" ssz-size:"32"` - BodyRoot [32]byte `json:"body_root" ssz-size:"32"` -} - -type SyncCommittee struct { - PubKeys [512][48]byte `json:"pubkeys" ssz-size:"512,48"` - AggregatePubKey [48]byte `json:"aggregate_pubkey" ssz-size:"48"` -} - -type SyncAggregate struct { - SyncCommiteeBits [64]byte `json:"sync_committee_bits" ssz-size:"64"` - SyncCommiteeSignature [96]byte `json:"sync_committee_signature" ssz-size:"96"` -} diff --git a/internal/genesis/structs_encoding.go b/internal/genesis/structs_encoding.go deleted file mode 100644 index c52823d..0000000 --- a/internal/genesis/structs_encoding.go +++ /dev/null @@ -1,4734 +0,0 @@ -// Code generated by fastssz. DO NOT EDIT. -// Hash: 3f4e5e9d12e9916f534222ba15dedb0012d53bce5ef7ebc2d1b9e8ef61dd0a65 -package genesis - -import ( - ssz "github.com/ferranbt/fastssz" -) - -// MarshalSSZ ssz marshals the AggregateAndProof object -func (a *AggregateAndProof) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(a) -} - -// MarshalSSZTo ssz marshals the AggregateAndProof object to a target array -func (a *AggregateAndProof) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(108) - - // Field (0) 'Index' - dst = ssz.MarshalUint64(dst, a.Index) - - // Offset (1) 'Aggregate' - dst = ssz.WriteOffset(dst, offset) - if a.Aggregate == nil { - a.Aggregate = new(Attestation) - } - offset += a.Aggregate.SizeSSZ() - - // Field (2) 'SelectionProof' - if size := len(a.SelectionProof); size != 96 { - err = ssz.ErrBytesLengthFn("AggregateAndProof.SelectionProof", size, 96) - return - } - dst = append(dst, a.SelectionProof...) - - // Field (1) 'Aggregate' - if dst, err = a.Aggregate.MarshalSSZTo(dst); err != nil { - return - } - - return -} - -// UnmarshalSSZ ssz unmarshals the AggregateAndProof object -func (a *AggregateAndProof) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 108 { - return ssz.ErrSize - } - - tail := buf - var o1 uint64 - - // Field (0) 'Index' - a.Index = ssz.UnmarshallUint64(buf[0:8]) - - // Offset (1) 'Aggregate' - if o1 = ssz.ReadOffset(buf[8:12]); o1 > size { - return ssz.ErrOffset - } - - if o1 < 108 { - return ssz.ErrInvalidVariableOffset - } - - // Field (2) 'SelectionProof' - if cap(a.SelectionProof) == 0 { - a.SelectionProof = make([]byte, 0, len(buf[12:108])) - } - a.SelectionProof = append(a.SelectionProof, buf[12:108]...) - - // Field (1) 'Aggregate' - { - buf = tail[o1:] - if a.Aggregate == nil { - a.Aggregate = new(Attestation) - } - if err = a.Aggregate.UnmarshalSSZ(buf); err != nil { - return err - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the AggregateAndProof object -func (a *AggregateAndProof) SizeSSZ() (size int) { - size = 108 - - // Field (1) 'Aggregate' - if a.Aggregate == nil { - a.Aggregate = new(Attestation) - } - size += a.Aggregate.SizeSSZ() - - return -} - -// HashTreeRoot ssz hashes the AggregateAndProof object -func (a *AggregateAndProof) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(a) -} - -// HashTreeRootWith ssz hashes the AggregateAndProof object with a hasher -func (a *AggregateAndProof) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Index' - hh.PutUint64(a.Index) - - // Field (1) 'Aggregate' - if err = a.Aggregate.HashTreeRootWith(hh); err != nil { - return - } - - // Field (2) 'SelectionProof' - if size := len(a.SelectionProof); size != 96 { - err = ssz.ErrBytesLengthFn("AggregateAndProof.SelectionProof", size, 96) - return - } - hh.PutBytes(a.SelectionProof) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the AggregateAndProof object -func (a *AggregateAndProof) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(a) -} - -// MarshalSSZ ssz marshals the Checkpoint object -func (c *Checkpoint) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(c) -} - -// MarshalSSZTo ssz marshals the Checkpoint object to a target array -func (c *Checkpoint) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Epoch' - dst = ssz.MarshalUint64(dst, c.Epoch) - - // Field (1) 'Root' - dst = append(dst, c.Root[:]...) - - return -} - -// UnmarshalSSZ ssz unmarshals the Checkpoint object -func (c *Checkpoint) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 40 { - return ssz.ErrSize - } - - // Field (0) 'Epoch' - c.Epoch = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'Root' - copy(c.Root[:], buf[8:40]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the Checkpoint object -func (c *Checkpoint) SizeSSZ() (size int) { - size = 40 - return -} - -// HashTreeRoot ssz hashes the Checkpoint object -func (c *Checkpoint) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(c) -} - -// HashTreeRootWith ssz hashes the Checkpoint object with a hasher -func (c *Checkpoint) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Epoch' - hh.PutUint64(c.Epoch) - - // Field (1) 'Root' - hh.PutBytes(c.Root[:]) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the Checkpoint object -func (c *Checkpoint) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(c) -} - -// MarshalSSZ ssz marshals the AttestationData object -func (a *AttestationData) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(a) -} - -// MarshalSSZTo ssz marshals the AttestationData object to a target array -func (a *AttestationData) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Slot' - dst = ssz.MarshalUint32(dst, a.Slot) - - // Field (1) 'Index' - dst = ssz.MarshalUint64(dst, a.Index) - - // Field (2) 'BeaconBlockHash' - dst = append(dst, a.BeaconBlockHash[:]...) - - // Field (3) 'Source' - if a.Source == nil { - a.Source = new(Checkpoint) - } - if dst, err = a.Source.MarshalSSZTo(dst); err != nil { - return - } - - // Field (4) 'Target' - if a.Target == nil { - a.Target = new(Checkpoint) - } - if dst, err = a.Target.MarshalSSZTo(dst); err != nil { - return - } - - return -} - -// UnmarshalSSZ ssz unmarshals the AttestationData object -func (a *AttestationData) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 124 { - return ssz.ErrSize - } - - // Field (0) 'Slot' - a.Slot = ssz.UnmarshallUint32(buf[0:4]) - - // Field (1) 'Index' - a.Index = ssz.UnmarshallUint64(buf[4:12]) - - // Field (2) 'BeaconBlockHash' - copy(a.BeaconBlockHash[:], buf[12:44]) - - // Field (3) 'Source' - if a.Source == nil { - a.Source = new(Checkpoint) - } - if err = a.Source.UnmarshalSSZ(buf[44:84]); err != nil { - return err - } - - // Field (4) 'Target' - if a.Target == nil { - a.Target = new(Checkpoint) - } - if err = a.Target.UnmarshalSSZ(buf[84:124]); err != nil { - return err - } - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the AttestationData object -func (a *AttestationData) SizeSSZ() (size int) { - size = 124 - return -} - -// HashTreeRoot ssz hashes the AttestationData object -func (a *AttestationData) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(a) -} - -// HashTreeRootWith ssz hashes the AttestationData object with a hasher -func (a *AttestationData) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Slot' - hh.PutUint32(a.Slot) - - // Field (1) 'Index' - hh.PutUint64(a.Index) - - // Field (2) 'BeaconBlockHash' - hh.PutBytes(a.BeaconBlockHash[:]) - - // Field (3) 'Source' - if err = a.Source.HashTreeRootWith(hh); err != nil { - return - } - - // Field (4) 'Target' - if err = a.Target.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the AttestationData object -func (a *AttestationData) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(a) -} - -// MarshalSSZ ssz marshals the Attestation object -func (a *Attestation) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(a) -} - -// MarshalSSZTo ssz marshals the Attestation object to a target array -func (a *Attestation) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(224) - - // Offset (0) 'AggregationBits' - dst = ssz.WriteOffset(dst, offset) - offset += len(a.AggregationBits) - - // Field (1) 'Data' - if a.Data == nil { - a.Data = new(AttestationData) - } - if dst, err = a.Data.MarshalSSZTo(dst); err != nil { - return - } - - // Field (2) 'Signature' - if size := len(a.Signature); size != 96 { - err = ssz.ErrBytesLengthFn("Attestation.Signature", size, 96) - return - } - dst = append(dst, a.Signature...) - - // Field (0) 'AggregationBits' - if size := len(a.AggregationBits); size > 2048 { - err = ssz.ErrBytesLengthFn("Attestation.AggregationBits", size, 2048) - return - } - dst = append(dst, a.AggregationBits...) - - return -} - -// UnmarshalSSZ ssz unmarshals the Attestation object -func (a *Attestation) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 224 { - return ssz.ErrSize - } - - tail := buf - var o0 uint64 - - // Offset (0) 'AggregationBits' - if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { - return ssz.ErrOffset - } - - if o0 < 224 { - return ssz.ErrInvalidVariableOffset - } - - // Field (1) 'Data' - if a.Data == nil { - a.Data = new(AttestationData) - } - if err = a.Data.UnmarshalSSZ(buf[4:128]); err != nil { - return err - } - - // Field (2) 'Signature' - if cap(a.Signature) == 0 { - a.Signature = make([]byte, 0, len(buf[128:224])) - } - a.Signature = append(a.Signature, buf[128:224]...) - - // Field (0) 'AggregationBits' - { - buf = tail[o0:] - if err = ssz.ValidateBitlist(buf, 2048); err != nil { - return err - } - if cap(a.AggregationBits) == 0 { - a.AggregationBits = make([]byte, 0, len(buf)) - } - a.AggregationBits = append(a.AggregationBits, buf...) - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the Attestation object -func (a *Attestation) SizeSSZ() (size int) { - size = 224 - - // Field (0) 'AggregationBits' - size += len(a.AggregationBits) - - return -} - -// HashTreeRoot ssz hashes the Attestation object -func (a *Attestation) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(a) -} - -// HashTreeRootWith ssz hashes the Attestation object with a hasher -func (a *Attestation) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'AggregationBits' - if len(a.AggregationBits) == 0 { - err = ssz.ErrEmptyBitlist - return - } - hh.PutBitlist(a.AggregationBits, 2048) - - // Field (1) 'Data' - if err = a.Data.HashTreeRootWith(hh); err != nil { - return - } - - // Field (2) 'Signature' - if size := len(a.Signature); size != 96 { - err = ssz.ErrBytesLengthFn("Attestation.Signature", size, 96) - return - } - hh.PutBytes(a.Signature) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the Attestation object -func (a *Attestation) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(a) -} - -// MarshalSSZ ssz marshals the DepositData object -func (d *DepositData) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(d) -} - -// MarshalSSZTo ssz marshals the DepositData object to a target array -func (d *DepositData) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Pubkey' - dst = append(dst, d.Pubkey[:]...) - - // Field (1) 'WithdrawalCredentials' - dst = append(dst, d.WithdrawalCredentials[:]...) - - // Field (2) 'Amount' - dst = ssz.MarshalUint64(dst, d.Amount) - - // Field (3) 'Signature' - if size := len(d.Signature); size != 96 { - err = ssz.ErrBytesLengthFn("DepositData.Signature", size, 96) - return - } - dst = append(dst, d.Signature...) - - return -} - -// UnmarshalSSZ ssz unmarshals the DepositData object -func (d *DepositData) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 184 { - return ssz.ErrSize - } - - // Field (0) 'Pubkey' - copy(d.Pubkey[:], buf[0:48]) - - // Field (1) 'WithdrawalCredentials' - copy(d.WithdrawalCredentials[:], buf[48:80]) - - // Field (2) 'Amount' - d.Amount = ssz.UnmarshallUint64(buf[80:88]) - - // Field (3) 'Signature' - if cap(d.Signature) == 0 { - d.Signature = make([]byte, 0, len(buf[88:184])) - } - d.Signature = append(d.Signature, buf[88:184]...) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the DepositData object -func (d *DepositData) SizeSSZ() (size int) { - size = 184 - return -} - -// HashTreeRoot ssz hashes the DepositData object -func (d *DepositData) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(d) -} - -// HashTreeRootWith ssz hashes the DepositData object with a hasher -func (d *DepositData) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Pubkey' - hh.PutBytes(d.Pubkey[:]) - - // Field (1) 'WithdrawalCredentials' - hh.PutBytes(d.WithdrawalCredentials[:]) - - // Field (2) 'Amount' - hh.PutUint64(d.Amount) - - // Field (3) 'Signature' - if size := len(d.Signature); size != 96 { - err = ssz.ErrBytesLengthFn("DepositData.Signature", size, 96) - return - } - hh.PutBytes(d.Signature) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the DepositData object -func (d *DepositData) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(d) -} - -// MarshalSSZ ssz marshals the Deposit object -func (d *Deposit) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(d) -} - -// MarshalSSZTo ssz marshals the Deposit object to a target array -func (d *Deposit) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Proof' - if size := len(d.Proof); size != 33 { - err = ssz.ErrVectorLengthFn("Deposit.Proof", size, 33) - return - } - for ii := 0; ii < 33; ii++ { - if size := len(d.Proof[ii]); size != 32 { - err = ssz.ErrBytesLengthFn("Deposit.Proof[ii]", size, 32) - return - } - dst = append(dst, d.Proof[ii]...) - } - - // Field (1) 'Data' - if d.Data == nil { - d.Data = new(DepositData) - } - if dst, err = d.Data.MarshalSSZTo(dst); err != nil { - return - } - - return -} - -// UnmarshalSSZ ssz unmarshals the Deposit object -func (d *Deposit) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 1240 { - return ssz.ErrSize - } - - // Field (0) 'Proof' - d.Proof = make([][]byte, 33) - for ii := 0; ii < 33; ii++ { - if cap(d.Proof[ii]) == 0 { - d.Proof[ii] = make([]byte, 0, len(buf[0:1056][ii*32:(ii+1)*32])) - } - d.Proof[ii] = append(d.Proof[ii], buf[0:1056][ii*32:(ii+1)*32]...) - } - - // Field (1) 'Data' - if d.Data == nil { - d.Data = new(DepositData) - } - if err = d.Data.UnmarshalSSZ(buf[1056:1240]); err != nil { - return err - } - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the Deposit object -func (d *Deposit) SizeSSZ() (size int) { - size = 1240 - return -} - -// HashTreeRoot ssz hashes the Deposit object -func (d *Deposit) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(d) -} - -// HashTreeRootWith ssz hashes the Deposit object with a hasher -func (d *Deposit) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Proof' - { - if size := len(d.Proof); size != 33 { - err = ssz.ErrVectorLengthFn("Deposit.Proof", size, 33) - return - } - subIndx := hh.Index() - for _, i := range d.Proof { - if len(i) != 32 { - err = ssz.ErrBytesLength - return - } - hh.Append(i) - } - hh.Merkleize(subIndx) - } - - // Field (1) 'Data' - if err = d.Data.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the Deposit object -func (d *Deposit) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(d) -} - -// MarshalSSZ ssz marshals the DepositMessage object -func (d *DepositMessage) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(d) -} - -// MarshalSSZTo ssz marshals the DepositMessage object to a target array -func (d *DepositMessage) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Pubkey' - if size := len(d.Pubkey); size != 48 { - err = ssz.ErrBytesLengthFn("DepositMessage.Pubkey", size, 48) - return - } - dst = append(dst, d.Pubkey...) - - // Field (1) 'WithdrawalCredentials' - if size := len(d.WithdrawalCredentials); size != 32 { - err = ssz.ErrBytesLengthFn("DepositMessage.WithdrawalCredentials", size, 32) - return - } - dst = append(dst, d.WithdrawalCredentials...) - - // Field (2) 'Amount' - dst = ssz.MarshalUint64(dst, d.Amount) - - return -} - -// UnmarshalSSZ ssz unmarshals the DepositMessage object -func (d *DepositMessage) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 88 { - return ssz.ErrSize - } - - // Field (0) 'Pubkey' - if cap(d.Pubkey) == 0 { - d.Pubkey = make([]byte, 0, len(buf[0:48])) - } - d.Pubkey = append(d.Pubkey, buf[0:48]...) - - // Field (1) 'WithdrawalCredentials' - if cap(d.WithdrawalCredentials) == 0 { - d.WithdrawalCredentials = make([]byte, 0, len(buf[48:80])) - } - d.WithdrawalCredentials = append(d.WithdrawalCredentials, buf[48:80]...) - - // Field (2) 'Amount' - d.Amount = ssz.UnmarshallUint64(buf[80:88]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the DepositMessage object -func (d *DepositMessage) SizeSSZ() (size int) { - size = 88 - return -} - -// HashTreeRoot ssz hashes the DepositMessage object -func (d *DepositMessage) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(d) -} - -// HashTreeRootWith ssz hashes the DepositMessage object with a hasher -func (d *DepositMessage) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Pubkey' - if size := len(d.Pubkey); size != 48 { - err = ssz.ErrBytesLengthFn("DepositMessage.Pubkey", size, 48) - return - } - hh.PutBytes(d.Pubkey) - - // Field (1) 'WithdrawalCredentials' - if size := len(d.WithdrawalCredentials); size != 32 { - err = ssz.ErrBytesLengthFn("DepositMessage.WithdrawalCredentials", size, 32) - return - } - hh.PutBytes(d.WithdrawalCredentials) - - // Field (2) 'Amount' - hh.PutUint64(d.Amount) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the DepositMessage object -func (d *DepositMessage) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(d) -} - -// MarshalSSZ ssz marshals the IndexedAttestation object -func (i *IndexedAttestation) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(i) -} - -// MarshalSSZTo ssz marshals the IndexedAttestation object to a target array -func (i *IndexedAttestation) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(224) - - // Offset (0) 'AttestationIndices' - dst = ssz.WriteOffset(dst, offset) - offset += len(i.AttestationIndices) * 8 - - // Field (1) 'Data' - if i.Data == nil { - i.Data = new(AttestationData) - } - if dst, err = i.Data.MarshalSSZTo(dst); err != nil { - return - } - - // Field (2) 'Signature' - if size := len(i.Signature); size != 96 { - err = ssz.ErrBytesLengthFn("IndexedAttestation.Signature", size, 96) - return - } - dst = append(dst, i.Signature...) - - // Field (0) 'AttestationIndices' - if size := len(i.AttestationIndices); size > 2048 { - err = ssz.ErrListTooBigFn("IndexedAttestation.AttestationIndices", size, 2048) - return - } - for ii := 0; ii < len(i.AttestationIndices); ii++ { - dst = ssz.MarshalUint64(dst, i.AttestationIndices[ii]) - } - - return -} - -// UnmarshalSSZ ssz unmarshals the IndexedAttestation object -func (i *IndexedAttestation) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 224 { - return ssz.ErrSize - } - - tail := buf - var o0 uint64 - - // Offset (0) 'AttestationIndices' - if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { - return ssz.ErrOffset - } - - if o0 < 224 { - return ssz.ErrInvalidVariableOffset - } - - // Field (1) 'Data' - if i.Data == nil { - i.Data = new(AttestationData) - } - if err = i.Data.UnmarshalSSZ(buf[4:128]); err != nil { - return err - } - - // Field (2) 'Signature' - if cap(i.Signature) == 0 { - i.Signature = make([]byte, 0, len(buf[128:224])) - } - i.Signature = append(i.Signature, buf[128:224]...) - - // Field (0) 'AttestationIndices' - { - buf = tail[o0:] - num, err := ssz.DivideInt2(len(buf), 8, 2048) - if err != nil { - return err - } - i.AttestationIndices = ssz.ExtendUint64(i.AttestationIndices, num) - for ii := 0; ii < num; ii++ { - i.AttestationIndices[ii] = ssz.UnmarshallUint64(buf[ii*8 : (ii+1)*8]) - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the IndexedAttestation object -func (i *IndexedAttestation) SizeSSZ() (size int) { - size = 224 - - // Field (0) 'AttestationIndices' - size += len(i.AttestationIndices) * 8 - - return -} - -// HashTreeRoot ssz hashes the IndexedAttestation object -func (i *IndexedAttestation) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(i) -} - -// HashTreeRootWith ssz hashes the IndexedAttestation object with a hasher -func (i *IndexedAttestation) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'AttestationIndices' - { - if size := len(i.AttestationIndices); size > 2048 { - err = ssz.ErrListTooBigFn("IndexedAttestation.AttestationIndices", size, 2048) - return - } - subIndx := hh.Index() - for _, i := range i.AttestationIndices { - hh.AppendUint64(i) - } - hh.FillUpTo32() - numItems := uint64(len(i.AttestationIndices)) - hh.MerkleizeWithMixin(subIndx, numItems, ssz.CalculateLimit(2048, numItems, 8)) - } - - // Field (1) 'Data' - if err = i.Data.HashTreeRootWith(hh); err != nil { - return - } - - // Field (2) 'Signature' - if size := len(i.Signature); size != 96 { - err = ssz.ErrBytesLengthFn("IndexedAttestation.Signature", size, 96) - return - } - hh.PutBytes(i.Signature) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the IndexedAttestation object -func (i *IndexedAttestation) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(i) -} - -// MarshalSSZ ssz marshals the PendingAttestation object -func (p *PendingAttestation) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(p) -} - -// MarshalSSZTo ssz marshals the PendingAttestation object to a target array -func (p *PendingAttestation) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(144) - - // Offset (0) 'AggregationBits' - dst = ssz.WriteOffset(dst, offset) - offset += len(p.AggregationBits) - - // Field (1) 'Data' - if p.Data == nil { - p.Data = new(AttestationData) - } - if dst, err = p.Data.MarshalSSZTo(dst); err != nil { - return - } - - // Field (2) 'InclusionDelay' - dst = ssz.MarshalUint64(dst, p.InclusionDelay) - - // Field (3) 'ProposerIndex' - dst = ssz.MarshalUint64(dst, p.ProposerIndex) - - // Field (0) 'AggregationBits' - if size := len(p.AggregationBits); size > 2048 { - err = ssz.ErrBytesLengthFn("PendingAttestation.AggregationBits", size, 2048) - return - } - dst = append(dst, p.AggregationBits...) - - return -} - -// UnmarshalSSZ ssz unmarshals the PendingAttestation object -func (p *PendingAttestation) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 144 { - return ssz.ErrSize - } - - tail := buf - var o0 uint64 - - // Offset (0) 'AggregationBits' - if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { - return ssz.ErrOffset - } - - if o0 < 144 { - return ssz.ErrInvalidVariableOffset - } - - // Field (1) 'Data' - if p.Data == nil { - p.Data = new(AttestationData) - } - if err = p.Data.UnmarshalSSZ(buf[4:128]); err != nil { - return err - } - - // Field (2) 'InclusionDelay' - p.InclusionDelay = ssz.UnmarshallUint64(buf[128:136]) - - // Field (3) 'ProposerIndex' - p.ProposerIndex = ssz.UnmarshallUint64(buf[136:144]) - - // Field (0) 'AggregationBits' - { - buf = tail[o0:] - if err = ssz.ValidateBitlist(buf, 2048); err != nil { - return err - } - if cap(p.AggregationBits) == 0 { - p.AggregationBits = make([]byte, 0, len(buf)) - } - p.AggregationBits = append(p.AggregationBits, buf...) - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the PendingAttestation object -func (p *PendingAttestation) SizeSSZ() (size int) { - size = 144 - - // Field (0) 'AggregationBits' - size += len(p.AggregationBits) - - return -} - -// HashTreeRoot ssz hashes the PendingAttestation object -func (p *PendingAttestation) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(p) -} - -// HashTreeRootWith ssz hashes the PendingAttestation object with a hasher -func (p *PendingAttestation) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'AggregationBits' - if len(p.AggregationBits) == 0 { - err = ssz.ErrEmptyBitlist - return - } - hh.PutBitlist(p.AggregationBits, 2048) - - // Field (1) 'Data' - if err = p.Data.HashTreeRootWith(hh); err != nil { - return - } - - // Field (2) 'InclusionDelay' - hh.PutUint64(p.InclusionDelay) - - // Field (3) 'ProposerIndex' - hh.PutUint64(p.ProposerIndex) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the PendingAttestation object -func (p *PendingAttestation) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(p) -} - -// MarshalSSZ ssz marshals the Fork object -func (f *Fork) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(f) -} - -// MarshalSSZTo ssz marshals the Fork object to a target array -func (f *Fork) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'PreviousVersion' - dst = append(dst, f.PreviousVersion[:]...) - - // Field (1) 'CurrentVersion' - dst = append(dst, f.CurrentVersion[:]...) - - // Field (2) 'Epoch' - dst = ssz.MarshalUint64(dst, f.Epoch) - - return -} - -// UnmarshalSSZ ssz unmarshals the Fork object -func (f *Fork) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 16 { - return ssz.ErrSize - } - - // Field (0) 'PreviousVersion' - copy(f.PreviousVersion[:], buf[0:4]) - - // Field (1) 'CurrentVersion' - copy(f.CurrentVersion[:], buf[4:8]) - - // Field (2) 'Epoch' - f.Epoch = ssz.UnmarshallUint64(buf[8:16]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the Fork object -func (f *Fork) SizeSSZ() (size int) { - size = 16 - return -} - -// HashTreeRoot ssz hashes the Fork object -func (f *Fork) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(f) -} - -// HashTreeRootWith ssz hashes the Fork object with a hasher -func (f *Fork) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'PreviousVersion' - hh.PutBytes(f.PreviousVersion[:]) - - // Field (1) 'CurrentVersion' - hh.PutBytes(f.CurrentVersion[:]) - - // Field (2) 'Epoch' - hh.PutUint64(f.Epoch) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the Fork object -func (f *Fork) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(f) -} - -// MarshalSSZ ssz marshals the Validator object -func (v *Validator) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(v) -} - -// MarshalSSZTo ssz marshals the Validator object to a target array -func (v *Validator) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Pubkey' - if size := len(v.Pubkey); size != 48 { - err = ssz.ErrBytesLengthFn("Validator.Pubkey", size, 48) - return - } - dst = append(dst, v.Pubkey...) - - // Field (1) 'WithdrawalCredentials' - if size := len(v.WithdrawalCredentials); size != 32 { - err = ssz.ErrBytesLengthFn("Validator.WithdrawalCredentials", size, 32) - return - } - dst = append(dst, v.WithdrawalCredentials...) - - // Field (2) 'EffectiveBalance' - dst = ssz.MarshalUint64(dst, v.EffectiveBalance) - - // Field (3) 'Slashed' - dst = ssz.MarshalBool(dst, v.Slashed) - - // Field (4) 'ActivationEligibilityEpoch' - dst = ssz.MarshalUint64(dst, v.ActivationEligibilityEpoch) - - // Field (5) 'ActivationEpoch' - dst = ssz.MarshalUint64(dst, v.ActivationEpoch) - - // Field (6) 'ExitEpoch' - dst = ssz.MarshalUint64(dst, v.ExitEpoch) - - // Field (7) 'WithdrawableEpoch' - dst = ssz.MarshalUint64(dst, v.WithdrawableEpoch) - - return -} - -// UnmarshalSSZ ssz unmarshals the Validator object -func (v *Validator) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 121 { - return ssz.ErrSize - } - - // Field (0) 'Pubkey' - if cap(v.Pubkey) == 0 { - v.Pubkey = make([]byte, 0, len(buf[0:48])) - } - v.Pubkey = append(v.Pubkey, buf[0:48]...) - - // Field (1) 'WithdrawalCredentials' - if cap(v.WithdrawalCredentials) == 0 { - v.WithdrawalCredentials = make([]byte, 0, len(buf[48:80])) - } - v.WithdrawalCredentials = append(v.WithdrawalCredentials, buf[48:80]...) - - // Field (2) 'EffectiveBalance' - v.EffectiveBalance = ssz.UnmarshallUint64(buf[80:88]) - - // Field (3) 'Slashed' - v.Slashed = ssz.UnmarshalBool(buf[88:89]) - - // Field (4) 'ActivationEligibilityEpoch' - v.ActivationEligibilityEpoch = ssz.UnmarshallUint64(buf[89:97]) - - // Field (5) 'ActivationEpoch' - v.ActivationEpoch = ssz.UnmarshallUint64(buf[97:105]) - - // Field (6) 'ExitEpoch' - v.ExitEpoch = ssz.UnmarshallUint64(buf[105:113]) - - // Field (7) 'WithdrawableEpoch' - v.WithdrawableEpoch = ssz.UnmarshallUint64(buf[113:121]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the Validator object -func (v *Validator) SizeSSZ() (size int) { - size = 121 - return -} - -// HashTreeRoot ssz hashes the Validator object -func (v *Validator) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(v) -} - -// HashTreeRootWith ssz hashes the Validator object with a hasher -func (v *Validator) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Pubkey' - if size := len(v.Pubkey); size != 48 { - err = ssz.ErrBytesLengthFn("Validator.Pubkey", size, 48) - return - } - hh.PutBytes(v.Pubkey) - - // Field (1) 'WithdrawalCredentials' - if size := len(v.WithdrawalCredentials); size != 32 { - err = ssz.ErrBytesLengthFn("Validator.WithdrawalCredentials", size, 32) - return - } - hh.PutBytes(v.WithdrawalCredentials) - - // Field (2) 'EffectiveBalance' - hh.PutUint64(v.EffectiveBalance) - - // Field (3) 'Slashed' - hh.PutBool(v.Slashed) - - // Field (4) 'ActivationEligibilityEpoch' - hh.PutUint64(v.ActivationEligibilityEpoch) - - // Field (5) 'ActivationEpoch' - hh.PutUint64(v.ActivationEpoch) - - // Field (6) 'ExitEpoch' - hh.PutUint64(v.ExitEpoch) - - // Field (7) 'WithdrawableEpoch' - hh.PutUint64(v.WithdrawableEpoch) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the Validator object -func (v *Validator) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(v) -} - -// MarshalSSZ ssz marshals the ValidatorSet object -func (v *ValidatorSet) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(v) -} - -// MarshalSSZTo ssz marshals the ValidatorSet object to a target array -func (v *ValidatorSet) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(4) - - // Offset (0) 'Set' - dst = ssz.WriteOffset(dst, offset) - offset += len(v.Set) * 121 - - // Field (0) 'Set' - if size := len(v.Set); size > 1099511627776 { - err = ssz.ErrListTooBigFn("ValidatorSet.Set", size, 1099511627776) - return - } - for ii := 0; ii < len(v.Set); ii++ { - if dst, err = v.Set[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - return -} - -// UnmarshalSSZ ssz unmarshals the ValidatorSet object -func (v *ValidatorSet) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 4 { - return ssz.ErrSize - } - - tail := buf - var o0 uint64 - - // Offset (0) 'Set' - if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { - return ssz.ErrOffset - } - - if o0 < 4 { - return ssz.ErrInvalidVariableOffset - } - - // Field (0) 'Set' - { - buf = tail[o0:] - num, err := ssz.DivideInt2(len(buf), 121, 1099511627776) - if err != nil { - return err - } - v.Set = make([]*Validator, num) - for ii := 0; ii < num; ii++ { - if v.Set[ii] == nil { - v.Set[ii] = new(Validator) - } - if err = v.Set[ii].UnmarshalSSZ(buf[ii*121 : (ii+1)*121]); err != nil { - return err - } - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the ValidatorSet object -func (v *ValidatorSet) SizeSSZ() (size int) { - size = 4 - - // Field (0) 'Set' - size += len(v.Set) * 121 - - return -} - -// HashTreeRoot ssz hashes the ValidatorSet object -func (v *ValidatorSet) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(v) -} - -// HashTreeRootWith ssz hashes the ValidatorSet object with a hasher -func (v *ValidatorSet) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Set' - { - subIndx := hh.Index() - num := uint64(len(v.Set)) - if num > 1099511627776 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range v.Set { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 1099511627776) - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the ValidatorSet object -func (v *ValidatorSet) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(v) -} - -// MarshalSSZ ssz marshals the VoluntaryExit object -func (v *VoluntaryExit) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(v) -} - -// MarshalSSZTo ssz marshals the VoluntaryExit object to a target array -func (v *VoluntaryExit) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Epoch' - dst = ssz.MarshalUint64(dst, v.Epoch) - - // Field (1) 'ValidatorIndex' - dst = ssz.MarshalUint64(dst, v.ValidatorIndex) - - return -} - -// UnmarshalSSZ ssz unmarshals the VoluntaryExit object -func (v *VoluntaryExit) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 16 { - return ssz.ErrSize - } - - // Field (0) 'Epoch' - v.Epoch = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'ValidatorIndex' - v.ValidatorIndex = ssz.UnmarshallUint64(buf[8:16]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the VoluntaryExit object -func (v *VoluntaryExit) SizeSSZ() (size int) { - size = 16 - return -} - -// HashTreeRoot ssz hashes the VoluntaryExit object -func (v *VoluntaryExit) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(v) -} - -// HashTreeRootWith ssz hashes the VoluntaryExit object with a hasher -func (v *VoluntaryExit) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Epoch' - hh.PutUint64(v.Epoch) - - // Field (1) 'ValidatorIndex' - hh.PutUint64(v.ValidatorIndex) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the VoluntaryExit object -func (v *VoluntaryExit) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(v) -} - -// MarshalSSZ ssz marshals the SignedVoluntaryExit object -func (s *SignedVoluntaryExit) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(s) -} - -// MarshalSSZTo ssz marshals the SignedVoluntaryExit object to a target array -func (s *SignedVoluntaryExit) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Exit' - if s.Exit == nil { - s.Exit = new(VoluntaryExit) - } - if dst, err = s.Exit.MarshalSSZTo(dst); err != nil { - return - } - - // Field (1) 'Signature' - dst = append(dst, s.Signature[:]...) - - return -} - -// UnmarshalSSZ ssz unmarshals the SignedVoluntaryExit object -func (s *SignedVoluntaryExit) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 112 { - return ssz.ErrSize - } - - // Field (0) 'Exit' - if s.Exit == nil { - s.Exit = new(VoluntaryExit) - } - if err = s.Exit.UnmarshalSSZ(buf[0:16]); err != nil { - return err - } - - // Field (1) 'Signature' - copy(s.Signature[:], buf[16:112]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the SignedVoluntaryExit object -func (s *SignedVoluntaryExit) SizeSSZ() (size int) { - size = 112 - return -} - -// HashTreeRoot ssz hashes the SignedVoluntaryExit object -func (s *SignedVoluntaryExit) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(s) -} - -// HashTreeRootWith ssz hashes the SignedVoluntaryExit object with a hasher -func (s *SignedVoluntaryExit) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Exit' - if err = s.Exit.HashTreeRootWith(hh); err != nil { - return - } - - // Field (1) 'Signature' - hh.PutBytes(s.Signature[:]) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the SignedVoluntaryExit object -func (s *SignedVoluntaryExit) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(s) -} - -// MarshalSSZ ssz marshals the Eth1Block object -func (e *Eth1Block) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(e) -} - -// MarshalSSZTo ssz marshals the Eth1Block object to a target array -func (e *Eth1Block) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Timestamp' - dst = ssz.MarshalUint64(dst, e.Timestamp) - - // Field (1) 'DepositRoot' - if size := len(e.DepositRoot); size != 32 { - err = ssz.ErrBytesLengthFn("Eth1Block.DepositRoot", size, 32) - return - } - dst = append(dst, e.DepositRoot...) - - // Field (2) 'DepositCount' - dst = ssz.MarshalUint64(dst, e.DepositCount) - - return -} - -// UnmarshalSSZ ssz unmarshals the Eth1Block object -func (e *Eth1Block) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 48 { - return ssz.ErrSize - } - - // Field (0) 'Timestamp' - e.Timestamp = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'DepositRoot' - if cap(e.DepositRoot) == 0 { - e.DepositRoot = make([]byte, 0, len(buf[8:40])) - } - e.DepositRoot = append(e.DepositRoot, buf[8:40]...) - - // Field (2) 'DepositCount' - e.DepositCount = ssz.UnmarshallUint64(buf[40:48]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the Eth1Block object -func (e *Eth1Block) SizeSSZ() (size int) { - size = 48 - return -} - -// HashTreeRoot ssz hashes the Eth1Block object -func (e *Eth1Block) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(e) -} - -// HashTreeRootWith ssz hashes the Eth1Block object with a hasher -func (e *Eth1Block) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Timestamp' - hh.PutUint64(e.Timestamp) - - // Field (1) 'DepositRoot' - if size := len(e.DepositRoot); size != 32 { - err = ssz.ErrBytesLengthFn("Eth1Block.DepositRoot", size, 32) - return - } - hh.PutBytes(e.DepositRoot) - - // Field (2) 'DepositCount' - hh.PutUint64(e.DepositCount) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the Eth1Block object -func (e *Eth1Block) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(e) -} - -// MarshalSSZ ssz marshals the Eth1Data object -func (e *Eth1Data) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(e) -} - -// MarshalSSZTo ssz marshals the Eth1Data object to a target array -func (e *Eth1Data) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'DepositRoot' - dst = append(dst, e.DepositRoot[:]...) - - // Field (1) 'DepositCount' - dst = ssz.MarshalUint64(dst, e.DepositCount) - - // Field (2) 'BlockHash' - dst = append(dst, e.BlockHash[:]...) - - return -} - -// UnmarshalSSZ ssz unmarshals the Eth1Data object -func (e *Eth1Data) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 72 { - return ssz.ErrSize - } - - // Field (0) 'DepositRoot' - copy(e.DepositRoot[:], buf[0:32]) - - // Field (1) 'DepositCount' - e.DepositCount = ssz.UnmarshallUint64(buf[32:40]) - - // Field (2) 'BlockHash' - copy(e.BlockHash[:], buf[40:72]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the Eth1Data object -func (e *Eth1Data) SizeSSZ() (size int) { - size = 72 - return -} - -// HashTreeRoot ssz hashes the Eth1Data object -func (e *Eth1Data) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(e) -} - -// HashTreeRootWith ssz hashes the Eth1Data object with a hasher -func (e *Eth1Data) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'DepositRoot' - hh.PutBytes(e.DepositRoot[:]) - - // Field (1) 'DepositCount' - hh.PutUint64(e.DepositCount) - - // Field (2) 'BlockHash' - hh.PutBytes(e.BlockHash[:]) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the Eth1Data object -func (e *Eth1Data) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(e) -} - -// MarshalSSZ ssz marshals the SigningRoot object -func (s *SigningRoot) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(s) -} - -// MarshalSSZTo ssz marshals the SigningRoot object to a target array -func (s *SigningRoot) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'ObjectRoot' - if size := len(s.ObjectRoot); size != 32 { - err = ssz.ErrBytesLengthFn("SigningRoot.ObjectRoot", size, 32) - return - } - dst = append(dst, s.ObjectRoot...) - - // Field (1) 'Domain' - if size := len(s.Domain); size != 8 { - err = ssz.ErrBytesLengthFn("SigningRoot.Domain", size, 8) - return - } - dst = append(dst, s.Domain...) - - return -} - -// UnmarshalSSZ ssz unmarshals the SigningRoot object -func (s *SigningRoot) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 40 { - return ssz.ErrSize - } - - // Field (0) 'ObjectRoot' - if cap(s.ObjectRoot) == 0 { - s.ObjectRoot = make([]byte, 0, len(buf[0:32])) - } - s.ObjectRoot = append(s.ObjectRoot, buf[0:32]...) - - // Field (1) 'Domain' - if cap(s.Domain) == 0 { - s.Domain = make([]byte, 0, len(buf[32:40])) - } - s.Domain = append(s.Domain, buf[32:40]...) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the SigningRoot object -func (s *SigningRoot) SizeSSZ() (size int) { - size = 40 - return -} - -// HashTreeRoot ssz hashes the SigningRoot object -func (s *SigningRoot) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(s) -} - -// HashTreeRootWith ssz hashes the SigningRoot object with a hasher -func (s *SigningRoot) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'ObjectRoot' - if size := len(s.ObjectRoot); size != 32 { - err = ssz.ErrBytesLengthFn("SigningRoot.ObjectRoot", size, 32) - return - } - hh.PutBytes(s.ObjectRoot) - - // Field (1) 'Domain' - if size := len(s.Domain); size != 8 { - err = ssz.ErrBytesLengthFn("SigningRoot.Domain", size, 8) - return - } - hh.PutBytes(s.Domain) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the SigningRoot object -func (s *SigningRoot) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(s) -} - -// MarshalSSZ ssz marshals the HistoricalBatch object -func (h *HistoricalBatch) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(h) -} - -// MarshalSSZTo ssz marshals the HistoricalBatch object to a target array -func (h *HistoricalBatch) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'BlockRoots' - if size := len(h.BlockRoots); size != 8192 { - err = ssz.ErrVectorLengthFn("HistoricalBatch.BlockRoots", size, 8192) - return - } - for ii := 0; ii < 8192; ii++ { - dst = append(dst, h.BlockRoots[ii][:]...) - } - - // Field (1) 'StateRoots' - if size := len(h.StateRoots); size != 8192 { - err = ssz.ErrVectorLengthFn("HistoricalBatch.StateRoots", size, 8192) - return - } - for ii := 0; ii < 8192; ii++ { - dst = append(dst, h.StateRoots[ii][:]...) - } - - return -} - -// UnmarshalSSZ ssz unmarshals the HistoricalBatch object -func (h *HistoricalBatch) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 524288 { - return ssz.ErrSize - } - - // Field (0) 'BlockRoots' - h.BlockRoots = make([][32]byte, 8192) - for ii := 0; ii < 8192; ii++ { - copy(h.BlockRoots[ii][:], buf[0:262144][ii*32:(ii+1)*32]) - } - - // Field (1) 'StateRoots' - h.StateRoots = make([][32]byte, 8192) - for ii := 0; ii < 8192; ii++ { - copy(h.StateRoots[ii][:], buf[262144:524288][ii*32:(ii+1)*32]) - } - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the HistoricalBatch object -func (h *HistoricalBatch) SizeSSZ() (size int) { - size = 524288 - return -} - -// HashTreeRoot ssz hashes the HistoricalBatch object -func (h *HistoricalBatch) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(h) -} - -// HashTreeRootWith ssz hashes the HistoricalBatch object with a hasher -func (h *HistoricalBatch) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'BlockRoots' - { - if size := len(h.BlockRoots); size != 8192 { - err = ssz.ErrVectorLengthFn("HistoricalBatch.BlockRoots", size, 8192) - return - } - subIndx := hh.Index() - for _, i := range h.BlockRoots { - hh.Append(i[:]) - } - hh.Merkleize(subIndx) - } - - // Field (1) 'StateRoots' - { - if size := len(h.StateRoots); size != 8192 { - err = ssz.ErrVectorLengthFn("HistoricalBatch.StateRoots", size, 8192) - return - } - subIndx := hh.Index() - for _, i := range h.StateRoots { - hh.Append(i[:]) - } - hh.Merkleize(subIndx) - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the HistoricalBatch object -func (h *HistoricalBatch) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(h) -} - -// MarshalSSZ ssz marshals the ProposerSlashing object -func (p *ProposerSlashing) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(p) -} - -// MarshalSSZTo ssz marshals the ProposerSlashing object to a target array -func (p *ProposerSlashing) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Header1' - if p.Header1 == nil { - p.Header1 = new(SignedBeaconBlockHeader) - } - if dst, err = p.Header1.MarshalSSZTo(dst); err != nil { - return - } - - // Field (1) 'Header2' - if p.Header2 == nil { - p.Header2 = new(SignedBeaconBlockHeader) - } - if dst, err = p.Header2.MarshalSSZTo(dst); err != nil { - return - } - - return -} - -// UnmarshalSSZ ssz unmarshals the ProposerSlashing object -func (p *ProposerSlashing) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 416 { - return ssz.ErrSize - } - - // Field (0) 'Header1' - if p.Header1 == nil { - p.Header1 = new(SignedBeaconBlockHeader) - } - if err = p.Header1.UnmarshalSSZ(buf[0:208]); err != nil { - return err - } - - // Field (1) 'Header2' - if p.Header2 == nil { - p.Header2 = new(SignedBeaconBlockHeader) - } - if err = p.Header2.UnmarshalSSZ(buf[208:416]); err != nil { - return err - } - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the ProposerSlashing object -func (p *ProposerSlashing) SizeSSZ() (size int) { - size = 416 - return -} - -// HashTreeRoot ssz hashes the ProposerSlashing object -func (p *ProposerSlashing) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(p) -} - -// HashTreeRootWith ssz hashes the ProposerSlashing object with a hasher -func (p *ProposerSlashing) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Header1' - if err = p.Header1.HashTreeRootWith(hh); err != nil { - return - } - - // Field (1) 'Header2' - if err = p.Header2.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the ProposerSlashing object -func (p *ProposerSlashing) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(p) -} - -// MarshalSSZ ssz marshals the AttesterSlashing object -func (a *AttesterSlashing) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(a) -} - -// MarshalSSZTo ssz marshals the AttesterSlashing object to a target array -func (a *AttesterSlashing) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(8) - - // Offset (0) 'Attestation1' - dst = ssz.WriteOffset(dst, offset) - if a.Attestation1 == nil { - a.Attestation1 = new(IndexedAttestation) - } - offset += a.Attestation1.SizeSSZ() - - // Offset (1) 'Attestation2' - dst = ssz.WriteOffset(dst, offset) - if a.Attestation2 == nil { - a.Attestation2 = new(IndexedAttestation) - } - offset += a.Attestation2.SizeSSZ() - - // Field (0) 'Attestation1' - if dst, err = a.Attestation1.MarshalSSZTo(dst); err != nil { - return - } - - // Field (1) 'Attestation2' - if dst, err = a.Attestation2.MarshalSSZTo(dst); err != nil { - return - } - - return -} - -// UnmarshalSSZ ssz unmarshals the AttesterSlashing object -func (a *AttesterSlashing) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 8 { - return ssz.ErrSize - } - - tail := buf - var o0, o1 uint64 - - // Offset (0) 'Attestation1' - if o0 = ssz.ReadOffset(buf[0:4]); o0 > size { - return ssz.ErrOffset - } - - if o0 < 8 { - return ssz.ErrInvalidVariableOffset - } - - // Offset (1) 'Attestation2' - if o1 = ssz.ReadOffset(buf[4:8]); o1 > size || o0 > o1 { - return ssz.ErrOffset - } - - // Field (0) 'Attestation1' - { - buf = tail[o0:o1] - if a.Attestation1 == nil { - a.Attestation1 = new(IndexedAttestation) - } - if err = a.Attestation1.UnmarshalSSZ(buf); err != nil { - return err - } - } - - // Field (1) 'Attestation2' - { - buf = tail[o1:] - if a.Attestation2 == nil { - a.Attestation2 = new(IndexedAttestation) - } - if err = a.Attestation2.UnmarshalSSZ(buf); err != nil { - return err - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the AttesterSlashing object -func (a *AttesterSlashing) SizeSSZ() (size int) { - size = 8 - - // Field (0) 'Attestation1' - if a.Attestation1 == nil { - a.Attestation1 = new(IndexedAttestation) - } - size += a.Attestation1.SizeSSZ() - - // Field (1) 'Attestation2' - if a.Attestation2 == nil { - a.Attestation2 = new(IndexedAttestation) - } - size += a.Attestation2.SizeSSZ() - - return -} - -// HashTreeRoot ssz hashes the AttesterSlashing object -func (a *AttesterSlashing) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(a) -} - -// HashTreeRootWith ssz hashes the AttesterSlashing object with a hasher -func (a *AttesterSlashing) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Attestation1' - if err = a.Attestation1.HashTreeRootWith(hh); err != nil { - return - } - - // Field (1) 'Attestation2' - if err = a.Attestation2.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the AttesterSlashing object -func (a *AttesterSlashing) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(a) -} - -// MarshalSSZ ssz marshals the Transfer object -func (t *Transfer) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(t) -} - -// MarshalSSZTo ssz marshals the Transfer object to a target array -func (t *Transfer) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Sender' - dst = ssz.MarshalUint64(dst, t.Sender) - - // Field (1) 'Recipient' - dst = ssz.MarshalUint64(dst, t.Recipient) - - // Field (2) 'Amount' - dst = ssz.MarshalUint64(dst, t.Amount) - - // Field (3) 'Fee' - dst = ssz.MarshalUint64(dst, t.Fee) - - // Field (4) 'Slot' - dst = ssz.MarshalUint64(dst, t.Slot) - - // Field (5) 'Pubkey' - if size := len(t.Pubkey); size != 48 { - err = ssz.ErrBytesLengthFn("Transfer.Pubkey", size, 48) - return - } - dst = append(dst, t.Pubkey...) - - // Field (6) 'Signature' - if size := len(t.Signature); size != 96 { - err = ssz.ErrBytesLengthFn("Transfer.Signature", size, 96) - return - } - dst = append(dst, t.Signature...) - - return -} - -// UnmarshalSSZ ssz unmarshals the Transfer object -func (t *Transfer) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 184 { - return ssz.ErrSize - } - - // Field (0) 'Sender' - t.Sender = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'Recipient' - t.Recipient = ssz.UnmarshallUint64(buf[8:16]) - - // Field (2) 'Amount' - t.Amount = ssz.UnmarshallUint64(buf[16:24]) - - // Field (3) 'Fee' - t.Fee = ssz.UnmarshallUint64(buf[24:32]) - - // Field (4) 'Slot' - t.Slot = ssz.UnmarshallUint64(buf[32:40]) - - // Field (5) 'Pubkey' - if cap(t.Pubkey) == 0 { - t.Pubkey = make([]byte, 0, len(buf[40:88])) - } - t.Pubkey = append(t.Pubkey, buf[40:88]...) - - // Field (6) 'Signature' - if cap(t.Signature) == 0 { - t.Signature = make([]byte, 0, len(buf[88:184])) - } - t.Signature = append(t.Signature, buf[88:184]...) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the Transfer object -func (t *Transfer) SizeSSZ() (size int) { - size = 184 - return -} - -// HashTreeRoot ssz hashes the Transfer object -func (t *Transfer) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(t) -} - -// HashTreeRootWith ssz hashes the Transfer object with a hasher -func (t *Transfer) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Sender' - hh.PutUint64(t.Sender) - - // Field (1) 'Recipient' - hh.PutUint64(t.Recipient) - - // Field (2) 'Amount' - hh.PutUint64(t.Amount) - - // Field (3) 'Fee' - hh.PutUint64(t.Fee) - - // Field (4) 'Slot' - hh.PutUint64(t.Slot) - - // Field (5) 'Pubkey' - if size := len(t.Pubkey); size != 48 { - err = ssz.ErrBytesLengthFn("Transfer.Pubkey", size, 48) - return - } - hh.PutBytes(t.Pubkey) - - // Field (6) 'Signature' - if size := len(t.Signature); size != 96 { - err = ssz.ErrBytesLengthFn("Transfer.Signature", size, 96) - return - } - hh.PutBytes(t.Signature) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the Transfer object -func (t *Transfer) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(t) -} - -// MarshalSSZ ssz marshals the BeaconStatePhase0 object -func (b *BeaconStatePhase0) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(b) -} - -// MarshalSSZTo ssz marshals the BeaconStatePhase0 object to a target array -func (b *BeaconStatePhase0) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(2687377) - - // Field (0) 'GenesisTime' - dst = ssz.MarshalUint64(dst, b.GenesisTime) - - // Field (1) 'GenesisValidatorsRoot' - dst = append(dst, b.GenesisValidatorsRoot[:]...) - - // Field (2) 'Slot' - dst = ssz.MarshalUint64(dst, b.Slot) - - // Field (3) 'Fork' - if b.Fork == nil { - b.Fork = new(Fork) - } - if dst, err = b.Fork.MarshalSSZTo(dst); err != nil { - return - } - - // Field (4) 'LatestBlockHeader' - if b.LatestBlockHeader == nil { - b.LatestBlockHeader = new(BeaconBlockHeader) - } - if dst, err = b.LatestBlockHeader.MarshalSSZTo(dst); err != nil { - return - } - - // Field (5) 'BlockRoots' - for ii := 0; ii < 8192; ii++ { - dst = append(dst, b.BlockRoots[ii][:]...) - } - - // Field (6) 'StateRoots' - for ii := 0; ii < 8192; ii++ { - dst = append(dst, b.StateRoots[ii][:]...) - } - - // Offset (7) 'HistoricalRoots' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.HistoricalRoots) * 32 - - // Field (8) 'Eth1Data' - if b.Eth1Data == nil { - b.Eth1Data = new(Eth1Data) - } - if dst, err = b.Eth1Data.MarshalSSZTo(dst); err != nil { - return - } - - // Offset (9) 'Eth1DataVotes' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.Eth1DataVotes) * 72 - - // Field (10) 'Eth1DepositIndex' - dst = ssz.MarshalUint64(dst, b.Eth1DepositIndex) - - // Offset (11) 'Validators' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.Validators) * 121 - - // Offset (12) 'Balances' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.Balances) * 8 - - // Field (13) 'RandaoMixes' - for ii := 0; ii < 65536; ii++ { - dst = append(dst, b.RandaoMixes[ii][:]...) - } - - // Field (14) 'Slashings' - if size := len(b.Slashings); size != 8192 { - err = ssz.ErrVectorLengthFn("BeaconStatePhase0.Slashings", size, 8192) - return - } - for ii := 0; ii < 8192; ii++ { - dst = ssz.MarshalUint64(dst, b.Slashings[ii]) - } - - // Offset (15) 'PreviousEpochAttestations' - dst = ssz.WriteOffset(dst, offset) - for ii := 0; ii < len(b.PreviousEpochAttestations); ii++ { - offset += 4 - offset += b.PreviousEpochAttestations[ii].SizeSSZ() - } - - // Offset (16) 'CurrentEpochAttestations' - dst = ssz.WriteOffset(dst, offset) - for ii := 0; ii < len(b.CurrentEpochAttestations); ii++ { - offset += 4 - offset += b.CurrentEpochAttestations[ii].SizeSSZ() - } - - // Field (17) 'JustificationBits' - dst = append(dst, b.JustificationBits[:]...) - - // Field (18) 'PreviousJustifiedCheckpoint' - if b.PreviousJustifiedCheckpoint == nil { - b.PreviousJustifiedCheckpoint = new(Checkpoint) - } - if dst, err = b.PreviousJustifiedCheckpoint.MarshalSSZTo(dst); err != nil { - return - } - - // Field (19) 'CurrentJustifiedCheckpoint' - if b.CurrentJustifiedCheckpoint == nil { - b.CurrentJustifiedCheckpoint = new(Checkpoint) - } - if dst, err = b.CurrentJustifiedCheckpoint.MarshalSSZTo(dst); err != nil { - return - } - - // Field (20) 'FinalizedCheckpoint' - if b.FinalizedCheckpoint == nil { - b.FinalizedCheckpoint = new(Checkpoint) - } - if dst, err = b.FinalizedCheckpoint.MarshalSSZTo(dst); err != nil { - return - } - - // Field (7) 'HistoricalRoots' - if size := len(b.HistoricalRoots); size > 16777216 { - err = ssz.ErrListTooBigFn("BeaconStatePhase0.HistoricalRoots", size, 16777216) - return - } - for ii := 0; ii < len(b.HistoricalRoots); ii++ { - dst = append(dst, b.HistoricalRoots[ii][:]...) - } - - // Field (9) 'Eth1DataVotes' - if size := len(b.Eth1DataVotes); size > 2048 { - err = ssz.ErrListTooBigFn("BeaconStatePhase0.Eth1DataVotes", size, 2048) - return - } - for ii := 0; ii < len(b.Eth1DataVotes); ii++ { - if dst, err = b.Eth1DataVotes[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (11) 'Validators' - if size := len(b.Validators); size > 1099511627776 { - err = ssz.ErrListTooBigFn("BeaconStatePhase0.Validators", size, 1099511627776) - return - } - for ii := 0; ii < len(b.Validators); ii++ { - if dst, err = b.Validators[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (12) 'Balances' - if size := len(b.Balances); size > 1099511627776 { - err = ssz.ErrListTooBigFn("BeaconStatePhase0.Balances", size, 1099511627776) - return - } - for ii := 0; ii < len(b.Balances); ii++ { - dst = ssz.MarshalUint64(dst, b.Balances[ii]) - } - - // Field (15) 'PreviousEpochAttestations' - if size := len(b.PreviousEpochAttestations); size > 4096 { - err = ssz.ErrListTooBigFn("BeaconStatePhase0.PreviousEpochAttestations", size, 4096) - return - } - { - offset = 4 * len(b.PreviousEpochAttestations) - for ii := 0; ii < len(b.PreviousEpochAttestations); ii++ { - dst = ssz.WriteOffset(dst, offset) - offset += b.PreviousEpochAttestations[ii].SizeSSZ() - } - } - for ii := 0; ii < len(b.PreviousEpochAttestations); ii++ { - if dst, err = b.PreviousEpochAttestations[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (16) 'CurrentEpochAttestations' - if size := len(b.CurrentEpochAttestations); size > 4096 { - err = ssz.ErrListTooBigFn("BeaconStatePhase0.CurrentEpochAttestations", size, 4096) - return - } - { - offset = 4 * len(b.CurrentEpochAttestations) - for ii := 0; ii < len(b.CurrentEpochAttestations); ii++ { - dst = ssz.WriteOffset(dst, offset) - offset += b.CurrentEpochAttestations[ii].SizeSSZ() - } - } - for ii := 0; ii < len(b.CurrentEpochAttestations); ii++ { - if dst, err = b.CurrentEpochAttestations[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - return -} - -// UnmarshalSSZ ssz unmarshals the BeaconStatePhase0 object -func (b *BeaconStatePhase0) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 2687377 { - return ssz.ErrSize - } - - tail := buf - var o7, o9, o11, o12, o15, o16 uint64 - - // Field (0) 'GenesisTime' - b.GenesisTime = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'GenesisValidatorsRoot' - copy(b.GenesisValidatorsRoot[:], buf[8:40]) - - // Field (2) 'Slot' - b.Slot = ssz.UnmarshallUint64(buf[40:48]) - - // Field (3) 'Fork' - if b.Fork == nil { - b.Fork = new(Fork) - } - if err = b.Fork.UnmarshalSSZ(buf[48:64]); err != nil { - return err - } - - // Field (4) 'LatestBlockHeader' - if b.LatestBlockHeader == nil { - b.LatestBlockHeader = new(BeaconBlockHeader) - } - if err = b.LatestBlockHeader.UnmarshalSSZ(buf[64:176]); err != nil { - return err - } - - // Field (5) 'BlockRoots' - - for ii := 0; ii < 8192; ii++ { - copy(b.BlockRoots[ii][:], buf[176:262320][ii*32:(ii+1)*32]) - } - - // Field (6) 'StateRoots' - - for ii := 0; ii < 8192; ii++ { - copy(b.StateRoots[ii][:], buf[262320:524464][ii*32:(ii+1)*32]) - } - - // Offset (7) 'HistoricalRoots' - if o7 = ssz.ReadOffset(buf[524464:524468]); o7 > size { - return ssz.ErrOffset - } - - if o7 < 2687377 { - return ssz.ErrInvalidVariableOffset - } - - // Field (8) 'Eth1Data' - if b.Eth1Data == nil { - b.Eth1Data = new(Eth1Data) - } - if err = b.Eth1Data.UnmarshalSSZ(buf[524468:524540]); err != nil { - return err - } - - // Offset (9) 'Eth1DataVotes' - if o9 = ssz.ReadOffset(buf[524540:524544]); o9 > size || o7 > o9 { - return ssz.ErrOffset - } - - // Field (10) 'Eth1DepositIndex' - b.Eth1DepositIndex = ssz.UnmarshallUint64(buf[524544:524552]) - - // Offset (11) 'Validators' - if o11 = ssz.ReadOffset(buf[524552:524556]); o11 > size || o9 > o11 { - return ssz.ErrOffset - } - - // Offset (12) 'Balances' - if o12 = ssz.ReadOffset(buf[524556:524560]); o12 > size || o11 > o12 { - return ssz.ErrOffset - } - - // Field (13) 'RandaoMixes' - - for ii := 0; ii < 65536; ii++ { - copy(b.RandaoMixes[ii][:], buf[524560:2621712][ii*32:(ii+1)*32]) - } - - // Field (14) 'Slashings' - b.Slashings = ssz.ExtendUint64(b.Slashings, 8192) - for ii := 0; ii < 8192; ii++ { - b.Slashings[ii] = ssz.UnmarshallUint64(buf[2621712:2687248][ii*8 : (ii+1)*8]) - } - - // Offset (15) 'PreviousEpochAttestations' - if o15 = ssz.ReadOffset(buf[2687248:2687252]); o15 > size || o12 > o15 { - return ssz.ErrOffset - } - - // Offset (16) 'CurrentEpochAttestations' - if o16 = ssz.ReadOffset(buf[2687252:2687256]); o16 > size || o15 > o16 { - return ssz.ErrOffset - } - - // Field (17) 'JustificationBits' - copy(b.JustificationBits[:], buf[2687256:2687257]) - - // Field (18) 'PreviousJustifiedCheckpoint' - if b.PreviousJustifiedCheckpoint == nil { - b.PreviousJustifiedCheckpoint = new(Checkpoint) - } - if err = b.PreviousJustifiedCheckpoint.UnmarshalSSZ(buf[2687257:2687297]); err != nil { - return err - } - - // Field (19) 'CurrentJustifiedCheckpoint' - if b.CurrentJustifiedCheckpoint == nil { - b.CurrentJustifiedCheckpoint = new(Checkpoint) - } - if err = b.CurrentJustifiedCheckpoint.UnmarshalSSZ(buf[2687297:2687337]); err != nil { - return err - } - - // Field (20) 'FinalizedCheckpoint' - if b.FinalizedCheckpoint == nil { - b.FinalizedCheckpoint = new(Checkpoint) - } - if err = b.FinalizedCheckpoint.UnmarshalSSZ(buf[2687337:2687377]); err != nil { - return err - } - - // Field (7) 'HistoricalRoots' - { - buf = tail[o7:o9] - num, err := ssz.DivideInt2(len(buf), 32, 16777216) - if err != nil { - return err - } - b.HistoricalRoots = make([][32]byte, num) - for ii := 0; ii < num; ii++ { - copy(b.HistoricalRoots[ii][:], buf[ii*32:(ii+1)*32]) - } - } - - // Field (9) 'Eth1DataVotes' - { - buf = tail[o9:o11] - num, err := ssz.DivideInt2(len(buf), 72, 2048) - if err != nil { - return err - } - b.Eth1DataVotes = make([]*Eth1Data, num) - for ii := 0; ii < num; ii++ { - if b.Eth1DataVotes[ii] == nil { - b.Eth1DataVotes[ii] = new(Eth1Data) - } - if err = b.Eth1DataVotes[ii].UnmarshalSSZ(buf[ii*72 : (ii+1)*72]); err != nil { - return err - } - } - } - - // Field (11) 'Validators' - { - buf = tail[o11:o12] - num, err := ssz.DivideInt2(len(buf), 121, 1099511627776) - if err != nil { - return err - } - b.Validators = make([]*Validator, num) - for ii := 0; ii < num; ii++ { - if b.Validators[ii] == nil { - b.Validators[ii] = new(Validator) - } - if err = b.Validators[ii].UnmarshalSSZ(buf[ii*121 : (ii+1)*121]); err != nil { - return err - } - } - } - - // Field (12) 'Balances' - { - buf = tail[o12:o15] - num, err := ssz.DivideInt2(len(buf), 8, 1099511627776) - if err != nil { - return err - } - b.Balances = ssz.ExtendUint64(b.Balances, num) - for ii := 0; ii < num; ii++ { - b.Balances[ii] = ssz.UnmarshallUint64(buf[ii*8 : (ii+1)*8]) - } - } - - // Field (15) 'PreviousEpochAttestations' - { - buf = tail[o15:o16] - num, err := ssz.DecodeDynamicLength(buf, 4096) - if err != nil { - return err - } - b.PreviousEpochAttestations = make([]*PendingAttestation, num) - err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) { - if b.PreviousEpochAttestations[indx] == nil { - b.PreviousEpochAttestations[indx] = new(PendingAttestation) - } - if err = b.PreviousEpochAttestations[indx].UnmarshalSSZ(buf); err != nil { - return err - } - return nil - }) - if err != nil { - return err - } - } - - // Field (16) 'CurrentEpochAttestations' - { - buf = tail[o16:] - num, err := ssz.DecodeDynamicLength(buf, 4096) - if err != nil { - return err - } - b.CurrentEpochAttestations = make([]*PendingAttestation, num) - err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) { - if b.CurrentEpochAttestations[indx] == nil { - b.CurrentEpochAttestations[indx] = new(PendingAttestation) - } - if err = b.CurrentEpochAttestations[indx].UnmarshalSSZ(buf); err != nil { - return err - } - return nil - }) - if err != nil { - return err - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the BeaconStatePhase0 object -func (b *BeaconStatePhase0) SizeSSZ() (size int) { - size = 2687377 - - // Field (7) 'HistoricalRoots' - size += len(b.HistoricalRoots) * 32 - - // Field (9) 'Eth1DataVotes' - size += len(b.Eth1DataVotes) * 72 - - // Field (11) 'Validators' - size += len(b.Validators) * 121 - - // Field (12) 'Balances' - size += len(b.Balances) * 8 - - // Field (15) 'PreviousEpochAttestations' - for ii := 0; ii < len(b.PreviousEpochAttestations); ii++ { - size += 4 - size += b.PreviousEpochAttestations[ii].SizeSSZ() - } - - // Field (16) 'CurrentEpochAttestations' - for ii := 0; ii < len(b.CurrentEpochAttestations); ii++ { - size += 4 - size += b.CurrentEpochAttestations[ii].SizeSSZ() - } - - return -} - -// HashTreeRoot ssz hashes the BeaconStatePhase0 object -func (b *BeaconStatePhase0) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(b) -} - -// HashTreeRootWith ssz hashes the BeaconStatePhase0 object with a hasher -func (b *BeaconStatePhase0) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'GenesisTime' - hh.PutUint64(b.GenesisTime) - - // Field (1) 'GenesisValidatorsRoot' - hh.PutBytes(b.GenesisValidatorsRoot[:]) - - // Field (2) 'Slot' - hh.PutUint64(b.Slot) - - // Field (3) 'Fork' - if err = b.Fork.HashTreeRootWith(hh); err != nil { - return - } - - // Field (4) 'LatestBlockHeader' - if err = b.LatestBlockHeader.HashTreeRootWith(hh); err != nil { - return - } - - // Field (5) 'BlockRoots' - { - subIndx := hh.Index() - for _, i := range b.BlockRoots { - hh.Append(i[:]) - } - hh.Merkleize(subIndx) - } - - // Field (6) 'StateRoots' - { - subIndx := hh.Index() - for _, i := range b.StateRoots { - hh.Append(i[:]) - } - hh.Merkleize(subIndx) - } - - // Field (7) 'HistoricalRoots' - { - if size := len(b.HistoricalRoots); size > 16777216 { - err = ssz.ErrListTooBigFn("BeaconStatePhase0.HistoricalRoots", size, 16777216) - return - } - subIndx := hh.Index() - for _, i := range b.HistoricalRoots { - hh.Append(i[:]) - } - numItems := uint64(len(b.HistoricalRoots)) - hh.MerkleizeWithMixin(subIndx, numItems, ssz.CalculateLimit(16777216, numItems, 32)) - } - - // Field (8) 'Eth1Data' - if err = b.Eth1Data.HashTreeRootWith(hh); err != nil { - return - } - - // Field (9) 'Eth1DataVotes' - { - subIndx := hh.Index() - num := uint64(len(b.Eth1DataVotes)) - if num > 2048 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.Eth1DataVotes { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 2048) - } - - // Field (10) 'Eth1DepositIndex' - hh.PutUint64(b.Eth1DepositIndex) - - // Field (11) 'Validators' - { - subIndx := hh.Index() - num := uint64(len(b.Validators)) - if num > 1099511627776 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.Validators { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 1099511627776) - } - - // Field (12) 'Balances' - { - if size := len(b.Balances); size > 1099511627776 { - err = ssz.ErrListTooBigFn("BeaconStatePhase0.Balances", size, 1099511627776) - return - } - subIndx := hh.Index() - for _, i := range b.Balances { - hh.AppendUint64(i) - } - hh.FillUpTo32() - numItems := uint64(len(b.Balances)) - hh.MerkleizeWithMixin(subIndx, numItems, ssz.CalculateLimit(1099511627776, numItems, 8)) - } - - // Field (13) 'RandaoMixes' - { - subIndx := hh.Index() - for _, i := range b.RandaoMixes { - hh.Append(i[:]) - } - hh.Merkleize(subIndx) - } - - // Field (14) 'Slashings' - { - if size := len(b.Slashings); size != 8192 { - err = ssz.ErrVectorLengthFn("BeaconStatePhase0.Slashings", size, 8192) - return - } - subIndx := hh.Index() - for _, i := range b.Slashings { - hh.AppendUint64(i) - } - hh.Merkleize(subIndx) - } - - // Field (15) 'PreviousEpochAttestations' - { - subIndx := hh.Index() - num := uint64(len(b.PreviousEpochAttestations)) - if num > 4096 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.PreviousEpochAttestations { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 4096) - } - - // Field (16) 'CurrentEpochAttestations' - { - subIndx := hh.Index() - num := uint64(len(b.CurrentEpochAttestations)) - if num > 4096 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.CurrentEpochAttestations { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 4096) - } - - // Field (17) 'JustificationBits' - hh.PutBytes(b.JustificationBits[:]) - - // Field (18) 'PreviousJustifiedCheckpoint' - if err = b.PreviousJustifiedCheckpoint.HashTreeRootWith(hh); err != nil { - return - } - - // Field (19) 'CurrentJustifiedCheckpoint' - if err = b.CurrentJustifiedCheckpoint.HashTreeRootWith(hh); err != nil { - return - } - - // Field (20) 'FinalizedCheckpoint' - if err = b.FinalizedCheckpoint.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the BeaconStatePhase0 object -func (b *BeaconStatePhase0) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(b) -} - -// MarshalSSZ ssz marshals the BeaconBlockBodyPhase0 object -func (b *BeaconBlockBodyPhase0) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(b) -} - -// MarshalSSZTo ssz marshals the BeaconBlockBodyPhase0 object to a target array -func (b *BeaconBlockBodyPhase0) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(220) - - // Field (0) 'RandaoReveal' - dst = append(dst, b.RandaoReveal[:]...) - - // Field (1) 'Eth1Data' - if b.Eth1Data == nil { - b.Eth1Data = new(Eth1Data) - } - if dst, err = b.Eth1Data.MarshalSSZTo(dst); err != nil { - return - } - - // Field (2) 'Graffiti' - dst = append(dst, b.Graffiti[:]...) - - // Offset (3) 'ProposerSlashings' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.ProposerSlashings) * 416 - - // Offset (4) 'AttesterSlashings' - dst = ssz.WriteOffset(dst, offset) - for ii := 0; ii < len(b.AttesterSlashings); ii++ { - offset += 4 - offset += b.AttesterSlashings[ii].SizeSSZ() - } - - // Offset (5) 'Attestations' - dst = ssz.WriteOffset(dst, offset) - for ii := 0; ii < len(b.Attestations); ii++ { - offset += 4 - offset += b.Attestations[ii].SizeSSZ() - } - - // Offset (6) 'Deposits' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.Deposits) * 1240 - - // Offset (7) 'VoluntaryExits' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.VoluntaryExits) * 112 - - // Field (3) 'ProposerSlashings' - if size := len(b.ProposerSlashings); size > 16 { - err = ssz.ErrListTooBigFn("BeaconBlockBodyPhase0.ProposerSlashings", size, 16) - return - } - for ii := 0; ii < len(b.ProposerSlashings); ii++ { - if dst, err = b.ProposerSlashings[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (4) 'AttesterSlashings' - if size := len(b.AttesterSlashings); size > 2 { - err = ssz.ErrListTooBigFn("BeaconBlockBodyPhase0.AttesterSlashings", size, 2) - return - } - { - offset = 4 * len(b.AttesterSlashings) - for ii := 0; ii < len(b.AttesterSlashings); ii++ { - dst = ssz.WriteOffset(dst, offset) - offset += b.AttesterSlashings[ii].SizeSSZ() - } - } - for ii := 0; ii < len(b.AttesterSlashings); ii++ { - if dst, err = b.AttesterSlashings[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (5) 'Attestations' - if size := len(b.Attestations); size > 128 { - err = ssz.ErrListTooBigFn("BeaconBlockBodyPhase0.Attestations", size, 128) - return - } - { - offset = 4 * len(b.Attestations) - for ii := 0; ii < len(b.Attestations); ii++ { - dst = ssz.WriteOffset(dst, offset) - offset += b.Attestations[ii].SizeSSZ() - } - } - for ii := 0; ii < len(b.Attestations); ii++ { - if dst, err = b.Attestations[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (6) 'Deposits' - if size := len(b.Deposits); size > 16 { - err = ssz.ErrListTooBigFn("BeaconBlockBodyPhase0.Deposits", size, 16) - return - } - for ii := 0; ii < len(b.Deposits); ii++ { - if dst, err = b.Deposits[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (7) 'VoluntaryExits' - if size := len(b.VoluntaryExits); size > 16 { - err = ssz.ErrListTooBigFn("BeaconBlockBodyPhase0.VoluntaryExits", size, 16) - return - } - for ii := 0; ii < len(b.VoluntaryExits); ii++ { - if dst, err = b.VoluntaryExits[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - return -} - -// UnmarshalSSZ ssz unmarshals the BeaconBlockBodyPhase0 object -func (b *BeaconBlockBodyPhase0) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 220 { - return ssz.ErrSize - } - - tail := buf - var o3, o4, o5, o6, o7 uint64 - - // Field (0) 'RandaoReveal' - copy(b.RandaoReveal[:], buf[0:96]) - - // Field (1) 'Eth1Data' - if b.Eth1Data == nil { - b.Eth1Data = new(Eth1Data) - } - if err = b.Eth1Data.UnmarshalSSZ(buf[96:168]); err != nil { - return err - } - - // Field (2) 'Graffiti' - copy(b.Graffiti[:], buf[168:200]) - - // Offset (3) 'ProposerSlashings' - if o3 = ssz.ReadOffset(buf[200:204]); o3 > size { - return ssz.ErrOffset - } - - if o3 < 220 { - return ssz.ErrInvalidVariableOffset - } - - // Offset (4) 'AttesterSlashings' - if o4 = ssz.ReadOffset(buf[204:208]); o4 > size || o3 > o4 { - return ssz.ErrOffset - } - - // Offset (5) 'Attestations' - if o5 = ssz.ReadOffset(buf[208:212]); o5 > size || o4 > o5 { - return ssz.ErrOffset - } - - // Offset (6) 'Deposits' - if o6 = ssz.ReadOffset(buf[212:216]); o6 > size || o5 > o6 { - return ssz.ErrOffset - } - - // Offset (7) 'VoluntaryExits' - if o7 = ssz.ReadOffset(buf[216:220]); o7 > size || o6 > o7 { - return ssz.ErrOffset - } - - // Field (3) 'ProposerSlashings' - { - buf = tail[o3:o4] - num, err := ssz.DivideInt2(len(buf), 416, 16) - if err != nil { - return err - } - b.ProposerSlashings = make([]*ProposerSlashing, num) - for ii := 0; ii < num; ii++ { - if b.ProposerSlashings[ii] == nil { - b.ProposerSlashings[ii] = new(ProposerSlashing) - } - if err = b.ProposerSlashings[ii].UnmarshalSSZ(buf[ii*416 : (ii+1)*416]); err != nil { - return err - } - } - } - - // Field (4) 'AttesterSlashings' - { - buf = tail[o4:o5] - num, err := ssz.DecodeDynamicLength(buf, 2) - if err != nil { - return err - } - b.AttesterSlashings = make([]*AttesterSlashing, num) - err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) { - if b.AttesterSlashings[indx] == nil { - b.AttesterSlashings[indx] = new(AttesterSlashing) - } - if err = b.AttesterSlashings[indx].UnmarshalSSZ(buf); err != nil { - return err - } - return nil - }) - if err != nil { - return err - } - } - - // Field (5) 'Attestations' - { - buf = tail[o5:o6] - num, err := ssz.DecodeDynamicLength(buf, 128) - if err != nil { - return err - } - b.Attestations = make([]*Attestation, num) - err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) { - if b.Attestations[indx] == nil { - b.Attestations[indx] = new(Attestation) - } - if err = b.Attestations[indx].UnmarshalSSZ(buf); err != nil { - return err - } - return nil - }) - if err != nil { - return err - } - } - - // Field (6) 'Deposits' - { - buf = tail[o6:o7] - num, err := ssz.DivideInt2(len(buf), 1240, 16) - if err != nil { - return err - } - b.Deposits = make([]*Deposit, num) - for ii := 0; ii < num; ii++ { - if b.Deposits[ii] == nil { - b.Deposits[ii] = new(Deposit) - } - if err = b.Deposits[ii].UnmarshalSSZ(buf[ii*1240 : (ii+1)*1240]); err != nil { - return err - } - } - } - - // Field (7) 'VoluntaryExits' - { - buf = tail[o7:] - num, err := ssz.DivideInt2(len(buf), 112, 16) - if err != nil { - return err - } - b.VoluntaryExits = make([]*SignedVoluntaryExit, num) - for ii := 0; ii < num; ii++ { - if b.VoluntaryExits[ii] == nil { - b.VoluntaryExits[ii] = new(SignedVoluntaryExit) - } - if err = b.VoluntaryExits[ii].UnmarshalSSZ(buf[ii*112 : (ii+1)*112]); err != nil { - return err - } - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the BeaconBlockBodyPhase0 object -func (b *BeaconBlockBodyPhase0) SizeSSZ() (size int) { - size = 220 - - // Field (3) 'ProposerSlashings' - size += len(b.ProposerSlashings) * 416 - - // Field (4) 'AttesterSlashings' - for ii := 0; ii < len(b.AttesterSlashings); ii++ { - size += 4 - size += b.AttesterSlashings[ii].SizeSSZ() - } - - // Field (5) 'Attestations' - for ii := 0; ii < len(b.Attestations); ii++ { - size += 4 - size += b.Attestations[ii].SizeSSZ() - } - - // Field (6) 'Deposits' - size += len(b.Deposits) * 1240 - - // Field (7) 'VoluntaryExits' - size += len(b.VoluntaryExits) * 112 - - return -} - -// HashTreeRoot ssz hashes the BeaconBlockBodyPhase0 object -func (b *BeaconBlockBodyPhase0) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(b) -} - -// HashTreeRootWith ssz hashes the BeaconBlockBodyPhase0 object with a hasher -func (b *BeaconBlockBodyPhase0) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'RandaoReveal' - hh.PutBytes(b.RandaoReveal[:]) - - // Field (1) 'Eth1Data' - if err = b.Eth1Data.HashTreeRootWith(hh); err != nil { - return - } - - // Field (2) 'Graffiti' - hh.PutBytes(b.Graffiti[:]) - - // Field (3) 'ProposerSlashings' - { - subIndx := hh.Index() - num := uint64(len(b.ProposerSlashings)) - if num > 16 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.ProposerSlashings { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 16) - } - - // Field (4) 'AttesterSlashings' - { - subIndx := hh.Index() - num := uint64(len(b.AttesterSlashings)) - if num > 2 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.AttesterSlashings { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 2) - } - - // Field (5) 'Attestations' - { - subIndx := hh.Index() - num := uint64(len(b.Attestations)) - if num > 128 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.Attestations { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 128) - } - - // Field (6) 'Deposits' - { - subIndx := hh.Index() - num := uint64(len(b.Deposits)) - if num > 16 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.Deposits { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 16) - } - - // Field (7) 'VoluntaryExits' - { - subIndx := hh.Index() - num := uint64(len(b.VoluntaryExits)) - if num > 16 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.VoluntaryExits { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 16) - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the BeaconBlockBodyPhase0 object -func (b *BeaconBlockBodyPhase0) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(b) -} - -// MarshalSSZ ssz marshals the BeaconStateAltair object -func (b *BeaconStateAltair) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(b) -} - -// MarshalSSZTo ssz marshals the BeaconStateAltair object to a target array -func (b *BeaconStateAltair) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(2736629) - - // Field (0) 'GenesisTime' - dst = ssz.MarshalUint64(dst, b.GenesisTime) - - // Field (1) 'GenesisValidatorsRoot' - dst = append(dst, b.GenesisValidatorsRoot[:]...) - - // Field (2) 'Slot' - dst = ssz.MarshalUint64(dst, b.Slot) - - // Field (3) 'Fork' - if b.Fork == nil { - b.Fork = new(Fork) - } - if dst, err = b.Fork.MarshalSSZTo(dst); err != nil { - return - } - - // Field (4) 'LatestBlockHeader' - if b.LatestBlockHeader == nil { - b.LatestBlockHeader = new(BeaconBlockHeader) - } - if dst, err = b.LatestBlockHeader.MarshalSSZTo(dst); err != nil { - return - } - - // Field (5) 'BlockRoots' - for ii := 0; ii < 8192; ii++ { - dst = append(dst, b.BlockRoots[ii][:]...) - } - - // Field (6) 'StateRoots' - for ii := 0; ii < 8192; ii++ { - dst = append(dst, b.StateRoots[ii][:]...) - } - - // Offset (7) 'HistoricalRoots' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.HistoricalRoots) * 32 - - // Field (8) 'Eth1Data' - if b.Eth1Data == nil { - b.Eth1Data = new(Eth1Data) - } - if dst, err = b.Eth1Data.MarshalSSZTo(dst); err != nil { - return - } - - // Offset (9) 'Eth1DataVotes' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.Eth1DataVotes) * 72 - - // Field (10) 'Eth1DepositIndex' - dst = ssz.MarshalUint64(dst, b.Eth1DepositIndex) - - // Offset (11) 'Validators' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.Validators) * 121 - - // Offset (12) 'Balances' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.Balances) * 8 - - // Field (13) 'RandaoMixes' - for ii := 0; ii < 65536; ii++ { - dst = append(dst, b.RandaoMixes[ii][:]...) - } - - // Field (14) 'Slashings' - if size := len(b.Slashings); size != 8192 { - err = ssz.ErrVectorLengthFn("BeaconStateAltair.Slashings", size, 8192) - return - } - for ii := 0; ii < 8192; ii++ { - dst = ssz.MarshalUint64(dst, b.Slashings[ii]) - } - - // Offset (15) 'PreviousEpochParticipation' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.PreviousEpochParticipation) - - // Offset (16) 'CurrentEpochParticipation' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.CurrentEpochParticipation) - - // Field (17) 'JustificationBits' - dst = append(dst, b.JustificationBits[:]...) - - // Field (18) 'PreviousJustifiedCheckpoint' - if b.PreviousJustifiedCheckpoint == nil { - b.PreviousJustifiedCheckpoint = new(Checkpoint) - } - if dst, err = b.PreviousJustifiedCheckpoint.MarshalSSZTo(dst); err != nil { - return - } - - // Field (19) 'CurrentJustifiedCheckpoint' - if b.CurrentJustifiedCheckpoint == nil { - b.CurrentJustifiedCheckpoint = new(Checkpoint) - } - if dst, err = b.CurrentJustifiedCheckpoint.MarshalSSZTo(dst); err != nil { - return - } - - // Field (20) 'FinalizedCheckpoint' - if b.FinalizedCheckpoint == nil { - b.FinalizedCheckpoint = new(Checkpoint) - } - if dst, err = b.FinalizedCheckpoint.MarshalSSZTo(dst); err != nil { - return - } - - // Offset (21) 'InactivityScores' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.InactivityScores) * 8 - - // Field (22) 'CurrentSyncCommittee' - if b.CurrentSyncCommittee == nil { - b.CurrentSyncCommittee = new(SyncCommittee) - } - if dst, err = b.CurrentSyncCommittee.MarshalSSZTo(dst); err != nil { - return - } - - // Field (23) 'NextSyncCommittee' - if b.NextSyncCommittee == nil { - b.NextSyncCommittee = new(SyncCommittee) - } - if dst, err = b.NextSyncCommittee.MarshalSSZTo(dst); err != nil { - return - } - - // Field (7) 'HistoricalRoots' - if size := len(b.HistoricalRoots); size > 16777216 { - err = ssz.ErrListTooBigFn("BeaconStateAltair.HistoricalRoots", size, 16777216) - return - } - for ii := 0; ii < len(b.HistoricalRoots); ii++ { - dst = append(dst, b.HistoricalRoots[ii][:]...) - } - - // Field (9) 'Eth1DataVotes' - if size := len(b.Eth1DataVotes); size > 2048 { - err = ssz.ErrListTooBigFn("BeaconStateAltair.Eth1DataVotes", size, 2048) - return - } - for ii := 0; ii < len(b.Eth1DataVotes); ii++ { - if dst, err = b.Eth1DataVotes[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (11) 'Validators' - if size := len(b.Validators); size > 1099511627776 { - err = ssz.ErrListTooBigFn("BeaconStateAltair.Validators", size, 1099511627776) - return - } - for ii := 0; ii < len(b.Validators); ii++ { - if dst, err = b.Validators[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (12) 'Balances' - if size := len(b.Balances); size > 1099511627776 { - err = ssz.ErrListTooBigFn("BeaconStateAltair.Balances", size, 1099511627776) - return - } - for ii := 0; ii < len(b.Balances); ii++ { - dst = ssz.MarshalUint64(dst, b.Balances[ii]) - } - - // Field (15) 'PreviousEpochParticipation' - if size := len(b.PreviousEpochParticipation); size > 1099511627776 { - err = ssz.ErrBytesLengthFn("BeaconStateAltair.PreviousEpochParticipation", size, 1099511627776) - return - } - dst = append(dst, b.PreviousEpochParticipation...) - - // Field (16) 'CurrentEpochParticipation' - if size := len(b.CurrentEpochParticipation); size > 1099511627776 { - err = ssz.ErrBytesLengthFn("BeaconStateAltair.CurrentEpochParticipation", size, 1099511627776) - return - } - dst = append(dst, b.CurrentEpochParticipation...) - - // Field (21) 'InactivityScores' - if size := len(b.InactivityScores); size > 1099511627776 { - err = ssz.ErrListTooBigFn("BeaconStateAltair.InactivityScores", size, 1099511627776) - return - } - for ii := 0; ii < len(b.InactivityScores); ii++ { - dst = ssz.MarshalUint64(dst, b.InactivityScores[ii]) - } - - return -} - -// UnmarshalSSZ ssz unmarshals the BeaconStateAltair object -func (b *BeaconStateAltair) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 2736629 { - return ssz.ErrSize - } - - tail := buf - var o7, o9, o11, o12, o15, o16, o21 uint64 - - // Field (0) 'GenesisTime' - b.GenesisTime = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'GenesisValidatorsRoot' - copy(b.GenesisValidatorsRoot[:], buf[8:40]) - - // Field (2) 'Slot' - b.Slot = ssz.UnmarshallUint64(buf[40:48]) - - // Field (3) 'Fork' - if b.Fork == nil { - b.Fork = new(Fork) - } - if err = b.Fork.UnmarshalSSZ(buf[48:64]); err != nil { - return err - } - - // Field (4) 'LatestBlockHeader' - if b.LatestBlockHeader == nil { - b.LatestBlockHeader = new(BeaconBlockHeader) - } - if err = b.LatestBlockHeader.UnmarshalSSZ(buf[64:176]); err != nil { - return err - } - - // Field (5) 'BlockRoots' - - for ii := 0; ii < 8192; ii++ { - copy(b.BlockRoots[ii][:], buf[176:262320][ii*32:(ii+1)*32]) - } - - // Field (6) 'StateRoots' - - for ii := 0; ii < 8192; ii++ { - copy(b.StateRoots[ii][:], buf[262320:524464][ii*32:(ii+1)*32]) - } - - // Offset (7) 'HistoricalRoots' - if o7 = ssz.ReadOffset(buf[524464:524468]); o7 > size { - return ssz.ErrOffset - } - - if o7 < 2736629 { - return ssz.ErrInvalidVariableOffset - } - - // Field (8) 'Eth1Data' - if b.Eth1Data == nil { - b.Eth1Data = new(Eth1Data) - } - if err = b.Eth1Data.UnmarshalSSZ(buf[524468:524540]); err != nil { - return err - } - - // Offset (9) 'Eth1DataVotes' - if o9 = ssz.ReadOffset(buf[524540:524544]); o9 > size || o7 > o9 { - return ssz.ErrOffset - } - - // Field (10) 'Eth1DepositIndex' - b.Eth1DepositIndex = ssz.UnmarshallUint64(buf[524544:524552]) - - // Offset (11) 'Validators' - if o11 = ssz.ReadOffset(buf[524552:524556]); o11 > size || o9 > o11 { - return ssz.ErrOffset - } - - // Offset (12) 'Balances' - if o12 = ssz.ReadOffset(buf[524556:524560]); o12 > size || o11 > o12 { - return ssz.ErrOffset - } - - // Field (13) 'RandaoMixes' - - for ii := 0; ii < 65536; ii++ { - copy(b.RandaoMixes[ii][:], buf[524560:2621712][ii*32:(ii+1)*32]) - } - - // Field (14) 'Slashings' - b.Slashings = ssz.ExtendUint64(b.Slashings, 8192) - for ii := 0; ii < 8192; ii++ { - b.Slashings[ii] = ssz.UnmarshallUint64(buf[2621712:2687248][ii*8 : (ii+1)*8]) - } - - // Offset (15) 'PreviousEpochParticipation' - if o15 = ssz.ReadOffset(buf[2687248:2687252]); o15 > size || o12 > o15 { - return ssz.ErrOffset - } - - // Offset (16) 'CurrentEpochParticipation' - if o16 = ssz.ReadOffset(buf[2687252:2687256]); o16 > size || o15 > o16 { - return ssz.ErrOffset - } - - // Field (17) 'JustificationBits' - copy(b.JustificationBits[:], buf[2687256:2687257]) - - // Field (18) 'PreviousJustifiedCheckpoint' - if b.PreviousJustifiedCheckpoint == nil { - b.PreviousJustifiedCheckpoint = new(Checkpoint) - } - if err = b.PreviousJustifiedCheckpoint.UnmarshalSSZ(buf[2687257:2687297]); err != nil { - return err - } - - // Field (19) 'CurrentJustifiedCheckpoint' - if b.CurrentJustifiedCheckpoint == nil { - b.CurrentJustifiedCheckpoint = new(Checkpoint) - } - if err = b.CurrentJustifiedCheckpoint.UnmarshalSSZ(buf[2687297:2687337]); err != nil { - return err - } - - // Field (20) 'FinalizedCheckpoint' - if b.FinalizedCheckpoint == nil { - b.FinalizedCheckpoint = new(Checkpoint) - } - if err = b.FinalizedCheckpoint.UnmarshalSSZ(buf[2687337:2687377]); err != nil { - return err - } - - // Offset (21) 'InactivityScores' - if o21 = ssz.ReadOffset(buf[2687377:2687381]); o21 > size || o16 > o21 { - return ssz.ErrOffset - } - - // Field (22) 'CurrentSyncCommittee' - if b.CurrentSyncCommittee == nil { - b.CurrentSyncCommittee = new(SyncCommittee) - } - if err = b.CurrentSyncCommittee.UnmarshalSSZ(buf[2687381:2712005]); err != nil { - return err - } - - // Field (23) 'NextSyncCommittee' - if b.NextSyncCommittee == nil { - b.NextSyncCommittee = new(SyncCommittee) - } - if err = b.NextSyncCommittee.UnmarshalSSZ(buf[2712005:2736629]); err != nil { - return err - } - - // Field (7) 'HistoricalRoots' - { - buf = tail[o7:o9] - num, err := ssz.DivideInt2(len(buf), 32, 16777216) - if err != nil { - return err - } - b.HistoricalRoots = make([][32]byte, num) - for ii := 0; ii < num; ii++ { - copy(b.HistoricalRoots[ii][:], buf[ii*32:(ii+1)*32]) - } - } - - // Field (9) 'Eth1DataVotes' - { - buf = tail[o9:o11] - num, err := ssz.DivideInt2(len(buf), 72, 2048) - if err != nil { - return err - } - b.Eth1DataVotes = make([]*Eth1Data, num) - for ii := 0; ii < num; ii++ { - if b.Eth1DataVotes[ii] == nil { - b.Eth1DataVotes[ii] = new(Eth1Data) - } - if err = b.Eth1DataVotes[ii].UnmarshalSSZ(buf[ii*72 : (ii+1)*72]); err != nil { - return err - } - } - } - - // Field (11) 'Validators' - { - buf = tail[o11:o12] - num, err := ssz.DivideInt2(len(buf), 121, 1099511627776) - if err != nil { - return err - } - b.Validators = make([]*Validator, num) - for ii := 0; ii < num; ii++ { - if b.Validators[ii] == nil { - b.Validators[ii] = new(Validator) - } - if err = b.Validators[ii].UnmarshalSSZ(buf[ii*121 : (ii+1)*121]); err != nil { - return err - } - } - } - - // Field (12) 'Balances' - { - buf = tail[o12:o15] - num, err := ssz.DivideInt2(len(buf), 8, 1099511627776) - if err != nil { - return err - } - b.Balances = ssz.ExtendUint64(b.Balances, num) - for ii := 0; ii < num; ii++ { - b.Balances[ii] = ssz.UnmarshallUint64(buf[ii*8 : (ii+1)*8]) - } - } - - // Field (15) 'PreviousEpochParticipation' - { - buf = tail[o15:o16] - if len(buf) > 1099511627776 { - return ssz.ErrBytesLength - } - if cap(b.PreviousEpochParticipation) == 0 { - b.PreviousEpochParticipation = make([]byte, 0, len(buf)) - } - b.PreviousEpochParticipation = append(b.PreviousEpochParticipation, buf...) - } - - // Field (16) 'CurrentEpochParticipation' - { - buf = tail[o16:o21] - if len(buf) > 1099511627776 { - return ssz.ErrBytesLength - } - if cap(b.CurrentEpochParticipation) == 0 { - b.CurrentEpochParticipation = make([]byte, 0, len(buf)) - } - b.CurrentEpochParticipation = append(b.CurrentEpochParticipation, buf...) - } - - // Field (21) 'InactivityScores' - { - buf = tail[o21:] - num, err := ssz.DivideInt2(len(buf), 8, 1099511627776) - if err != nil { - return err - } - b.InactivityScores = ssz.ExtendUint64(b.InactivityScores, num) - for ii := 0; ii < num; ii++ { - b.InactivityScores[ii] = ssz.UnmarshallUint64(buf[ii*8 : (ii+1)*8]) - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the BeaconStateAltair object -func (b *BeaconStateAltair) SizeSSZ() (size int) { - size = 2736629 - - // Field (7) 'HistoricalRoots' - size += len(b.HistoricalRoots) * 32 - - // Field (9) 'Eth1DataVotes' - size += len(b.Eth1DataVotes) * 72 - - // Field (11) 'Validators' - size += len(b.Validators) * 121 - - // Field (12) 'Balances' - size += len(b.Balances) * 8 - - // Field (15) 'PreviousEpochParticipation' - size += len(b.PreviousEpochParticipation) - - // Field (16) 'CurrentEpochParticipation' - size += len(b.CurrentEpochParticipation) - - // Field (21) 'InactivityScores' - size += len(b.InactivityScores) * 8 - - return -} - -// HashTreeRoot ssz hashes the BeaconStateAltair object -func (b *BeaconStateAltair) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(b) -} - -// HashTreeRootWith ssz hashes the BeaconStateAltair object with a hasher -func (b *BeaconStateAltair) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'GenesisTime' - hh.PutUint64(b.GenesisTime) - - // Field (1) 'GenesisValidatorsRoot' - hh.PutBytes(b.GenesisValidatorsRoot[:]) - - // Field (2) 'Slot' - hh.PutUint64(b.Slot) - - // Field (3) 'Fork' - if err = b.Fork.HashTreeRootWith(hh); err != nil { - return - } - - // Field (4) 'LatestBlockHeader' - if err = b.LatestBlockHeader.HashTreeRootWith(hh); err != nil { - return - } - - // Field (5) 'BlockRoots' - { - subIndx := hh.Index() - for _, i := range b.BlockRoots { - hh.Append(i[:]) - } - hh.Merkleize(subIndx) - } - - // Field (6) 'StateRoots' - { - subIndx := hh.Index() - for _, i := range b.StateRoots { - hh.Append(i[:]) - } - hh.Merkleize(subIndx) - } - - // Field (7) 'HistoricalRoots' - { - if size := len(b.HistoricalRoots); size > 16777216 { - err = ssz.ErrListTooBigFn("BeaconStateAltair.HistoricalRoots", size, 16777216) - return - } - subIndx := hh.Index() - for _, i := range b.HistoricalRoots { - hh.Append(i[:]) - } - numItems := uint64(len(b.HistoricalRoots)) - hh.MerkleizeWithMixin(subIndx, numItems, ssz.CalculateLimit(16777216, numItems, 32)) - } - - // Field (8) 'Eth1Data' - if err = b.Eth1Data.HashTreeRootWith(hh); err != nil { - return - } - - // Field (9) 'Eth1DataVotes' - { - subIndx := hh.Index() - num := uint64(len(b.Eth1DataVotes)) - if num > 2048 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.Eth1DataVotes { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 2048) - } - - // Field (10) 'Eth1DepositIndex' - hh.PutUint64(b.Eth1DepositIndex) - - // Field (11) 'Validators' - { - subIndx := hh.Index() - num := uint64(len(b.Validators)) - if num > 1099511627776 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.Validators { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 1099511627776) - } - - // Field (12) 'Balances' - { - if size := len(b.Balances); size > 1099511627776 { - err = ssz.ErrListTooBigFn("BeaconStateAltair.Balances", size, 1099511627776) - return - } - subIndx := hh.Index() - for _, i := range b.Balances { - hh.AppendUint64(i) - } - hh.FillUpTo32() - numItems := uint64(len(b.Balances)) - hh.MerkleizeWithMixin(subIndx, numItems, ssz.CalculateLimit(1099511627776, numItems, 8)) - } - - // Field (13) 'RandaoMixes' - { - subIndx := hh.Index() - for _, i := range b.RandaoMixes { - hh.Append(i[:]) - } - hh.Merkleize(subIndx) - } - - // Field (14) 'Slashings' - { - if size := len(b.Slashings); size != 8192 { - err = ssz.ErrVectorLengthFn("BeaconStateAltair.Slashings", size, 8192) - return - } - subIndx := hh.Index() - for _, i := range b.Slashings { - hh.AppendUint64(i) - } - hh.Merkleize(subIndx) - } - - // Field (15) 'PreviousEpochParticipation' - { - elemIndx := hh.Index() - byteLen := uint64(len(b.PreviousEpochParticipation)) - if byteLen > 1099511627776 { - err = ssz.ErrIncorrectListSize - return - } - hh.PutBytes(b.PreviousEpochParticipation) - hh.MerkleizeWithMixin(elemIndx, byteLen, (1099511627776+31)/32) - } - - // Field (16) 'CurrentEpochParticipation' - { - elemIndx := hh.Index() - byteLen := uint64(len(b.CurrentEpochParticipation)) - if byteLen > 1099511627776 { - err = ssz.ErrIncorrectListSize - return - } - hh.PutBytes(b.CurrentEpochParticipation) - hh.MerkleizeWithMixin(elemIndx, byteLen, (1099511627776+31)/32) - } - - // Field (17) 'JustificationBits' - hh.PutBytes(b.JustificationBits[:]) - - // Field (18) 'PreviousJustifiedCheckpoint' - if err = b.PreviousJustifiedCheckpoint.HashTreeRootWith(hh); err != nil { - return - } - - // Field (19) 'CurrentJustifiedCheckpoint' - if err = b.CurrentJustifiedCheckpoint.HashTreeRootWith(hh); err != nil { - return - } - - // Field (20) 'FinalizedCheckpoint' - if err = b.FinalizedCheckpoint.HashTreeRootWith(hh); err != nil { - return - } - - // Field (21) 'InactivityScores' - { - if size := len(b.InactivityScores); size > 1099511627776 { - err = ssz.ErrListTooBigFn("BeaconStateAltair.InactivityScores", size, 1099511627776) - return - } - subIndx := hh.Index() - for _, i := range b.InactivityScores { - hh.AppendUint64(i) - } - hh.FillUpTo32() - numItems := uint64(len(b.InactivityScores)) - hh.MerkleizeWithMixin(subIndx, numItems, ssz.CalculateLimit(1099511627776, numItems, 8)) - } - - // Field (22) 'CurrentSyncCommittee' - if err = b.CurrentSyncCommittee.HashTreeRootWith(hh); err != nil { - return - } - - // Field (23) 'NextSyncCommittee' - if err = b.NextSyncCommittee.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the BeaconStateAltair object -func (b *BeaconStateAltair) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(b) -} - -// MarshalSSZ ssz marshals the BeaconBlockBodyAltair object -func (b *BeaconBlockBodyAltair) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(b) -} - -// MarshalSSZTo ssz marshals the BeaconBlockBodyAltair object to a target array -func (b *BeaconBlockBodyAltair) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - offset := int(380) - - // Field (0) 'RandaoReveal' - dst = append(dst, b.RandaoReveal[:]...) - - // Field (1) 'Eth1Data' - if b.Eth1Data == nil { - b.Eth1Data = new(Eth1Data) - } - if dst, err = b.Eth1Data.MarshalSSZTo(dst); err != nil { - return - } - - // Field (2) 'Graffiti' - dst = append(dst, b.Graffiti[:]...) - - // Offset (3) 'ProposerSlashings' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.ProposerSlashings) * 416 - - // Offset (4) 'AttesterSlashings' - dst = ssz.WriteOffset(dst, offset) - for ii := 0; ii < len(b.AttesterSlashings); ii++ { - offset += 4 - offset += b.AttesterSlashings[ii].SizeSSZ() - } - - // Offset (5) 'Attestations' - dst = ssz.WriteOffset(dst, offset) - for ii := 0; ii < len(b.Attestations); ii++ { - offset += 4 - offset += b.Attestations[ii].SizeSSZ() - } - - // Offset (6) 'Deposits' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.Deposits) * 1240 - - // Offset (7) 'VoluntaryExits' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.VoluntaryExits) * 112 - - // Field (8) 'SyncAggregate' - if b.SyncAggregate == nil { - b.SyncAggregate = new(SyncAggregate) - } - if dst, err = b.SyncAggregate.MarshalSSZTo(dst); err != nil { - return - } - - // Field (3) 'ProposerSlashings' - if size := len(b.ProposerSlashings); size > 16 { - err = ssz.ErrListTooBigFn("BeaconBlockBodyAltair.ProposerSlashings", size, 16) - return - } - for ii := 0; ii < len(b.ProposerSlashings); ii++ { - if dst, err = b.ProposerSlashings[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (4) 'AttesterSlashings' - if size := len(b.AttesterSlashings); size > 2 { - err = ssz.ErrListTooBigFn("BeaconBlockBodyAltair.AttesterSlashings", size, 2) - return - } - { - offset = 4 * len(b.AttesterSlashings) - for ii := 0; ii < len(b.AttesterSlashings); ii++ { - dst = ssz.WriteOffset(dst, offset) - offset += b.AttesterSlashings[ii].SizeSSZ() - } - } - for ii := 0; ii < len(b.AttesterSlashings); ii++ { - if dst, err = b.AttesterSlashings[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (5) 'Attestations' - if size := len(b.Attestations); size > 128 { - err = ssz.ErrListTooBigFn("BeaconBlockBodyAltair.Attestations", size, 128) - return - } - { - offset = 4 * len(b.Attestations) - for ii := 0; ii < len(b.Attestations); ii++ { - dst = ssz.WriteOffset(dst, offset) - offset += b.Attestations[ii].SizeSSZ() - } - } - for ii := 0; ii < len(b.Attestations); ii++ { - if dst, err = b.Attestations[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (6) 'Deposits' - if size := len(b.Deposits); size > 16 { - err = ssz.ErrListTooBigFn("BeaconBlockBodyAltair.Deposits", size, 16) - return - } - for ii := 0; ii < len(b.Deposits); ii++ { - if dst, err = b.Deposits[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - // Field (7) 'VoluntaryExits' - if size := len(b.VoluntaryExits); size > 16 { - err = ssz.ErrListTooBigFn("BeaconBlockBodyAltair.VoluntaryExits", size, 16) - return - } - for ii := 0; ii < len(b.VoluntaryExits); ii++ { - if dst, err = b.VoluntaryExits[ii].MarshalSSZTo(dst); err != nil { - return - } - } - - return -} - -// UnmarshalSSZ ssz unmarshals the BeaconBlockBodyAltair object -func (b *BeaconBlockBodyAltair) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size < 380 { - return ssz.ErrSize - } - - tail := buf - var o3, o4, o5, o6, o7 uint64 - - // Field (0) 'RandaoReveal' - copy(b.RandaoReveal[:], buf[0:96]) - - // Field (1) 'Eth1Data' - if b.Eth1Data == nil { - b.Eth1Data = new(Eth1Data) - } - if err = b.Eth1Data.UnmarshalSSZ(buf[96:168]); err != nil { - return err - } - - // Field (2) 'Graffiti' - copy(b.Graffiti[:], buf[168:200]) - - // Offset (3) 'ProposerSlashings' - if o3 = ssz.ReadOffset(buf[200:204]); o3 > size { - return ssz.ErrOffset - } - - if o3 < 380 { - return ssz.ErrInvalidVariableOffset - } - - // Offset (4) 'AttesterSlashings' - if o4 = ssz.ReadOffset(buf[204:208]); o4 > size || o3 > o4 { - return ssz.ErrOffset - } - - // Offset (5) 'Attestations' - if o5 = ssz.ReadOffset(buf[208:212]); o5 > size || o4 > o5 { - return ssz.ErrOffset - } - - // Offset (6) 'Deposits' - if o6 = ssz.ReadOffset(buf[212:216]); o6 > size || o5 > o6 { - return ssz.ErrOffset - } - - // Offset (7) 'VoluntaryExits' - if o7 = ssz.ReadOffset(buf[216:220]); o7 > size || o6 > o7 { - return ssz.ErrOffset - } - - // Field (8) 'SyncAggregate' - if b.SyncAggregate == nil { - b.SyncAggregate = new(SyncAggregate) - } - if err = b.SyncAggregate.UnmarshalSSZ(buf[220:380]); err != nil { - return err - } - - // Field (3) 'ProposerSlashings' - { - buf = tail[o3:o4] - num, err := ssz.DivideInt2(len(buf), 416, 16) - if err != nil { - return err - } - b.ProposerSlashings = make([]*ProposerSlashing, num) - for ii := 0; ii < num; ii++ { - if b.ProposerSlashings[ii] == nil { - b.ProposerSlashings[ii] = new(ProposerSlashing) - } - if err = b.ProposerSlashings[ii].UnmarshalSSZ(buf[ii*416 : (ii+1)*416]); err != nil { - return err - } - } - } - - // Field (4) 'AttesterSlashings' - { - buf = tail[o4:o5] - num, err := ssz.DecodeDynamicLength(buf, 2) - if err != nil { - return err - } - b.AttesterSlashings = make([]*AttesterSlashing, num) - err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) { - if b.AttesterSlashings[indx] == nil { - b.AttesterSlashings[indx] = new(AttesterSlashing) - } - if err = b.AttesterSlashings[indx].UnmarshalSSZ(buf); err != nil { - return err - } - return nil - }) - if err != nil { - return err - } - } - - // Field (5) 'Attestations' - { - buf = tail[o5:o6] - num, err := ssz.DecodeDynamicLength(buf, 128) - if err != nil { - return err - } - b.Attestations = make([]*Attestation, num) - err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) { - if b.Attestations[indx] == nil { - b.Attestations[indx] = new(Attestation) - } - if err = b.Attestations[indx].UnmarshalSSZ(buf); err != nil { - return err - } - return nil - }) - if err != nil { - return err - } - } - - // Field (6) 'Deposits' - { - buf = tail[o6:o7] - num, err := ssz.DivideInt2(len(buf), 1240, 16) - if err != nil { - return err - } - b.Deposits = make([]*Deposit, num) - for ii := 0; ii < num; ii++ { - if b.Deposits[ii] == nil { - b.Deposits[ii] = new(Deposit) - } - if err = b.Deposits[ii].UnmarshalSSZ(buf[ii*1240 : (ii+1)*1240]); err != nil { - return err - } - } - } - - // Field (7) 'VoluntaryExits' - { - buf = tail[o7:] - num, err := ssz.DivideInt2(len(buf), 112, 16) - if err != nil { - return err - } - b.VoluntaryExits = make([]*SignedVoluntaryExit, num) - for ii := 0; ii < num; ii++ { - if b.VoluntaryExits[ii] == nil { - b.VoluntaryExits[ii] = new(SignedVoluntaryExit) - } - if err = b.VoluntaryExits[ii].UnmarshalSSZ(buf[ii*112 : (ii+1)*112]); err != nil { - return err - } - } - } - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the BeaconBlockBodyAltair object -func (b *BeaconBlockBodyAltair) SizeSSZ() (size int) { - size = 380 - - // Field (3) 'ProposerSlashings' - size += len(b.ProposerSlashings) * 416 - - // Field (4) 'AttesterSlashings' - for ii := 0; ii < len(b.AttesterSlashings); ii++ { - size += 4 - size += b.AttesterSlashings[ii].SizeSSZ() - } - - // Field (5) 'Attestations' - for ii := 0; ii < len(b.Attestations); ii++ { - size += 4 - size += b.Attestations[ii].SizeSSZ() - } - - // Field (6) 'Deposits' - size += len(b.Deposits) * 1240 - - // Field (7) 'VoluntaryExits' - size += len(b.VoluntaryExits) * 112 - - return -} - -// HashTreeRoot ssz hashes the BeaconBlockBodyAltair object -func (b *BeaconBlockBodyAltair) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(b) -} - -// HashTreeRootWith ssz hashes the BeaconBlockBodyAltair object with a hasher -func (b *BeaconBlockBodyAltair) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'RandaoReveal' - hh.PutBytes(b.RandaoReveal[:]) - - // Field (1) 'Eth1Data' - if err = b.Eth1Data.HashTreeRootWith(hh); err != nil { - return - } - - // Field (2) 'Graffiti' - hh.PutBytes(b.Graffiti[:]) - - // Field (3) 'ProposerSlashings' - { - subIndx := hh.Index() - num := uint64(len(b.ProposerSlashings)) - if num > 16 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.ProposerSlashings { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 16) - } - - // Field (4) 'AttesterSlashings' - { - subIndx := hh.Index() - num := uint64(len(b.AttesterSlashings)) - if num > 2 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.AttesterSlashings { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 2) - } - - // Field (5) 'Attestations' - { - subIndx := hh.Index() - num := uint64(len(b.Attestations)) - if num > 128 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.Attestations { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 128) - } - - // Field (6) 'Deposits' - { - subIndx := hh.Index() - num := uint64(len(b.Deposits)) - if num > 16 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.Deposits { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 16) - } - - // Field (7) 'VoluntaryExits' - { - subIndx := hh.Index() - num := uint64(len(b.VoluntaryExits)) - if num > 16 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.VoluntaryExits { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - hh.MerkleizeWithMixin(subIndx, num, 16) - } - - // Field (8) 'SyncAggregate' - if err = b.SyncAggregate.HashTreeRootWith(hh); err != nil { - return - } - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the BeaconBlockBodyAltair object -func (b *BeaconBlockBodyAltair) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(b) -} - -// MarshalSSZ ssz marshals the SignedBeaconBlockHeader object -func (s *SignedBeaconBlockHeader) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(s) -} - -// MarshalSSZTo ssz marshals the SignedBeaconBlockHeader object to a target array -func (s *SignedBeaconBlockHeader) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Header' - if s.Header == nil { - s.Header = new(BeaconBlockHeader) - } - if dst, err = s.Header.MarshalSSZTo(dst); err != nil { - return - } - - // Field (1) 'Signature' - if size := len(s.Signature); size != 96 { - err = ssz.ErrBytesLengthFn("SignedBeaconBlockHeader.Signature", size, 96) - return - } - dst = append(dst, s.Signature...) - - return -} - -// UnmarshalSSZ ssz unmarshals the SignedBeaconBlockHeader object -func (s *SignedBeaconBlockHeader) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 208 { - return ssz.ErrSize - } - - // Field (0) 'Header' - if s.Header == nil { - s.Header = new(BeaconBlockHeader) - } - if err = s.Header.UnmarshalSSZ(buf[0:112]); err != nil { - return err - } - - // Field (1) 'Signature' - if cap(s.Signature) == 0 { - s.Signature = make([]byte, 0, len(buf[112:208])) - } - s.Signature = append(s.Signature, buf[112:208]...) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the SignedBeaconBlockHeader object -func (s *SignedBeaconBlockHeader) SizeSSZ() (size int) { - size = 208 - return -} - -// HashTreeRoot ssz hashes the SignedBeaconBlockHeader object -func (s *SignedBeaconBlockHeader) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(s) -} - -// HashTreeRootWith ssz hashes the SignedBeaconBlockHeader object with a hasher -func (s *SignedBeaconBlockHeader) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Header' - if err = s.Header.HashTreeRootWith(hh); err != nil { - return - } - - // Field (1) 'Signature' - if size := len(s.Signature); size != 96 { - err = ssz.ErrBytesLengthFn("SignedBeaconBlockHeader.Signature", size, 96) - return - } - hh.PutBytes(s.Signature) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the SignedBeaconBlockHeader object -func (s *SignedBeaconBlockHeader) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(s) -} - -// MarshalSSZ ssz marshals the BeaconBlockHeader object -func (b *BeaconBlockHeader) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(b) -} - -// MarshalSSZTo ssz marshals the BeaconBlockHeader object to a target array -func (b *BeaconBlockHeader) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'Slot' - dst = ssz.MarshalUint64(dst, b.Slot) - - // Field (1) 'ProposerIndex' - dst = ssz.MarshalUint64(dst, b.ProposerIndex) - - // Field (2) 'ParentRoot' - dst = append(dst, b.ParentRoot[:]...) - - // Field (3) 'StateRoot' - dst = append(dst, b.StateRoot[:]...) - - // Field (4) 'BodyRoot' - dst = append(dst, b.BodyRoot[:]...) - - return -} - -// UnmarshalSSZ ssz unmarshals the BeaconBlockHeader object -func (b *BeaconBlockHeader) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 112 { - return ssz.ErrSize - } - - // Field (0) 'Slot' - b.Slot = ssz.UnmarshallUint64(buf[0:8]) - - // Field (1) 'ProposerIndex' - b.ProposerIndex = ssz.UnmarshallUint64(buf[8:16]) - - // Field (2) 'ParentRoot' - copy(b.ParentRoot[:], buf[16:48]) - - // Field (3) 'StateRoot' - copy(b.StateRoot[:], buf[48:80]) - - // Field (4) 'BodyRoot' - copy(b.BodyRoot[:], buf[80:112]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the BeaconBlockHeader object -func (b *BeaconBlockHeader) SizeSSZ() (size int) { - size = 112 - return -} - -// HashTreeRoot ssz hashes the BeaconBlockHeader object -func (b *BeaconBlockHeader) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(b) -} - -// HashTreeRootWith ssz hashes the BeaconBlockHeader object with a hasher -func (b *BeaconBlockHeader) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'Slot' - hh.PutUint64(b.Slot) - - // Field (1) 'ProposerIndex' - hh.PutUint64(b.ProposerIndex) - - // Field (2) 'ParentRoot' - hh.PutBytes(b.ParentRoot[:]) - - // Field (3) 'StateRoot' - hh.PutBytes(b.StateRoot[:]) - - // Field (4) 'BodyRoot' - hh.PutBytes(b.BodyRoot[:]) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the BeaconBlockHeader object -func (b *BeaconBlockHeader) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(b) -} - -// MarshalSSZ ssz marshals the SyncCommittee object -func (s *SyncCommittee) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(s) -} - -// MarshalSSZTo ssz marshals the SyncCommittee object to a target array -func (s *SyncCommittee) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'PubKeys' - for ii := 0; ii < 512; ii++ { - dst = append(dst, s.PubKeys[ii][:]...) - } - - // Field (1) 'AggregatePubKey' - dst = append(dst, s.AggregatePubKey[:]...) - - return -} - -// UnmarshalSSZ ssz unmarshals the SyncCommittee object -func (s *SyncCommittee) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 24624 { - return ssz.ErrSize - } - - // Field (0) 'PubKeys' - - for ii := 0; ii < 512; ii++ { - copy(s.PubKeys[ii][:], buf[0:24576][ii*48:(ii+1)*48]) - } - - // Field (1) 'AggregatePubKey' - copy(s.AggregatePubKey[:], buf[24576:24624]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the SyncCommittee object -func (s *SyncCommittee) SizeSSZ() (size int) { - size = 24624 - return -} - -// HashTreeRoot ssz hashes the SyncCommittee object -func (s *SyncCommittee) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(s) -} - -// HashTreeRootWith ssz hashes the SyncCommittee object with a hasher -func (s *SyncCommittee) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'PubKeys' - { - subIndx := hh.Index() - for _, i := range s.PubKeys { - hh.PutBytes(i[:]) - } - hh.Merkleize(subIndx) - } - - // Field (1) 'AggregatePubKey' - hh.PutBytes(s.AggregatePubKey[:]) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the SyncCommittee object -func (s *SyncCommittee) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(s) -} - -// MarshalSSZ ssz marshals the SyncAggregate object -func (s *SyncAggregate) MarshalSSZ() ([]byte, error) { - return ssz.MarshalSSZ(s) -} - -// MarshalSSZTo ssz marshals the SyncAggregate object to a target array -func (s *SyncAggregate) MarshalSSZTo(buf []byte) (dst []byte, err error) { - dst = buf - - // Field (0) 'SyncCommiteeBits' - dst = append(dst, s.SyncCommiteeBits[:]...) - - // Field (1) 'SyncCommiteeSignature' - dst = append(dst, s.SyncCommiteeSignature[:]...) - - return -} - -// UnmarshalSSZ ssz unmarshals the SyncAggregate object -func (s *SyncAggregate) UnmarshalSSZ(buf []byte) error { - var err error - size := uint64(len(buf)) - if size != 160 { - return ssz.ErrSize - } - - // Field (0) 'SyncCommiteeBits' - copy(s.SyncCommiteeBits[:], buf[0:64]) - - // Field (1) 'SyncCommiteeSignature' - copy(s.SyncCommiteeSignature[:], buf[64:160]) - - return err -} - -// SizeSSZ returns the ssz encoded size in bytes for the SyncAggregate object -func (s *SyncAggregate) SizeSSZ() (size int) { - size = 160 - return -} - -// HashTreeRoot ssz hashes the SyncAggregate object -func (s *SyncAggregate) HashTreeRoot() ([32]byte, error) { - return ssz.HashWithDefaultHasher(s) -} - -// HashTreeRootWith ssz hashes the SyncAggregate object with a hasher -func (s *SyncAggregate) HashTreeRootWith(hh ssz.HashWalker) (err error) { - indx := hh.Index() - - // Field (0) 'SyncCommiteeBits' - hh.PutBytes(s.SyncCommiteeBits[:]) - - // Field (1) 'SyncCommiteeSignature' - hh.PutBytes(s.SyncCommiteeSignature[:]) - - hh.Merkleize(indx) - return -} - -// GetTree ssz hashes the SyncAggregate object -func (s *SyncAggregate) GetTree() (*ssz.Node, error) { - return ssz.ProofTree(s) -} diff --git a/internal/http/http.go b/internal/http/http.go deleted file mode 100644 index 7bb0a74..0000000 --- a/internal/http/http.go +++ /dev/null @@ -1,68 +0,0 @@ -package http - -import ( - "encoding/json" - "io/ioutil" - "net/http" -) - -// HttpClient is an http over the standard http interface -type HttpClient struct { - addr string -} - -// NewHttpClient creates a new http client -func NewHttpClient(addr string) *HttpClient { - return &HttpClient{addr: addr} -} - -func (h *HttpClient) get(url string, objResp interface{}) error { - fullURL := h.addr + url - - resp, err := http.Get(fullURL) - if err != nil { - return err - } - defer resp.Body.Close() - - data, err := ioutil.ReadAll(resp.Body) - if err != nil { - return err - } - var obj struct { - Data json.RawMessage - } - if err := json.Unmarshal(data, &obj); err != nil { - return err - } - - if err := json.Unmarshal(obj.Data, &objResp); err != nil { - return err - } - return nil -} - -type Identity struct { - PeerID string `json:"peer_id"` - ENR string `json:"enr"` -} - -// NodeIdentity returns the node network identity -func (h *HttpClient) NodeIdentity() (*Identity, error) { - var out *Identity - err := h.get("/eth/v1/node/identity", &out) - return out, err -} - -type Syncing struct { - HeadSlot string - SyncDistance string - IsSyncing bool - IsOptimisitic bool -} - -func (h *HttpClient) Syncing() (*Syncing, error) { - var out *Syncing - err := h.get("/eth/v1/node/syncing", &out) - return out, err -} From 63ae59f9c2aa775acc6ffda16f2c3b2573185a18 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Tue, 23 Aug 2022 20:10:59 +0200 Subject: [PATCH 3/3] prov --- e2e/framework/chaintime.go | 106 -------------- e2e/single/single.go | 114 +++++++++++++-- go.mod | 2 +- go.sum | 2 + internal/cmd/node_list.go | 2 +- internal/genesis/genesis.go | 4 +- internal/server/config.go | 4 +- internal/server/fixtures/config.yaml.tmpl | 2 +- internal/server/proto/service.pb.go | 162 +++++++++++----------- internal/server/proto/service.proto | 2 +- internal/server/server.go | 4 +- 11 files changed, 194 insertions(+), 210 deletions(-) delete mode 100644 e2e/framework/chaintime.go diff --git a/e2e/framework/chaintime.go b/e2e/framework/chaintime.go deleted file mode 100644 index 36ab91c..0000000 --- a/e2e/framework/chaintime.go +++ /dev/null @@ -1,106 +0,0 @@ -package framework - -import ( - "time" -) - -type chainTime struct { - genesisTime time.Time - secondsPerSlot uint64 - slotsPerEpoch uint64 - ResCh chan SlotResult - CloseCh chan struct{} - ReadyCh chan struct{} - startEpoch uint64 -} - -func NewChainTime(genesisTime time.Time, secondsPerSlot, slotsPerEpoch uint64) *chainTime { - return &chainTime{ - genesisTime: genesisTime, - secondsPerSlot: secondsPerSlot, - slotsPerEpoch: slotsPerEpoch, - ReadyCh: make(chan struct{}), - CloseCh: make(chan struct{}), - ResCh: make(chan SlotResult), - } -} - -type SlotResult struct { - Epoch uint64 - StartTime time.Time - GenesisTime time.Time - SecondsPerSlot uint64 - - FirstSlot uint64 - LastSlot uint64 -} - -func (s *SlotResult) AtSlot(slot uint64) time.Time { - return s.GenesisTime.Add(time.Duration(slot*s.SecondsPerSlot) * time.Second) -} - -func (s *SlotResult) AtSlotAndStage(slot uint64) time.Time { - return s.GenesisTime.Add(time.Duration(slot*s.SecondsPerSlot) * time.Second) -} - -func (b *chainTime) Run() { - secondsPerEpoch := time.Duration(b.secondsPerSlot*b.slotsPerEpoch) * time.Second - - // time since genesis - currentTime := time.Now() - timeSinceGenesis := currentTime.Sub(b.genesisTime) - - if timeSinceGenesis < 0 { - // wait until the chain has started - timeUntilGenesis := b.genesisTime.Sub(currentTime) - select { - case <-time.After(timeUntilGenesis): - timeSinceGenesis = 0 - - case <-b.CloseCh: - return - } - } - - nextTick := timeSinceGenesis.Truncate(secondsPerEpoch) + secondsPerEpoch - epoch := uint64(nextTick / secondsPerEpoch) - nextTickTime := b.genesisTime.Add(nextTick) - - b.startEpoch = epoch - - // close the ready channel to notify that the - // chain has started - close(b.ReadyCh) - - emitEpoch := func(epoch uint64) { - startTime := b.genesisTime.Add(time.Duration(epoch*b.slotsPerEpoch*b.secondsPerSlot) * time.Second) - - firstSlot := epoch * b.slotsPerEpoch - lastSlot := epoch*b.slotsPerEpoch + b.slotsPerEpoch - - b.ResCh <- SlotResult{ - Epoch: epoch, - StartTime: startTime, - SecondsPerSlot: b.secondsPerSlot, - GenesisTime: b.genesisTime, - FirstSlot: firstSlot, - LastSlot: lastSlot, - } - } - - emitEpoch(epoch - 1) - - for { - timeToWait := nextTickTime.Sub(time.Now()) - - select { - case <-time.After(timeToWait): - case <-b.CloseCh: - return - } - - emitEpoch(epoch) - epoch++ - nextTickTime = nextTickTime.Add(secondsPerEpoch) - } -} diff --git a/e2e/single/single.go b/e2e/single/single.go index 1fc05f2..0b312fc 100644 --- a/e2e/single/single.go +++ b/e2e/single/single.go @@ -3,9 +3,12 @@ package single import ( "context" "fmt" + "reflect" "time" "github.com/hashicorp/go-hclog" + consensus "github.com/umbracle/go-eth-consensus" + "github.com/umbracle/go-eth-consensus/chaintime" "github.com/umbracle/go-eth-consensus/http" "github.com/umbracle/viewpoint/e2e/framework" "github.com/umbracle/viewpoint/internal/server" @@ -21,22 +24,26 @@ func init() { type SingleDeployment struct { } +func uintP(i int) *int { + return &i +} + func (s *SingleDeployment) Run(f *framework.F) { - genesisTime := time.Now().Add(10 * time.Second) config := server.DefaultConfig() config.NumGenesisValidators = 10 config.NumTranches = 1 config.Spec.MinGenesisValidatorCount = 10 - config.Spec.MinGenesisTime = int(genesisTime.Unix()) + config.Spec.MinGenesisTime = int(time.Now().Add(10 * time.Second).Unix()) + config.Spec.Altair = uintP(1) srv, err := server.NewServer(hclog.NewNullLogger(), config) if err != nil { panic(err) } - resp, err := srv.NodeDeploy(context.Background(), &proto.NodeDeployRequest{ - NodeClient: proto.NodeClient_Lighthouse, + _, err = srv.NodeDeploy(context.Background(), &proto.NodeDeployRequest{ + NodeClient: proto.NodeClient_Prysm, NodeType: &proto.NodeDeployRequest_Validator_{ Validator: &proto.NodeDeployRequest_Validator{ NumTranch: 0, @@ -49,20 +56,101 @@ func (s *SingleDeployment) Run(f *framework.F) { panic(err) } - timer := framework.NewChainTime(genesisTime, uint64(config.Spec.SecondsPerSlot), uint64(config.Spec.SlotsPerEpoch)) - go timer.Run() + { + _, err = srv.NodeDeploy(context.Background(), &proto.NodeDeployRequest{ + NodeClient: proto.NodeClient_Lighthouse, + NodeType: &proto.NodeDeployRequest_Beacon_{ + Beacon: &proto.NodeDeployRequest_Beacon{ + Count: 1, + }, + }, + }) + if err != nil { + panic(err) + } + _, err = srv.NodeDeploy(context.Background(), &proto.NodeDeployRequest{ + NodeClient: proto.NodeClient_Teku, + NodeType: &proto.NodeDeployRequest_Beacon_{ + Beacon: &proto.NodeDeployRequest_Beacon{ + Count: 1, + }, + }, + }) + if err != nil { + panic(err) + } + } + + time.Sleep(10 * time.Second) + + xx, err := srv.NodeList(context.Background(), &proto.NodeListRequest{}) + if err != nil { + panic(err) + } + beacons := []*proto.Node{} + for _, i := range xx.Nodes { + if i.Type == proto.NodeType_Beacon { + beacons = append(beacons, i) + } + } + + var genesisTime uint64 - for c := range timer.ResCh { - if c.Epoch == 2 { - break + specs := []*consensus.Spec{} + for _, node := range beacons { + client := http.New(node.GetAddr(proto.NodePortHttp)) + spec, err := client.Config().Spec() + if err != nil { + panic(err) } + genesis, err := client.Beacon().Genesis() + if err != nil { + panic(err) + } + genesisTime = genesis.Time + specs = append(specs, spec) } - fmt.Println("- done -") - for _, node := range resp.Nodes { - if node.Type == proto.NodeType_Beacon { + for i := 0; i < len(specs)-1; i++ { + if !compareSpec(specs[i], specs[i+1]) { + fmt.Println(specs[i], specs[i+1]) + panic("bad") + } + } + + genesis := specs[0] + cTime := chaintime.New(time.Unix(int64(genesisTime), 0).UTC(), genesis.SecondsPerSlot, genesis.SlotsPerEpoch) + + // wait for slot 10 + fmt.Println("time", time.Now(), cTime.Epoch(3).Time) + fmt.Println(config.Spec.SecondsPerSlot, 10*config.Spec.SecondsPerSlot) + + timer := cTime.Epoch(3).C() + select { + case <-timer.C: + fmt.Println("- epoch 3 -") + + for _, node := range beacons { client := http.New(node.GetAddr(proto.NodePortHttp)) - fmt.Println(client.Node().Identity()) + syncing, err := client.Node().Syncing() + if err != nil { + panic(err) + } + fmt.Println(syncing.HeadSlot, syncing.SyncDistance) } } + + /* + fmt.Println("- done -") + for _, node := range resp.Nodes { + if node.Type == proto.NodeType_Beacon { + client := http.New(node.GetAddr(proto.NodePortHttp)) + fmt.Println(client.Node().Identity()) + } + } + */ +} + +func compareSpec(a, b *consensus.Spec) bool { + return reflect.DeepEqual(a, b) } diff --git a/go.mod b/go.mod index c274bc7..ed35ba6 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/ryanuber/columnize v2.1.2+incompatible github.com/stretchr/testify v1.8.0 github.com/umbracle/ethgo v0.1.3 - github.com/umbracle/go-eth-consensus v0.1.1-0.20220804213956-353d32a1ea06 + github.com/umbracle/go-eth-consensus v0.1.1-0.20220806161958-5dc5ccba6075 google.golang.org/grpc v1.47.0 google.golang.org/protobuf v1.28.0 ) diff --git a/go.sum b/go.sum index 4e25f36..f34946a 100644 --- a/go.sum +++ b/go.sum @@ -209,6 +209,8 @@ github.com/umbracle/go-eth-consensus v0.1.0 h1:xm/0HCvFxrIHeiVfYoMJ9ZLbMe7IghWA5 github.com/umbracle/go-eth-consensus v0.1.0/go.mod h1:qEdbWIH3Ud7mRhUlOxNfScXX1JjcqHOqP355Ei14G3s= github.com/umbracle/go-eth-consensus v0.1.1-0.20220804213956-353d32a1ea06 h1:1/OT5qmvr4nQBHMQnqpZJsc33iln/NLRjT7vO/lxI+E= github.com/umbracle/go-eth-consensus v0.1.1-0.20220804213956-353d32a1ea06/go.mod h1:qEdbWIH3Ud7mRhUlOxNfScXX1JjcqHOqP355Ei14G3s= +github.com/umbracle/go-eth-consensus v0.1.1-0.20220806161958-5dc5ccba6075 h1:9EXK1q371lbmHYepXuOxGyP38eLxtAjhoPAvPagvOBI= +github.com/umbracle/go-eth-consensus v0.1.1-0.20220806161958-5dc5ccba6075/go.mod h1:qEdbWIH3Ud7mRhUlOxNfScXX1JjcqHOqP355Ei14G3s= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.4.0 h1:PuaTGZIw3mjYhhhbVbCQp8aciRZN9YdoB7MGX9Ko76A= diff --git a/internal/cmd/node_list.go b/internal/cmd/node_list.go index 5c90700..c99c692 100644 --- a/internal/cmd/node_list.go +++ b/internal/cmd/node_list.go @@ -42,7 +42,7 @@ func (c *NodeListCommand) Run(args []string) int { return 1 } - c.UI.Output(formatNodes(resp.Node)) + c.UI.Output(formatNodes(resp.Nodes)) return 0 } diff --git a/internal/genesis/genesis.go b/internal/genesis/genesis.go index e0482db..fb8b9ef 100644 --- a/internal/genesis/genesis.go +++ b/internal/genesis/genesis.go @@ -77,7 +77,7 @@ func GenerateGenesis(input *Input) (ssz.Marshaler, error) { state = &consensus.BeaconStatePhase0{ GenesisTime: uint64(input.GenesisTime), - GenesisValidatorsRoot: genesisValidatorRoot[:], + GenesisValidatorsRoot: genesisValidatorRoot, Fork: fork, LatestBlockHeader: &consensus.BeaconBlockHeader{ BodyRoot: bodyRoot, @@ -102,7 +102,7 @@ func GenerateGenesis(input *Input) (ssz.Marshaler, error) { state = &consensus.BeaconStateAltair{ GenesisTime: uint64(input.GenesisTime), - GenesisValidatorsRoot: genesisValidatorRoot[:], + GenesisValidatorsRoot: genesisValidatorRoot, Fork: fork, LatestBlockHeader: &consensus.BeaconBlockHeader{ BodyRoot: bodyRoot, diff --git a/internal/server/config.go b/internal/server/config.go index 6063fff..799a6ae 100644 --- a/internal/server/config.go +++ b/internal/server/config.go @@ -55,8 +55,8 @@ func DefaultEth2Spec() *Eth2Spec { SecondsPerEth1Block: 1, EpochsPerEth1VotingPeriod: 64, ShardCommitteePeriod: 4, - SlotsPerEpoch: 12, - SecondsPerSlot: 3, + SlotsPerEpoch: 32, + SecondsPerSlot: 12, } } diff --git a/internal/server/fixtures/config.yaml.tmpl b/internal/server/fixtures/config.yaml.tmpl index ba3c5b9..bcf9eab 100644 --- a/internal/server/fixtures/config.yaml.tmpl +++ b/internal/server/fixtures/config.yaml.tmpl @@ -71,6 +71,6 @@ DEPOSIT_NETWORK_ID: 1337 DEPOSIT_CONTRACT_ADDRESS: {{.DepositContract}} # Overrides -SLOTS_PER_EPOCH: 6 +SLOTS_PER_EPOCH: {{.SlotsPerEpoch}} EPOCHS_PER_ETH1_VOTING_PERIOD: 2 MAX_SEED_LOOKAHEAD: 1 diff --git a/internal/server/proto/service.pb.go b/internal/server/proto/service.pb.go index b22444c..6c96a3e 100644 --- a/internal/server/proto/service.pb.go +++ b/internal/server/proto/service.pb.go @@ -559,7 +559,7 @@ type NodeListResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Node []*Node `protobuf:"bytes,1,rep,name=node,proto3" json:"node,omitempty"` + Nodes []*Node `protobuf:"bytes,1,rep,name=nodes,proto3" json:"nodes,omitempty"` } func (x *NodeListResponse) Reset() { @@ -594,9 +594,9 @@ func (*NodeListResponse) Descriptor() ([]byte, []int) { return file_internal_server_proto_service_proto_rawDescGZIP(), []int{7} } -func (x *NodeListResponse) GetNode() []*Node { +func (x *NodeListResponse) GetNodes() []*Node { if x != nil { - return x.Node + return x.Nodes } return nil } @@ -1070,84 +1070,84 @@ var file_internal_server_proto_service_proto_rawDesc = []byte{ 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x22, 0x11, 0x0a, 0x0f, 0x4e, 0x6f, 0x64, - 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x33, 0x0a, 0x10, + 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x35, 0x0a, 0x10, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x1f, 0x0a, 0x04, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x6e, 0x6f, 0x64, - 0x65, 0x22, 0x27, 0x0a, 0x11, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x35, 0x0a, 0x12, 0x4e, 0x6f, - 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x1f, 0x0a, 0x04, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x6e, 0x6f, 0x64, - 0x65, 0x22, 0xbe, 0x02, 0x0a, 0x04, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x23, - 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, - 0x79, 0x70, 0x65, 0x12, 0x29, 0x0a, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x0e, 0x32, 0x11, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, - 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x2f, - 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x2e, 0x4c, 0x61, 0x62, 0x65, - 0x6c, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x12, - 0x2c, 0x0a, 0x05, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x16, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x2e, 0x50, 0x6f, 0x72, 0x74, - 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x1a, 0x39, 0x0a, - 0x0b, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, - 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x38, 0x0a, 0x0a, 0x50, 0x6f, 0x72, 0x74, - 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, - 0x38, 0x01, 0x22, 0x3f, 0x0a, 0x0b, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x75, - 0x62, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x69, 0x76, 0x4b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x69, 0x76, 0x4b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x70, - 0x75, 0x62, 0x4b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x75, 0x62, - 0x4b, 0x65, 0x79, 0x22, 0x7b, 0x0a, 0x0b, 0x54, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x53, 0x74, - 0x75, 0x62, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x04, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x2e, 0x0a, 0x08, 0x61, 0x63, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, - 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, - 0x70, 0x61, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, - 0x2a, 0x42, 0x0a, 0x08, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0d, 0x0a, 0x09, - 0x4f, 0x74, 0x68, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x42, - 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x56, 0x61, 0x6c, 0x69, 0x64, - 0x61, 0x74, 0x6f, 0x72, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x42, 0x6f, 0x6f, 0x74, 0x6e, 0x6f, - 0x64, 0x65, 0x10, 0x03, 0x2a, 0x42, 0x0a, 0x0a, 0x4e, 0x6f, 0x64, 0x65, 0x43, 0x6c, 0x69, 0x65, - 0x6e, 0x74, 0x12, 0x0f, 0x0a, 0x0b, 0x4f, 0x74, 0x68, 0x65, 0x72, 0x43, 0x6c, 0x69, 0x65, 0x6e, - 0x74, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x50, 0x72, 0x79, 0x73, 0x6d, 0x10, 0x01, 0x12, 0x08, - 0x0a, 0x04, 0x54, 0x65, 0x6b, 0x75, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x4c, 0x69, 0x67, 0x68, - 0x74, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x10, 0x03, 0x2a, 0x29, 0x0a, 0x04, 0x46, 0x6f, 0x72, 0x6b, - 0x12, 0x0a, 0x0a, 0x06, 0x50, 0x68, 0x61, 0x73, 0x65, 0x30, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, - 0x41, 0x6c, 0x74, 0x61, 0x69, 0x72, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x4d, 0x65, 0x72, 0x67, - 0x65, 0x10, 0x02, 0x32, 0xe1, 0x02, 0x0a, 0x0a, 0x45, 0x32, 0x45, 0x53, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x12, 0x4a, 0x0a, 0x0d, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x43, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x12, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x70, 0x6f, - 0x73, 0x69, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, - 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, - 0x0a, 0x0b, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x19, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x4c, 0x69, 0x73, - 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0a, 0x4e, 0x6f, 0x64, 0x65, 0x44, 0x65, 0x70, 0x6c, - 0x6f, 0x79, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x44, - 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x4e, 0x6f, 0x64, 0x65, 0x4c, - 0x69, 0x73, 0x74, 0x12, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, - 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0a, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x53, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x18, 0x5a, 0x16, 0x2f, 0x69, 0x6e, 0x74, 0x65, - 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x21, 0x0a, 0x05, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x0b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x6e, 0x6f, + 0x64, 0x65, 0x73, 0x22, 0x27, 0x0a, 0x11, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x35, 0x0a, 0x12, + 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x6e, + 0x6f, 0x64, 0x65, 0x22, 0xbe, 0x02, 0x0a, 0x04, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x12, 0x23, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, + 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x29, 0x0a, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x11, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, + 0x64, 0x65, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, + 0x12, 0x2f, 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x2e, 0x4c, 0x61, + 0x62, 0x65, 0x6c, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, + 0x73, 0x12, 0x2c, 0x0a, 0x05, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x2e, 0x50, 0x6f, + 0x72, 0x74, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x1a, + 0x39, 0x0a, 0x0b, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, + 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, + 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x38, 0x0a, 0x0a, 0x50, 0x6f, + 0x72, 0x74, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x3a, 0x02, 0x38, 0x01, 0x22, 0x3f, 0x0a, 0x0b, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, + 0x74, 0x75, 0x62, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x69, 0x76, 0x4b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x69, 0x76, 0x4b, 0x65, 0x79, 0x12, 0x16, 0x0a, + 0x06, 0x70, 0x75, 0x62, 0x4b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, + 0x75, 0x62, 0x4b, 0x65, 0x79, 0x22, 0x7b, 0x0a, 0x0b, 0x54, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x65, + 0x53, 0x74, 0x75, 0x62, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x2e, 0x0a, 0x08, 0x61, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x75, 0x62, + 0x52, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, + 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, + 0x74, 0x68, 0x2a, 0x42, 0x0a, 0x08, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0d, + 0x0a, 0x09, 0x4f, 0x74, 0x68, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x10, 0x00, 0x12, 0x0a, 0x0a, + 0x06, 0x42, 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x56, 0x61, 0x6c, + 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x42, 0x6f, 0x6f, 0x74, + 0x6e, 0x6f, 0x64, 0x65, 0x10, 0x03, 0x2a, 0x42, 0x0a, 0x0a, 0x4e, 0x6f, 0x64, 0x65, 0x43, 0x6c, + 0x69, 0x65, 0x6e, 0x74, 0x12, 0x0f, 0x0a, 0x0b, 0x4f, 0x74, 0x68, 0x65, 0x72, 0x43, 0x6c, 0x69, + 0x65, 0x6e, 0x74, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x50, 0x72, 0x79, 0x73, 0x6d, 0x10, 0x01, + 0x12, 0x08, 0x0a, 0x04, 0x54, 0x65, 0x6b, 0x75, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x4c, 0x69, + 0x67, 0x68, 0x74, 0x68, 0x6f, 0x75, 0x73, 0x65, 0x10, 0x03, 0x2a, 0x29, 0x0a, 0x04, 0x46, 0x6f, + 0x72, 0x6b, 0x12, 0x0a, 0x0a, 0x06, 0x50, 0x68, 0x61, 0x73, 0x65, 0x30, 0x10, 0x00, 0x12, 0x0a, + 0x0a, 0x06, 0x41, 0x6c, 0x74, 0x61, 0x69, 0x72, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x4d, 0x65, + 0x72, 0x67, 0x65, 0x10, 0x02, 0x32, 0xe1, 0x02, 0x0a, 0x0a, 0x45, 0x32, 0x45, 0x53, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x12, 0x4a, 0x0a, 0x0d, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, + 0x70, 0x6f, 0x73, 0x69, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x70, 0x6f, 0x73, + 0x69, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x44, 0x0a, 0x0b, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x12, + 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x4c, + 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0a, 0x4e, 0x6f, 0x64, 0x65, 0x44, 0x65, + 0x70, 0x6c, 0x6f, 0x79, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, + 0x65, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x44, 0x65, 0x70, 0x6c, 0x6f, + 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x4e, 0x6f, 0x64, + 0x65, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, + 0x64, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0a, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, + 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x18, 0x5a, 0x16, 0x2f, 0x69, 0x6e, + 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1193,7 +1193,7 @@ var file_internal_server_proto_service_proto_depIdxs = []int32{ 16, // 3: proto.NodeDeployRequest.beacon:type_name -> proto.NodeDeployRequest.Beacon 17, // 4: proto.NodeDeployRequest.validator:type_name -> proto.NodeDeployRequest.Validator 13, // 5: proto.NodeDeployResponse.nodes:type_name -> proto.Node - 13, // 6: proto.NodeListResponse.node:type_name -> proto.Node + 13, // 6: proto.NodeListResponse.nodes:type_name -> proto.Node 13, // 7: proto.NodeStatusResponse.node:type_name -> proto.Node 0, // 8: proto.Node.type:type_name -> proto.NodeType 1, // 9: proto.Node.client:type_name -> proto.NodeClient diff --git a/internal/server/proto/service.proto b/internal/server/proto/service.proto index d0f6b79..7737e33 100644 --- a/internal/server/proto/service.proto +++ b/internal/server/proto/service.proto @@ -58,7 +58,7 @@ message NodeListRequest { } message NodeListResponse { - repeated Node node = 1; + repeated Node nodes = 1; } message NodeStatusRequest { diff --git a/internal/server/server.go b/internal/server/server.go index c395d89..58acde8 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -537,14 +537,14 @@ func (s *Server) NodeList(ctx context.Context, req *proto.NodeListRequest) (*pro defer s.lock.Unlock() resp := &proto.NodeListResponse{ - Node: []*proto.Node{}, + Nodes: []*proto.Node{}, } for _, n := range s.nodes { stub, err := specNodeToNode(n) if err != nil { return nil, err } - resp.Node = append(resp.Node, stub) + resp.Nodes = append(resp.Nodes, stub) } return resp, nil }