Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Jan 31, 2025
2 parents c83f59a + 87bc6c8 commit 8416d1d
Show file tree
Hide file tree
Showing 57 changed files with 1,503 additions and 666 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
run: make test-integration SHORT=true TAGS=sync

pruning_tests:
name: Integration Tests Sync
name: Integration Tests Pruning
runs-on: ubuntu-latest

steps:
Expand All @@ -143,3 +143,18 @@ jobs:

- name: run sync tests
run: make test-integration SHORT=true TAGS=pruning

share_tests:
name: Integration Tests Share
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: set up go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}

- name: run share tests
run: make test-integration SHORT=true TAGS=share
16 changes: 16 additions & 0 deletions blob/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package blob
import (
"sort"

"github.com/celestiaorg/go-square/merkle"
"github.com/celestiaorg/go-square/v2/inclusion"
libshare "github.com/celestiaorg/go-square/v2/share"
)

Expand Down Expand Up @@ -32,6 +34,20 @@ func ToLibBlobs(blobs ...*Blob) []*libshare.Blob {
return libBlobs
}

// ToNodeBlobs converts libshare blob type to the node's specific blob type.
func ToNodeBlobs(blobs ...*libshare.Blob) ([]*Blob, error) {
nodeBlobs := make([]*Blob, len(blobs))
hashFromByteSlices := merkle.HashFromByteSlices
for i, blob := range blobs {
com, err := inclusion.CreateCommitment(blob, hashFromByteSlices, subtreeRootThreshold)
if err != nil {
return nil, err
}
nodeBlobs[i] = &Blob{Blob: blob, Commitment: com, index: -1}
}
return nodeBlobs, nil
}

func calculateIndex(rowLength, blobIndex int) (row, col int) {
row = blobIndex / rowLength
col = blobIndex - (row * rowLength)
Expand Down
26 changes: 0 additions & 26 deletions core/client.go

This file was deleted.

4 changes: 2 additions & 2 deletions core/eds.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
// extendBlock extends the given block data, returning the resulting
// ExtendedDataSquare (EDS). If there are no transactions in the block,
// nil is returned in place of the eds.
func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) {
if app.IsEmptyBlockRef(&data, appVersion) {
func extendBlock(data *types.Data, appVersion uint64, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) {
if app.IsEmptyBlockRef(data, appVersion) {
return share.EmptyEDS(), nil
}

Expand Down
4 changes: 2 additions & 2 deletions core/eds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestTrulyEmptySquare(t *testing.T) {
SquareSize: 1,
}

eds, err := extendBlock(data, appconsts.LatestVersion)
eds, err := extendBlock(&data, appconsts.LatestVersion)
require.NoError(t, err)
require.True(t, eds.Equals(share.EmptyEDS()))
}
Expand All @@ -38,7 +38,7 @@ func TestEmptySquareWithZeroTxs(t *testing.T) {
Txs: []types.Tx{},
}

eds, err := extendBlock(data, appconsts.LatestVersion)
eds, err := extendBlock(&data, appconsts.LatestVersion)
require.NoError(t, err)
require.True(t, eds.Equals(share.EmptyEDS()))

Expand Down
25 changes: 8 additions & 17 deletions core/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"time"

"github.com/tendermint/tendermint/types"
"golang.org/x/sync/errgroup"

libhead "github.com/celestiaorg/go-header"
Expand Down Expand Up @@ -62,8 +61,7 @@ func NewExchange(

func (ce *Exchange) GetByHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, error) {
log.Debugw("requesting header", "height", height)
intHeight := int64(height)
return ce.getExtendedHeaderByHeight(ctx, &intHeight)
return ce.getExtendedHeaderByHeight(ctx, int64(height))
}

func (ce *Exchange) GetRangeByHeight(
Expand Down Expand Up @@ -129,12 +127,12 @@ func (ce *Exchange) Get(ctx context.Context, hash libhead.Hash) (*header.Extende
return nil, fmt.Errorf("fetching block by hash %s: %w", hash.String(), err)
}

comm, vals, err := ce.fetcher.GetBlockInfo(ctx, &block.Height)
comm, vals, err := ce.fetcher.GetBlockInfo(ctx, block.Height)
if err != nil {
return nil, fmt.Errorf("fetching block info for height %d: %w", &block.Height, err)
}

eds, err := extendBlock(block.Data, block.Header.Version.App)
eds, err := extendBlock(&block.Data, block.Header.Version.App)
if err != nil {
return nil, fmt.Errorf("extending block data for height %d: %w", &block.Height, err)
}
Expand Down Expand Up @@ -162,29 +160,22 @@ func (ce *Exchange) Head(
_ ...libhead.HeadOption[*header.ExtendedHeader],
) (*header.ExtendedHeader, error) {
log.Debug("requesting head")
return ce.getExtendedHeaderByHeight(ctx, nil)
return ce.getExtendedHeaderByHeight(ctx, 0)
}

func (ce *Exchange) getExtendedHeaderByHeight(ctx context.Context, height *int64) (*header.ExtendedHeader, error) {
func (ce *Exchange) getExtendedHeaderByHeight(ctx context.Context, height int64) (*header.ExtendedHeader, error) {
b, err := ce.fetcher.GetSignedBlock(ctx, height)
if err != nil {
if height == nil {
return nil, fmt.Errorf("fetching signed block for head from core: %w", err)
}
return nil, fmt.Errorf("fetching signed block at height %d from core: %w", *height, err)
return nil, fmt.Errorf("fetching signed block at height %d from core: %w", height, err)
}
log.Debugw("fetched signed block from core", "height", b.Header.Height)

eds, err := extendBlock(b.Data, b.Header.Version.App)
if err != nil {
return nil, fmt.Errorf("extending block data for height %d: %w", b.Header.Height, err)
}

// TODO(@Wondertan): This is a hack to deref Data, allowing GC to pick it up.
// The better footgun-less solution is to change core.ResultSignedBlock fields to be pointers instead of values.
b.Data = types.Data{}

eh, err := ce.construct(&b.Header, &b.Commit, &b.ValidatorSet, eds)
// create extended header
eh, err := ce.construct(b.Header, b.Commit, b.ValidatorSet, eds)
if err != nil {
panic(fmt.Errorf("constructing extended header for height %d: %w", b.Header.Height, err))
}
Expand Down
24 changes: 18 additions & 6 deletions core/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"bytes"
"context"
"net"
"testing"
"time"

Expand Down Expand Up @@ -34,7 +35,7 @@ func TestCoreExchange_RequestHeaders(t *testing.T) {

// initialize store with genesis block
genHeight := int64(1)
genBlock, err := fetcher.GetBlock(ctx, &genHeight)
genBlock, err := fetcher.GetBlock(ctx, genHeight)
require.NoError(t, err)
genHeader, err := ce.Get(ctx, genBlock.Header.Hash().Bytes())
require.NoError(t, err)
Expand All @@ -61,6 +62,7 @@ func TestCoreExchange_RequestHeaders(t *testing.T) {
require.NoError(t, err)
assert.True(t, has)
}
require.NoError(t, fetcher.Stop(ctx))
}

// TestExchange_DoNotStoreHistoric tests that the CoreExchange will not
Expand All @@ -87,7 +89,7 @@ func TestExchange_DoNotStoreHistoric(t *testing.T) {

// initialize store with genesis block
genHeight := int64(1)
genBlock, err := fetcher.GetBlock(ctx, &genHeight)
genBlock, err := fetcher.GetBlock(ctx, genHeight)
require.NoError(t, err)
genHeader, err := ce.Get(ctx, genBlock.Header.Hash().Bytes())
require.NoError(t, err)
Expand Down Expand Up @@ -136,15 +138,15 @@ func TestExchange_StoreHistoricIfArchival(t *testing.T) {

// initialize store with genesis block
genHeight := int64(1)
genBlock, err := fetcher.GetBlock(ctx, &genHeight)
genBlock, err := fetcher.GetBlock(ctx, genHeight)
require.NoError(t, err)
genHeader, err := ce.Get(ctx, genBlock.Header.Hash().Bytes())
require.NoError(t, err)

headers, err := ce.GetRangeByHeight(ctx, genHeader, 30)
require.NoError(t, err)

// ensure all "historic" EDSs were stored
// ensure all "historic" EDSs were stored but not the .q4 files
for _, h := range headers {
has, err := store.HasByHeight(ctx, h.Height())
require.NoError(t, err)
Expand All @@ -157,6 +159,11 @@ func TestExchange_StoreHistoricIfArchival(t *testing.T) {
has, err = store.HasByHash(ctx, h.DAH.Hash())
require.NoError(t, err)
assert.True(t, has)

// ensure .q4 file was not stored
has, err = store.HasQ4ByHash(ctx, h.DAH.Hash())
require.NoError(t, err)
assert.False(t, has)
}
}

Expand All @@ -166,7 +173,12 @@ func createCoreFetcher(t *testing.T, cfg *testnode.Config) (*BlockFetcher, testn
// flakiness with accessing account state)
_, err := cctx.WaitForHeightWithTimeout(2, time.Second*2) // TODO @renaynay: configure?
require.NoError(t, err)
return NewBlockFetcher(cctx.Client), cctx
host, port, err := net.SplitHostPort(cctx.GRPCClient.Target())
require.NoError(t, err)
client := newTestClient(t, host, port)
fetcher, err := NewBlockFetcher(client)
require.NoError(t, err)
return fetcher, cctx
}

// fillBlocks fills blocks until the context is canceled.
Expand Down Expand Up @@ -202,7 +214,7 @@ func generateNonEmptyBlocks(
sub, err := fetcher.SubscribeNewBlockEvent(ctx)
require.NoError(t, err)
defer func() {
err = fetcher.UnsubscribeNewBlockEvent(ctx)
err = fetcher.Stop(ctx)
require.NoError(t, err)
}()

Expand Down
Loading

0 comments on commit 8416d1d

Please sign in to comment.