Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,19 +849,13 @@ func (m *Manager) execCreateBlock(_ context.Context, height uint64, lastSignatur
return header, blockData, nil
}

type headerContextKey struct{}

// HeaderContextKey is used to store the header in the context.
// This is useful if the execution client needs to access the header during transaction execution.
var HeaderContextKey = headerContextKey{}

func (m *Manager) execApplyBlock(ctx context.Context, lastState types.State, header *types.SignedHeader, data *types.Data) (types.State, error) {
rawTxs := make([][]byte, len(data.Txs))
for i := range data.Txs {
rawTxs[i] = data.Txs[i]
}

ctx = context.WithValue(ctx, HeaderContextKey, header)
ctx = context.WithValue(ctx, types.SignedHeaderContextKey, header)
newStateRoot, _, err := m.exec.ExecuteTxs(ctx, rawTxs, header.Height(), header.Time(), lastState.AppHash)
if err != nil {
return types.State{}, fmt.Errorf("failed to execute transactions: %w", err)
Expand Down
16 changes: 16 additions & 0 deletions types/signed_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@

import (
"bytes"
"context"
"errors"
"fmt"

"github.com/celestiaorg/go-header"
)

type signedHeaderContextKey struct{}

// SignedHeaderContextKey is used to store the signed header in the context.
// This is useful if the execution client needs to access the signed header during transaction execution.
var SignedHeaderContextKey = signedHeaderContextKey{}

func SignedHeaderFromContext(ctx context.Context) (*SignedHeader, bool) {
sh, ok := ctx.Value(SignedHeaderContextKey).(*SignedHeader)
if !ok {
return nil, false
}

Check warning on line 22 in types/signed_header.go

View check run for this annotation

Codecov / codecov/patch

types/signed_header.go#L18-L22

Added lines #L18 - L22 were not covered by tests

return sh, true

Check warning on line 24 in types/signed_header.go

View check run for this annotation

Codecov / codecov/patch

types/signed_header.go#L24

Added line #L24 was not covered by tests
}

var (
// ErrLastHeaderHashMismatch is returned when the last header hash doesn't match.
ErrLastHeaderHashMismatch = errors.New("last header hash mismatch")
Expand Down
Loading