// Copyright © 2020 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 null import ( "context" "encoding/json" api "github.com/attestantio/go-eth2-client/api/v1" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/pkg/errors" "github.com/rs/zerolog" zerologger "github.com/rs/zerolog/log" ) // Service is the submitter for signed items. type Service struct{} // module-wide log. var log zerolog.Logger // New creates a new submitter. func New(ctx context.Context, params ...Parameter) (*Service, error) { parameters, err := parseAndCheckParameters(params...) if err != nil { return nil, errors.Wrap(err, "problem with parameters") } // Set logging. log = zerologger.With().Str("service", "submitter").Str("impl", "null").Logger() if parameters.logLevel != log.GetLevel() { log = log.Level(parameters.logLevel) } s := &Service{} return s, nil } // SubmitBeaconBlock submits a block. func (s *Service) SubmitBeaconBlock(ctx context.Context, block *phase0.SignedBeaconBlock) error { if block == nil { return errors.New("no beacon block supplied") } if e := log.Trace(); e.Enabled() { data, err := json.Marshal(block) if err == nil { e.Str("block", string(data)).Msg("Not submitting beacon block") } } return nil } // SubmitAttestations submits multiple attestations. func (s *Service) SubmitAttestations(ctx context.Context, attestations []*phase0.Attestation) error { if len(attestations) == 0 { return errors.New("no attestations supplied") } if e := log.Trace(); e.Enabled() { data, err := json.Marshal(attestations) if err == nil { e.Str("attestations", string(data)).Msg("Not submitting attestations") } } return nil } // SubmitBeaconCommitteeSubscriptions submits a batch of beacon committee subscriptions. func (s *Service) SubmitBeaconCommitteeSubscriptions(ctx context.Context, subscriptions []*api.BeaconCommitteeSubscription) error { if subscriptions == nil { return errors.New("no subscriptions supplied") } if e := log.Trace(); e.Enabled() { // Summary counts. aggregating := 0 for i := range subscriptions { if subscriptions[i].IsAggregator { aggregating++ } } data, err := json.Marshal(subscriptions) if err == nil { e.Str("subscriptions", string(data)).Int("subscribing", len(subscriptions)).Int("aggregating", aggregating).Msg("Not submitting subscriptions") } } return nil } // SubmitAggregateAttestations submits aggregate attestations. func (s *Service) SubmitAggregateAttestations(ctx context.Context, aggregates []*phase0.SignedAggregateAndProof) error { if len(aggregates) == 0 { return errors.New("no aggregate attestations supplied") } if e := log.Trace(); e.Enabled() { data, err := json.Marshal(aggregates) if err == nil { e.Str("attestation", string(data)).Msg("Not submitting aggregate attestations") } } return nil }