Skip to content

Commit

Permalink
Merge branch 'main' into simplify-light-samples
Browse files Browse the repository at this point in the history
# Conflicts:
#	share/availability/light/availability.go
  • Loading branch information
walldiss committed Oct 30, 2024
2 parents c81592b + 7a70dd5 commit 8874842
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 172 deletions.
34 changes: 1 addition & 33 deletions .github/workflows/ci_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ on:
pull_request:
workflow_dispatch:
inputs:
version-bump:
# Friendly description to be shown in the UI instead of 'name'
description: "Semver type of new version (major / minor / patch)"
# Input has to be provided for the workflow to run
required: true
type: choice
options:
- patch
- minor
- major
tag-as:
description: 'Tag for snapshot release (optional)'
required: false
Expand Down Expand Up @@ -88,31 +78,9 @@ jobs:
with:
go-version: ${{ needs.setup.outputs.go-version }}

# If this was a workflow dispatch event, we need to generate and push a tag
# for goreleaser to grab
version_bump:
needs: [hadolint, yamllint, markdown-lint, go-ci, setup]
runs-on: ubuntu-latest
permissions: "write-all"
steps:
- uses: actions/checkout@v4

- name: Bump version and push tag
# Placing the if condition here is a workaround for needing to block
# on this step during workflow dispatch events but the step not
# needing to run on tags. If we had the if condition on the full
# version_bump section, it would skip and not run, which would result
# in goreleaser not running either.
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: ${{ inputs.version-bump }}
release_branches: ${{ needs.setup.outputs.branch }}

# Generate the release with goreleaser to include pre-built binaries
goreleaser:
needs: [version_bump, setup]
needs: [setup]
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
Expand Down
5 changes: 1 addition & 4 deletions api/gateway/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ const (

const addrKey = "address"

var (
ErrInvalidAddressFormat = errors.New("address must be a valid account or validator address")
ErrMissingAddress = errors.New("address not specified")
)
var ErrInvalidAddressFormat = errors.New("address must be a valid account or validator address")

func (h *Handler) handleBalanceRequest(w http.ResponseWriter, r *http.Request) {
var (
Expand Down
24 changes: 13 additions & 11 deletions das/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,20 @@ func (w *worker) sample(ctx context.Context, timeout time.Duration, height uint6

w.metrics.observeSample(ctx, h, time.Since(start), w.state.jobType, err)
if err != nil {
if !errors.Is(err, context.Canceled) {
log.Debugw(
"failed to sample header",
"type", w.state.jobType,
"height", h.Height(),
"hash", h.Hash(),
"square width", len(h.DAH.RowRoots),
"data root", h.DAH.String(),
"err", err,
"finished (s)", time.Since(start),
)
if errors.Is(err, context.Canceled) {
return err
}

log.Errorw(
"failed to sample header",
"type", w.state.jobType,
"height", h.Height(),
"hash", h.Hash(),
"square width", len(h.DAH.RowRoots),
"data root", h.DAH.String(),
"err", err,
"finished (s)", time.Since(start),
)
return err
}

Expand Down
31 changes: 0 additions & 31 deletions header/serde.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,6 @@ func UnmarshalExtendedHeader(data []byte) (*ExtendedHeader, error) {
return out, nil
}

func ExtendedHeaderToProto(eh *ExtendedHeader) (*header_pb.ExtendedHeader, error) {
pb := &header_pb.ExtendedHeader{
Header: eh.RawHeader.ToProto(),
Commit: eh.Commit.ToProto(),
}
valSet, err := eh.ValidatorSet.ToProto()
if err != nil {
return nil, err
}
pb.ValidatorSet = valSet
dah, err := eh.DAH.ToProto()
if err != nil {
return nil, err
}
pb.Dah = dah
return pb, nil
}

func ProtoToExtendedHeader(pb *header_pb.ExtendedHeader) (*ExtendedHeader, error) {
bin, err := pb.Marshal()
if err != nil {
return nil, err
}
header := new(ExtendedHeader)
err = header.UnmarshalBinary(bin)
if err != nil {
return nil, err
}
return header, nil
}

// msgID computes an id for a pubsub message
// TODO(@Wondertan): This cause additional allocations per each recvd message in the topic
//
Expand Down
4 changes: 0 additions & 4 deletions share/availability/light/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header

// if any of the samples failed, return an error
if len(failedSamples) > 0 {
log.Errorw("availability validation failed",
"height", header.Height(),
"failed_samples", failedSamples,
)
return share.ErrNotAvailable
}
return nil
Expand Down
4 changes: 0 additions & 4 deletions share/eds/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package eds

import (
"context"
"errors"
"fmt"
"sync/atomic"

Expand All @@ -14,9 +13,6 @@ import (

var _ Accessor = validation{}

// ErrOutOfBounds is returned whenever an index is out of bounds.
var ErrOutOfBounds = errors.New("index is out of bounds")

// validation is a Accessor implementation that performs sanity checks on methods. It wraps
// another Accessor and performs bounds checks on index arguments.
type validation struct {
Expand Down
12 changes: 0 additions & 12 deletions share/empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,11 @@ func EmptyEDS() *rsmt2d.ExtendedDataSquare {
return emptyBlockEDS
}

// EmptyBlockShares returns the shares of the empty block.
func EmptyBlockShares() []libshare.Share {
initEmpty()
return emptyBlockShares
}

var (
emptyOnce sync.Once
emptyBlockDataHash DataHash
emptyBlockRoots *AxisRoots
emptyBlockEDS *rsmt2d.ExtendedDataSquare
emptyBlockShares []libshare.Share
)

// initEmpty enables lazy initialization for constant empty block data.
Expand Down Expand Up @@ -68,11 +61,6 @@ func computeEmpty() {
"expected %s, got %s", minDAH.String(), emptyBlockRoots.String()))
}

sh := eds.FlattenedODS()
emptyBlockShares, err = libshare.FromBytes(sh)
if err != nil {
panic(fmt.Errorf("failed to create shares: %w", err))
}
// precompute Hash, so it's cached internally to avoid potential races
emptyBlockDataHash = emptyBlockRoots.Hash()
}
11 changes: 0 additions & 11 deletions share/ipld/nmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"hash"
"math/rand"

"github.com/ipfs/boxo/blockservice"
blocks "github.com/ipfs/go-block-format"
Expand Down Expand Up @@ -155,16 +154,6 @@ func MustCidFromNamespacedSha256(hash []byte) cid.Cid {
return cidFromHash
}

// Translate transforms square coordinates into IPLD NMT tree path to a leaf node.
// It also adds randomization to evenly spread fetching from Rows and Columns.
func Translate(roots *share.AxisRoots, row, col int) (cid.Cid, int) {
if rand.Intn(2) == 0 { //nolint:gosec
return MustCidFromNamespacedSha256(roots.ColumnRoots[col]), row
}

return MustCidFromNamespacedSha256(roots.RowRoots[row]), col
}

// NamespacedSha256FromCID derives the Namespaced hash from the given CID.
func NamespacedSha256FromCID(cid cid.Cid) []byte {
return cid.Hash()[cidPrefixSize:]
Expand Down
18 changes: 0 additions & 18 deletions share/ipld/test_helpers.go

This file was deleted.

26 changes: 0 additions & 26 deletions share/ipld/utils.go

This file was deleted.

14 changes: 0 additions & 14 deletions share/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package share
import (
"bytes"
"crypto/sha256"
"encoding/hex"
"fmt"
"hash"

Expand Down Expand Up @@ -80,19 +79,6 @@ func RootHashForCoordinates(r *AxisRoots, axisType rsmt2d.Axis, rowIdx, colIdx u
return r.ColumnRoots[colIdx]
}

// MustDataHashFromString converts a hex string to a valid datahash.
func MustDataHashFromString(datahash string) DataHash {
dh, err := hex.DecodeString(datahash)
if err != nil {
panic(fmt.Sprintf("datahash conversion: passed string was not valid hex: %s", datahash))
}
err = DataHash(dh).Validate()
if err != nil {
panic(fmt.Sprintf("datahash validation: passed hex string failed: %s", err))
}
return dh
}

// IsOutsideRange checks if the namespace is outside the min-max range of the given hashes.
func IsOutsideRange(namespace libshare.Namespace, leftHash, rightHash []byte) (bool, error) {
if len(leftHash) < libshare.NamespaceSize {
Expand Down
8 changes: 6 additions & 2 deletions share/shwap/p2p/shrex/shrexeds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ type Server struct {

store *store.Store

params *Parameters
params *Parameters
// TODO: decouple middleware metrics from shrex and remove middleware from Server
middleware *shrex.Middleware
metrics *shrex.Metrics
}
Expand All @@ -55,7 +56,10 @@ func (s *Server) Start(context.Context) error {
ctx, cancel := context.WithCancel(context.Background())
s.cancel = cancel

s.host.SetStreamHandler(s.protocolID, s.middleware.RateLimitHandler(s.streamHandler(ctx)))
handler := s.streamHandler(ctx)
withRateLimit := s.middleware.RateLimitHandler(handler)
withRecovery := shrex.RecoveryMiddleware(withRateLimit)
s.host.SetStreamHandler(s.protocolID, withRecovery)
return nil
}

Expand Down
8 changes: 6 additions & 2 deletions share/shwap/p2p/shrex/shrexnd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type Server struct {
handler network.StreamHandler
store *store.Store

params *Parameters
params *Parameters
// TODO: decouple middleware metrics from shrex and remove middleware from Server
middleware *shrex.Middleware
metrics *shrex.Metrics
}
Expand All @@ -54,7 +55,10 @@ func NewServer(params *Parameters, host host.Host, store *store.Store) (*Server,
ctx, cancel := context.WithCancel(context.Background())
srv.cancel = cancel

srv.handler = srv.middleware.RateLimitHandler(srv.streamHandler(ctx))
handler := srv.streamHandler(ctx)
withRateLimit := srv.middleware.RateLimitHandler(handler)
withRecovery := shrex.RecoveryMiddleware(withRateLimit)
srv.handler = withRecovery
return srv, nil
}

Expand Down

0 comments on commit 8874842

Please sign in to comment.