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 @@ package types

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
}

return sh, true
}

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