Skip to content

Commit

Permalink
Merge pull request #116 from attestantio/v3-proposals
Browse files Browse the repository at this point in the history
Unified proposals using v3.
  • Loading branch information
mcdee authored Mar 19, 2024
2 parents aee7c4b + cd0eaf4 commit 605f842
Show file tree
Hide file tree
Showing 15 changed files with 906 additions and 555 deletions.
8 changes: 6 additions & 2 deletions api/proposalopts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Attestant Limited.
// Copyright © 2023, 2024 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -23,9 +23,13 @@ type ProposalOpts struct {
Slot phase0.Slot
// RandaoReveal is the RANDAO reveal for the proposal.
RandaoReveal phase0.BLSSignature
// Graffit is the graffiti to be included in the beacon block body.
// Graffiti is the graffiti to be included in the beacon block body.
Graffiti [32]byte
// SkipRandaoVerification is true if we do not want the server to verify our RANDAO reveal.
// If this is set then the RANDAO reveal should be passed as the point at infinity (0xc0…00)
SkipRandaoVerification bool
// BuilderBoostFactor is the relative weight of the builder payload versus a locally-produced
// payload, as per https://ethereum.github.io/beacon-APIs/#/Validator/produceBlockV3
// This is optional; if not supplied it will use the default value of 100.
BuilderBoostFactor *uint64
}
27 changes: 27 additions & 0 deletions api/submitblindedproposalopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright © 2024 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package api

import v2 "github.com/attestantio/go-eth2-client/api/v2"

// SubmitBlindedProposalOpts are the options for submitting proposals.
type SubmitBlindedProposalOpts struct {
Common CommonOpts

// Proposal is the proposal to submit.
Proposal *VersionedSignedBlindedProposal

// BroadcastValidation is the validation required of the consensus node before broadcasting the proposal.
BroadcastValidation *v2.BroadcastValidation
}
27 changes: 27 additions & 0 deletions api/submitproposalopts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright © 2024 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package api

import v2 "github.com/attestantio/go-eth2-client/api/v2"

// SubmitProposalOpts are the options for submitting proposals.
type SubmitProposalOpts struct {
Common CommonOpts

// Proposal is the proposal to submit.
Proposal *VersionedSignedProposal

// BroadcastValidation is the validation required of the consensus node before broadcasting the proposal.
BroadcastValidation *v2.BroadcastValidation
}
67 changes: 67 additions & 0 deletions api/v2/broadcastvalidation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright © 2024 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v2

import (
"fmt"
"strings"
)

// BroadcastValidation defines the validation to carry out prior to broadcasting proposals.
type BroadcastValidation int

const (
// BroadcastValidationGossip means carry out lightweight gossip checks.
BroadcastValidationGossip BroadcastValidation = iota
// BroadcastValidationConsensus means carry out full consensus checks.
BroadcastValidationConsensus
// BroadcastValidationConsensusAndEquivocation means carry out consensus and equivocation checks.
BroadcastValidationConsensusAndEquivocation
)

var broadcastValidationStrings = [...]string{
"gossip",
"consensus",
"consensus_and_equivocation",
}

// MarshalJSON implements json.Marshaler.
func (b *BroadcastValidation) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("%q", broadcastValidationStrings[*b])), nil
}

// UnmarshalJSON implements json.Unmarshaler.
func (b *BroadcastValidation) UnmarshalJSON(input []byte) error {
var err error
switch strings.ToLower(string(input)) {
case `"gossip"`:
*b = BroadcastValidationGossip
case `"consensus"`:
*b = BroadcastValidationConsensus
case `"consensus_and_equivocation"`:
*b = BroadcastValidationConsensusAndEquivocation
default:
err = fmt.Errorf("unrecognised broadcast validation %s", string(input))
}

return err
}

func (b BroadcastValidation) String() string {
if b < 0 || int(b) >= len(broadcastValidationStrings) {
return broadcastValidationStrings[0] // unknown
}

return broadcastValidationStrings[b]
}
Loading

0 comments on commit 605f842

Please sign in to comment.