Skip to content

Commit

Permalink
Show builder pubkey on index page (ethereum#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruteri authored and avalonche committed Feb 6, 2023
1 parent b875142 commit bcca78c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
24 changes: 19 additions & 5 deletions builder/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Backend struct {
builderSecretKey *bls.SecretKey
builderPublicKey boostTypes.PublicKey
serializedBuilderPoolPubkey hexutil.Bytes
fd ForkData
builderSigningDomain boostTypes.Domain
proposerSigningDomain boostTypes.Domain
enableBeaconChecks bool
Expand All @@ -56,7 +57,13 @@ type Backend struct {
indexTemplate *template.Template
}

func NewBackend(sk *bls.SecretKey, bc IBeaconClient, builderSigningDomain boostTypes.Domain, proposerSigningDomain boostTypes.Domain, enableBeaconChecks bool) *Backend {
type ForkData struct {
GenesisForkVersion string
BellatrixForkVersion string
GenesisValidatorsRoot string
}

func NewBackend(sk *bls.SecretKey, bc IBeaconClient, fd ForkData, builderSigningDomain boostTypes.Domain, proposerSigningDomain boostTypes.Domain, enableBeaconChecks bool) *Backend {
pkBytes := bls.PublicKeyFromSecretKey(sk).Compress()
pk := boostTypes.PublicKey{}
pk.FromSlice(pkBytes)
Expand All @@ -77,6 +84,7 @@ func NewBackend(sk *bls.SecretKey, bc IBeaconClient, builderSigningDomain boostT
builderPublicKey: pk,
serializedBuilderPoolPubkey: pkBytes,

fd: fd,
builderSigningDomain: builderSigningDomain,
proposerSigningDomain: proposerSigningDomain,
enableBeaconChecks: enableBeaconChecks,
Expand Down Expand Up @@ -107,10 +115,16 @@ func (b *Backend) handleIndex(w http.ResponseWriter, req *http.Request) {
}

statusData := struct {
NoValidators int
Header string
Blocks string
}{noValidators, string(headerData), string(payloadData)}
Pubkey string
NoValidators int
GenesisForkVersion string
BellatrixForkVersion string
GenesisValidatorsRoot string
BuilderSigningDomain string
ProposerSigningDomain string
Header string
Blocks string
}{hexutil.Encode(b.serializedBuilderPoolPubkey), noValidators, b.fd.GenesisForkVersion, b.fd.BellatrixForkVersion, b.fd.GenesisValidatorsRoot, hexutil.Encode(b.builderSigningDomain[:]), hexutil.Encode(b.proposerSigningDomain[:]), string(headerData), string(payloadData)}

if err := b.indexTemplate.Execute(w, statusData); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down
7 changes: 6 additions & 1 deletion builder/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func newTestBackend(t *testing.T) (*Backend, *ValidatorPrivateData) {
bDomain := boostTypes.ComputeDomain(boostTypes.DomainTypeAppBuilder, [4]byte{0x02, 0x0, 0x0, 0x0}, boostTypes.Hash{})
genesisValidatorsRoot := boostTypes.Hash(common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"))
cDomain := boostTypes.ComputeDomain(boostTypes.DomainTypeBeaconProposer, [4]byte{0x02, 0x0, 0x0, 0x0}, genesisValidatorsRoot)
backend := NewBackend(sk, &testBeaconClient{validator}, bDomain, cDomain, true)
backend := NewBackend(sk, &testBeaconClient{validator}, ForkData{}, bDomain, cDomain, true)
// service := NewService("127.0.0.1:31545", backend)

return backend, validator
Expand Down Expand Up @@ -231,3 +231,8 @@ func TestGetPayload(t *testing.T) {
require.NoError(t, err)
require.Equal(t, bid.Data.Message.Header.BlockHash, getPayloadResponse.Data.BlockHash)
}

func TestXxx(t *testing.T) {
sk, _ := bls.GenerateRandomSecretKey()
fmt.Println(hexutil.Encode(sk.Serialize()))
}
16 changes: 16 additions & 0 deletions builder/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ func parseIndexTemplate() (*template.Template, error) {
<h1>
Boost Block Builder
</h1>
<h2>
Pubkey {{ .Pubkey }}
</h2>
<p>
<ul>
<li>Genesis fork version {{ .GenesisForkVersion }}</li>
<li>Bellatrix fork version {{ .BellatrixForkVersion }}</li>
<li>Genesis validators root {{ .GenesisValidatorsRoot }}</li>
</ul>
</p>
<p>
<ul>
<li>Builder signing domain {{ .BuilderSigningDomain }}</li>
<li>Proposer signing domain {{ .ProposerSigningDomain }}</li>
</ul>
</p>
<p>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion builder/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func Register(stack *node.Node, backend *eth.Ethereum, cfg *BuilderConfig) error
var beaconClient IBeaconClient
beaconClient = NewBeaconClient(cfg.BeaconEndpoint)

builderBackend := NewBackend(sk, beaconClient, builderSigningDomain, proposerSigningDomain, cfg.EnableValidatorChecks)
builderBackend := NewBackend(sk, beaconClient, ForkData{cfg.GenesisForkVersion, cfg.BellatrixForkVersion, cfg.GenesisValidatorsRoot}, builderSigningDomain, proposerSigningDomain, cfg.EnableValidatorChecks)
builderService := NewService(cfg.ListenAddr, builderBackend)
builderService.Start()

Expand Down

0 comments on commit bcca78c

Please sign in to comment.